PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/client/Container/src/uCnrRunningCtx.pas

http://drcp.googlecode.com/
Pascal | 234 lines | 166 code | 59 blank | 9 comment | 0 complexity | cf68d24b9d578b22e506bd638db5dd76 MD5 | raw file
  1unit uCnrRunningCtx;
  2
  3{
  4  two running context, for local and remote.
  5
  6}
  7interface
  8uses DrcpSvc,types,uPlugInIntf,IniFiles,SysUtils;
  9
 10const
 11  //below const used in ini configure file for key, and default value
 12  RS_KEY_RunningMode='RunningMode';
 13  RS_KEY_Debug='Debug';
 14  RS_KEY_PluginPath='PluginPath';
 15  RS_KEY_GlobalVariableFileName='GlobalVariableFileName';
 16  RS_KEY_ClientConfigFileName='ClientConfigFileName';
 17  RS_KEY_AppServerSoapAddr = 'AppServerSoapAddr';
 18
 19  RS_DEFAULT_RunningMode='Offline';
 20  RS_DEFAULT_Debug='false';
 21  RS_DEFAULT_PluginPath ='Plugin';
 22  RS_DEFAULT_GlobalVariableFileName='global_variable.ini';
 23  RS_DEFAULT_ClientConfigFileName='client_config.ini';
 24  RS_DEFAULT_AppServerSoapAddr = 'http://not-exist.com/no-service';
 25
 26type
 27
 28  TContainerRunningContext=class
 29
 30  public
 31    function GetGlobalVariable(AName : string):string;virtual;abstract;
 32
 33    function OnCheckPassword(AUserName : string; APassword : string):boolean;virtual;abstract;
 34    function Plugin_GetVersionByName(APluginName : string):string;virtual;abstract;
 35    function Plugin_GetDataByName(APluginName : string):TByteDynArray;virtual;abstract;
 36
 37    function GetHostModuleParams(const AHost, AModule: string): string;virtual;abstract;
 38    procedure SetHostModuleParams(const AHost, AModule, AParams: string);virtual;abstract;
 39
 40    function GetFunctionAuthorization(const AUserId, AFunctionPath : string):boolean;virtual;abstract;
 41
 42    procedure AddLog(const userId: String; const computerName: String; const source: String; const type_: Integer; const category: String; const action: String; const comment: String);virtual;abstract;
 43  end;
 44
 45  TContainerRunningContextLocal=class(TContainerRunningContext)
 46  private
 47    FConfigFileName : string;
 48    FContainer : IContainer;
 49    FStartupPlugins : string;
 50
 51  public
 52    constructor Create(AConfigFileName : string; AContainer : IContainer);
 53    procedure LoadConfig;
 54
 55    function GetGlobalVariable(AName : string):string;override;
 56
 57    function OnCheckPassword(AUserName : string; APassword : string):boolean;override;
 58
 59    function GetHostModuleParams(const AHost, AModule: string): string;override;
 60    procedure SetHostModuleParams(const AHost, AModule, AParams: string);override;
 61
 62    function GetFunctionAuthorization(const AUserId, AFunctionPath : string):boolean;override;
 63
 64    procedure AddLog(const userId: String; const computerName: String; const source: String; const type_: Integer; const category: String; const action: String; const comment: String);override;
 65  end;
 66
 67  TContainerRunningContextRemote=class(TContainerRunningContext)
 68  private
 69    FSoap : DrcpService;
 70  public
 71    constructor Create(ASoapPath : string);
 72
 73
 74    function GetGlobalVariable(AName : string):string;override;
 75
 76    function OnCheckPassword(AUserName : string; APassword : string):boolean;override;
 77
 78    function Plugin_GetVersionByName(APluginName : string):string;override;
 79    function Plugin_GetDataByName(APluginName : string):TByteDynArray;override;
 80
 81    function GetHostModuleParams(const AHost, AModule: string): string;override;
 82    procedure SetHostModuleParams(const AHost, AModule, AParams: string);override;
 83
 84    function GetFunctionAuthorization(const AUserId, AFunctionPath : string):boolean;override;
 85
 86    procedure AddLog(const userId: String; const computerName: String; const source: String; const type_: Integer; const category: String; const action: String; const comment: String);override;
 87  end;
 88
 89
 90
 91implementation
 92
 93uses Classes;
 94
 95{ TContainerRunningContextRemote }
 96
 97procedure TContainerRunningContextRemote.AddLog(const userId, computerName,
 98  source: String; const type_: Integer; const category, action,
 99  comment: String);
