コード例 #1
0
        private Task(MenuItemBaseProperties baseProperties, string progressCaption, string[] activities, bool?continueOnError, DecoratedMessage postMessage)
            : base(baseProperties)
        {
            ProgressCaption = progressCaption ?? throw new ArgumentNullException("progressCaption");
            mActivities     = activities ?? throw new ArgumentNullException("activities");

            if (continueOnError != null)
            {
                mContinueOnError = continueOnError.Value;
            }

            mPostMessage = postMessage;
        }
コード例 #2
0
        public static Task CreateFromXML(XmlElement taskElement, Menu parentMenu)
        {
            if (taskElement.Name != "task")
            {
                throw new ArgumentException("argument must be a task element", "taskElement");
            }

            MenuItemBaseProperties baseProperties = new MenuItemBaseProperties();

            baseProperties.FillFromXml(taskElement, parentMenu);

            DecoratedMessage postMessage = null;

            XmlElement postMessageElement = taskElement["postMessage"];

            if (postMessageElement != null)
            {
                MessageBoxIcon?messageTypeIcon = null;

                XmlAttribute messageTypeAttribute = postMessageElement.Attributes["messageType"];
                if (messageTypeAttribute != null)
                {
                    switch (messageTypeAttribute.Value)
                    {
                    case "neutral":
                        messageTypeIcon = MessageBoxIcon.None;
                        break;

                    case "information":
                        messageTypeIcon = MessageBoxIcon.Information;
                        break;

                    case "warning":
                        messageTypeIcon = MessageBoxIcon.Warning;
                        break;
                    }
                }

                postMessage = new DecoratedMessage(TextParser.ParseMultilineElementText(postMessageElement.InnerText.Trim()), postMessageElement.Attributes["caption"].Value,
                                                   false, TextParser.ParseNullableXmlBoolean(postMessageElement.Attributes["showIfFailed"]), null, messageTypeIcon);
            }


            return(new Task(baseProperties, taskElement.Attributes["progressCaption"].Value,
                            TextParser.ParseActivities(taskElement["activities"].InnerText), TextParser.ParseNullableXmlBoolean(taskElement.Attributes["continueOnError"]), postMessage));
        }
コード例 #3
0
        private void HandleExecutionEnd(bool success, DecoratedMessage postMessage)
        {
            if (InvokeRequired)
            {
                Invoke(new handleExecutionEndDelegate(HandleExecutionEnd), success, postMessage);
                return;
            }

            SuspendLayout();
            mTaskLabel.Text      = success ? Resources.LblExecutionSuccessful : Resources.LblExecutionNotSuccessful;
            UseWaitCursor        = false;
            mAbortButton.Enabled = false;
            mCloseButton.Enabled = true;
            ResumeLayout(true);

            if (postMessage != null && (success || postMessage.ShowIfFailed))
            {
                MessageBox.Show(this, postMessage.Message, postMessage.Caption, postMessage.Buttons, postMessage.Type);
            }
        }
