Exemplo n.º 1
0
        private bool RemoveItemFromTemplate(string projectItemFullPath, string projectItemKind, LoadedXMLProvisioningTemplate loadedTemplate)
        {
            if (loadedTemplate != null && loadedTemplate.Template != null)
            {
                var src = ProvisioningHelper.MakeRelativePath(projectItemFullPath, loadedTemplate.ResourcesPath);

                if (projectItemKind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
                {
                    // Remove all files where src path starts with given folder path
                    loadedTemplate.Template.Files.RemoveAll(f => f.Src.StartsWith(src, StringComparison.InvariantCultureIgnoreCase));
                }
                else if (projectItemKind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                {
                    // Remove all files where src path equals item path
                    loadedTemplate.Template.Files.RemoveAll(f => f.Src.Equals(src, StringComparison.InvariantCultureIgnoreCase));
                }
                else
                {
                    return(false); //terminate, wrong "kind"
                }

                LogService.Info("Item removed from template: " + src);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool RenameTemplateItem(string projectItemFullPath, string projectItemKind, string oldName, LoadedXMLProvisioningTemplate loadedTemplate)
        {
            if (loadedTemplate != null && loadedTemplate.Template != null)
            {
                var src = ProvisioningHelper.MakeRelativePath(projectItemFullPath, loadedTemplate.ResourcesPath);

                if (projectItemKind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
                {
                    var oldSrc = Path.Combine(src.Substring(0, src.TrimEnd('\\').LastIndexOf('\\')), oldName) + "\\";

                    // Remove all files where src path starts with given folder path
                    var filesToRename = loadedTemplate.Template.Files.Where(f => f.Src.StartsWith(oldSrc, StringComparison.InvariantCultureIgnoreCase));

                    foreach (var file in filesToRename)
                    {
                        file.Src = Regex.Replace(file.Src, Regex.Escape(oldSrc), src, RegexOptions.IgnoreCase);
                    }
                }
                else if (projectItemKind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                {
                    var oldSrc = Path.Combine(Path.GetDirectoryName(src), oldName);

                    var file =
                        loadedTemplate.Template.Files.Where(
                            f => f.Src.Equals(oldSrc, StringComparison.InvariantCultureIgnoreCase))
                        .FirstOrDefault();

                    if (file != null)
                    {
                        file.Src = src;
                    }
                }
                else
                {
                    return(false); //terminate, wrong item type
                }

                LogService.Info("Item renamed in template: " + src);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        private bool AddItemToTemplate(string projectItemFullPath, LoadedXMLProvisioningTemplate loadedTemplate)
        {
            if (loadedTemplate != null && loadedTemplate.Template != null)
            {
                // Item is PnP resource.
                var src          = ProvisioningHelper.MakeRelativePath(projectItemFullPath, loadedTemplate.ResourcesPath);
                var targetFolder = String.Join("/", Path.GetDirectoryName(src).Split('\\'));

                loadedTemplate.Template.Files.Add(new OfficeDevPnP.Core.Framework.Provisioning.Model.File()
                {
                    Src       = src,
                    Folder    = targetFolder,
                    Overwrite = true,
                    Security  = null
                });

                LogService.Info("Item added to template: " + src);
                return(true);
            }

            return(false);
        }