我在开发中有一个基于实体框架的多层项目,数据访问和业务逻辑最终转移到基于C#的服务器应用程序. (数据访问已经迁移)客户端在Delphi 2010中.
我已经使用数据传输对象在客户端和服务器之间传递信息,但是有必要从Delphi实现我自己的更改跟踪.我最初是通过继承wsdl中的Dtos并“覆盖”getter和setter来实现的.
wsdl import中的基类(无法真正控制):
// ************************************************************************ // // XML : DtoCONTAINER_JNL,global,<complexType> // namespace : http://k3scs.com/WCF // ************************************************************************ // DtoCONTAINER_JNL = class(DtoBase) private FJNL_ID: Integer; FJNL_TYPE_ID: Integer; FJNL_DATE: TXSDateTime; published property JNL_ID: Integer read FJNL_ID write FJNL_ID; property JNL_TYPE_ID: Integer read FJNL_TYPE_ID write FJNL_TYPE_ID; property JNL_DATE: TXSDateTime read FJNL_DATE write FJNL_DATE;
派生类:
TDtoCONTAINER_JNL = class(DtoCONTAINER_JNL,IDto) private Fname : string; FReferenceCounted : boolean; _isNew : boolean; FModifIEd : boolean; FJNL_ID : integer; FJNL_TYPE_ID : integer; FJNL_DATE : TDateTime; public property JNL_ID : integer read FJNL_ID write SetJNL_ID; property JNL_TYPE_ID : integer read FJNL_TYPE_ID write SetJNL_TYPE_ID; property JNL_DATE : TDateTime read GetJNL_DATE write SetJNL_DATE;
典型的setter方法:
procedure TDtoCONTAINER_JNL.SetJNL_DATE(const value : TDateTime);begin ChangedPropertIEs:= DtoGenerics.ChangeTracker('JNL_DATE',value,inherited JNL_DATE,self.IsLoaded,ChangedPropertIEs); inherited JNL_DATE := DtoGenerics.GetXsDate(value);end;
典型的吸气方法:
function TDtoCONTAINER_JNL.GetJNL_DATE : TDateTime;begin Result := DtoGenerics.GetDate(inherited JNL_DATE);end;
无论何时设置属性,更改跟踪器都会将此属性名称添加到已更改属性的列表中以返回到服务器.这样可以使更新语句具有针对性和高效性.问题是每个getter / setter实际上使得派生类与base不兼容,也就是说,多态性被破坏,并且cast不再按预期工作.
上面的类是根据相应的数据库表/实体从C#中的t4模板生成的,因此更改100多个类应该不是问题.
有人对这个有经验么?
任何建议将不胜感激.
编辑
Wsdl导入器主要由使用字符串格式的常量或类似的东西组成,以创建复杂类型的Delphi等价物.我做了以下更改,使用类似的常量名称来轻松识别我的更改,以及将它们放在与预先存在的代码相关的位置.
理想情况下,我会完全摆脱继承,只是在wsdl中使用我的类的修改版本,因为即使我将它转换回Dto类,我仍然无法提交修改后的Tdto,因为Web服务拒绝它带有消息比如“期待DtoObject,但得到了undtoUnit.TdtoObject”.
因此,我使用继承来处理ArrayOfObjects到TList之间的转换,反之亦然.
以下是我记忆中的最佳变化:
// In WSDlimpConst// I changed sRemoteClassDeclPas constant value of 'private' to 'proctected'// Then I added these after SUnitinitsTrackerDec = sTrackerProcPrefix+ sTrackerProcArgs + slineBreak;sTrackerProc = sTrackerDec + 'begin' + slineBreak + ' Result:= nProps;' + slineBreak + ' if (_loaded) and (oval <> pVal) then' + slineBreak + ' begin ' + slineBreak + ' Result := TrackChange(pname,nProps);' + slineBreak + ' end;' + slineBreak + 'end;' + slineBreak ;sTracker2Dec = sTrackerProcPrefix+ sTracker2ProcArgs + slineBreak;sTracker2Proc = sTracker2Dec + 'begin' + slineBreak + ' Result:= nProps;' + slineBreak + ' if (_loaded) and (oval <> DateTimetoXSDateTime(pVal)) then' + slineBreak + ' begin ' + slineBreak + ' Result := TrackChange(pname,nProps);' + slineBreak + ' end;' + slineBreak + 'end;' + slineBreak ;sTracker3Dec = sTrackerProcPrefix+ sTracker3ProcArgs + slineBreak;sTracker3Proc = sTracker3Dec + 'begin' + slineBreak + ' Result:= nProps;' + slineBreak + ' if nProps = '''' then' + slineBreak + ' nProps := pname' + slineBreak + ' else' + slineBreak + ' nProps := pname + '','' + nProps;' + slineBreak + ' Result:= nProps;' + slineBreak + 'end;' + slineBreak ;sTracker4Dec = sTrackerProcPrefix+ sTracker4ProcArgs + slineBreak;sTracker4Proc = sTracker4Dec + 'begin' + slineBreak + ' Result:= nProps;' + slineBreak + ' if (_loaded) and (oval <> pVal) then' + slineBreak + ' begin ' + slineBreak + ' Result := TrackChange(pname,nProps);' + slineBreak + ' end;' + slineBreak + 'end;'//Added my own setters:sRemoteClassSetterImplPas = 'procedure %0:s.Set%1:s(const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + 'end;' + slineBreak;sRemoteClassSetterImplPas2= 'procedure %0:s.Set%1:s(const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + ' F%1:s_SpecifIEd := True;' + slineBreak + 'end;' + slineBreak;sRemoteClassSetterImplPas3 = 'procedure %0:s.Set%1:s(const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' ChangedPropertIEs:= TrackChange(''%1:s'',A%2:s,F%1:s,ChangedPropertIEs);' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + 'end;' + slineBreak;sRemoteClassSetterImplPas4 = 'procedure %0:s.Set%1:s(const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' ChangedPropertIEs:= TrackChange(A%2:s,''%1:s'',ChangedPropertIEs);' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + 'end;' + slineBreak;// And for indexed propertIEssRemoteClassSetterImplPasIDx2= 'procedure %0:s.Set%1:s(Index: Integer; const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + ' F%1:s_SpecifIEd := True;' + slineBreak + 'end;' + slineBreak;sRemoteClassSetterImplPasIDx3 = 'procedure %0:s.Set%1:s(Index: Integer; const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' ChangedPropertIEs:= TrackChange(''%1:s'',ChangedPropertIEs);' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + 'end;' + slineBreak;sRemoteClassSetterImplPasIDx4 = 'procedure %0:s.Set%1:s(Index: Integer; const A%2:s: %2:s);' + slineBreak + 'begin' + slineBreak + ' ChangedPropertIEs:= TrackChange(A%2:s,ChangedPropertIEs);' + slineBreak + ' F%1:s := A%2:s;' + slineBreak + 'end;' + slineBreak;// Added these before the SImplDecl constant:sIntfFactoryDecl = '_di_%0:s Get%0:s(bool useWSDL=false,AnsiString addr="",ThttpRIO* httpRIO=0);' + slineBreak + slineBreak;sTrackerProcPrefix = 'function TrackChange';sTrackerProcArgs = '(const pname: string; pVal,oval: variant; _loaded: boolean; nProps: string): string; overload';sTracker2ProcArgs = '(const pname: string; pVal: TDateTime; oval: txsdateTime; _loaded:boolean; nProps: string): string; overload;';sTracker3ProcArgs = '(const pname: string; nProps: string): string; overload;';sTracker4ProcArgs = '(pVal,oval: TByteDynArray; const pname: string; _loaded: boolean; nProps: string): string; overload';sIntfTrackDecl = sTrackerProcPrefix + sTrackerProcArgs+ slineBreak;sIntfTrack2Decl = sTrackerProcPrefix + sTracker2ProcArgs+ slineBreak;sIntfTrack3Decl = sTrackerProcPrefix + sTracker3ProcArgs+ slineBreak;sIntfTrack4Decl = sTrackerProcPrefix + sTracker4ProcArgs+ slineBreak;// Then in WSDLPasWriter I added my new constant arrays:SetterImpl2:array[Boolean] of string = (sRemoteClassSetterImplPas2,sRemoteClassSetterImplPasIDx2);SetterImpl3:array[Boolean] of string = (sRemoteClassSetterImplPas3,sRemoteClassSetterImplPasIDx3);SetterImpl4:array[Boolean] of string = (sRemoteClassSetterImplPas4,sRemoteClassSetterImplPasIDx4);// then modifIEd the setter section in 'WriteComplexTypeClass'{ Setter }if UseSetGets or GenspecifIEdSupport(Member) thenbeginif GenspecifIEdSupport(Member) thenbegin WriteFmt(SetterImpl2[HasIndexDecl(Member)],[WSDLType.Langname,Member.Langname,Member.DataType.Langname])endelsebegin if (Containsstr(Basename,'Dto')) and (not Containsstr(Member.DataType.Langname,'XS')) and (not Containsstr(Member.DataType.Langname,'ArrayOf')) then if (Containsstr(Member.DataType.Langname,'TByteDynArray')) then WriteFmt(SetterImpl4[HasIndexDecl(Member)],Member.DataType.Langname]) else WriteFmt(SetterImpl3[HasIndexDecl(Member)],Member.DataType.Langname]) else WriteFmt(SetterImpl1[HasIndexDecl(Member)],Member.DataType.Langname]);end;// at WriteInterfaceEnd I addedWriteFmt(sIntfTrackDecl,[]);WriteFmt(sIntfTrack2Decl,[]);WriteFmt(sIntfTrack3Decl,[]);WriteFmt(sIntfTrack4Decl,[]);// at WriteInterfaceBegin I addedWriteLn(sTrackerProc,[]);WriteLn(sTracker2Proc,[]);WriteLn(sTracker3Proc,[]);WriteLn(sTracker4Proc,[]);// finally I changed the wsdlimp dpr and replaced 'AnsiString' (or 'wIDestring' I can't remember) with 'string'解决方法 如果我没弄错的话,WSDL to Delphi转换器源代码是Delphi企业及更高版本的一部分(在wsdlimporter目录中称为WSDlimp.dpr).
我会调整它直接生成自己的类.
总结以上是内存溢出为你收集整理的我可以对从Delphi 2010中的wsdl导入类派生的类实现更改跟踪吗?全部内容,希望文章能够帮你解决我可以对从Delphi 2010中的wsdl导入类派生的类实现更改跟踪吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)