public override bool RemoveItem(IProjectItemData item)
        {
            MSBuildProjectItemData mSBuildProjectItemDatum = item as MSBuildProjectItemData;

            if (mSBuildProjectItemDatum == null || mSBuildProjectItemDatum.ProjectItem.IsImported)
            {
                return(false);
            }
            bool flag = this.MsBuildProject.RemoveItem(mSBuildProjectItemDatum.ProjectItem);

            if (!flag)
            {
                string   path                    = base.DocumentReference.Path;
                string   unknownError            = StringTable.UnknownError;
                string   removeProjectItemAction = StringTable.RemoveProjectItemAction;
                object[] itemType                = new object[] { item.ItemType, item.Value };
                ProjectLog.LogError(path, unknownError, removeProjectItemAction, itemType);
            }
            else
            {
                string   str = base.DocumentReference.Path;
                string   removeProjectItemAction1 = StringTable.RemoveProjectItemAction;
                object[] objArray = new object[] { item.ItemType, item.Value };
                ProjectLog.LogSuccess(str, removeProjectItemAction1, objArray);
            }
            return(flag);
        }
예제 #2
0
        public bool SetItemMetadata(string metadataName, string metadataValue)
        {
            bool   flag;
            string str;
            string metadata = this.GetMetadata(metadataName);

            if (string.Equals(metadata, metadataValue))
            {
                return(true);
            }
            flag = (metadataValue != null ? this.ProjectItem.SetMetadataValue(metadataName, metadataValue) != null : this.ProjectItem.RemoveMetadata(metadataName));
            if (!string.IsNullOrEmpty(metadata))
            {
                CultureInfo currentCulture           = CultureInfo.CurrentCulture;
                string      updateItemMetadataAction = StringTable.UpdateItemMetadataAction;
                object[]    objArray = new object[] { metadataName, this.ItemType, this.Value, metadata, metadataValue };
                str = string.Format(currentCulture, updateItemMetadataAction, objArray);
            }
            else
            {
                CultureInfo cultureInfo           = CultureInfo.CurrentCulture;
                string      setItemMetadataAction = StringTable.SetItemMetadataAction;
                object[]    objArray1             = new object[] { metadataName, this.ItemType, this.Value, metadataValue };
                str = string.Format(cultureInfo, setItemMetadataAction, objArray1);
            }
            if (!flag)
            {
                ProjectLog.LogError(this.ProjectItem.Project.FullPath, StringTable.UnknownError, str, new object[0]);
            }
            else
            {
                ProjectLog.LogSuccess(this.ProjectItem.Project.FullPath, str, new object[0]);
            }
            return(flag);
        }
