Ignore:
Timestamp:
Sep 7, 2012, 8:36:13 PM (12 years ago)
Author:
chronos
Message:
  • Upraveno: Modulární systém přepracován tak, aby podporoval metody Install, Uninstall a Upgrade použitelné pro persistentní data. Původní metody Install a Uninstall přejmenovýny na Start a Stop.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/ModularSystem/UModularSystem.pas

    r89 r91  
    1919  TModule = class(TComponent)
    2020  private
     21    FRunning: Boolean;
    2122    FInstalled: Boolean;
    2223    Manager: TModuleManager;
     
    2930    FDescription: TStringList;
    3031    procedure SetInstalled(AValue: Boolean);
     32    procedure SetRunning(AValue: Boolean);
    3133  public
    3234    API: TAPI;
    3335    MarkForInstall: Boolean;
     36    procedure Start; virtual;
     37    procedure Stop; virtual;
    3438    procedure Install; virtual;
    3539    procedure Uninstall; virtual;
    36     procedure Update; virtual;
     40    procedure Upgrade; virtual;
     41    procedure EnumModulesStart(ModuleList: TStringList);
     42    procedure EnumModulesStop(ModuleList: TStringList);
    3743    procedure EnumModulesInstall(ModuleList: TStringList);
    3844    procedure EnumModulesUninstall(ModuleList: TStringList);
    3945    constructor Create(Owner: TComponent); virtual;
    4046    destructor Destroy; override;
     47    property Running: Boolean read FRunning write SetRunning;
    4148    property Installed: Boolean read FInstalled write SetInstalled;
    4249  published
     
    5966    Modules: TObjectList; // TObjectList<TModule>
    6067    function FindModuleByName(Name: string): TModule;
     68    procedure StartDependencies(ModuleName: string; Dependencies: TStringList);
     69    procedure StopDependencies(ModuleName: string);
     70    procedure EnumModulesStart(Dependencies, ModuleList: TStringList);
     71    procedure EnumModulesStop(ModuleName: string; ModuleList: TStringList);
    6172    procedure InstallDependencies(ModuleName: string; Dependencies: TStringList);
    6273    procedure UninstallDependencies(ModuleName: string);
     
    6576    procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False);
    6677    procedure UnregisterModule(Module: TModule);
     78    procedure StartInstalled;
    6779    procedure InstallMarked;
     80    procedure StopAll;
    6881    procedure UninstallAll;
    6982    constructor Create(AOwner: TComponent); override;
     
    107120end;
    108121
    109 procedure TModuleManager.InstallDependencies(ModuleName: string; Dependencies: TStringList);
     122procedure TModuleManager.StartDependencies(ModuleName: string; Dependencies: TStringList);
     123var
     124  Module: TModule;
     125  I: Integer;
     126begin
     127  for I := 0 to Dependencies.Count - 1 do begin
     128    Module := FindModuleByName(Dependencies[I]);
     129    if Assigned(Module) then begin
     130      if not Module.Running then Module.Start;
     131    end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]);
     132  end;
     133end;
     134
     135procedure TModuleManager.StopDependencies(ModuleName: string);
     136var
     137  I: Integer;
     138begin
     139  for I := 0 to Modules.Count - 1 do
     140  with TModule(Modules[I]) do begin
     141    if (Dependencies.IndexOf(ModuleName) <> - 1) and Running then Stop;
     142  end;
     143end;
     144
     145procedure TModuleManager.EnumModulesStart(Dependencies,
     146  ModuleList: TStringList);
     147var
     148  Module: TModule;
     149  I: Integer;
     150begin
     151  for I := 0 to Dependencies.Count - 1 do begin
     152    Module := FindModuleByName(Dependencies[I]);
     153    if Assigned(Module) then begin
     154      if not Module.Running and (ModuleList.IndexOf(Module.Identification) = -1) then begin
     155        ModuleList.Add(Module.Identification);
     156        EnumModulesStart(Module.Dependencies, ModuleList);
     157      end;
     158    end else raise Exception.CreateFmt(SModuleNotFound, [Module.Identification]);
     159  end;
     160end;
     161
     162procedure TModuleManager.EnumModulesStop(ModuleName: string;
     163  ModuleList: TStringList);
     164var
     165  I: Integer;
     166begin
     167  for I := 0 to Modules.Count - 1 do
     168  with TModule(Modules[I]) do begin
     169    if (Dependencies.IndexOf(ModuleName) <> -1) and Running and
     170      (ModuleList.IndexOf(Identification) = -1) then begin
     171      ModuleList.Add(Identification);
     172      Self.EnumModulesStop(Identification, ModuleList);
     173    end;
     174  end;
     175end;
     176
     177procedure TModuleManager.InstallDependencies(ModuleName: string;
     178  Dependencies: TStringList);
    110179var
    111180  Module: TModule;
     
    176245end;
    177246
     247procedure TModuleManager.StartInstalled;
     248var
     249  I: Integer;
     250begin
     251  for I := 0 to Modules.Count - 1 do
     252  with TModule(Modules[I]) do
     253    if not Running and Installed then Start;
     254end;
     255
    178256procedure TModuleManager.InstallMarked;
    179257var
     
    185263end;
    186264
     265procedure TModuleManager.StopAll;
     266var
     267  I: Integer;
     268begin
     269  for I := 0 to Modules.Count - 1 do
     270  with TModule(Modules[I]) do
     271    if Running then Stop;
     272end;
     273
    187274procedure TModuleManager.UninstallAll;
    188275var
     
    202289destructor TModuleManager.Destroy;
    203290begin
    204   UninstallAll;
     291  StopAll;
    205292  FreeAndNil(Modules);
    206293  inherited Destroy;
     
    209296{ TModule }
    210297
     298procedure TModule.SetRunning(AValue: Boolean);
     299begin
     300  if FRunning = AValue then Exit;
     301  if AValue then Start else Stop;
     302end;
     303
    211304procedure TModule.SetInstalled(AValue: Boolean);
    212305begin
    213306  if FInstalled = AValue then Exit;
    214307  if AValue then Install else Uninstall;
     308end;
     309
     310procedure TModule.Start;
     311begin
     312  if Running then Exit;
     313  Manager.StartDependencies(Identification, Dependencies);
     314  FRunning := True;
     315end;
     316
     317procedure TModule.Stop;
     318begin
     319  if not Running then Exit;
     320  Manager.StopDependencies(Identification);
     321  FRunning := False;
    215322end;
    216323
     
    225332begin
    226333  if not Installed then Exit;
     334  if Running then Stop;
    227335  Manager.UninstallDependencies(Identification);
    228336  FInstalled := False;
    229337end;
    230338
    231 procedure TModule.Update;
    232 begin
    233   if not Installed then Exit;
     339procedure TModule.Upgrade;
     340begin
     341  if not Running then Exit;
     342end;
     343
     344procedure TModule.EnumModulesStart(ModuleList: TStringList);
     345begin
     346  ModuleList.Clear;
     347  Manager.EnumModulesStart(Dependencies, ModuleList);
     348end;
     349
     350procedure TModule.EnumModulesStop(ModuleList: TStringList);
     351begin
     352  ModuleList.Clear;
     353  Manager.EnumModulesStop(Identification, ModuleList);
    234354end;
    235355
     
    255375destructor TModule.Destroy;
    256376begin
    257   Installed := False;
     377  Running := False;
    258378  Description.Free;
    259379  Dependencies.Free;
Note: See TracChangeset for help on using the changeset viewer.