Ignore:
Timestamp:
Nov 19, 2012, 2:40:44 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Optiomization using Update blocking during mass operations.
  • Added: Measuring modules start time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ModularSystem/UModularSystem.pas

    r431 r439  
    4343    FFileName: string;
    4444    FWebSite: string;
     45    FStartUpTime: TDateTime;
    4546    procedure SetEnabled(AValue: Boolean);
    4647    procedure SetInstalled(AValue: Boolean);
     
    7475    property Installed: Boolean read FInstalled write SetInstalled;
    7576    property Enabled: Boolean read FEnabled write SetEnabled;
     77    property StartUpTime: TDateTime read FStartUpTime;
    7678  published
    7779    property Identification: string read FIdentification write FIdentification; // Unique system name
     
    110112    FOptions: TModuleManagerOptions;
    111113    procedure SetAPI(AValue: TAPI);
    112     procedure DoUpdate;
     114    procedure DoUpdate(Sender: TObject);
    113115  public
    114116    Modules: TListModule; // TObjectList<TModule>
     
    122124    procedure LoadFromRegistry(Context: TRegistryContext);
    123125    procedure SaveToRegistry(Context: TRegistryContext);
    124     procedure BeginUpdate;
    125     procedure EndUpdate;
    126     procedure Update;
    127126    constructor Create(AOwner: TComponent); override;
    128127    destructor Destroy; override;
     
    154153  A: Integer;
    155154begin
     155  try
     156    BeginUpdate;
    156157  for I := 0 to Count - 1 do
    157158  with TModule(Items[I]) do
     
    169170      if Actions[A] = maUninstall then Uninstall;
    170171      if Actions[A] = maUpgrade then Upgrade;
    171       if Actions[A] = maEnable then Enabled := True;
    172       if Actions[A] = maDisable then Enabled := False;
     172      if Actions[A] = maEnable then Enable;
     173      if Actions[A] = maDisable then Disable;
    173174    end;
     175  finally
     176    EndUpdate;
     177  end;
    174178end;
    175179
     
    196200end;
    197201
    198 procedure TModuleManager.DoUpdate;
     202procedure TModuleManager.DoUpdate(Sender: TObject);
    199203begin
    200204  if Assigned(FOnUpdate) then FOnUpdate(Self);
     
    263267  Module.FManager := Self;
    264268  Module.API := API;
    265   Update;
     269  Modules.Update;
    266270end;
    267271
     
    269273begin
    270274  Modules.Remove(Module);
    271   Update;
     275  Modules.Update;
    272276end;
    273277
     
    277281  Modules := TListModule.Create;
    278282  Modules.OwnsObjects := False;
     283  Modules.OnUpdate := DoUpdate;
    279284end;
    280285
     
    296301    with TModule(Modules[I]) do begin
    297302      OpenKey(Context.Key + '\' + Identification, True);
    298       Enabled := ReadBoolWithDefault('Enable', Enabled);
     303      Installed := ReadBoolWithDefault('Installed', Installed);
     304      Enabled := ReadBoolWithDefault('Enabled', Enabled);
    299305    end;
    300306  finally
     
    313319    with TModule(Modules[I]) do begin
    314320      OpenKey(Context.Key + '\' + Identification, True);
    315       WriteBool('Enable', Enabled);
     321      WriteBool('Enabled', Enabled);
     322      WriteBool('Installed', Installed);
    316323    end;
    317324  finally
    318325    Free;
    319326  end;
    320 end;
    321 
    322 procedure TModuleManager.BeginUpdate;
    323 begin
    324   Inc(FUpdateCount);
    325 end;
    326 
    327 procedure TModuleManager.EndUpdate;
    328 begin
    329   if FUpdateCount > 0 then Dec(FUpdateCount);
    330   if FUpdateCount = 0 then DoUpdate;
    331 end;
    332 
    333 procedure TModuleManager.Update;
    334 begin
    335   if FUpdateCount = 0 then DoUpdate;
    336327end;
    337328
     
    378369    List := TListModule.Create;
    379370    List.OwnsObjects := False;
    380     EnumSuperiorDependenciesCascade(List);
     371    EnumDependenciesCascade(List, [mcNotEnabled]);
    381372    List.Perform([maEnable], [mcNotEnabled]);
    382373  finally
     
    397388    List := TListModule.Create;
    398389    List.OwnsObjects := False;
    399     EnumSuperiorDependenciesCascade(List);
     390    EnumSuperiorDependenciesCascade(List, [mcEnabled]);
    400391    List.Perform([maDisable], [mcEnabled]);
    401392  finally
    402393    List.Free;
    403394  end;
    404   Manager.Update;
     395  Manager.Modules.Update;
    405396end;
    406397
     
    422413begin
    423414  if FEnabled = AValue then Exit;
    424   if FEnabled then Enable else Disable;
     415  if AValue then Enable else Disable;
    425416end;
    426417
     
    428419var
    429420  List: TListModule;
     421  StartTime: TDateTime;
    430422begin
    431423  if not Enabled or Running then Exit;
     
    434426    List := TListModule.Create;
    435427    List.OwnsObjects := False;
    436     EnumDependenciesCascade(List);
     428    EnumDependenciesCascade(List, [mcNotRunning]);
    437429    List.Perform([maStart], [mcNotRunning]);
    438430  finally
    439431    List.Free;
    440432  end;
     433  StartTime := Now;
    441434  DoStart;
     435  FStartUpTime := Now - StartTime;
    442436  FRunning := True;
    443   Manager.Update;
     437  Manager.Modules.Update;
    444438end;
    445439
     
    453447    List := TListModule.Create;
    454448    List.OwnsObjects := False;
    455     EnumSuperiorDependenciesCascade(List);
     449    EnumSuperiorDependenciesCascade(List, [mcRunning]);
    456450    List.Perform([maStop], [mcRunning]);
    457451  finally
     
    459453  end;
    460454  DoStop;
    461   Manager.Update;
     455  Manager.Modules.Update;
    462456end;
    463457
     
    476470    List := TListModule.Create;
    477471    List.OwnsObjects := False;
    478     EnumDependenciesCascade(List);
     472    EnumDependenciesCascade(List, [mcNotInstalled]);
    479473    List.Perform([maInstall], [mcNotInstalled]);
    480474  finally
     
    483477  FInstalled := True;
    484478  DoInstall;
    485   Enable; // Auto enable installed module
    486   Manager.Update;
     479  //Enable; // Auto enable installed module
     480  Manager.Modules.Update;
    487481end;
    488482
     
    496490    List := TListModule.Create;
    497491    List.OwnsObjects := False;
    498     EnumSuperiorDependenciesCascade(List);
     492    EnumSuperiorDependenciesCascade(List, [mcInstalled]);
    499493    List.Perform([maUninstall], [mcInstalled]);
    500494  finally
     
    503497  FInstalled := False;
    504498  DoUninstall;
    505   Manager.Update;
     499  Manager.Modules.Update;
    506500end;
    507501
     
    521515    Start;
    522516  end else DoUpgrade;
    523   Manager.Update;
     517  Manager.Modules.Update;
    524518end;
    525519
     
    541535begin
    542536  FInstalled := Value;
    543   Manager.Update;
     537  Manager.Modules.Update;
    544538end;
    545539
Note: See TracChangeset for help on using the changeset viewer.