예제 #3
0
        private void UpdateToolkitXmlNamespace()
        {
            string str;

            if (string.Compare(Path.GetExtension(this.currentXamlPath), ".xaml", StringComparison.OrdinalIgnoreCase) != 0)
            {
                return;
            }
            if (!this.ContainsWpfToolkitNamespace(this.currentXamlPath, out str))
            {
                return;
            }
            string str1 = File.ReadAllText(this.currentXamlPath, Encoding.UTF8);
            string str2 = this.ReplaceWpfToolkitNamespace(str1, str);

            if (str2 != null)
            {
                try
                {
                    if (this.context == null || ProjectPathHelper.AttemptToMakeWritable(DocumentReference.Create(this.currentXamlPath), this.context))
                    {
                        File.WriteAllText(this.currentXamlPath, str2, Encoding.UTF8);
                        ProjectLog.LogSuccess(this.currentXamlPath, StringTable.SaveAction, new object[0]);
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    ProjectLog.LogError(this.currentXamlPath, exception, StringTable.SaveAction, new object[0]);
                }
            }
        }
예제 #4
0
        public string ReplaceWpfToolkitNamespace(string xaml, string rootElementName)
        {
            string      str              = "[_\\w][\\w\\d\\S]*";
            string      str1             = "[\\s\\n]*";
            string      str2             = "(?:'[^']*'|\"[^\"]*\")";
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[]    objArray    = new object[] { str, str1, str2 };
            string      str3        = string.Format(invariantCulture, "{0}{1}={1}{2}", objArray);
            CultureInfo cultureInfo = CultureInfo.InvariantCulture;

            object[] objArray1 = new object[] { rootElementName, str1, str3 };
            string   str4      = string.Format(cultureInfo, "<{0}(?:{1}{2})*{1}/?>", objArray1);
            Match    match     = (new Regex(str4)).Match(xaml);

            if (!match.Success)
            {
                ProjectLog.LogError(this.currentXamlPath, StringTable.UnknownError, StringTable.FixWpfToolkitNamespace, new object[0]);
                return(null);
            }
            string      value             = match.Value;
            CultureInfo invariantCulture1 = CultureInfo.InvariantCulture;

            object[] objArray2 = new object[] { str1, str, WpfToolkitRemover.wpfToolkitXmlns };
            Regex    regex     = new Regex(string.Format(invariantCulture1, "{0}xmlns(?:\\:{1})?{0}={0}(?<quote>'|\"){2}\\k<quote>", objArray2));
            string   str5      = regex.Replace(value, new MatchEvaluator(WpfToolkitRemover.ReplaceToolokitReference));
            string   str6      = xaml.Substring(0, match.Index);
            string   str7      = xaml.Substring(match.Index + match.Length);
            string   str8      = string.Concat(str6, str5, str7);

            ProjectLog.LogSuccess(this.currentXamlPath, StringTable.FixWpfToolkitNamespace, new object[0]);
            return(str8);
        }
예제 #5
0
        public static bool AttemptToMakeWritable(DocumentReference documentReference, IProjectActionContext context)
        {
            bool flag;

            if (!documentReference.IsValidPathFormat || Microsoft.Expression.Framework.Documents.PathHelper.IsDirectory(documentReference.Path))
            {
                return(false);
            }
            if (!Microsoft.Expression.Framework.Documents.PathHelper.FileOrDirectoryExists(documentReference.Path))
            {
                return(true);
            }
            if (context == null)
            {
                return(false);
            }
            SourceControlHelper.UpdateSourceControl(EnumerableExtensions.AsEnumerable <DocumentReference>(documentReference), UpdateSourceControlActions.Checkout, context);
            try
            {
                FileAttributes attributes = File.GetAttributes(documentReference.Path);
                if ((attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
                {
                    flag = true;
                }
                else if (!context.CanOverwrite(documentReference))
                {
                    ProjectLog.LogError(documentReference.Path, StringTable.ActionCanceled, StringTable.MakeWritableAction, new object[0]);
                    flag = false;
                }
                else if (!Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(documentReference.Path))
                {
                    attributes = attributes & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Directory | FileAttributes.Archive | FileAttributes.Device | FileAttributes.Normal | FileAttributes.Temporary | FileAttributes.SparseFile | FileAttributes.ReparsePoint | FileAttributes.Compressed | FileAttributes.Offline | FileAttributes.NotContentIndexed | FileAttributes.Encrypted | FileAttributes.IntegrityStream | FileAttributes.NoScrubData);
                    File.SetAttributes(documentReference.Path, attributes);
                    ProjectLog.LogSuccess(documentReference.Path, StringTable.MakeWritableAction, new object[0]);
                    flag = true;
                }
                else
                {
                    ProjectLog.LogSuccess(documentReference.Path, StringTable.MakeWritableAction, new object[0]);
                    flag = true;
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ProjectLog.LogError(documentReference.Path, exception, StringTable.MakeWritableAction, new object[0]);
                if (!context.HandleException(documentReference, exception))
                {
                    throw;
                }
                return(false);
            }
            return(flag);
        }
 public override void Save()
 {
     this.SetProperty("ExpressionBlendVersion", this.blendVersion, true);
     try
     {
         this.MsBuildProject.Save(base.DocumentReference.Path);
         ProjectLog.LogSuccess(base.DocumentReference.Path, StringTable.SaveAction, new object[0]);
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         ProjectLog.LogError(base.DocumentReference.Path, exception, StringTable.SaveAction, new object[0]);
         throw;
     }
 }
        public override bool AddImport(string importValue)
        {
            bool flag = this.MsBuildProject.Xml.AddImport(importValue) != null;

            if (!flag)
            {
                string   path            = base.DocumentReference.Path;
                string   unknownError    = StringTable.UnknownError;
                string   addImportAction = StringTable.AddImportAction;
                object[] objArray        = new object[] { importValue };
                ProjectLog.LogError(path, unknownError, addImportAction, objArray);
            }
            else
            {
                ProjectLog.LogSuccess(base.DocumentReference.Path, StringTable.AddImportAction, new object[] { importValue });
            }
            return(flag);
        }
 public override IProjectItemData AddItem(string itemType, string itemValue)
 {
     Microsoft.Build.Evaluation.ProjectItem projectItem = this.AddMsBuildItem(itemType, itemValue);
     if (projectItem == null)
     {
         string   path                 = base.DocumentReference.Path;
         string   unknownError         = StringTable.UnknownError;
         string   addProjectItemAction = StringTable.AddProjectItemAction;
         object[] objArray             = new object[] { itemType, itemValue };
         ProjectLog.LogError(path, unknownError, addProjectItemAction, objArray);
     }
     else
     {
         string   str = base.DocumentReference.Path;
         string   addProjectItemAction1 = StringTable.AddProjectItemAction;
         object[] objArray1             = new object[] { itemType, itemValue };
         ProjectLog.LogSuccess(str, addProjectItemAction1, objArray1);
     }
     if (projectItem == null)
     {
         return(null);
     }
     return(new MSBuildProjectItemData(projectItem));
 }
        protected override bool SetProperty(string name, string value, bool persisted)
        {
            string str;
            string unevaluatedValue;

            if (!persisted)
            {
                return(this.MsBuildProject.SetGlobalProperty(name, value));
            }
            ProjectProperty property = this.MsBuildProject.GetProperty(name);

            if (!this.IsPropertyWritable(property))
            {
                return(false);
            }
            if (value == null)
            {
                if (property == null)
                {
                    return(true);
                }
                if (property.IsImported)
                {
                    return(false);
                }
                bool flag = this.MsBuildProject.RemoveProperty(property);
                if (!flag)
                {
                    string   path                 = base.DocumentReference.Path;
                    string   unknownError         = StringTable.UnknownError;
                    string   removePropertyAction = StringTable.RemovePropertyAction;
                    object[] objArray             = new object[] { name };
                    ProjectLog.LogError(path, unknownError, removePropertyAction, objArray);
                }
                else
                {
                    ProjectLog.LogSuccess(base.DocumentReference.Path, StringTable.RemovePropertyAction, new object[] { name });
                }
                return(flag);
            }
            if (property != null)
            {
                unevaluatedValue = property.UnevaluatedValue;
            }
            else
            {
                unevaluatedValue = null;
            }
            string          str1            = unevaluatedValue;
            ProjectProperty projectProperty = this.MsBuildProject.SetProperty(name, value);

            if (!string.Equals(str1, value))
            {
                if (string.IsNullOrEmpty(str1))
                {
                    CultureInfo currentCulture    = CultureInfo.CurrentCulture;
                    string      setPropertyAction = StringTable.SetPropertyAction;
                    object[]    objArray1         = new object[] { name, value };
                    str = string.Format(currentCulture, setPropertyAction, objArray1);
                }
                else
                {
                    CultureInfo cultureInfo          = CultureInfo.CurrentCulture;
                    string      updatePropertyAction = StringTable.UpdatePropertyAction;
                    object[]    objArray2            = new object[] { name, str1, value };
                    str = string.Format(cultureInfo, updatePropertyAction, objArray2);
                }
                if (projectProperty == null)
                {
                    ProjectLog.LogError(base.DocumentReference.Path, StringTable.UnknownError, str, new object[0]);
                }
                else
                {
                    ProjectLog.LogSuccess(base.DocumentReference.Path, str, new object[0]);
                }
            }
            return(projectProperty != null);
        }