private static bool IsTargetsToolkitVersionCurrent()
        {
            var targetsInfo = new TargetsInfo
            {
                TargetsPath = TargetsFilePath,
            };

            VersionHelper.ReadTargetsValues(targetsInfo);
            return AuthoringPackage.CurrentToolkitVersion.Equals(targetsInfo.ToolkitVersion);
        }
        private static bool IsTargetsFileExtensionPathsCurrent()
        {
            var targetsInfo = new TargetsInfo
            {
                TargetsPath = TargetsFilePath,
                InstalledExtensionProperties = AuthoringPackage.InstalledExtensionProperties,
            };

            VersionHelper.ReadTargetsValues(targetsInfo);
            return !targetsInfo.InstalledExtensionProperties.Any(ie => string.IsNullOrEmpty(ie.Value));
        }
Exemple #3
0
        /// <summary>
        /// Synchronizes the targets file on disk with targets file in this version of the toolkit.
        /// </summary>
        internal static void SyncTargets(ITracer tracer, TargetsInfo targetsInfo)
        {
            try
            {
                tracer.Info(Resources.AuthoringPackage_TraceSyncTargetsInitial);

                //Write updated targets file
                WriteUpdatedTargets(tracer, targetsInfo);
            }
            catch (Exception ex)
            {
                tracer.Error(ex, Resources.AuthoringPackage_FailedSyncTargets);
            }
        }
Exemple #4
0
        /// <summary>
        /// Synchronizes the targets file on disk with targets file in this version of the toolkit.
        /// </summary>
        internal static void SyncTargets(ITracer tracer, TargetsInfo targetsInfo)
        {
            try
            {
                tracer.Info(Resources.AuthoringPackage_TraceSyncTargetsInitial);

                //Write updated targets file
                WriteUpdatedTargets(tracer, targetsInfo);
            }
            catch (Exception ex)
            {
                tracer.Error(ex, Resources.AuthoringPackage_FailedSyncTargets);
            }
        }
Exemple #5
0
        internal static void ReadTargetsValues(TargetsInfo targetsInfo)
        {
            // Read toolkit version number
            targetsInfo.ToolkitVersion = ReadPropertyValue(targetsInfo, PatternToolkitVersionElementName);

            // Read extension paths
            if (targetsInfo.InstalledExtensionProperties != null)
            {
                var readInstalledExtensions = new Dictionary <string, string>();
                targetsInfo.InstalledExtensionProperties.ToList().ForEach(ie =>
                {
                    readInstalledExtensions.Add(ie.Key, ReadPropertyValue(targetsInfo, ie.Key));
                });
                targetsInfo.InstalledExtensionProperties = readInstalledExtensions;
            }
        }
