又过了一周,又是一周琐碎事,周末闲下来继续这个系列的第二部。
使用AgileEAS框架及辅助开发中间件把你的程序做好了,总要发布啊,由于我做的事winform形式的客户端应用,所以自动更新是必不可少的,顺道的,竟然说的是如何在服务器发布,那就一定要说说分布式通信。
分布式通信的好处自然是很多的,但对我来说,在读取oracle数据库的时候不用装客户端、访问外单位服务器的时候可以控制访问源这些都是极好的。
步入正题,通过第一篇的介绍,相信各位对于这个框架的用法肯定有了一定的了解,通过orm、form设计器快速的建立一系列的基本模块,组合了一些基础功能,现在,我们需要把你的程序做成安装包,然后通过SmartUpdate实现客户端的自动更新,首先我们看一下上一篇中的一直没用到的关键文件夹 AppServer
这个文件夹就是需要发布在服务器上的全部了,直接拷到你的服务器上吧,看看里面都有些啥
Bin文件夹承载着EAS平台服务端的核心服务,通过这个服务,客户端才能够完成自动更新、分布式通信的功能,服务的开启方法不多说,在药店的案例和帮助pdf中都有详细的描述,这里我们主要看一下下面这个配置文件:
代码如下:
<?xml version="1.0"?> <configuration> <configSections> <section name="eas" type="EAS.ConfigHandler,EAS.MicroKernel"/> </configSections> <eas> <configurations> <item name="Key" value="Value"/> </configurations> <soa> <config httpPort="8088" tcpPort="6688"/> <services> <service key="EAS.RMIService" type="EAS.Distributed.RMIService,EAS.Distributed.ServiceHost"/> <service key="EAS.UpdateService" type="EAS.SmartUpdate.UpdateService,EAS.Distributed.ServiceHost"/> <service key="EAS.StorageService" type="EAS.FileStorage.StorageService,EAS.Distributed.ServiceHost"/> </services> </soa> <objects> <!--定义数据访问相关组件。--> <object name="DbProvider" assembly="EAS.Data" type="EAS.Data.Access.SqlClientProvider" LifestyleType="Thread"> <property name="ConnectionString" type="string" value="Data Source=192.168.8.81\SQLEXPRESS;Initial Catalog=liantie;User ID=sa;Password=Furnace123" /> </object> <object name="DataAccessor" assembly="EAS.Data" type="EAS.Data.Access.DataAccessor" LifestyleType="Thread"> <property name="DbProvider" type="object" value="DbProvider"/> <property name="Language" type="object" value="TSqlLanguage"/> </object> <object name="OrmAccessor" assembly="EAS.Data" type="EAS.Data.ORM.OrmAccessor" LifestyleType="Thread"> <property name="DataAccessor" type="object" value="DataAccessor"/> </object> <object name="ServiceBridger" assembly="EAS.MicroKernel" type="EAS.Services.LocalServiceBridger" LifestyleType="Thread" /> <object name="Logger" assembly="EAS.MicroKernel" type="EAS.Services.TextLogger" LifestyleType="Singleton"> <property name="Path" type="string" value="E:\程序\AppServer\logs" /> </object> <!--分布式服务上下文参数定义。--> <object name="EAS.Distributed.ServiceContext" type="EAS.Distributed.ServiceContext,EAS.Distributed.ServiceHost" LifestyleType="Singleton"> <property name="MaxMemory" type="int" value="512" /> <property name="StoragePath" type="string" value="E:\程序\AppServer\EMRFiles" /> <property name="EnableLogging" type="bool" value="true" /> </object> <!--ORACLE HBWL--> <object name="DbProvider2" assembly="EAS.Data.Provider" type="EAS.Data.Access.OracleProvider" LifestyleType="Thread"> <property name="ConnectionString" type="string" value="Data Source=JZJL;User Id=query;Password=query" /> </object> <object name="DataAccessor2" assembly="EAS.Data" type="EAS.Data.Access.DataAccessor" LifestyleType="Thread"> <property name="DbProvider" type="object" value="DbProvider2"/> <property name="Language" type="object" value="PLSqlLanguage"/> </object> <object name="OrmAccessor2" assembly="EAS.Data" type="EAS.Data.ORM.OrmAccessor" LifestyleType="Singleton"> <property name="DataAccessor" type="object" value="DataAccessor2"/> </object> <!--ORACLE LEV3--> <object name="DbProvider3" assembly="EAS.Data.Provider" type="EAS.Data.Access.OracleProvider" LifestyleType="Thread"> <property name="ConnectionString" type="string" value="Data Source=LEV3;User Id=ltcx;Password=ltcx2009" /> </object> <object name="DataAccessor3" assembly="EAS.Data" type="EAS.Data.Access.DataAccessor" LifestyleType="Thread"> <property name="DbProvider" type="object" value="DbProvider3"/> <property name="Language" type="object" value="PLSqlLanguage"/> </object> <object name="OrmAccessor3" assembly="EAS.Data" type="EAS.Data.ORM.OrmAccessor" LifestyleType="Singleton"> <property name="DataAccessor" type="object" value="DataAccessor3"/> </object> <object name="TSqlLanguage" assembly="EAS.Data" type="EAS.Data.Linq.TSqlLanguage" LifestyleType="Thread"/> <object name="PLSqlLanguage" assembly="EAS.Data.Provider" type="EAS.Data.Linq.PLSqlLanguage" LifestyleType="Thread"/> </objects> </eas> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> </configuration>
上面的代码中定义了3个数据库连接,大家可以看到,他们分别是默认的MSSql连接,一个HBWL的Oracle数据连接,一个名叫LEV3的Oracle数据连接,在使用的时候,默认的数据库连接可以通过直接使用中间件提供给你的数据查询方式来进行查询,另外两个在使用的时候需要进行ORMDataAccessor的手动指定,代码如下
IDataAccessor da = EAS.Objects.ContainerBuilder.BuilderDefault().GetComponentInstance("DataAccessor3") as IDataAccessor; IOrmAccessor oa = EAS.Objects.ContainerBuilder.BuilderDefault().GetComponentInstance("OrmAccessor3") as IOrmAccessor; public IList<IronMES.Entities.QualityInfo.DD_JCGYSZLCX> DD_JCGYSZLCXList(DateTime dateTimeStart, DateTime dateTimeEnd, string materiel_code, string materiel, string provider) { DataEntityQuery<IronMES.Entities.QualityInfo.DD_JCGYSZLCX> query = DataEntityQuery<IronMES.Entities.QualityInfo.DD_JCGYSZLCX>.Create(); query.DataAccessor = da; query.OrmAccessor = oa; var v = (from item in query where (item.DICTATE_TIME >= dateTimeStart && item.DICTATE_TIME <= dateTimeEnd) && (materiel_code.Trim().Length == 0 || item.MATERIEL_CODE.StartsWith(materiel_code)) && (materiel.Trim().Length == 0 || item.MATERIEL.Contains(materiel)) && (provider.Trim().Length == 0 || item.PROVIDER.Contains(provider)) orderby item.DICTATE_TIME descending select item); return v.ToList(); }
其实,细心的你一定发现了,这个配置文件和你项目中的appstart.config其实是一个类型的文件,它的主要功能就是定义了程序连接数据库的配置信息和服务端的发布端口号之类的东西,直接复制即可(该配置为分布式通信部署的配置)。配置之后就安装服务,win+r建,找到agileeas(服务名),启动,以后如果有新的服务端更新就扔到这个文件夹里即可(粘贴之前停止服务,然后再启动,无需重复安装)。appserver/Bin里面需要放的文件有:Entities类库、Contact接口类库、Service服务类库。
上面的无视,里面存的就是用于SmartUpdate的当前版本信息,下面这个Files是用来存放客户端更新文件的,其实说白了,你就把你自己源码里面Bin/DotNet4.0文件夹里的东西全拷过来即可。以后更新那个在拷哪个。然后用里面的介个工具更新一下config文件夹里面的xml,用法如下
最后,为了顺利的实现自动更新,你还需要修改一个客户端配置文件,下面的文件是重点
在服务器的xClient更新文件夹和你的安装包中这个配置文件需要把Update值设为1(开启更新),但是你自己的项目中也就是Bin/DotNet4.0中记得改成0,不然你每次调试都会更新,那就没法调试了
最后还剩一个客户端的appConfig的设置,下面直接放出分布式通信的配置文件,如果你不想要分布式通信,就按照上面服务端数据库配置改一下你的客户端appconfig即可。。。
分布式通信的客户端配置如下:
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="eas" type="EAS.ConfigHandler,EAS.MicroKernel" /> </configSections> <eas> <configurations> <item name="WorkstationUser" value="Administrator" /> <item name="LastUser" value="Administrator" /> <item name="SmartLogin" value="true" /> <item name="SystemStyle" value="MdiStyle" /> <item name="NavigationStyle" value="TreeStyle" /> <item name="MultiInstance" value="Enabled" /> <item name="EnableSkin" value="true" /> <item name="SkinStyle" value="MacOS" /> </configurations> <objects> <!--分布式通信组件。--> <object name="ServiceBridger" assembly="EAS.Distributed.Client" type="EAS.Distributed.ServiceBridger" LifestyleType="Singleton" > <property name="ServiceName" type="string" value="EAS.RMIService.Service" /> </object> <object name="DataAccessor" assembly="EAS.Distributed.Client" type="EAS.Distributed.DataAccessor" LifestyleType="Singleton" > <property name="ServiceBridger" type="object" value="ServiceBridger" /> <property name="Language" type="object" value="TSqlLanguage"/> </object> <object name="OrmAccessor" assembly="EAS.Distributed.Client" type="EAS.Distributed.OrmAccessor" LifestyleType="Singleton" > <property name="ServiceBridger" type="object" value="ServiceBridger" /> <property name="DataAccessor" type="object" value="DataAccessor" /> </object> <object name="TSqlLanguage" assembly="EAS.Data" type="EAS.Data.Linq.TSqlLanguage" LifestyleType="Thread"/> <!--日志管理--> <object name="Logger" assembly="EAS.MicroKernel" type="EAS.Services.TextLogger" LifestyleType="Singleton"/> <!--资源平台所需组件--> <object name="EAS.Explorer.DAL" assembly="EAS.Explorer.DAL.SQLServer" type="EAS.Explorer.DAL.SQLServer.DALManager" LifestyleType="Singleton" /> <object name="EAS.Explorer.Resource" assembly="IronMES.Res" type="IronMES.Res.Resources" LifestyleType="Singleton" /> </objects> <services> <service name="EAS.RMIService.Service" service-type="WcfService" singleton="true" url="net.tcp://192.168.8.81:6688/eas/services/EAS.RMIService" /> </services> </eas> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EAS.MicroKernel" publicKeyToken="A550803C4CD9DBB5" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="EAS.Data" publicKeyToken="A550803C4CD9DBB5" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
下面看一个分布式访问的例子吧
首先,修改你的GetList()如下,使用ServiceContainer来执行服务端的service,这里注意请把参数传到服务端去,不要再服务端使用linq查询类型。。。也就是DataEntityQuery,这个是不能序列化的哦。。。
public void GetDataList(DateTime dateTimeStart,DateTime dateTimeEnd ,string materiel_code ,string materiel,string provider ) { var query = ServiceContainer.GetService<IOracleService>().DD_JCGYSZLCXList(dateTimeStart,dateTimeEnd ,materiel_code ,materiel,provider ); this.vList = query.ToList(); }
接下来是服务端的Service
public IList<IronMES.Entities.QualityInfo.DD_JCGYSZLCX> DD_JCGYSZLCXList(DateTime dateTimeStart, DateTime dateTimeEnd, string materiel_code, string materiel, string provider) { DataEntityQuery<IronMES.Entities.QualityInfo.DD_JCGYSZLCX> query = DataEntityQuery<IronMES.Entities.QualityInfo.DD_JCGYSZLCX>.Create(); query.DataAccessor = da; query.OrmAccessor = oa; var v = (from item in query where (item.DICTATE_TIME >= dateTimeStart && item.DICTATE_TIME <= dateTimeEnd) && (materiel_code.Trim().Length == 0 || item.MATERIEL_CODE.StartsWith(materiel_code)) && (materiel.Trim().Length == 0 || item.MATERIEL.Contains(materiel)) && (provider.Trim().Length == 0 || item.PROVIDER.Contains(provider)) orderby item.DICTATE_TIME descending select item); return v.ToList(); }
这样就可以实现多数据库连接的分布式通信部署了。。。今天总觉的莫名其妙不太会讲话了。。。哪里说的不明白的各位及时跟贴或联系我,我会尽量给各位解答的,要是哪里说的不对欢迎各位大神的批评指正!