示例#1
0
        /// <summary>
        ///     Executes this CreateBusinessFormCommand.
        /// </summary>
        public override void Execute()
        {
            logger.Trace("Entered Execute()");
            try
            {
                ClassEntity classEntity = null;
                var         Guids       = PtHelpers.GetProjectTypeGuids(
                    Application.ActiveDocument.ProjectItem.ContainingProject).Split(';');
                if (PtHelpers.IsProjectSilverlight(Guids))
                {
                    classEntity = new ClassEntity(string.Empty, true)
                    {
                        SilverlightVersion =
                            this.Application.ActiveDocument
                            .ProjectItem.ContainingProject
                            .Properties.Item(
                                "TargetFrameworkMoniker")
                            .Value.ToString()
                            .Replace(
                                "Silverlight,Version=v",
                                string.Empty)
                    };
                }

                var createBusinessFormWindow = new CreateBusinessFormWindow(classEntity);
                var result = createBusinessFormWindow.ShowDialog();
                if (!(result ?? false))
                {
                    return;
                }

                var ts = this.Application.ActiveDocument.Selection as TextSelection;
                if (ts == null)
                {
                    throw new Exception("ts is null.");
                }

                ts.Insert(createBusinessFormWindow.BusinessForm);
            }
            catch (Exception ex)
            {
                UIUtilities.ShowExceptionMessage(Caption, ex.Message);
                logger.Debug("An exception was raised in Execute().", ex);
            }
        }
示例#2
0
 /// <summary>
 ///     Executes this CreateBusinessFormCommand.
 /// </summary>
 public override void Execute()
 {
     try
     {
         ClassEntity classEntity = null;
         var         Guids       = PtHelpers.GetProjectTypeGuids(Application.ActiveDocument.ProjectItem.ContainingProject).Split(';');
         if (PtHelpers.IsProjectSilverlight(Guids))
         {
             classEntity = new ClassEntity(string.Empty, true);
             classEntity.SilverlightVersion = Application.ActiveDocument.ProjectItem.ContainingProject.Properties.Item("TargetFrameworkMoniker").Value.ToString().Replace("Silverlight,Version=v", string.Empty);
         }
         var createBusinessFormWindow = new CreateBusinessFormWindow(classEntity);
         var result = createBusinessFormWindow.ShowDialog();
         if (result ?? false)
         {
             var ts = Application.ActiveDocument.Selection as TextSelection;
             ts.Insert(createBusinessFormWindow.BusinessForm);
         }
     }
     catch (Exception ex)
     {
         UIUtilities.ShowExceptionMessage(Caption, ex.Message, string.Empty, ex.ToString());
     }
 }
示例#3
0
        /// <summary>
        ///     Executes this ExtractSelectedPropertiesToStyleCommand.
        /// </summary>
        public override void Execute()
        {
            logger.Trace("Entered Execute()");
            try
            {
                if (_addedNamespaces == null)
                {
                    _addedNamespaces = new List <string>();
                }
                else
                {
                    _addedNamespaces.Clear();
                }
                var selectedCodeBlock = Application.ActiveDocument.Selection as
                                        TextSelection;
                var XAML             = selectedCodeBlock.Text.Trim(WhiteSpaceCharacters);
                var nameTable        = new NameTable();
                var nameSpaceManager = new XmlNamespaceManager(nameTable);
                AddNameSpaces(XAML, nameSpaceManager);

                var xmlParseContext = new XmlParserContext(null, nameSpaceManager, null,
                                                           XmlSpace.None);
                var document = new XmlDocument();
                document.PreserveWhitespace = true;
                document.XmlResolver        = null;

                var xmlSettings = new XmlReaderSettings();
                xmlSettings.ValidationFlags =
                    System.Xml.Schema.XmlSchemaValidationFlags.None;
                xmlSettings.ValidationType = ValidationType.None;

                using (var reader = XmlReader.Create(new StringReader(XAML), xmlSettings,
                                                     xmlParseContext))
                {
                    document.Load(reader);
                }

                var isSilverlight = PtHelpers.IsProjectSilverlight(
                    PtHelpers.GetProjectTypeGuids(Application.SelectedItems.Item(
                                                      1).ProjectItem.ContainingProject).Split(';'));
                var silverlightVersion = string.Empty;
                if (isSilverlight)
                {
                    silverlightVersion =
                        Application.ActiveDocument.ProjectItem.ContainingProject.Properties.Item("TargetFrameworkMoniker").Value.ToString().Replace("Silverlight,Version=v",
                                                                                                                                                    String.Empty);
                }

                var extractSelectedPropertiesToStyle = new
                                                       ExtractSelectedPropertiesToStyleWindow(document, isSilverlight,
                                                                                              silverlightVersion);
                var result = extractSelectedPropertiesToStyle.ShowDialog();

                if (result ?? false)
                {
                    var sb             = new StringBuilder(10240);
                    var writerSettings = new XmlWriterSettings()
                    {
                        Indent = true,
                        NewLineOnAttributes = false,
                        OmitXmlDeclaration  = true
                    };

                    using (var writer = XmlWriter.Create(sb, writerSettings))
                    {
                        extractSelectedPropertiesToStyle.Document.Save(writer);
                    }

                    foreach (string item in _addedNamespaces)
                    {
                        sb.Replace(item, string.Empty);
                    }

                    sb.Replace(" >", ">");
                    sb.Replace("    ", " ");
                    sb.Replace("   ", " ");
                    sb.Replace("  ", " ");

                    var editPoint = selectedCodeBlock.TopPoint.CreateEditPoint();
                    selectedCodeBlock.Delete();
                    editPoint.Insert(sb.ToString());
                    sb.Length = 0;

                    sb.AppendFormat(
                        isSilverlight ? "<Style TargetType=\"{0}\"" :
                        "<Style TargetType=\"{{x:Type {0}}}\"",
                        extractSelectedPropertiesToStyle.TypeName);

                    sb.AppendFormat(
                        extractSelectedPropertiesToStyle.StyleName.IsNotNullOrEmpty() ?
                        " x:Key=\"{0}\">" : ">",
                        extractSelectedPropertiesToStyle.StyleName
                        );

                    sb.Append(Environment.NewLine);

                    foreach (var item in extractSelectedPropertiesToStyle.ExtractedProperties)
                    {
                        if (item.IsSelected)
                        {
                            sb.AppendFormat("<Setter Property=\"{0}\" Value=\"{1}\" />{2}",
                                            item.PropertyName, item.PropertyValue, Environment.NewLine);
                        }
                    }

                    sb.AppendLine("</Style>");
                    Clipboard.Clear();
                    Clipboard.SetText(sb.ToString());
                    UIUtilities.ShowInformationMessage("Paste Style",
                                                       "Place insertion point and paste created style into the resource section of a XAML document.");
                }
            }
            catch (XmlException ex)
            {
                UIUtilities.ShowExceptionMessage("Paste Style",
                                                 "Place insertion point and paste created style into the resource section of a XAML document.");
                logger.Error("An XmlException was raised in Execute().", ex);
            }
            catch (Exception ex)
            {
                UIUtilities.ShowExceptionMessage(this.Caption, ex.Message);
                logger.Error("An exception was raised in Execute().", ex);
            }
        }