Пример #1
0
 public ClinicalButtonViewModel(PanaceaServices core, ClinicalButtonsPlugin plugin, ActionButtonModel actionButton)
 {
     this.core         = core;
     this.actionButton = actionButton;
     Name        = actionButton.Name;
     PluginName  = actionButton.Settings.PluginName;
     ImgUrl      = core.HttpClient.RelativeToAbsoluteUri(actionButton.ImgUrl);
     OpenCommand = new RelayCommand(args =>
     {
         plugin.OpenItem(actionButton);
     });
 }
        public async Task ProcessStart(ActionButtonModel action)
        {
            if (_action != null)
            {
                throw new InvalidOperationException("Cannot start a new process if another one is running");
            }
            _action = action;
            if (!string.IsNullOrEmpty(_action.Settings.PreRunScript))
            {
                try
                {
                    await ExecuteScriptAsync(_action.Settings.PreRunScript);
                }
                catch (Exception ex)
                {
                    _core.Logger.Error(this, $"PreRun script failed with message: {ex.Message}");
                    OnProcessCompleted();
                    return;
                }
            }
            try
            {
                var mainProcess = new Process
                {
                    StartInfo = new ProcessStartInfo(_action.Settings.Path)
                    {
                        Arguments = _action.Settings.ProgramParams ?? ""
                    }
                };

                mainProcess.Start();
                mainProcess.WaitForInputIdle();
                _processTimer = new IdleTimer(TimeSpan.FromSeconds(_action.Settings.IdleTime * 1000 * 60));
                _processTimer.Start();

                _processTimer.Tick += ProcessTimerCheck;
            }
            catch (Exception ex)
            {
                _core.Logger.Error(this, $"Main process failed with message: {ex.Message}");
                OnProcessCompleted();
                return;
            }
        }
Пример #3
0
        private void ActionMonitorOnProcessCompleted(object sender, ActionButtonModel action)
        {
            if (action == null)
            {
                return;
            }
            var monitor = sender as ProcessMonitor;

            if (monitor != null)
            {
                monitor.ProcessCompleted -= ActionMonitorOnProcessCompleted;
            }

            _actionsRunning.Remove(action);
            if (action.Settings.PausePanacea)
            {
                Resume();
            }
        }
        private async Task CloseCurrentAction()
        {
            if (_action == null)
            {
                return;
            }
            try
            {
                if (!string.IsNullOrEmpty(_action.Settings.CloseScript))
                {
                    await ExecuteScriptAsync(_action.Settings.CloseScript);
                }
                //var isRunning = await IsRunning();
                //if (isRunning) Host.Logger.Error(this,$"Close script failed to close {_action.Name}");
            }
            catch (Exception ex)
            {
                _core.Logger.Error(this, $"Close script failed with message: {ex.Message}");
            }

            try
            {
                if (!string.IsNullOrEmpty(_action.Settings.PostRunScript))
                {
                    await ExecuteScriptAsync(_action.Settings.PostRunScript);
                }
            }
            catch (Exception ex)
            {
                _core.Logger.Error(this, $"PostRun script failed with message: {ex.Message}");
            }
            finally
            {
                OnProcessCompleted();
                _action = null;
            }
        }