Changeset 91
- Timestamp:
- Sep 7, 2012, 8:36:13 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/User/UModuleUser.pas
r90 r91 16 16 constructor Create(Owner: TComponent); override; 17 17 destructor Destroy; override; 18 procedure Start; override; 19 procedure Stop; override; 18 20 procedure Install; override; 19 21 procedure Uninstall; override; 20 procedure Up date; override;22 procedure Upgrade; override; 21 23 end; 22 24 25 23 26 implementation 27 28 uses 29 UCore, UUserControlPage, USqlDatabase; 24 30 25 31 { TModuleUser } … … 28 34 begin 29 35 inherited; 36 Identification := 'User'; 37 Title := 'User management'; 38 Version := '0.1'; 39 License := 'GNU/LGPL v3'; 40 Author := 'Chronosoft'; 30 41 end; 31 42 … … 35 46 end; 36 47 37 procedure TModuleUser. Install;48 procedure TModuleUser.Start; 38 49 begin 50 Core.Pages.RegisterPage(TUserControlPage, UserControlPage, 'uzivatel'); 51 //RegisterPage(TUserControlPage, UserControlPage, ''); 39 52 inherited; 40 53 end; 41 54 42 procedure TModuleUser. Uninstall;55 procedure TModuleUser.Stop; 43 56 begin 44 57 inherited; 58 Core.Pages.UnregisterPage('uzivatel'); 45 59 end; 46 60 47 procedure TModuleUser.Update; 61 procedure TModuleUser.Install; 62 var 63 DbRows: TDbRows; 64 begin 65 try 66 DbRows := TDbRows.Create; 67 Core.CommonDatabase.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `User` (' + 68 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 69 '`Name` varchar(255) NOT NULL,' + 70 '`FullName` varchar(255) NOT NULL,' + 71 '`Password` varchar(255) NOT NULL,' + 72 '`Salt` varchar(255) NOT NULL,' + 73 '`Email` varchar(255) NOT NULL,' + 74 '`RegistrationTime` datetime NOT NULL,' + 75 'PRIMARY KEY (`Id`)' + 76 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'); 77 Core.CommonDatabase.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `UserOnline` (' + 78 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 79 '`User` int(11) NOT NULL DEFAULT ''0'',' + 80 '`ActivityTime` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',' + 81 '`LoginTime` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',' + 82 '`SessionId` varchar(255) COLLATE utf8_czech_ci NOT NULL DEFAULT '''',' + 83 '`IpAddress` varchar(16) COLLATE utf8_czech_ci NOT NULL DEFAULT '''',' + 84 '`HostName` varchar(255) COLLATE utf8_czech_ci NOT NULL DEFAULT '''',' + 85 '`ScriptName` varchar(255) COLLATE utf8_czech_ci NOT NULL,' + 86 'PRIMARY KEY (`Id`),' + 87 'KEY `User` (`User`)' + 88 ') ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=2 ;'); 89 finally 90 DbRows.Free; 91 end; 92 inherited Install; 93 end; 94 95 procedure TModuleUser.Uninstall; 96 var 97 DbRows: TDbRows; 98 begin 99 inherited Uninstall; 100 try 101 DbRows := TDbRows.Create; 102 Core.CommonDatabase.Query(DbRows, 'DROP TABLE `User`'); 103 Core.CommonDatabase.Query(DbRows, 'DROP TABLE `UserOnline`'); 104 finally 105 DbRows.Free; 106 end; 107 end; 108 109 procedure TModuleUser.Upgrade; 48 110 begin 49 111 inherited; -
trunk/Packages/CoolWeb/WebServer/UWebApp.pas
r84 r91 23 23 function FindByName(Name: string): TRegistredPage; 24 24 procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string); 25 procedure UnregisterPage(Path: string); 25 26 function ProducePage(HandlerData: THTTPHandlerData): Boolean; 26 27 end; … … 119 120 end; 120 121 122 procedure TPageList.UnregisterPage(Path: string); 123 var 124 Page: TRegistredPage; 125 begin 126 Page := FindByName(Path); 127 Remove(Page); 128 end; 129 121 130 function TPageList.ProducePage(HandlerData: THTTPHandlerData): Boolean; 122 131 var -
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; -
trunk/UCore.pas
r89 r91 51 51 procedure RegisterModules; 52 52 public 53 CommonDatabase: TSqlDatabase; 53 54 ModuleManager: TModuleManager; 54 55 Load: string; … … 110 111 SessionStorage.Free; 111 112 Database.Free; 112 inherited Destroy;113 inherited; 113 114 end; 114 115 … … 173 174 ModuleManager := TModuleManager.Create(nil); 174 175 Pages := TPageList.Create; 175 176 RegisterModules; 177 ModuleManager.InstallMarked; 176 CommonDatabase := TSqlDatabase.Create(nil); 178 177 179 178 LoadFromRegistry; … … 188 187 RegisterPage(TServerInfoPage, ServerInfoPage, 'serverinfo'); 189 188 RegisterPage(TWebCamPage, WebCamPage, 'kamery'); 190 //RegisterPage(TUserControlPage, UserControlPage, 'uzivatel');191 189 RegisterPage(TPlansPage, PlansPage, 'plany'); 192 190 RegisterPage(TNetworkPage, NetworkPage, 'sit'); 193 191 RegisterPage(TProjectsPage, ProjectsPage, 'projekty'); 194 192 RegisterPage(TAboutPage, AboutPage, ''); 195 //RegisterPage(TUserControlPage, UserControlPage, '');196 193 end; 197 194 with WebApp1 do begin … … 207 204 begin 208 205 //SaveToRegistry; 209 Pages.Free; 210 inherited Destroy; 206 FreeAndNil(CommonDatabase); 207 FreeAndNil(ModuleManager); 208 FreeAndNil(Pages); 209 inherited; 211 210 end; 212 211 … … 419 418 procedure TCore.Run; 420 419 begin 420 CommonDatabase.UserName := DatabaseUserName; 421 CommonDatabase.HostName := DatabaseHostname; 422 CommonDatabase.Database := DatabaseSchema; 423 CommonDatabase.Password := DatabasePassword; 424 CommonDatabase.Connect; 425 426 RegisterModules; 427 ModuleManager.StartInstalled; 428 421 429 WebApp1.HTTPServer.DocumentRoot := ExtractFileDir(ParamStrUTF8(0)); 422 430 WebApp1.Run; -
trunk/ZdechovNET.lpi
r89 r91 164 164 </Unit14> 165 165 <Unit15> 166 <Filename Value="Pages/U UserControlPage.pas"/>167 <IsPartOfProject Value="True"/> 168 <ComponentName Value=" UserControlPage"/>169 <HasResources Value="True"/> 170 <ResourceBaseClass Value="DataModule"/> 171 <UnitName Value="U UserControlPage"/>166 <Filename Value="Pages/UNetworkPage.pas"/> 167 <IsPartOfProject Value="True"/> 168 <ComponentName Value="NetworkPage"/> 169 <HasResources Value="True"/> 170 <ResourceBaseClass Value="DataModule"/> 171 <UnitName Value="UNetworkPage"/> 172 172 </Unit15> 173 173 <Unit16> 174 <Filename Value="Pages/U NetworkPage.pas"/>175 <IsPartOfProject Value="True"/> 176 <ComponentName Value=" NetworkPage"/>177 <HasResources Value="True"/> 178 <ResourceBaseClass Value="DataModule"/> 179 <UnitName Value="U NetworkPage"/>174 <Filename Value="Pages/UAboutPage.pas"/> 175 <IsPartOfProject Value="True"/> 176 <ComponentName Value="AboutPage"/> 177 <HasResources Value="True"/> 178 <ResourceBaseClass Value="DataModule"/> 179 <UnitName Value="UAboutPage"/> 180 180 </Unit16> 181 181 <Unit17> 182 <Filename Value="Pages/UAboutPage.pas"/> 183 <IsPartOfProject Value="True"/> 184 <ComponentName Value="AboutPage"/> 185 <HasResources Value="True"/> 186 <ResourceBaseClass Value="DataModule"/> 187 <UnitName Value="UAboutPage"/> 182 <Filename Value="ReadMe.txt"/> 183 <IsPartOfProject Value="True"/> 188 184 </Unit17> 189 185 <Unit18> 190 <Filename Value="ReadMe.txt"/> 191 <IsPartOfProject Value="True"/> 186 <Filename Value="Pages/UProjectsPage.pas"/> 187 <IsPartOfProject Value="True"/> 188 <ComponentName Value="ProjectsPage"/> 189 <HasResources Value="True"/> 190 <ResourceBaseClass Value="DataModule"/> 191 <UnitName Value="UProjectsPage"/> 192 192 </Unit18> 193 193 <Unit19> 194 <Filename Value="Pages/UProjectsPage.pas"/> 195 <IsPartOfProject Value="True"/> 196 <ComponentName Value="ProjectsPage"/> 197 <HasResources Value="True"/> 198 <ResourceBaseClass Value="DataModule"/> 199 <UnitName Value="UProjectsPage"/> 194 <Filename Value="Modules/User/UModuleUser.pas"/> 195 <IsPartOfProject Value="True"/> 196 <UnitName Value="UModuleUser"/> 200 197 </Unit19> 201 198 <Unit20> 202 <Filename Value="Modules/User/UModuleUser.pas"/> 203 <IsPartOfProject Value="True"/> 204 <UnitName Value="UModuleUser"/> 199 <Filename Value="UCore.pas"/> 200 <IsPartOfProject Value="True"/> 201 <ComponentName Value="Core"/> 202 <HasResources Value="True"/> 203 <ResourceBaseClass Value="DataModule"/> 204 <UnitName Value="UCore"/> 205 205 </Unit20> 206 206 <Unit21> 207 <Filename Value=" UCore.pas"/>208 <IsPartOfProject Value="True"/> 209 <ComponentName Value=" Core"/>210 <HasResources Value="True"/> 211 <ResourceBaseClass Value="DataModule"/> 212 <UnitName Value="U Core"/>207 <Filename Value="Modules/User/UUserControlPage.pas"/> 208 <IsPartOfProject Value="True"/> 209 <ComponentName Value="UserControlPage"/> 210 <HasResources Value="True"/> 211 <ResourceBaseClass Value="DataModule"/> 212 <UnitName Value="UUserControlPage"/> 213 213 </Unit21> 214 214 </Units>
Note:
See TracChangeset
for help on using the changeset viewer.