100begin
101  FSoap.Log_Add(userId,computerName,source,type_,category,action,comment);
102end;
103
104constructor TContainerRunningContextRemote.Create(ASoapPath: string);
105begin
106  FSoap := GetDrcpService(false,ASoapPath);
107end;
108
109function TContainerRunningContextRemote.GetFunctionAuthorization(
110  const AUserId, AFunctionPath: string): boolean;
111begin
112  Result :=FSoap.FunctionAuthorization_IsUserAuthorizedByPath(AUserId,AFunctionPath);
113end;
114
115function TContainerRunningContextRemote.GetHostModuleParams(const AHost,
116  AModule: string): string;
117begin
118  Result := FSoap.ClientConfig_GetContent(AHost,AModule);
119end;
120
121function TContainerRunningContextRemote.GetGlobalVariable(AName: string): string;
122begin
123  Result := FSoap.GlobalVariable_GetValue(AName);
124end;
125
126function TContainerRunningContextRemote.OnCheckPassword(AUserName,
127  APassword: string): boolean;
128begin
129 Result := FSoap.Login(AUserName,APassword);
130end;
131
132function TContainerRunningContextRemote.Plugin_GetDataByName(
133  APluginName: string): TByteDynArray;
134begin
135  Result := FSoap.Plugin_GetDataByName(APluginName);
136end;
137
138function TContainerRunningContextRemote.Plugin_GetVersionByName(
139  APluginName: string): string;
140begin
141  Result := FSoap.Plugin_GetVersionByName(APluginName);
142end;
143
144procedure TContainerRunningContextRemote.SetHostModuleParams(const AHost,
145  AModule, AParams: string);
146begin
147  FSoap.ClientConfig_SetContent(AHost,AModule,AParams);
148end;
149
150{ TContainerRunningContextLocal }
151
152procedure TContainerRunningContextLocal.AddLog(const userId, computerName,
153  source: String; const type_: Integer; const category, action,
154  comment: String);
155begin
156  //write to txt file
157
158end;
159
160constructor TContainerRunningContextLocal.Create(AConfigFileName: string; AContainer : IContainer);
161begin
162  FConfigFileName := AConfigFileName;
163  FContainer := AContainer;
164  //
165  LoadConfig;  
166end;
167
168function TContainerRunningContextLocal.GetFunctionAuthorization(
169  const AUserId, AFunctionPath: string): boolean;
170begin
171  Result := true;
172end;
173
174function TContainerRunningContextLocal.GetHostModuleParams(const AHost,
175  AModule: string): string;
176var
177  lFileName : string;
178begin
179  lFileName := format('%s%s',[FContainer.Variable[RS_APPLICATION_PATH],FContainer.Variable[RS_KEY_ClientConfigFileName]]);
180  with TIniFile.Create(lFileName) do
181  begin
182    Result := ReadString('variables',AModule,'');
183
184    Free;
185  end;
186  Result := StringReplace(Result,'<BR>',#$D#$A,[rfReplaceAll, rfIgnoreCase]);
187end;
188
189function TContainerRunningContextLocal.GetGlobalVariable(AName: string): string;
190var
191  lFileName : string;
192begin
193
194  lFileName := format('%s%s',[FContainer.Variable[RS_APPLICATION_PATH],FContainer.Variable[RS_KEY_GlobalVariableFileName]]);
195  with TIniFile.Create(lFileName) do
196  begin
197    Result := ReadString('variables',AName,'');
198
199    Free;
200  end;
201
202end;
203
204procedure TContainerRunningContextLocal.LoadConfig;
205begin
206
207
208end;
209
210function TContainerRunningContextLocal.OnCheckPassword(AUserName,
211  APassword: string): boolean;
212begin
213  Result := true;
214end;
215
216procedure TContainerRunningContextLocal.SetHostModuleParams(const AHost,
217  AModule, AParams: string);
218var
219  S : string;
220  lFileName : string;
221begin
222  S := StringReplace(AParams,#$D#$A,'<BR>',[rfReplaceAll, rfIgnoreCase]);
223
224  lFileName := format('%s%s',[FContainer.Variable[RS_APPLICATION_PATH],FContainer.Variable[RS_KEY_ClientConfigFileName]]);
225  with TIniFile.Create(lFileName) do
226  begin
227    WriteString('variables',AModule,AParams);
228
229    Free;
230  end;
231
232end;
233
234end.