Exemple #1
0
        /// <summary>
        /// Configures the files included in the template for VSIX packaging,
        /// and returns the Uri for the template.
        /// </summary>
        public IVsTemplate Configure(IItem templateItem, string displayName, string description, string path)
        {
            Guard.NotNull(() => templateItem, templateItem);

            // Calculate the new Identifier
            var unicySeed            = Guid.NewGuid().ToString(@"N");
            var unicyIdentifier      = unicySeed.Substring(unicySeed.Length - MaxUnicyLength);
            var remainingNamedLength = MaxTemplateIdLength - MaxUnicyLength - 1;
            var namedIdentifier      = path.Substring(path.Length <= remainingNamedLength ? 0 : (path.Length - remainingNamedLength));
            var templateId           = string.Format(CultureInfo.InvariantCulture, @"{0}-{1}", unicyIdentifier, namedIdentifier);

            // Update the vstemplate
            var template = VsTemplateFile.Read(templateItem.PhysicalPath);

            template.SetTemplateId(templateId);
            template.SetDefaultName(SanitizeName(displayName));
            template.SetName(displayName);
            template.SetDescription(description);
            VsHelper.CheckOut(template.PhysicalPath);
            VsTemplateFile.Write(template);

            UpdateDirectoryProperties(templateItem);

            // Set VS attributes on the vstemplate file
            if (template.Type == VsTemplateType.Item)
            {
                templateItem.Data.ItemType = @"ItemTemplate";
            }
            else
            {
                templateItem.Data.ItemType = @"ProjectTemplate";
            }

            return(template);
        }
Exemple #2
0
        private bool VerifyDslVersion(string storeFile)
        {
            bool isValidVersion = true;

            var exception =
                tracer.Shield(
                    () =>
            {
                var document   = XDocument.Load(storeFile);
                var dslVersion = new Version(document.Root.Attribute(DslVersionAttribute).Value);

                if (dslVersion != StoreConstants.DslVersion)
                {
                    if (this.messageService.PromptWarning(
                            string.Format(CultureInfo.InvariantCulture,
                                          Properties.Resources.PatternManager_NewerDslVersionUpgrade, Path.GetFileName(this.StoreFile), StoreConstants.ProductName)))
                    {
                        document.Root.Attribute(DslVersionAttribute).Value = StoreConstants.DslVersion.ToString();

                        VsHelper.CheckOut(storeFile);

                        document.Save(storeFile);
                    }
                    else
                    {
                        isValidVersion = false;
                    }
                }
            }, Properties.Resources.PatternManager_FailedToVerifyDslVersion);

            return(isValidVersion && exception == null);
        }
        /// <summary>
        /// Loads the Blackboard from the global XML file
        /// </summary>
        /// <returns>A &lt;string,string&gt; dictionary deserialized from the file</returns>
        private Dictionary <string, string> GetBlackboardDataFromFile()
        {
            Dictionary <string, string> result;

            if (!IsPersistent)
            {
                return(this.blackboard);
            }

            //
            // Check it out if it's under source control
            //
            VsHelper.CheckOut(blackboardFileName);

            if (!File.Exists(this.blackboardFileName))
            {
                this.blackboard = new Dictionary <string, string>();
                this.WriteBlackboardDataToFile();
            }

            using (XmlReader reader = XmlReader.Create(this.blackboardFileName))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary <string, string>));

                result = (Dictionary <string, string>)serializer.ReadObject(reader);
            }

            return(result);
        }
Exemple #4
0
        private void DeleteViewDiagram(IItemContainer parentItem, IViewSchema viewSchema)
        {
            var path      = GetDiagramFileName(parentItem, viewSchema);
            var childItem = parentItem.Items.FirstOrDefault(i => i.PhysicalPath == path);

            if (childItem != null)
            {
                VsHelper.CheckOut(childItem.PhysicalPath);
                childItem.As <EnvDTE.ProjectItem>().Remove();
            }
        }
Exemple #5
0
        private static void SaveDocument(XDocument document, string filePath)
        {
            var serviceProvider = ServiceProvider.GlobalProvider;

            tracer.Info(ShellResources.SchemaUpgradeContext_TraceSaveSchemaFile, filePath);

            // Save file content
            VsHelper.CheckOut(filePath);
            VsHelper.WithoutFileChangeNotification(serviceProvider, filePath, () =>
            {
                document.Save(filePath);
            });
        }
Exemple #6
0
        /// <summary>
        /// Writes a .vstemplate file from the given instance.
        /// </summary>
        public static void Write(IVsTemplate templateInstance, string templateFilename)
        {
            var hasFragment = templateFilename.Contains('?');

            if (hasFragment || templateFilename.EndsWith(TemplateArchiveFileExtension, StringComparison.InvariantCultureIgnoreCase))
            {
                var vsTemplateFileName = templateInstance.TemplateFileName;

                var tempDir = UncompressToTempDir(templateFilename);

                var tempFile = Path.Combine(tempDir, vsTemplateFileName);
                File.SetAttributes(tempFile, FileAttributes.Normal);
                // call recursivly for the .vstemplate file in the temp directory)
                Write(templateInstance, tempFile);

                VsHelper.CheckOut(templateFilename);

                new ZipFileCompressor(
                    templateFilename,
                    tempDir,
                    Directory
                    .GetFiles(tempDir, @"*.*", SearchOption.AllDirectories)
                    .Select(x => x.Replace(tempDir + Path.DirectorySeparatorChar, ""))
                    .ToArray(),
                    true,
                    true);
            }
            else if (templateFilename.EndsWith(TemplateFileExtension, StringComparison.InvariantCultureIgnoreCase))
            {
                VsHelper.CheckOut(templateFilename);

                using (var file = new StreamWriter(templateFilename, false))
                    using (var writer = XmlWriter.Create(file, new XmlWriterSettings {
                        Indent = true
                    }))
                    {
                        var namespaces = new XmlSerializerNamespaces(new[] { TemplateDefaultNamespace });
                        Serializer.Serialize(writer, templateInstance, namespaces);
                    }
            }
            else
            {
                throw new InvalidOperationException(Resources.VsTemplateFile_ErrorUnsupportedVsTemplateExtension);
            }
        }