示例#1
0
        private void AddItem(object sender, RoutedEventArgs e)
        {
            GroupElement groupElement = ItemGroups.SelectedItem as GroupElement;

            if (groupElement != null)
            {
                ItemGroupElement selElm = groupElement.ElementBase as ItemGroupElement;

                if (selElm != null)
                {
                    if (!selElm.IsImported)
                    {
                        AddItemDialog dialog       = new AddItemDialog(selElm.PredominateType);
                        bool?         dialogResult = dialog.ShowDialog();

                        if (!dialogResult.HasValue)
                        {
                            return;
                        }

                        if (dialogResult.Value)
                        {
                            //Catch any errors and display them to the user
                            try
                            {
                                selElm.ItemGroup.AddNewItem(dialog.ItemName, "(Nothing)");
                                groupElement.Refresh();
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                ErrorDialog errorMessage = new ErrorDialog(ex.Message);
                                errorMessage.ShowDialog();
                            }
                            catch (ArgumentException ex)
                            {
                                ErrorDialog errorMessage = new ErrorDialog(ex.Message);
                                errorMessage.ShowDialog();
                            }
                        }
                    }
                }
                else
                {
                    AddItemBtn.IsEnabled = false;
                }
            }
        }
示例#2
0
        private void AddTask(object sender, RoutedEventArgs e)
        {
            GroupElement groupElement = Targets.SelectedItem as GroupElement;

            if (groupElement != null)
            {
                TargetElement selElm = groupElement.ElementBase as TargetElement;

                if (selElm != null)
                {
                    if (!selElm.IsImported)
                    {
                        AddTaskDialog dialog       = new AddTaskDialog();
                        bool?         dialogResult = dialog.ShowDialog();

                        if (!dialogResult.HasValue)
                        {
                            return;
                        }

                        if (dialogResult.Value)
                        {
                            try
                            {
                                Microsoft.Build.BuildEngine.BuildTask elm = selElm.TargetObject.AddNewTask(dialog.TaskName);

                                elm.Condition = dialog.Condition;

                                if (dialog.TaskParam.Length > 0)
                                {
                                    string[] pList = dialog.TaskParam.Split(',');

                                    foreach (string param in pList)
                                    {
                                        string[] pPart = param.Split('=');

                                        if (pPart.Length == 2)
                                        {
                                            elm.SetParameterValue(pPart[0], pPart[1]);
                                        }
                                    }
                                }
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                ErrorDialog errorMessage = new ErrorDialog(ex.Message);
                                errorMessage.ShowDialog();
                            }
                            catch (ArgumentException ex)
                            {
                                ErrorDialog errorMessage = new ErrorDialog(ex.Message);
                                errorMessage.ShowDialog();
                            }

                            groupElement.Refresh();
                        }
                    }
                }
                else
                {
                    AddTaskBtn.IsEnabled = false;
                }
            }
        }