コード例 #4
0
        private void MMenuItemControl_MenuItemSelected(object sender, MenuItemSelectedEventArgs eventArgs)
        {
            MenuItem selectedItem = eventArgs.SelectedMenuItem;

            DecoratedMessage preMessage = selectedItem.PreMessage;

            if (preMessage != null && !(preMessage.ShowOnce && preMessage.Shown))
            {
                DialogResult preMessageResult = MessageBox.Show(this, preMessage.Message, preMessage.Caption, preMessage.Buttons, preMessage.Type);

                preMessage.Shown = true;

                if (preMessageResult == DialogResult.No || preMessageResult == DialogResult.Cancel)
                {
                    return;
                }
            }

            if (selectedItem is Menu menu)
            {
                SetCurrentMenu(menu, mActivityExecutor.ProductModel);
            }
            else if (selectedItem is Task task)
            {
                if (mTaskProgressForm == null)
                {
                    mTaskProgressForm = new TaskProgressForm
                    {
                        ActivityExecutor = mActivityExecutor
                    };
                }

                mTaskProgressForm.Task = task;
                mTaskProgressForm.ShowDialog(this);

                if (selectedItem.ParentMenu.ReturnToMainMenu)
                {
                    SetCurrentMenu(mCommands.MainMenu, mActivityExecutor.ProductModel);
                }
            }
            else
            {
                try
                {
                    Query       query  = (Query)selectedItem;
                    QueryResult result = mActivityExecutor.ExecuteQuery(query);
                    if (!result.Success)
                    {
                        MessageBox.Show(this, result.Message, Resources.CptQueryFailed, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (query.OfferClipboardCopy)
                    {
                        if (MessageBox.Show(this, string.Format(Resources.MsgQueryOfferClipboardCopy, result.Message), Resources.CptQueryCompleted, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            Clipboard.SetData(DataFormats.Text, result.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, result.Message, Resources.CptQueryCompleted, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception exception)
                {
                    HandleQueryException(exception);
                }
            }
        }
コード例 #5
0
ファイル: MenuItem.cs プロジェクト: rbergen/CherryUpdater
        public virtual void FillFromXml(XmlElement element, Menu parentMenu)
        {
            ParentMenu = parentMenu;

            XmlAttribute compatibleProductModelsAttribute = element.Attributes["compatibleProductModels"];

            string[] compatibleProductModels = null;
            if (compatibleProductModelsAttribute != null)
            {
                compatibleProductModels = TextParser.ParseProductModels(compatibleProductModelsAttribute.Value);
            }

            CompatibleProductModels = compatibleProductModels;

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace("cf", "http://schema.vanbergen.local/Tools/CherryUpdater/CommandFile");

            List <Requirement> requirementList = new List <Requirement>();
            XmlNodeList        requireNodes    = element.SelectNodes("child::cf:require", namespaceManager);

            foreach (XmlElement requireElement in requireNodes)
            {
                requirementList.Add(Requirement.CreateFromXML(requireElement));
            }

            Requirements = requirementList.Count > 0 ? requirementList.ToArray() : null;

            XmlElement helpTextElement = element["helpText"];
            string     helpText        = null;

            if (helpTextElement != null)
            {
                helpText = TextParser.ParseMultilineElementText(helpTextElement.InnerText.Trim());
            }

            HelpText = helpText;

            XmlElement preMessageElement = element["preMessage"];

            if (preMessageElement != null)
            {
                MessageBoxButtons?showButtons = null;

                XmlAttribute showButtonsAttribute = preMessageElement.Attributes["showButtons"];
                if (showButtonsAttribute != null)
                {
                    switch (showButtonsAttribute.Value)
                    {
                    case "ok":
                        showButtons = MessageBoxButtons.OK;
                        break;

                    case "okCancel":
                        showButtons = MessageBoxButtons.OKCancel;
                        break;

                    case "yesNo":
                        showButtons = MessageBoxButtons.YesNo;
                        break;
                    }
                }

                MessageBoxIcon?messageTypeIcon = null;

                XmlAttribute messageTypeAttribute = preMessageElement.Attributes["messageType"];
                if (messageTypeAttribute != null)
                {
                    switch (messageTypeAttribute.Value)
                    {
                    case "neutral":
                        messageTypeIcon = MessageBoxIcon.None;
                        break;

                    case "information":
                        messageTypeIcon = MessageBoxIcon.Information;
                        break;

                    case "question":
                        messageTypeIcon = MessageBoxIcon.Question;
                        break;

                    case "warning":
                        messageTypeIcon = MessageBoxIcon.Warning;
                        break;
                    }
                }

                PreMessage = new DecoratedMessage(TextParser.ParseMultilineElementText(preMessageElement.InnerText.Trim()), preMessageElement.Attributes["caption"].Value,
                                                  TextParser.ParseNullableXmlBoolean(preMessageElement.Attributes["showOnce"]), false, showButtons, messageTypeIcon);
            }

            Title = element.Attributes["title"].Value;
        }