/client/Container/src/uCnrRunningCtx.pas

http://drcp.googlecode.com/ · Pascal · 234 lines · 166 code · 59 blank · 9 comment · 0 complexity · cf68d24b9d578b22e506bd638db5dd76 MD5 · raw file

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