예제 #1
0
        private IEnumerable <ICommand> loadCustomCommands(string filename, ICommandCallback commandCallback)
        {
            CustomCommandLoader loader = new CustomCommandLoader(commandCallback);

            try
            {
                return(loader.LoadCommands(filename));
            }
            catch (CustomCommandLoaderException ex)
            {
                // If file doesn't exist the loader throws, leaving the app in an undesirable state.
                // Do not try to load custom actions if they don't exist.
                ExceptionHandlers.Handle("Cannot load custom actions", ex);
            }
            return(null);
        }
예제 #2
0
        public static List <ICommand> LoadCustomActions(ICommandCallback callback)
        {
            CustomCommandLoader loader = new CustomCommandLoader(callback);

            try
            {
                return(loader.LoadCommands(CustomActionsFileName));
            }
            catch (CustomCommandLoaderException ex)
            {
                // If file doesn't exist the loader throws, leaving the app in an undesirable state.
                // Do not try to load custom actions if they don't exist.
                ExceptionHandlers.Handle(ex, "Cannot load custom actions");
            }
            return(null);
        }
예제 #3
0
        private void addCustomActions()
        {
            CustomCommandLoader loader = new CustomCommandLoader(this);

            _customCommands = null;
            try
            {
                string CustomActionsFileName = "CustomActions.xml";
                _customCommands = loader.LoadCommands(CustomActionsFileName);
            }
            catch (CustomCommandLoaderException ex)
            {
                // If file doesn't exist the loader throws, leaving the app in an undesirable state.
                // Do not try to load custom actions if they don't exist.
                ExceptionHandlers.Handle("Cannot load custom actions", ex);
            }

            _keywords = _customCommands?
                        .Where(x => x is SendNoteCommand)
                        .Select(x => (x as SendNoteCommand).GetBody()) ?? null;

            if (_customCommands == null)
            {
                return;
            }

            int id = 0;

            foreach (ICommand command in _customCommands)
            {
                string name   = command.GetName();
                var    button = new System.Windows.Forms.Button
                {
                    Name     = "customAction" + id,
                    Location = new System.Drawing.Point {
                        X = 0, Y = 19
                    },
                    Size = new System.Drawing.Size {
                        Width = 72, Height = 32
                    },
                    MinimumSize = new System.Drawing.Size {
                        Width = 72, Height = 0
                    },
                    Text = name,
                    UseVisualStyleBackColor = true,
                    Enabled = false,
                    TabStop = false,
                    Tag     = command.GetDependency()
                };
                toolTip.SetToolTip(button, command.GetHint());
                button.Click += async(x, y) =>
                {
                    MergeRequestKey?mergeRequestKey = getMergeRequestKey(null);
                    if (!mergeRequestKey.HasValue)
                    {
                        return;
                    }

                    ITotalTimeCache totalTimeCache = getDataCache(!isSearchMode())?.TotalTimeCache;

                    labelWorkflowStatus.Text = "Command " + name + " is in progress";
                    try
                    {
                        await command.Run();
                    }
                    catch (Exception ex) // Whatever happened in Run()
                    {
                        string errorMessage = "Custom action failed";
                        ExceptionHandlers.Handle(errorMessage, ex);
                        MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        labelWorkflowStatus.Text = "Command " + name + " failed";
                        return;
                    }

                    string statusMessage = String.Format("Command {0} completed for merge request !{1} in project {2}",
                                                         name, mergeRequestKey.Value.IId, mergeRequestKey.Value.ProjectKey.ProjectName);
                    labelWorkflowStatus.Text = statusMessage;
                    Trace.TraceInformation(String.Format("[MainForm] {0}", statusMessage));

                    if (command.GetStopTimer())
                    {
                        await onStopTimer(true);

                        onTimerStopped(totalTimeCache);
                    }

                    bool reload = command.GetReload();
                    if (reload)
                    {
                        requestUpdates(mergeRequestKey, new int[] {
                            Program.Settings.OneShotUpdateFirstChanceDelayMs,
                            Program.Settings.OneShotUpdateSecondChanceDelayMs
                        });
                    }
                };
                groupBoxActions.Controls.Add(button);
                id++;
            }
        }