예제 #1
0
        public DeployTemplateItem GetDeployItem(Services.ILogService logService)
        {
            LoadedXMLProvisioningTemplate loadedTemplate = null;

            try
            {
                //load the template xml file
                loadedTemplate = this.TemplateInfo.LoadXmlTemplate();
            }
            catch (Exception ex)
            {
                logService.Exception("Error reading template file " + this.ItemPath, ex);
                return(null);
            }

            if (loadedTemplate.Template != null)
            {
                if (this.TemplateInfo.TemplatePath == this.ItemPath)
                {
                    //deploy complete template
                    var deployItem = new DeployTemplateItem()
                    {
                        Config             = this.ProvisioningConfig,
                        Template           = loadedTemplate.Template,
                        TemplateName       = loadedTemplate.TemplateFileName,
                        IsCompleteTemplate = true,
                    };
                    return(deployItem);
                }
                else
                {
                    //deploy specific file(s)
                    var src = Helpers.ProvisioningHelper.MakeRelativePath(this.ItemPath, this.TemplateInfo.ResourcesPath);

                    var files = loadedTemplate.Template.Files.Where(
                        f => f.Src.StartsWith(src, StringComparison.InvariantCultureIgnoreCase)
                        ).ToList();

                    if (files.Count > 0)
                    {
                        //create a new template for the specified file
                        var filesUnderFolderTemplate = new OfficeDevPnP.Core.Framework.Provisioning.Model.ProvisioningTemplate(loadedTemplate.Template.Connector);
                        filesUnderFolderTemplate.Files.AddRange(files);

                        var deployItem = new DeployTemplateItem()
                        {
                            Config             = this.ProvisioningConfig,
                            Template           = filesUnderFolderTemplate,
                            TemplateName       = loadedTemplate.TemplateFileName,
                            IsCompleteTemplate = false,
                        };
                        return(deployItem);
                    }
                }
            }

            return(null);
        }
        public LoadedXMLProvisioningTemplate LoadXmlTemplate(string containerName = "")
        {
            LoadedXMLProvisioningTemplate loadedTemplate = new LoadedXMLProvisioningTemplate()
            {
                ResourcesPath      = this.ResourcesPath,
                TemplateFileName   = this.TemplateFileName,
                TemplateFolderPath = this.TemplateFolderPath,
            };

            try
            {
                loadedTemplate.Provider           = new OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml.XMLFileSystemTemplateProvider(this.TemplateFolderPath, containerName);
                loadedTemplate.Template           = loadedTemplate.Provider.GetTemplate(this.TemplateFileName);
                loadedTemplate.Template.Connector = new OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileSystemConnector(this.ResourcesPath, containerName);
            }
            catch (Exception ex)
            {
                var logService = IoCBootstrapper.GetLoggerInstance();
                logService.Info(string.Format("Error parsing Provisioning Template: {0}, {1}", ex.Message, ex.StackTrace));
            }

            return(loadedTemplate);
        }
        public LoadedXMLProvisioningTemplate LoadXmlTemplate(string containerName = "")
        {
            LoadedXMLProvisioningTemplate loadedTemplate = new LoadedXMLProvisioningTemplate()
            {
                ResourcesPath = this.ResourcesPath,
                TemplateFileName = this.TemplateFileName,
                TemplateFolderPath = this.TemplateFolderPath,
            };

            try
            {
                loadedTemplate.Provider = new OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml.XMLFileSystemTemplateProvider(this.TemplateFolderPath, containerName);
                loadedTemplate.Template = loadedTemplate.Provider.GetTemplate(this.TemplateFileName);
                loadedTemplate.Template.Connector = new OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileSystemConnector(this.ResourcesPath, containerName);
            }
            catch (Exception ex)
            {
                var logService = IoCBootstrapper.GetLoggerInstance();
                logService.Info(string.Format("Error parsing Provisioning Template: {0}, {1}", ex.Message, ex.StackTrace));
            }

            return loadedTemplate;
        }
예제 #4
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;
        }
예제 #5
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;
        }
예제 #6
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;
        }