Exemple #6
0
        private static string ReadPropertyValue(TargetsInfo targetsInfo, string propertyName)
        {
            XDocument document  = XDocument.Load(targetsInfo.TargetsPath);
            var       nsManager = new XmlNamespaceManager(new NameTable());

            nsManager.AddNamespace(string.Empty, MSBuildNamespace);

            var propertyElement = document.Descendants(XName.Get(
                                                           string.Format(CultureInfo.InvariantCulture, "{{{1}}}{0}", propertyName, MSBuildNamespace))).FirstOrDefault();

            if (propertyElement != null)
            {
                return(propertyElement.Value);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        private static void WriteUpdatedTargets(ITracer tracer, TargetsInfo targetsInfo)
        {
            tracer.Info(Resources.AuthoringPackage_TraceSyncTargetsWritingNewTargets, targetsInfo.TargetsPath, targetsInfo.ToolkitVersion);

            //Delete file if exists
            if (File.Exists(targetsInfo.TargetsPath))
            {
                File.Delete(targetsInfo.TargetsPath);
            }

            // Ensure directory exists
            var targetsFolder = Path.GetDirectoryName(targetsInfo.TargetsPath);
            if (!Directory.Exists(targetsFolder))
            {
                Directory.CreateDirectory(targetsFolder);
            }

            // Write new targets
            PopulateTargets(targetsInfo);
        }
Exemple #8
0
        private static void WriteUpdatedTargets(ITracer tracer, TargetsInfo targetsInfo)
        {
            tracer.Info(Resources.AuthoringPackage_TraceSyncTargetsWritingNewTargets, targetsInfo.TargetsPath, targetsInfo.ToolkitVersion);

            //Delete file if exists
            if (File.Exists(targetsInfo.TargetsPath))
            {
                File.Delete(targetsInfo.TargetsPath);
            }

            // Ensure directory exists
            var targetsFolder = Path.GetDirectoryName(targetsInfo.TargetsPath);

            if (!Directory.Exists(targetsFolder))
            {
                Directory.CreateDirectory(targetsFolder);
            }

            // Write new targets
            PopulateTargets(targetsInfo);
        }
Exemple #9
0
        private static void PopulateTargets(TargetsInfo targetsInfo)
        {
            using (var stream = new MemoryStream(Resources.Microsoft_VisualStudio_Patterning_Authoring_PatternToolkitVersion))
            {
                XDocument document  = XDocument.Load(stream);
                var       nsManager = new XmlNamespaceManager(new NameTable());
                nsManager.AddNamespace(string.Empty, MSBuildNamespace);

                // Update extension paths
                targetsInfo.InstalledExtensionProperties.ToList().ForEach(ie =>
                {
                    var extensionProp = document.Descendants(XName.Get(
                                                                 string.Format(CultureInfo.InvariantCulture, "{{{1}}}{0}", ie.Key, MSBuildNamespace))).FirstOrDefault();
                    if (extensionProp != null)
                    {
                        extensionProp.Value = ie.Value ?? string.Empty;
                    }
                });

                // Save targets
                document.Save(targetsInfo.TargetsPath, SaveOptions.None);
            }
        }
Exemple #10
0
        internal static void ReadTargetsValues(TargetsInfo targetsInfo)
        {
            // Read toolkit version number
            targetsInfo.ToolkitVersion = ReadPropertyValue(targetsInfo, PatternToolkitVersionElementName);

            // Read extension paths
            if (targetsInfo.InstalledExtensionProperties != null)
            {
                var readInstalledExtensions = new Dictionary<string, string>();
                targetsInfo.InstalledExtensionProperties.ToList().ForEach(ie =>
                    {
                        readInstalledExtensions.Add(ie.Key, ReadPropertyValue(targetsInfo, ie.Key));
                    });
                targetsInfo.InstalledExtensionProperties = readInstalledExtensions;
            }
        }
Exemple #11
0
        private static void PopulateTargets(TargetsInfo targetsInfo)
        {
            using (var stream = new MemoryStream(Resources.Microsoft_VisualStudio_Patterning_Authoring_PatternToolkitVersion))
            {
                XDocument document = XDocument.Load(stream);
                var nsManager = new XmlNamespaceManager(new NameTable());
                nsManager.AddNamespace(string.Empty, MSBuildNamespace);

                // Update extension paths
                targetsInfo.InstalledExtensionProperties.ToList().ForEach(ie =>
                    {
                        var extensionProp = document.Descendants(XName.Get(
                            string.Format(CultureInfo.InvariantCulture, "{{{1}}}{0}", ie.Key, MSBuildNamespace))).FirstOrDefault();
                        if (extensionProp != null)
                        {
                            extensionProp.Value = ie.Value ?? string.Empty;
                        }
                    });

                // Save targets
                document.Save(targetsInfo.TargetsPath, SaveOptions.None);
            }
        }
Exemple #12
0
        private static string ReadPropertyValue(TargetsInfo targetsInfo, string propertyName)
        {
            XDocument document = XDocument.Load(targetsInfo.TargetsPath);
            var nsManager = new XmlNamespaceManager(new NameTable());
            nsManager.AddNamespace(string.Empty, MSBuildNamespace);

            var propertyElement = document.Descendants(XName.Get(
                            string.Format(CultureInfo.InvariantCulture, "{{{1}}}{0}", propertyName, MSBuildNamespace))).FirstOrDefault();
            if (propertyElement != null)
            {
                return propertyElement.Value;
            }
            else
            {
                return null;
            }
        }