public override bool SetStoreVersion(Version version)
        {
            string toolsVersion = this.MsBuildProject.Xml.ToolsVersion;
            string str          = version.ToString();

            this.MsBuildProject.Xml.ToolsVersion = str;
            if (!string.Equals(toolsVersion, str))
            {
                if (!Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(base.DocumentReference.Path))
                {
                    return(false);
                }
                this.Save();
                this.UnloadProject();
                this.LoadProject();
                if (string.IsNullOrEmpty(toolsVersion))
                {
                    ProjectLog.LogSuccess(base.DocumentReference.Path, StringTable.SetToolVersionAction, new object[] { str });
                }
                else
                {
                    string   path = base.DocumentReference.Path;
                    string   updateToolversionAction = StringTable.UpdateToolversionAction;
                    object[] objArray = new object[] { toolsVersion, str };
                    ProjectLog.LogSuccess(path, updateToolversionAction, objArray);
                }
            }
            return(true);
        }
        public override bool ChangeImport(string oldImportValue, string newImportValue)
        {
            bool flag;

            if (string.Equals(oldImportValue, newImportValue))
            {
                return(true);
            }
            using (IEnumerator <ResolvedImport> enumerator = this.MsBuildProject.Imports.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ResolvedImport current = enumerator.Current;
                    if (string.Compare(current.ImportingElement.Project, oldImportValue, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        continue;
                    }
                    current.ImportingElement.Project = newImportValue;
                    string   path = base.DocumentReference.Path;
                    string   updateImportAction = StringTable.UpdateImportAction;
                    object[] objArray           = new object[] { oldImportValue, newImportValue };
                    ProjectLog.LogSuccess(path, updateImportAction, objArray);
                    flag = true;
                    return(flag);
                }
                return(false);
            }
            return(flag);
        }
        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);
        }
Beispiel #4
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]);
                }
            }
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
        protected override bool SetProperty(string name, string value, bool persisted)
        {
            bool flag;

            if (!persisted)
            {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }
            using (IEnumerator <XElement> enumerator = this.GetProperties(name).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    XElement    current              = enumerator.Current;
                    string      path                 = base.DocumentReference.Path;
                    CultureInfo currentCulture       = CultureInfo.CurrentCulture;
                    string      updatePropertyAction = StringTable.UpdatePropertyAction;
                    object[]    objArray             = new object[] { name, current.Value, value };
                    ProjectLog.LogSuccess(path, string.Format(currentCulture, updatePropertyAction, objArray), new object[0]);
                    current.Value = value;
                    flag          = true;
                }
                else
                {
                    XElement    orCreatePropertyGroup = this.GetOrCreatePropertyGroup();
                    XElement    xElement          = new XElement(XmlMSBuildProjectStore.msbuild + name);
                    string      str               = base.DocumentReference.Path;
                    CultureInfo cultureInfo       = CultureInfo.CurrentCulture;
                    string      setPropertyAction = StringTable.SetPropertyAction;
                    object[]    objArray1         = new object[] { name, xElement.Value, value };
                    ProjectLog.LogSuccess(str, string.Format(cultureInfo, setPropertyAction, objArray1), new object[0]);
                    xElement.Value = value;
                    orCreatePropertyGroup.Add(xElement);
                    return(true);
                }
            }
            return(flag);
        }
 public override bool ChangeImport(string oldImportValue, string newImportValue)
 {
     XAttribute[] array = (
         from import in this.ProjectImportAttributes
         where import.Value == oldImportValue
         select import).ToArray <XAttribute>();
     if ((int)array.Length == 0)
     {
         return(false);
     }
     XAttribute[] xAttributeArray = array;
     for (int i = 0; i < (int)xAttributeArray.Length; i++)
     {
         XAttribute xAttribute         = xAttributeArray[i];
         string     path               = base.DocumentReference.Path;
         string     updateImportAction = StringTable.UpdateImportAction;
         object[]   value              = new object[] { xAttribute.Value, newImportValue };
         ProjectLog.LogSuccess(path, updateImportAction, value);
         xAttribute.Value = newImportValue;
     }
     return(true);
 }
 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);
        }
 public void Dispose()
 {
     ProjectLog.Unregister(this);
     GC.SuppressFinalize(this);
 }
