Exemple #1
0
 // This is more reliable than OnPluginExited as this even handler is wired up before the process
 // has even started, while OnPluginExited is wired up after.
 private void OnPluginProcessExited(object sender, IPluginProcess pluginProcess, string pluginId)
 {
     if (_logger.IsEnabled)
     {
         _logger.Write(new PluginInstanceLogMessage(_logger.Now, pluginId, PluginState.Exited, pluginProcess.Id));
     }
 }
        /// <summary>
        /// Instantiates a new <see cref="StandardOutputReceiver" /> class.
        /// </summary>
        /// <param name="process">A plugin process.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="process" /> is <c>null</c>.</exception>
        public StandardOutputReceiver(IPluginProcess process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            _process = process;
        }
Exemple #3
0
        public PluginManager(ICatapultEngineConfig engineConfig, IPluginProcess pluginProcess, ILogger <PluginManager> logger)
        {
            PluginLocations = new List <string>()
            {
                engineConfig.PluginsLocation
            };

            _pluginProcess = pluginProcess;

            _logger = logger;
        }
Exemple #4
0
        public PluginManager(Dictionary <string, List <PluginItem> > plugins, ICatapultEngineConfig engineConfig, IPluginProcess pluginProcess, ILogger <PluginManager> logger)
        {
            _plugins = plugins;

            PluginLocations = new List <string>()
            {
                engineConfig.PluginsLocation
            };

            _pluginProcess = pluginProcess;

            _logger = logger;
        }
        internal Plugin(string filePath, IConnection connection, IPluginProcess process, bool isOwnProcess, TimeSpan idleTimeout, string id)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(filePath));
            }

            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            if (idleTimeout < Timeout.InfiniteTimeSpan)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(idleTimeout),
                          idleTimeout,
                          Strings.Plugin_IdleTimeoutMustBeGreaterThanOrEqualToInfiniteTimeSpan);
            }

            Name           = Path.GetFileNameWithoutExtension(filePath);
            FilePath       = filePath;
            Id             = id ?? CreateNewId();
            Connection     = connection;
            _process       = process;
            _isOwnProcess  = isOwnProcess;
            _idleTimerLock = new object();
            _idleTimeout   = idleTimeout;

            if (idleTimeout != Timeout.InfiniteTimeSpan)
            {
                _idleTimer = new Timer(OnIdleTimer, state: null, dueTime: idleTimeout, period: Timeout.InfiniteTimeSpan);
            }

            Connection.Faulted         += OnFaulted;
            Connection.MessageReceived += OnMessageReceived;

            if (!isOwnProcess)
            {
                process.Exited += OnExited;
            }
        }
        public void Exited_WhenProcessExits_Fires()
        {
            ProcessStartInfo startInfo = CreateProcessStartInfo();

            using (var exitedEvent = new ManualResetEventSlim(initialState: false))
                using (var pluginProcess = new PluginProcess(startInfo))
                {
                    IPluginProcess argument = null;

                    pluginProcess.Exited += (object sender, IPluginProcess e) =>
                    {
                        argument = e;

                        exitedEvent.Set();
                    };

                    pluginProcess.Start();

                    exitedEvent.Wait();

                    Assert.Same(pluginProcess, argument);
                }
        }
 /// <summary>
 /// Instantiates a new <see cref="Plugin" /> class.
 /// </summary>
 /// <param name="filePath">The plugin file path.</param>
 /// <param name="connection">The plugin connection.</param>
 /// <param name="process">The plugin process.</param>
 /// <param name="isOwnProcess"><c>true</c> if <paramref name="process" /> is the current process;
 /// otherwise, <c>false</c>.</param>
 /// <param name="idleTimeout">The plugin idle timeout.  Can be <see cref="Timeout.InfiniteTimeSpan" />.</param>
 /// <exception cref="ArgumentException">Thrown if <paramref name="filePath" /> is either <c>null</c>
 /// or an empty string.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="connection" /> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="process" /> is <c>null</c>.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="idleTimeout" /> is smaller than
 /// <see cref="Timeout.InfiniteTimeSpan" />.</exception>
 public Plugin(string filePath, IConnection connection, IPluginProcess process, bool isOwnProcess, TimeSpan idleTimeout)
     : this(filePath, connection, process, isOwnProcess, idleTimeout, id : null)
 {
 }
 private void OnExited(object sender, IPluginProcess pluginProcess)
 {
     Exited?.Invoke(this, new PluginEventArgs(this));
 }
 protected MessageDialogResult ProcessUnauthorizedAccessException(ChangeItemErrorEventArgs e)
 {
     MessageDialogResult none = MessageDialogResult.None;
     if ((e.Error is UnauthorizedAccessException) && e.CanElevate)
     {
         IElevatable item = e.Item as IElevatable;
         if ((item == null) || !item.CanElevate)
         {
             return none;
         }
         bool checkBoxChecked = true;
         none = MessageDialog.Show(this, string.Format(Resources.sAskElevateOperationPermissions, e.Item.FullName), Resources.sWarning, Resources.sDoThisForAll, ref checkBoxChecked, new MessageDialogResult[] { MessageDialogResult.Shield, MessageDialogResult.Skip, MessageDialogResult.Cancel }, MessageBoxIcon.Exclamation, MessageDialogResult.Shield);
         if (none == MessageDialogResult.Shield)
         {
             if (checkBoxChecked)
             {
                 this.AutoElevateProcess = new ElevatedProcess(true, TimeSpan.FromSeconds(9.0));
             }
             if (item.Elevate(this.AutoElevateProcess ?? new ElevatedProcess()))
             {
                 return MessageDialogResult.Retry;
             }
             if (this.AutoElevateProcess != null)
             {
                 this.AutoElevateProcess.Shutdown();
             }
             this.AutoElevateProcess = null;
             return MessageDialogResult.None;
         }
         if ((none == MessageDialogResult.Retry) && checkBoxChecked)
         {
             none = MessageDialogResult.SkipAll;
         }
     }
     return none;
 }
 private void Form_Disposed(object sender, EventArgs e)
 {
     this.DetachEvents();
     if (this.AutoElevateProcess != null)
     {
         this.AutoElevateProcess.KeepAlive = false;
     }
     this.AutoElevateProcess = null;
     this.WorkerTrace.Close();
 }
 public bool Elevate(IPluginProcess process)
 {
     if (process == null)
     {
         throw new ArgumentNullException();
     }
     if (RemotingServices.IsTransparentProxy(this.Proxy))
     {
         return false;
     }
     IPluginActivator activator = process as IPluginActivator;
     if (activator == null)
     {
         return false;
     }
     if (!(process.IsAlive || process.Start()))
     {
         return false;
     }
     this.FProxy = activator.Create<IFileProxy>("filesystemproxy");
     return true;
 }