예제 #1
0
        private bool StartProcess()
        {
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

            info.CreateNoWindow = true;
            info.ErrorDialog = false;
            info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            info.WorkingDirectory = settings.WorkingDirectory;
            info.UseShellExecute = false; // Documents can also be opened
            info.Arguments = settings.Arguments;
            info.FileName = settings.Executable;

            info.LoadUserProfile = true;
            info.UserName = settings.Username;
            info.Password = settings.Password.SecureString;

            info.RedirectStandardError = info.RedirectStandardInput = info.RedirectStandardOutput = true;

            StopProcess();

            Logger.Info("Starting server " + GetName());
            Process newProcess = new Process();
            try
            {
                newProcess.StartInfo = info;
                if (newProcess.Start())
                {
                    this.Process = newProcess;
                    return true;
                }
            }
            catch (ObjectDisposedException ode)
            {
                Logger.Error("Object unexpectedly disposed.", ode);
                throw new SC.Interfaces.SCException(ode);
            }
            catch (ArgumentException ae)
            {
                Logger.Error("Invalid argument used.", ae);
                throw new SC.Interfaces.SCException(ae);
            }
            catch (InvalidOperationException ioe)
            {
                Logger.Error("Could not start process: " + settings.Executable + " " + settings.Arguments, ioe);
            }
            catch (System.ComponentModel.Win32Exception w32e)
            {
                Logger.Error("Unexpected error occurred.", w32e);
            }
            return false;
        }
예제 #2
0
 private void StopProcess()
 {
     if (Process != null)
     {
         if (!Process.HasExited)
         {
             Logger.Info("Stopping server " + GetName() + ".");
             Process.Kill();
             Process.WaitForExit(1000);
         }
         Process.Close();
         Process.Dispose();
         Process = null;
     }
 }
예제 #3
0
        protected override void Initialize()
        {
            object set = settProvider.RestoreSettings(settings.GetType());
            if (set != null)
                settings = (ServerSettings)set;

            Logger.Info("Loading plugins...");
            foreach (string plugin in settings.Plugins)
                LoadPlugin(plugin);

            if (settings.AcquireOnStart)
            {
                Process = ProcessHelper.GetProcess(settings.EndPoint);
                if (Process != null)
                    Logger.Info("Process acquired...");
                else
                    Logger.Info("Process not found...");
            }

            lastIteration = DateTime.Now;
        }