`
csstome
  • 浏览: 1522192 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

TEcoForumServices 类(繁体版4月15日博客)

阅读更多

TEcoForumServices

有位大陆的读者写信跟我说他在《Delphi MDA/DDA程序设计——使用ECO》一书的CD中找不到TEcoForumServices 类的源代码,虽然我记得我已经把整本书下的Source打包到CD中了,而且TEcoForumServices 是一个很简易的类.Anyway,如果有人也需要这个类的源代码,下面就是它完整的列表。

unit EcoForumWrapperServices;

interface

uses System.Web, ECOForumWebAppDemo1EcoSpace, PECOForumUnit,
Borland.Eco.Handles, Borland.Eco.ObjectRepresentation,
System.Web.Security, Borland.Eco.Services;

type
TEcoForumServices = class
private
{ Private Declarations }
public
class function CreateMemeber(mySpace : Borland.Eco.Handles.EcoSpace) : ForumMember;
class function getForumSite(objl : IObjectList) : ForumSite;
class function MemberLogin(mySpace : Borland.Eco.Handles.EcoSpace; const UserId : string; const sPassword : string) : ForumMember;
end;

implementation


{ TEcoForumServices }

class function TEcoForumServices.CreateMemeber(mySpace : Borland.Eco.Handles.EcoSpace): ForumMember;
begin
Result := ForumMember.Create(mySpace);
end;

class function TEcoForumServices.getForumSite(objl: IObjectList): ForumSite;
var
obj : System.Object;
begin
Result := HttpContext.Current.Session['ForumSite'] as ForumSite;

if (Result = nil) then
begin
obj := objl[0].AsObject;
Result := obj as ForumSite;
HttpContext.Current.Session['ForumSite'] := Result;
end;
end;

class function TEcoForumServices.MemberLogin(mySpace : Borland.Eco.Handles.EcoSpace;
const UserId, sPassword: string): ForumMember;
const
selectUser = 'ForumMember.allInstances->select( M | (M.Name = ''{0}'') and (M.Password = ''{1}'') )->First';
var
enPW : string;
userOCL : string;
OCLResult : IElement;
oclService : IOclService;
begin
enPW := FormsAuthentication.HashPasswordForStoringInConfigFile(sPassword,'md5');
oclService := mySpace.GetEcoService(typeof(IOclService)) as IOclService;
userOCL := System.String.Format(selectUser,UserId,enPW);
OCLResult := oclService.Evaluate(userOCL);
Result := nil;
if (OCLResult.GetAsCollection.Count <> 0) then
Result := OCLResult.GetAsCollection.Item[0].AsObject as ForumMember;
HttpContext.Current.Session['ForumMember'] := Result;
end;

end.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics