示例#1
0
 /// <summary>
 /// Start (or Connect) event handler.
 /// <para>There are 2 instances of the process control control.</para>
 /// <para>When context is null, this function handles the Start event for the local TPE.</para>
 /// <para>When context is not null, this function handles the Connect event for a remote TPE.</para>
 /// </summary>
 /// <param name="context">Indicates to handler method whether it is from the local or remote TPE.</param>
 public void Start(object context)
 {
     // Start Event from local TPE
     if (context == null)
     {
         // ensure that this tpe host is unique host session base on engineId
         // When the Overwrite parameter of appSession.Start is false
         // we will receive an error message when there is an existing record.
         // As long as we receive an error message, the session already exists
         // so user will be presented with dialog box.
         // When user confirms, then we call function with Overwrite = true;
         string sessionExists = _appSession.Start(_configSettings, "Application Startup", false, _hostEndpointAddress);
         while (!string.IsNullOrEmpty(sessionExists))
         {
             if (MessageBox.Show(sessionExists + " Press OK to reset; CANCEL to stop."
                                 , "Session Startup Conflict", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
             {
                 return;
             }
             // otherwise reset session record (remove existing)
             else
             {
                 sessionExists = _appSession.Start(_configSettings
                                                   , "Application Startup After Session Conflict Reset"
                                                   , true
                                                   , _hostEndpointAddress); // host address of this local TPE to be used for other applications to connect to.
             }
         }
         // instantiate this application's local TPE
         _localTpe = new TaskProcessing.TaskProcessingEngine(_daMgr
                                                             , _taskAssemblyPath
                                                             , _engineId
                                                             , _configId
                                                             , _appSession.SignonControl
                                                             , _maxTasks
                                                             , _hostEndpointAddress);
         // start the TPE
         _localTpe.Start();
         // display status
         Status();
     }
     else
     {
         // WCF Connect
         pagingTableRemoteHosts.IsEnabled = false;
         EndpointAddress remoteAddress = new EndpointAddress(string.Format("{0}{1}", _hostEndpointAddress
                                                                           , _engineId));
         WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
         _remoteTpe = new RemoteHostClient(binding, remoteAddress);
         RemoteHostResponse response = _remoteTpe.Connect(_engineId);
         if (response.Success)
         {
             RemoteHostResponseString configSettingsResponse = _remoteTpe.ConfigSettings();
             RemoteHostResponseString dynamicSettingsReponse = _remoteTpe.DynamicSettings();
             if (configSettingsResponse.Success && dynamicSettingsReponse.Success)
             {
                 Dictionary <string, string> configSettings = (Dictionary <string, string>)
                                                              Core.Functions.Deserialize <Dictionary <string, string> >
                                                                  (configSettingsResponse.ReturnValue);
                 Dictionary <string, string> dynamicSettings = (Dictionary <string, string>)
                                                               Core.Functions.Deserialize <Dictionary <string, string> >
                                                                   (dynamicSettingsReponse.ReturnValue);
                 DisplayRemoteTpeConfiguration(configSettings, dynamicSettings);
             }
             else
             {
                 remoteTpeStatus.Status = string.Format("{0}{1}{2}", configSettingsResponse.ErrorMsg
                                                        , Environment.NewLine, dynamicSettingsReponse.ErrorMsg);
             }
         }
         else
         {
             HostConnectionAborted(response.ErrorMsg);
         }
     }
 }