Beispiel #15
0
        internal static void UpdateSourceControl(IEnumerable <DocumentReference> paths, UpdateSourceControlActions updateSourceControlAction, IProjectActionContext context)
        {
            if (context == null)
            {
                return;
            }
            IProjectManager projectManager = context.ServiceProvider.ProjectManager();

            if (projectManager == null)
            {
                return;
            }
            ISolution currentSolution = projectManager.CurrentSolution;

            if (currentSolution == null || !currentSolution.IsSourceControlActive)
            {
                return;
            }
            SourceControlStatusCache.UpdateStatus(paths, context.ServiceProvider.SourceControlProvider());
            IEnumerable <DocumentReference> documentReferences = paths.Where <DocumentReference>((DocumentReference path) => {
                if (!context.IsSourceControlled(path))
                {
                    return(false);
                }
                return(PathHelper.FileExists(path.Path));
            });
            IEnumerable <DocumentReference> documentReferences1 = Enumerable.Empty <DocumentReference>();

            if ((updateSourceControlAction & UpdateSourceControlActions.Checkout) == UpdateSourceControlActions.Checkout)
            {
                IEnumerable <DocumentReference> cachedStatus =
                    from path in documentReferences
                    where SourceControlStatusCache.GetCachedStatus(path) == SourceControlStatus.CheckedIn
                    select path;
                if (context.ServiceProvider.SourceControlProvider().Checkout((
                                                                                 from path in cachedStatus
                                                                                 select path.Path).ToArray <string>()) != SourceControlSuccess.Success)
                {
                    documentReferences1.Concat <DocumentReference>(cachedStatus);
                }
                else
                {
                    SourceControlStatusCache.SetCachedStatus(cachedStatus, SourceControlStatus.CheckedOut);
                    foreach (DocumentReference cachedStatu in cachedStatus)
                    {
                        ProjectLog.LogSuccess(cachedStatu.Path, StringTable.MakeWritableAction, new object[0]);
                    }
                }
            }
            if ((updateSourceControlAction & UpdateSourceControlActions.PendAdd) == UpdateSourceControlActions.PendAdd)
            {
                IEnumerable <DocumentReference> cachedStatus1 =
                    from path in documentReferences
                    where SourceControlStatusCache.GetCachedStatus(path) == SourceControlStatus.None
                    select path;
                if (context.ServiceProvider.SourceControlProvider().Add((
                                                                            from path in cachedStatus1
                                                                            select path.Path).ToArray <string>()) != SourceControlSuccess.Success)
                {
                    documentReferences1.Concat <DocumentReference>(cachedStatus1);
                }
                else
                {
                    SourceControlStatusCache.SetCachedStatus(cachedStatus1, SourceControlStatus.Add);
                }
            }
            SourceControlStatusCache.UpdateStatus(documentReferences1, context.ServiceProvider.SourceControlProvider());
        }
Beispiel #16
0
        internal static void RepairAssemblyReferences(IProjectStore projectStore)
        {
            MSBuildBasedProjectStore mSBuildBasedProjectStore = projectStore as MSBuildBasedProjectStore;

            if (mSBuildBasedProjectStore == null)
            {
                return;
            }
            ProjectBuildContext projectBuildContext = mSBuildBasedProjectStore.GenerateNewBuildContext(null);

            AssemblyReferenceHelper.RebuildAssemblyReferencePaths(projectBuildContext);
            foreach (ItemResolutionPair itemResolutionPair in
                     from assemblyPath in AssemblyReferenceHelper.GetAssemblyPaths(projectStore, projectBuildContext)
                     where assemblyPath.ResolvedItem == null
                     select assemblyPath)
            {
                string value = itemResolutionPair.SourceItem.Value;
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }
                int    num = value.IndexOf(',');
                string fileNameWithoutExtension = null;
                if (num <= 0)
                {
                    try
                    {
                        fileNameWithoutExtension = Path.GetFileNameWithoutExtension(value);
                    }
                    catch (IOException oException)
                    {
                        continue;
                    }
                    catch (ArgumentException argumentException)
                    {
                        continue;
                    }
                    if (string.Equals(fileNameWithoutExtension, value, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }
                else
                {
                    fileNameWithoutExtension = value.Substring(0, num);
                }
                itemResolutionPair.SourceItem.Value = fileNameWithoutExtension;
                itemResolutionPair.SourceItem.SetItemMetadata("UpgraderOriginalValue", value);
            }
            projectBuildContext = mSBuildBasedProjectStore.GenerateNewBuildContext(null);
            AssemblyReferenceHelper.RebuildAssemblyReferencePaths(projectBuildContext);
            foreach (ItemResolutionPair itemResolutionPair1 in AssemblyReferenceHelper.GetAssemblyPaths(projectStore, projectBuildContext))
            {
                string metadata = itemResolutionPair1.SourceItem.GetMetadata("UpgraderOriginalValue");
                if (string.IsNullOrEmpty(metadata))
                {
                    continue;
                }
                if (itemResolutionPair1.ResolvedItem != null)
                {
                    string   path = projectStore.DocumentReference.Path;
                    string   updateItemMetadataAction = StringTable.UpdateItemMetadataAction;
                    object[] itemType = new object[] { "Include", itemResolutionPair1.SourceItem.ItemType, metadata, metadata, itemResolutionPair1.SourceItem.Value };
                    ProjectLog.LogSuccess(path, updateItemMetadataAction, itemType);
                    string metadataValue = itemResolutionPair1.ResolvedItem.GetMetadataValue("RequiredTargetFramework");
                    if (!string.IsNullOrEmpty(metadataValue))
                    {
                        itemResolutionPair1.SourceItem.SetItemMetadata("RequiredTargetFramework", metadataValue);
                    }
                }
                else
                {
                    itemResolutionPair1.SourceItem.Value = metadata;
                }
                itemResolutionPair1.SourceItem.SetItemMetadata("UpgraderOriginalValue", null);
            }
        }
 public ProjectUpgradeLogger()
 {
     this.isEnabled = true;
     this.log       = new Dictionary <string, List <ProjectUpgradeLogger.LogItem> >(StringComparer.OrdinalIgnoreCase);
     ProjectLog.Register(this);
 }