Changeset 91 for trunk/Packages/ModularSystem/UModularSystem.pas
- Timestamp:
- Sep 7, 2012, 8:36:13 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/ModularSystem/UModularSystem.pas
r89 r91 19 19 TModule = class(TComponent) 20 20 private 21 FRunning: Boolean; 21 22 FInstalled: Boolean; 22 23 Manager: TModuleManager; … … 29 30 FDescription: TStringList; 30 31 procedure SetInstalled(AValue: Boolean); 32 procedure SetRunning(AValue: Boolean); 31 33 public 32 34 API: TAPI; 33 35 MarkForInstall: Boolean; 36 procedure Start; virtual; 37 procedure Stop; virtual; 34 38 procedure Install; virtual; 35 39 procedure Uninstall; virtual; 36 procedure Update; virtual; 40 procedure Upgrade; virtual; 41 procedure EnumModulesStart(ModuleList: TStringList); 42 procedure EnumModulesStop(ModuleList: TStringList); 37 43 procedure EnumModulesInstall(ModuleList: TStringList); 38 44 procedure EnumModulesUninstall(ModuleList: TStringList); 39 45 constructor Create(Owner: TComponent); virtual; 40 46 destructor Destroy; override; 47 property Running: Boolean read FRunning write SetRunning; 41 48 property Installed: Boolean read FInstalled write SetInstalled; 42 49 published … … 59 66 Modules: TObjectList; // TObjectList<TModule> 60 67 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); 61 72 procedure InstallDependencies(ModuleName: string; Dependencies: TStringList); 62 73 procedure UninstallDependencies(ModuleName: string); … … 65 76 procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False); 66 77 procedure UnregisterModule(Module: TModule); 78 procedure StartInstalled; 67 79 procedure InstallMarked; 80 procedure StopAll; 68 81 procedure UninstallAll; 69 82 constructor Create(AOwner: TComponent); override; … … 107 120 end; 108 121 109 procedure TModuleManager.InstallDependencies(ModuleName: string; Dependencies: TStringList); 122 procedure TModuleManager.StartDependencies(ModuleName: string; Dependencies: TStringList); 123 var 124 Module: TModule; 125 I: Integer; 126 begin 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; 133 end; 134 135 procedure TModuleManager.StopDependencies(ModuleName: string); 136 var 137 I: Integer; 138 begin 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; 143 end; 144 145 procedure TModuleManager.EnumModulesStart(Dependencies, 146 ModuleList: TStringList); 147 var 148 Module: TModule; 149 I: Integer; 150 begin 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; 160 end; 161 162 procedure TModuleManager.EnumModulesStop(ModuleName: string; 163 ModuleList: TStringList); 164 var 165 I: Integer; 166 begin 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; 175 end; 176 177 procedure TModuleManager.InstallDependencies(ModuleName: string; 178 Dependencies: TStringList); 110 179 var 111 180 Module: TModule; … … 176 245 end; 177 246 247 procedure TModuleManager.StartInstalled; 248 var 249 I: Integer; 250 begin 251 for I := 0 to Modules.Count - 1 do 252 with TModule(Modules[I]) do 253 if not Running and Installed then Start; 254 end; 255 178 256 procedure TModuleManager.InstallMarked; 179 257 var … … 185 263 end; 186 264 265 procedure TModuleManager.StopAll; 266 var 267 I: Integer; 268 begin 269 for I := 0 to Modules.Count - 1 do 270 with TModule(Modules[I]) do 271 if Running then Stop; 272 end; 273 187 274 procedure TModuleManager.UninstallAll; 188 275 var … … 202 289 destructor TModuleManager.Destroy; 203 290 begin 204 UninstallAll;291 StopAll; 205 292 FreeAndNil(Modules); 206 293 inherited Destroy; … … 209 296 { TModule } 210 297 298 procedure TModule.SetRunning(AValue: Boolean); 299 begin 300 if FRunning = AValue then Exit; 301 if AValue then Start else Stop; 302 end; 303 211 304 procedure TModule.SetInstalled(AValue: Boolean); 212 305 begin 213 306 if FInstalled = AValue then Exit; 214 307 if AValue then Install else Uninstall; 308 end; 309 310 procedure TModule.Start; 311 begin 312 if Running then Exit; 313 Manager.StartDependencies(Identification, Dependencies); 314 FRunning := True; 315 end; 316 317 procedure TModule.Stop; 318 begin 319 if not Running then Exit; 320 Manager.StopDependencies(Identification); 321 FRunning := False; 215 322 end; 216 323 … … 225 332 begin 226 333 if not Installed then Exit; 334 if Running then Stop; 227 335 Manager.UninstallDependencies(Identification); 228 336 FInstalled := False; 229 337 end; 230 338 231 procedure TModule.Update; 232 begin 233 if not Installed then Exit; 339 procedure TModule.Upgrade; 340 begin 341 if not Running then Exit; 342 end; 343 344 procedure TModule.EnumModulesStart(ModuleList: TStringList); 345 begin 346 ModuleList.Clear; 347 Manager.EnumModulesStart(Dependencies, ModuleList); 348 end; 349 350 procedure TModule.EnumModulesStop(ModuleList: TStringList); 351 begin 352 ModuleList.Clear; 353 Manager.EnumModulesStop(Identification, ModuleList); 234 354 end; 235 355 … … 255 375 destructor TModule.Destroy; 256 376 begin 257 Installed:= False;377 Running := False; 258 378 Description.Free; 259 379 Dependencies.Free;
Note:
See TracChangeset
for help on using the changeset viewer.