Changeset 428
- Timestamp:
- Oct 9, 2012, 11:48:44 AM (12 years ago)
- Location:
- ModularSystem
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
ModularSystem/Demo/Demo.lpi
r397 r428 35 35 <Item1> 36 36 <PackageName Value="ModularSystem"/> 37 <DefaultFilename Value="..\ModularSystem.lpk" Prefer="True"/> 37 38 </Item1> 38 39 <Item2> -
ModularSystem/Demo/UMainForm.lfm
r394 r428 10 10 OnDestroy = FormDestroy 11 11 OnShow = FormShow 12 LCLVersion = '1. 1'12 LCLVersion = '1.0.1.3' 13 13 object ListViewModules: TListView 14 14 Left = 8 … … 30 30 end 31 31 item 32 Caption = 'State' 32 Caption = 'Installed' 33 Width = 80 34 end 35 item 36 Caption = 'Running' 33 37 Width = 80 34 38 end … … 80 84 TabOrder = 3 81 85 end 86 object ButtonUpdate1: TButton 87 Left = 248 88 Height = 25 89 Top = 281 90 Width = 75 91 Action = AModuleStart 92 Anchors = [akLeft, akBottom] 93 TabOrder = 4 94 end 95 object ButtonUpdate2: TButton 96 Left = 328 97 Height = 25 98 Top = 281 99 Width = 75 100 Action = AModuleStop 101 Anchors = [akLeft, akBottom] 102 TabOrder = 5 103 end 82 104 object PopupMenu1: TPopupMenu 83 105 left = 183 … … 92 114 Action = AModuleUpdate 93 115 end 116 object MenuItem4: TMenuItem 117 Action = AModuleStart 118 end 119 object MenuItem5: TMenuItem 120 Action = AModuleStop 121 end 94 122 end 95 123 object ActionList1: TActionList 96 left = 1 3797 top = 1 65124 left = 184 125 top = 136 98 126 object AModuleInstall: TAction 99 127 Caption = 'Install' … … 108 136 OnExecute = ButtonUpdateClick 109 137 end 138 object AModuleStart: TAction 139 Caption = 'Start' 140 OnExecute = AModuleStartExecute 141 end 142 object AModuleStop: TAction 143 Caption = 'Stop' 144 OnExecute = AModuleStopExecute 145 end 110 146 end 111 147 end -
ModularSystem/Demo/UMainForm.pas
r397 r428 15 15 TMainForm = class(TForm) 16 16 published 17 AModuleStart: TAction; 18 AModuleStop: TAction; 17 19 AModuleInstall: TAction; 18 20 AModuleUninstall: TAction; … … 22 24 ButtonUninstall: TButton; 23 25 ButtonInstall: TButton; 26 ButtonUpdate1: TButton; 27 ButtonUpdate2: TButton; 24 28 ListViewModules: TListView; 25 29 MenuItem1: TMenuItem; 26 30 MenuItem2: TMenuItem; 27 31 MenuItem3: TMenuItem; 32 MenuItem4: TMenuItem; 33 MenuItem5: TMenuItem; 28 34 PopupMenu1: TPopupMenu; 35 procedure AModuleStartExecute(Sender: TObject); 36 procedure AModuleStopExecute(Sender: TObject); 29 37 procedure ButtonInstallClick(Sender: TObject); 30 38 procedure ButtonUninstallClick(Sender: TObject); … … 44 52 45 53 const 46 InstalledText: array[Boolean] of string = ('Not installed', 'Installed');54 BoolText: array[Boolean] of string = ('No', 'Yes'); 47 55 48 56 var … … 66 74 Item.Caption := Title; 67 75 Item.Data := ModuleManager.Modules[Item.Index]; 68 Item.SubItems.Add( Name);76 Item.SubItems.Add(Identification); 69 77 Item.SubItems.Add(Version); 70 Item.SubItems.Add(InstalledText[Installed]); 78 Item.SubItems.Add(BoolText[Installed]); 79 Item.SubItems.Add(BoolText[Running]); 71 80 Item.SubItems.Add(License); 72 81 Item.SubItems.Add(StringReplace(Dependencies.Text, LineEnding, ', ', [rfReplaceAll])); … … 79 88 var 80 89 Installed: Boolean; 90 Running: Boolean; 81 91 begin 82 92 if Assigned(ListViewModules.Selected) then Installed := TModule(ListViewModules.Selected.Data).Installed; 93 if Assigned(ListViewModules.Selected) then Running := TModule(ListViewModules.Selected.Data).Running; 83 94 AModuleInstall.Enabled := Assigned(ListViewModules.Selected) and not Installed; 84 95 AModuleUninstall.Enabled := Assigned(ListViewModules.Selected) and Installed; 85 96 AModuleUpdate.Enabled := Assigned(ListViewModules.Selected) and Installed; 97 AModuleStart.Enabled := Assigned(ListViewModules.Selected) and not Running; 98 AModuleStop.Enabled := Assigned(ListViewModules.Selected) and Running; 86 99 end; 87 100 88 101 procedure TMainForm.RegisterModules; 89 102 begin 90 ModuleManager.RegisterModule(TModuleUser.Create );91 ModuleManager.RegisterModule(TModuleBase.Create );92 ModuleManager.RegisterModule(TModuleACL.Create );103 ModuleManager.RegisterModule(TModuleUser.Create(nil)); 104 ModuleManager.RegisterModule(TModuleBase.Create(nil)); 105 ModuleManager.RegisterModule(TModuleACL.Create(nil)); 93 106 end; 94 107 … … 129 142 end; 130 143 144 procedure TMainForm.AModuleStartExecute(Sender: TObject); 145 var 146 ModuleList: TStringList; 147 begin 148 if Assigned(ListViewModules.Selected) then begin 149 try 150 ModuleList := TStringList.Create; 151 TModule(ListViewModules.Selected.Data).EnumModulesStart(ModuleList); 152 if ModuleList.Count > 0 then begin 153 if MessageDlg('These modules will be started in addition to ' + 154 TModule(ListViewModules.Selected.Data).Name + ': ' + 155 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]), 156 mtConfirmation, [mbYes, mbNo], 0) = mrYes then 157 TModule(ListViewModules.Selected.Data).Start; 158 end else TModule(ListViewModules.Selected.Data).Start; 159 finally 160 ModuleList.Free; 161 end; 162 RefreshList; 163 end; 164 end; 165 166 procedure TMainForm.AModuleStopExecute(Sender: TObject); 167 var 168 ModuleList: TStringList; 169 begin 170 if Assigned(ListViewModules.Selected) then begin 171 try 172 ModuleList := TStringList.Create; 173 TModule(ListViewModules.Selected.Data).EnumModulesStop(ModuleList); 174 if ModuleList.Count > 0 then begin 175 if MessageDlg('These modules will be stopped in addition to ' + 176 TModule(ListViewModules.Selected.Data).Name + ': ' + 177 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]), 178 mtConfirmation, [mbYes, mbNo], 0) = mrYes then 179 TModule(ListViewModules.Selected.Data).Stop; 180 end else TModule(ListViewModules.Selected.Data).Stop; 181 finally 182 ModuleList.Free; 183 end; 184 185 RefreshList; 186 end; 187 end; 188 131 189 procedure TMainForm.ButtonUninstallClick(Sender: TObject); 132 190 var … … 155 213 begin 156 214 if Assigned(ListViewModules.Selected) then begin 157 TModule(ListViewModules.Selected.Data).Up date;215 TModule(ListViewModules.Selected.Data).Upgrade; 158 216 RefreshList; 159 217 end; … … 162 220 procedure TMainForm.FormDestroy(Sender: TObject); 163 221 begin 164 ModuleManager.Free;222 FreeAndNil(ModuleManager); 165 223 end; 166 224 -
ModularSystem/Demo/UModuleACL.pas
r394 r428 12 12 13 13 TModuleACL = class(TModule) 14 constructor Create ; override;14 constructor Create(AOwner: TComponent); override; 15 15 destructor Destroy; override; 16 16 end; … … 21 21 { TModuleACL } 22 22 23 constructor TModuleACL.Create ;23 constructor TModuleACL.Create(AOwner: TComponent); 24 24 begin 25 25 inherited; 26 Name:= 'UserACL';26 Identification := 'UserACL'; 27 27 Title := 'User ACL'; 28 28 Version := '1.0'; -
ModularSystem/Demo/UModuleBase.pas
r394 r428 10 10 type 11 11 TModuleBase = class(TModule) 12 constructor Create ; override;12 constructor Create(AOwner: TComponent); override; 13 13 destructor Destroy; override; 14 14 end; … … 19 19 { TModuleUser } 20 20 21 constructor TModuleBase.Create ;21 constructor TModuleBase.Create(AOwner: TComponent); 22 22 begin 23 23 inherited; 24 Name:= 'Base';24 Identification := 'Base'; 25 25 Title := 'Base'; 26 26 Version := '1.0'; -
ModularSystem/Demo/UModuleUser.pas
r394 r428 13 13 14 14 TModuleUser = class(TModule) 15 constructor Create ; override;15 constructor Create(AOwner: TComponent); override; 16 16 destructor Destroy; override; 17 17 end; … … 21 21 { TModuleUser } 22 22 23 constructor TModuleUser.Create ;23 constructor TModuleUser.Create(AOwner: TComponent); 24 24 begin 25 25 inherited; 26 Name:= 'User';26 Identification := 'User'; 27 27 Title := 'User'; 28 28 Version := '1.0'; -
ModularSystem/ModularSystem.lpk
r399 r428 28 28 </Item1> 29 29 </Files> 30 <i18n> 31 <EnableI18N Value="True"/> 32 <OutDir Value="Language"/> 33 <EnableI18NForLFM Value="True"/> 34 </i18n> 30 35 <Type Value="RunAndDesignTime"/> 31 <RequiredPkgs Count=" 1">36 <RequiredPkgs Count="2"> 32 37 <Item1> 38 <PackageName Value="Common"/> 39 </Item1> 40 <Item2> 33 41 <PackageName Value="FCL"/> 34 </Item 1>42 </Item2> 35 43 </RequiredPkgs> 36 44 <UsageOptions> -
ModularSystem/UModularSystem.pas
r421 r428 6 6 7 7 uses 8 Classes, SysUtils, Contnrs ;8 Classes, SysUtils, Contnrs, URegistry; 9 9 10 10 type … … 19 19 TModule = class(TComponent) 20 20 private 21 FEnabled: Boolean; 21 22 FRunning: Boolean; 22 23 FInstalled: Boolean; … … 29 30 FDependencies: TStringList; 30 31 FDescription: TStringList; 32 procedure SetEnabled(AValue: Boolean); 31 33 procedure SetInstalled(AValue: Boolean); 32 34 procedure SetRunning(AValue: Boolean); 35 protected 36 procedure BeforeStart; virtual; 37 procedure AfterStart; virtual; 38 procedure BeforeStop; virtual; 39 procedure AfterStop; virtual; 33 40 public 34 41 API: TAPI; 35 MarkForInstall: Boolean;36 42 procedure Start; virtual; 37 43 procedure Stop; virtual; … … 48 54 property Running: Boolean read FRunning write SetRunning; 49 55 property Installed: Boolean read FInstalled write SetInstalled; 56 property Enabled: Boolean read FEnabled write SetEnabled; 50 57 published 51 58 property Version: string read FVersion write FVersion; … … 79 86 procedure EnumModulesInstall(Dependencies, ModuleList: TStringList); 80 87 procedure EnumModulesUninstall(ModuleName: string; ModuleList: TStringList); 81 procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False);88 procedure RegisterModule(Module: TModule; Enabled: Boolean = True); 82 89 procedure UnregisterModule(Module: TModule); 83 90 procedure StartInstalled; 84 procedure Install Marked;91 procedure InstallEnabled; 85 92 procedure StopAll; 86 93 procedure UninstallAll; 94 procedure LoadFromRegistry(Context: TRegistryContext); 95 procedure SaveToRegistry(Context: TRegistryContext); 87 96 constructor Create(AOwner: TComponent); override; 88 97 destructor Destroy; override; … … 143 152 for I := 0 to Dependencies.Count - 1 do begin 144 153 Module := FindModuleByName(Dependencies[I]); 145 if Assigned(Module) then begin154 if Assigned(Module) and Module.Enabled then begin 146 155 if not Module.Running then Module.Start; 147 156 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); … … 199 208 for I := 0 to Dependencies.Count - 1 do begin 200 209 Module := FindModuleByName(Dependencies[I]); 201 if Assigned(Module) then begin210 if Assigned(Module) and Module.Enabled then begin 202 211 if not Module.Installed then Module.Install; 203 212 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); … … 248 257 249 258 procedure TModuleManager.RegisterModule(Module: TModule; 250 MarkForInstall: Boolean = False);259 Enabled: Boolean = True); 251 260 begin 252 261 Modules.Add(Module); 253 262 Module.Manager := Self; 254 263 Module.API := API; 255 Module. MarkForInstall := MarkForInstall;264 Module.Enabled := Enabled; 256 265 end; 257 266 … … 270 279 end; 271 280 272 procedure TModuleManager.Install Marked;281 procedure TModuleManager.InstallEnabled; 273 282 var 274 283 I: Integer; … … 276 285 for I := 0 to Modules.Count - 1 do 277 286 with TModule(Modules[I]) do 278 if not Installed and MarkForInstallthen Install;287 if not Installed and Enabled then Install; 279 288 end; 280 289 … … 310 319 end; 311 320 321 procedure TModuleManager.LoadFromRegistry(Context: TRegistryContext); 322 var 323 I: Integer; 324 begin 325 with TRegistryEx.Create do 326 try 327 RootKey := Context.RootKey; 328 for I := 0 to Modules.Count - 1 do 329 with TModule(Modules[I]) do begin 330 OpenKey(Context.Key + '\' + Identification, True); 331 Running := ReadBoolWithDefault('Run', Enabled); 332 end; 333 finally 334 Free; 335 end; 336 end; 337 338 procedure TModuleManager.SaveToRegistry(Context: TRegistryContext); 339 var 340 I: Integer; 341 begin 342 with TRegistryEx.Create do 343 try 344 RootKey := Context.RootKey; 345 for I := 0 to Modules.Count - 1 do 346 with TModule(Modules[I]) do begin 347 OpenKey(Context.Key + '\' + Identification, True); 348 WriteBool('Run', Running); 349 end; 350 finally 351 Free; 352 end; 353 end; 354 312 355 { TModule } 313 356 … … 318 361 end; 319 362 363 procedure TModule.BeforeStart; 364 begin 365 if Running then Exit; 366 if not Installed then Install; 367 Manager.StartDependencies(Identification, Dependencies); 368 end; 369 370 procedure TModule.AfterStart; 371 begin 372 FRunning := True; 373 end; 374 375 procedure TModule.BeforeStop; 376 begin 377 if not Running then Exit; 378 FRunning := False; 379 Manager.StopDependencies(Identification); 380 end; 381 382 procedure TModule.AfterStop; 383 begin 384 end; 385 320 386 procedure TModule.SetInstalled(AValue: Boolean); 321 387 begin … … 324 390 end; 325 391 392 procedure TModule.SetEnabled(AValue: Boolean); 393 begin 394 if FEnabled = AValue then Exit; 395 FEnabled := AValue; 396 if not FEnabled and FInstalled then Uninstall; 397 end; 398 326 399 procedure TModule.Start; 327 400 begin 328 if Running then Exit; 329 Manager.StartDependencies(Identification, Dependencies); 330 FRunning := True; 401 BeforeStart; 402 AfterStart; 331 403 end; 332 404 333 405 procedure TModule.Stop; 334 406 begin 335 if not Running then Exit; 336 Manager.StopDependencies(Identification); 337 FRunning := False; 407 BeforeStop; 408 AfterStop; 338 409 end; 339 410
Note:
See TracChangeset
for help on using the changeset viewer.