Changeset 105 for trunk/UCore.pas
- Timestamp:
- Oct 9, 2012, 1:58:45 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r103 r105 17 17 18 18 type 19 TCore = class;20 21 22 19 { TCore } 23 20 … … 27 24 procedure WebApp1PageProduce(HandlerData: THTTPHandlerData); 28 25 private 29 FGeneratePage: TGeneratePageEvent;30 26 procedure Show(Content: string); 31 procedure RegisterModules;32 procedure CheckModules;33 27 public 34 28 CommonDatabase: TSqlDatabase; 35 ModuleManager: TModuleManager;36 29 Load: string; 37 30 Unload: string; … … 47 40 NetworkPort: Integer; 48 41 MaxConnections: Integer; 49 Pages: TPageList;50 42 DatabaseHostname: string; 51 43 DatabaseUserName: string; 52 44 DatabasePassword: string; 53 45 DatabaseSchema: string; 54 procedure GeneratePageDefault(ASession: TWebSession; Page: TWebPage);55 46 procedure LoadFromRegistry; 56 47 procedure SaveToRegistry; … … 58 49 constructor Create(AOwner: TComponent); override; 59 50 destructor Destroy; override; 60 property GeneratePage: TGeneratePageEvent read FGeneratePage write FGeneratePage;61 51 end; 62 52 … … 67 57 implementation 68 58 69 uses70 UModuleSystem, UModuleZdechovNET, UModuleUser, UPageAdmin, UModuleTV,71 UModuleFinance, UModuleNetwork, UModulePortal, UModuleIS;72 73 resourcestring74 SError = '<div>Error: %s</div>';75 76 59 77 60 { TCore } 78 79 procedure TCore.GeneratePageDefault(ASession: TWebSession; Page: TWebPage);80 var81 I: Integer;82 begin83 with ASession do begin84 HtmlDocument.ContentLanguage := 'cs';85 GlobalTitle := 'WebSystem';86 87 //Page.Page.OnProduce(HandlerData);88 HtmlDocument.Title := Page.Caption;89 with HtmlDocument.AsXmlDocument do90 try91 Formated := TCore(MainModule).FormatHTML;92 Response.Content.WriteString(AsString);93 finally94 Free;95 end;96 end;97 end;98 61 99 62 constructor TCore.Create(AOwner: TComponent); 100 63 begin 101 64 inherited; 102 ModuleManager := TModuleManager.Create(nil);103 Pages := TPageList.Create;104 65 CommonDatabase := TSqlDatabase.Create(nil); 105 66 106 67 LoadFromRegistry; 107 with Pages do begin108 RegisterPage(TPageAdmin, PageAdmin, 'administration');109 end;110 68 with WebApp1 do begin 111 69 if ServerType = stTCP then begin … … 121 79 //SaveToRegistry; 122 80 FreeAndNil(CommonDatabase); 123 ModuleManager.StopAll;124 FreeAndNil(ModuleManager);125 FreeAndNil(Pages);126 81 inherited; 127 82 end; … … 154 109 end; 155 110 156 procedure TCore.RegisterModules;157 begin158 with ModuleManager do begin159 RegisterModule(TModuleSystem.Create(nil), True);160 RegisterModule(TModuleUser.Create(nil), True);161 RegisterModule(TModuleZdechovNET.Create(nil), True);162 RegisterModule(TModuleTV.Create(nil), True);163 RegisterModule(TModuleFinance.Create(nil), True);164 RegisterModule(TModuleNetwork.Create(nil), True);165 RegisterModule(TModulePortal.Create(nil), True);166 RegisterModule(TModuleIS.Create(nil), True);167 end;168 end;169 170 procedure TCore.CheckModules;171 var172 DbRows: TDbRows;173 Module: TModule;174 I: Integer;175 begin176 try177 DbRows := TDbRows.Create;178 CommonDatabase.Query(DbRows, 'SELECT * FROM INFORMATION_SCHEMA.TABLES ' +179 'WHERE TABLE_SCHEMA = "' + CommonDatabase.Database + '" AND TABLE_NAME = "SystemModule"');180 Module := ModuleManager.FindModuleByName('System');181 if DbRows.Count > 0 then Module.SetInstalledState(True)182 else Module.SetInstalledState(False);183 finally184 DbRows.Free;185 end;186 end;187 188 111 procedure TCore.WebApp1PageProduce(HandlerData: THTTPHandlerData); 189 112 var 190 FileName: string;191 PageName: string;192 Page: TRegistredPage;193 113 NewSession: TWebSession; 194 BaseUrlParts: TListString;195 114 begin 196 with HandlerData do begin 197 try 198 BaseUrlParts := TListString.Create; 199 BaseUrlParts.Explode(BaseURL, '/', StrToStr); 200 while (BaseUrlParts.Count > 0) and (Request.Path.Count > 0) and 201 (BaseUrlParts[0] = Request.Path[0]) do begin 202 BaseUrlParts.Delete(0); 203 Request.Path.Delete(0); 204 end; 205 finally 206 BaseUrlParts.Free; 207 end; 208 if Request.Path.Count > 0 then PageName := Request.Path[0] 209 else PageName := ''; 210 Page := Pages.FindByName(PageName); 211 if Assigned(Page) then begin 212 NewSession := TWebSession.Create; 213 NewSession.MainModule := Self; 214 NewSession.Assign(HandlerData); 215 NewSession.TimeStart := Now; 216 NewSession.Database.HostName := DatabaseHostName; 217 NewSession.Database.Password := DatabasePassword; 218 NewSession.Database.Database := DatabaseSchema; 219 NewSession.Database.UserName := DatabaseUserName; 220 NewSession.InitDatabase; 221 try 222 Page.Page.OnProduce(NewSession); 223 except 224 on E: Exception do begin 225 THTMLString(TWebSession(NewSession).HtmlDocument.Body.SubItems.AddNew(THtmlString.Create)). 226 Text := Format(SError, [E.Message]); 227 if Assigned(GeneratePage) then GeneratePage(NewSession, Page.Page) 228 else GeneratePageDefault(NewSession, Page.Page); 229 end; 230 end; 231 HandlerData.Assign(NewSession); 232 end else begin 233 WebApp1.HTTPServer.FileResponse(HandlerData) 234 end; 235 end; 115 NewSession := TWebSession.Create; 116 NewSession.MainModule := Self; 117 NewSession.Assign(HandlerData); 118 NewSession.TimeStart := Now; 119 NewSession.Database.HostName := DatabaseHostName; 120 NewSession.Database.Password := DatabasePassword; 121 NewSession.Database.Database := DatabaseSchema; 122 NewSession.Database.UserName := DatabaseUserName; 123 NewSession.InitDatabase; 124 NewSession.BaseURL := BaseURL; 125 NewSession.Run; 126 HandlerData.Assign(NewSession); 236 127 end; 237 128 … … 296 187 CommonDatabase.Connect; 297 188 298 RegisterModules;299 CheckModules;300 ModuleManager.StartInstalled;301 302 189 WebApp1.HTTPServer.DocumentRoot := ExtractFileDir(ParamStrUTF8(0)); 303 190 WebApp1.Run;
Note:
See TracChangeset
for help on using the changeset viewer.