private void CreateScriptHandler(string MainScript) { // Selecting service provider... string SPProviderFileName; AppDomain ad = AppDomain.CreateDomain("SP Files Search"); { System.Type spsType = typeof(ServiceProviders); ServiceProviders sps = (ServiceProviders)ad.CreateInstanceAndUnwrap(spsType.Assembly.FullName, spsType.Namespace + "." + spsType.Name); sps.FindProviders(System.Windows.Forms.Application.StartupPath); this.opt.SetSPTypesDinamically(sps.GetProviders()); SPProviderFileName = sps.GetProviderFileName(this.opt.ServiceProviderType); } AppDomain.Unload(ad); if (SPProviderFileName == null) { TraceOut.Put("No Service provider is found - Exiting!!"); return; } this.SPType = ServiceProviders.GetProviderType(SPProviderFileName); TraceOut.Put("Creating " + "\"" + MainScript + "\"" + " script handler..."); ScriptHandler sh = new ScriptHandler(MainScript, this.ServiceName, this.SPType, this.opt); this.ActiveScripts.Add(sh); this.spStatus.Status = "OK"; this.spStatus.AdditionalInfo = "Initializing"; sh.SPStatusChanged += new Diacom.APCService.OnSPStatusChange(SPStatusChangedHandler); TraceOut.Put("Script handler for " + "\"" + MainScript + "\"" + " created."); sh.Start(); }
private void SPStatusChangedHandler(object sender, SPStatusChangedEventArgs data) { TraceOut.Put("SPStatusChanged Event arrived. Status = " + data.spStatus.Status + ". Info = " + data.spStatus.AdditionalInfo); this.spStatus.Status = data.spStatus.Status; this.spStatus.AdditionalInfo = data.spStatus.AdditionalInfo; if (!spStatus.Status.ToUpper().Equals("OK")) { ScriptHandler currentSH = (ScriptHandler)sender; TraceOut.Put("Restarting connection: disposing objects, creating timer..."); currentSH.SPStatusChanged -= new Diacom.APCService.OnSPStatusChange(SPStatusChangedHandler); this.ActiveScripts.Remove(currentSH); currentSH.Dispose(); this.RestartTimer = new System.Threading.Timer(new System.Threading.TimerCallback(this.RestartTimerCallbackEntry), currentSH.FileName, 20000L, System.Threading.Timeout.Infinite); } }