Public void run ()
{
// Moab Initialization
Offlineblockbuilder myofflineblockbuilder = offlineblockbuilder. instance;
// Register offline and online events
Myofflineblockbuilder. connectionmanager. connectionstatechangedevent ++ =
New connectionstatechangedeventhandler (
This. connectionmanagerconnectionstatechangedevent );
// Handle registration errors
Failsafeserviceagent cuowuchuli = myofflineblockbuilder. failsafeserviceagent;
Cuowuchuli. errorevent + = new methodexecutionfailurereporteventhandler (failsafeserviceagenterrorevent );
// Start Moab
Myofflineblockbuilder. Start ();
// Force launch
Myofflineblockbuilder. connectionmanager. goonline ();
// Force offline
Myofflineblockbuilder. connectionmanager. gooffline ();
// Send a request, which does not return data
String chengxuzujianmingcheng = "fpms_xiang ";
String wangluodaibiaoleiming = "JSW. FPMS. Xiang. yewu. clswangluodaili ";
String fangfaming = "fangfaming ";
String xiangyinghanshu = "xiangyinghanshu ";
Guid = guid. newguid ();
String gengxinshuju = "gengxinshuju ";
// Program component name
String onlineproxyassemblyname = chengxuzujianmingcheng;
// Indicates the absolute name of the class.
String onlineproxyclassname = wangluodaibiaoleiming;
// Indicates the method name of the network.
String onlineproxymethodname = fangfaming;
// Response method of the business representative
String specificserviceagentmethodtobeinvoked = xiangyinghanshu;
Onlineproxycontext onlineproxymethodcontext = new onlineproxycontext (onlineproxyassemblyname,
Onlineproxyclassname,
Onlineproxymethodname );
Serviceagentcontext specificserviceagentcontext = new serviceagentcontext (specificserviceagentmethodtobeinvoked );
Payload messagetoenqueue = new payload (onlineproxymethodcontext, guid,
Specificserviceagentcontext, gengxinshuju );
// Request data to the queue
Myofflineblockbuilder. payloadconsumer. enqueue (messagetoenqueue );
}
/// <Summary>
/// Request submission
/// </Summary>
Public payload xuqiutijiao (payload qingqiu)
{
Try
{
Dataset shuju = (Dataset) qingqiu. requestdata;
// Fuwu. xuqiutijiao (shuju );
}
Catch (exception E)
{
// Qingqiu. recordfailure (E );
}
Return qingqiu;
}
/// <Summary>
/// Put the data in the network service into the request
/// </Summary>
/// <Param name = "shuju"> data returned by the network service </param>
/// <Returns> request: playload </returns>
Private payload qingqiuchuli (payload qingqiu, dataset shuju)
{
Referencecachedatapayload huancunqingqiu = qingqiu as referencecachedatapayload;
Try
{
// Obtain Network Service Data
Huancunqingqiu. updatedatatoreturn (shuju );
// Get the Offline Control instance and operate the cached data
Offlineblockbuilder lixianshili = offlineblockbuilder. instance;
//
If (! (Huancunqingqiu. isrefreshmessage () & huancunqingqiu. datadefinition. Dirty = true ))
{
Try
{
// Store data in the reference cache data block
Lixianshili. referencedatacache. Store (huancunqingqiu. datadefinition,
Huancunqingqiu. Results );
}
Catch (exception genexception)
{
Throw genexception;
}
}
// Set the data to clean
Lixianshili. referencedatacache. markasclean (huancunqingqiu. datadefinition. originalkey );
Return huancunqingqiu;
}
Catch (exception genexception)
{
// Record errors in the request
Huancunqingqiu. recordfailure (genexception );
Return huancunqingqiu;
}
}
/// <Summary>
/// Error handling function
/// </Summary>
Private void failsafeserviceagenterrorevent (Object sender, methodexecutionfailurereporteventargs ARGs)
{
String cuowuxinxi = "";
// Handle errors
If (ARGs. payload. failurereason. GetType () = typeof (system. Web. Services. Protocols. soapexception ))
{
System. Text. regularexpressions. matchcollection MC = system. Text. regularexpressions. RegEx. Matches (
Args. payload. failurereason. Message,
"---> ([^:] + ):");
If (MC. Count> = 1 & Mc [0]. Groups [1]. value = "system. Data. dbconcurrencyexception ")
{
Cuowuxinxi + = "data synchronization error ";
}
}
Cuowuxinxi + = args. payload. failurereason. message;
// Clsrizhichuli. jilurizhi (cuowuxinxi );
// Resend the request as needed
}
/// <Summary>
/// Register offline and online events
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "ARGs"> </param>
Private void connectionmanagerconnectionstatechangedevent (Object sender,
Connectionstatechangedeventargs ARGs)
{
MessageBox. Show ("......" + args. currentstate. tostring ());
Microsoft. applicationblocks. smartclient. offline. connectionstate wangluozhuangtai = args. currentstate;
If (Microsoft. applicationblocks. smartclient. offline. connectionstate. Online = wangluozhuangtai) // It is online
{
// Shifoulianjie = true;
// Start component update
// This. kaishizujiangengxin ();
}
Else // not online
{
// Shifoulianjie = false;
// Stop component update
// This. tingzhizujiangengxin ();
}
// Set the interface status bar
// This. jiemian. lianjiezhuangtai (this. shifoulianjie );
// Set the data update clock running on the Interface
// This. jiemian. shezhitimer (this. shifoulianjie );
}
/// <Summary>
/// Requirement Query
/// </Summary>
Public payload xuqiuchaxun (payload qingqiu)
{
// Query requirements
Return qingqiuchuli (qingqiu, new dataset ());
}
/// <Summary>
/// Obtain basic data
/// </Summary>
Public payload huodejibenshuju (payload qingqiu)
{
// Query requirements
Return qingqiuchuli (qingqiu, new dataset ());
}
/// <Summary>
/// Send a request that returns data
/// </Summary>
/// <Param name = "fangfaming"> the network to be called indicates the method name. </param>
/// <Param name = "xiangyinghanshu"> Method Name of the Response Request </param>
/// <Param name = "shujujianzhi"> return the data key value </param>
/// <Param name = "guoqishijian"> expiration time </param>
Private void fasongqingqiuhuodeshuju (string fangfaming, string xiangyinghanshu,
Int guoqishijian, string shujujianzhi)
{
String chengxuzujianmingcheng = "chengxuzujianmingcheng ";
String wangluodaibiaoleiming = "wangluodaibiaoleiming ";
String fangfaming1 = "fangfaming ";
String xiangyinghanshu1 = "xiangyinghanshu ";
Int guoqishijian1 = 1;
String shujujianzhi1 = "shujujianzhi ";
Guid = guid. newguid ();
// Program component name
String onlineproxyassemblyname = chengxuzujianmingcheng;
// Indicates the absolute name of the class.
String onlineproxyclassname = wangluodaibiaoleiming;
// Indicates the method name of the network.
String onlineproxymethodname = fangfaming1;
// Response method of the business representative
String specificserviceagentmethodtobeinvoked = xiangyinghanshu1;
// Expiration time
Int absoluteexpirationtime = guoqishijian1;
// Data cache key value
String cachekey = shujujianzhi1;
Onlineproxycontext onlineproxymethodcontext = new onlineproxycontext (onlineproxyassemblyname,
Onlineproxyclassname,
Onlineproxymethodname );
Serviceagentcontext specificserviceagentcontext = new serviceagentcontext (
Specificserviceagentmethodtobeinvoked );
Referencedatadefinition refdatadefination = new referencedatadefinition (cachekey,
Absoluteexpirationtime,
Onlineproxymethodcontext );
// Send the request
Offlineblockbuilder lixiankongzhi = offlineblockbuilder. instance;
Lixiankongzhi. dataloadermanager. loaddata (guid,
Specificserviceagentcontext,
Refdatadefination );
}
/// <Summary>
/// Dynamically update the program
/// </Summary>
Public void downloadassembly ()
{
// Obtain the muab
Applicationupdatemanager gengxinkongzhi = new applicationupdatemanager ();
// Starts the download event.
Gengxinkongzhi. downloadstarted + = new updateractioneventhandler (chengxuxiazaikaishi );
// Download file verification success event
Gengxinkongzhi. filesvalidated + = new updateractioneventhandler (chengxuwenjiankeyiyunxing );
// Detects events of the new version.
Gengxinkongzhi. updateavailable + = new updateractioneventhandler (chengxuzujiankeyixiazai );
// Events after the download is complete
Gengxinkongzhi. downloadcompleted + = new updateractioneventhandler (chengxuxiazaiwancheng );
// Start component update
Gengxinkongzhi. startupdater ();
// Stop the component Update Service
Gengxinkongzhi. stopupdater ();
}
/// <Summary>
/// Download and update the program
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void chengxuxiazaikaishi (Object sender, updateractioneventargs E)
{
}
/// <Summary>
/// Download file verification success event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void chengxuwenjiankeyiyunxing (Object sender, updateractioneventargs E)
{
}
/// <Summary>
/// Detect new version events
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void chengxuzujiankeyixiazai (Object sender, updateractioneventargs E)
{
}
/// <Summary>
/// Events after the download is complete
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void chengxuxiazaiwancheng (Object sender, updateractioneventargs E)
{
}