private static void UpdateSpklMapping(SpklConfig spklConfig, Project project, string profile, WebResourceItem webResourceItem) { List <SpklConfigWebresourceFile> spklConfigWebresourceFiles = GetSpklConfigWebresourceFiles(profile, spklConfig); if (spklConfigWebresourceFiles == null) { return; } if (!string.IsNullOrEmpty(webResourceItem.BoundFile)) { bool isTs = WebResourceTypes.GetExtensionType(webResourceItem.BoundFile) == D365DeveloperExtensions.Core.Enums.FileExtensionType.Ts; foreach (SpklConfigWebresourceFile spklConfigWebresourceFile in spklConfigWebresourceFiles.Where(w => w.uniquename == webResourceItem.Name)) { spklConfigWebresourceFile.file = webResourceItem.BoundFile; spklConfigWebresourceFile.description = webResourceItem.Description; spklConfigWebresourceFile.ts = null; if (!isTs) { continue; } spklConfigWebresourceFile.file = TsHelper.GetJsForTsPath(webResourceItem.BoundFile, project); spklConfigWebresourceFile.ts = webResourceItem.BoundFile; } } else { spklConfigWebresourceFiles.RemoveAll(w => w.uniquename == webResourceItem.Name); } if (profile.StartsWith(ExtensionConstants.NoProfilesText)) { spklConfig.webresources[0].files = spklConfigWebresourceFiles; } else { WebresourceDeployConfig webresourceDeployConfig = spklConfig.webresources.FirstOrDefault(w => w.profile == profile); if (webresourceDeployConfig != null) { webresourceDeployConfig.files = spklConfigWebresourceFiles; } } string projectPath = D365DeveloperExtensions.Core.Vs.ProjectWorker.GetProjectPath(project); ConfigFile.UpdateSpklConfigFile(projectPath, spklConfig); }
private static void UpdateSpklMapping(SpklConfig spklConfig, Project project, string profile, WebResourceItem webResourceItem) { List <SpklConfigWebresourceFile> spklConfigWebresourceFiles = GetSpklConfigWebresourceFiles(profile, spklConfig); if (spklConfigWebresourceFiles == null) { return; } if (!string.IsNullOrEmpty(webResourceItem.BoundFile)) { foreach (SpklConfigWebresourceFile spklConfigWebresourceFile in spklConfigWebresourceFiles.Where(w => w.uniquename == webResourceItem.Name)) { spklConfigWebresourceFile.file = webResourceItem.BoundFile; spklConfigWebresourceFile.description = webResourceItem.Description; } } else { spklConfigWebresourceFiles.RemoveAll(w => w.uniquename == webResourceItem.Name); } if (profile.StartsWith(ExtensionConstants.NoProfilesText)) { spklConfig.webresources[0].files = spklConfigWebresourceFiles; } else { WebresourceDeployConfig webresourceDeployConfig = spklConfig.webresources.FirstOrDefault(w => w.profile == profile); if (webresourceDeployConfig != null) { webresourceDeployConfig.files = spklConfigWebresourceFiles; } } string projectPath = CrmDeveloperExtensions2.Core.Vs.ProjectWorker.GetProjectPath(project); ConfigFile.UpdateSpklConfigFile(projectPath, spklConfig); }
private void AutoDetect(OrganizationServiceContext ctx, string webresourceRoot, WebresourceDeployConfig webresources, List <Guid> webresourcesToPublish) { if (Solution == null) { throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.WEBRESOURCE_ERROR, $"Solution name required for AutoDetect."); } if (webresources.deleteaction != null) { switch (webresources.deleteaction.ToLower()) { case "delete": webresources.deleteaction = webresources.deleteaction.ToLower(); break; case "remove": webresources.deleteaction = webresources.deleteaction.ToLower(); break; case "no": case "none": case "leave": case "nothing": webresources.deleteaction = "no"; break; default: throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.WEBRESOURCE_ERROR, $"Invalid deleteaction settng found: '{webresources.deleteaction}'"); } } else { webresources.deleteaction = "no"; } if (!Directory.Exists(webresourceRoot)) { throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.WEBRESOURCE_ERROR, $"WebResource source folder not found: '{webresourceRoot}'"); } // Get existing solution WRs List <WebResource> curWebResources = ServiceLocator.Queries.GetWebresourcesInSolution(ctx, this.Solution); _trace.WriteLine(string.Format("{0} Current WebResourceCount: {1}", this.Solution, curWebResources.Count)); // Make sure the delimiters are all the same & remove any trailing delims webresourceRoot = webresourceRoot.Replace('/', '\\'); while (webresourceRoot.Substring(webresourceRoot.Length - 1, 1) == "\\") { webresourceRoot = webresourceRoot.Substring(0, webresourceRoot.Length - 1); } DeployDirectory(ctx, webresourceRoot, webresourceRoot, webresourcesToPublish, curWebResources); _trace.WriteLine(string.Format("{0} WebResources no longer present in directory", curWebResources.Count)); if (webresources.deleteaction == "delete" || webresources.deleteaction == "remove") { bool errEncountered = false; foreach (var curWebResource in curWebResources) { try { if (webresources.deleteaction == "delete") { _trace.WriteLine(string.Format("Deleting '{0}'", curWebResource.Name)); _service.Delete(WebResource.EntityLogicalName, curWebResource.Id); } else { _trace.WriteLine(string.Format("Remove from solution '{0}'", curWebResource.Name)); RemoveWebresourceFromSolution(this.Solution, curWebResource); } } catch (Exception ex) { errEncountered = true; _trace.WriteLine(string.Format("Error processing Delete/Remove - {0}", ex.Message)); } } if (errEncountered) { throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.WEBRESOURCE_ERROR, $"Error encountered processing {webresources.deleteaction} for missing files."); } } }
public List <Guid> DeployWebresources(OrganizationServiceContext ctx, ConfigFile config, WebresourceDeployConfig webresources) { var webresourceRoot = Path.Combine(config.filePath, "" + webresources.root); this.Solution = webresources.solution; bool autodetect = false; if (webresources.autodetect != null) { switch (webresources.autodetect.ToLower()) { case "yes": case "true": autodetect = true; break; case "no": case "false": autodetect = false; break; default: throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.WEBRESOURCE_ERROR, $"Invalid autodetect settng found: '{webresources.autodetect}'"); } } var webresourcesToPublish = new List <Guid>(); if (autodetect) { AutoDetect(ctx, webresourceRoot, webresources, webresourcesToPublish); } else { foreach (var file in webresources.files) { DeployWebResource(ctx, webresourceRoot, webresourcesToPublish, file); } } _trace.WriteLine("Deployed {0} webresource(s)", webresourcesToPublish.Count); return(webresourcesToPublish); }
public IEnumerable <Guid> DeployWebresources(OrganizationServiceContext ctx, ConfigFile config, WebresourceDeployConfig webresources) { var webresourceRoot = Path.Combine(config.filePath, "" + webresources.root); this.Solution = webresources.solution; var webresourcesToPublish = new List <Guid>(webresources.files.Count); foreach (var file in webresources.files) { if (file.uniquename == null) { // Make the name uniquename the same as the file name file.uniquename = file.file.Replace("\\", "/"); } if (file.displayname == null) { // make the same as the unique name file.displayname = file.uniquename; } WebResource webresource = ServiceLocator.Queries.GetWebResource(ctx, file.uniquename); if (webresource == null) { webresource = new WebResource(); } var fullPath = Path.Combine(webresourceRoot, file.file); var filecontent = Convert.ToBase64String(File.ReadAllBytes(fullPath)); // Update webresource.Name = file.uniquename; webresource.DisplayName = file.displayname; webresource.Description = file.description; webresource.Content = filecontent; var webResourceFileInfo = new FileInfo(fullPath); webresource_webresourcetype filetype = webresource_webresourcetype.Script_JScript; switch (webResourceFileInfo.Extension.ToLower().TrimStart('.')) { case "html": case "htm": filetype = webresource_webresourcetype.Webpage_HTML; break; case "js": filetype = webresource_webresourcetype.Script_JScript; break; case "png": filetype = webresource_webresourcetype.PNGformat; break; case "gif": filetype = webresource_webresourcetype.GIFformat; break; case "jpg": case "jpeg": filetype = webresource_webresourcetype.JPGformat; break; case "css": filetype = webresource_webresourcetype.StyleSheet_CSS; break; case "ico": filetype = webresource_webresourcetype.ICOformat; break; case "xml": filetype = webresource_webresourcetype.Data_XML; break; case "xsl": case "xslt": filetype = webresource_webresourcetype.StyleSheet_XSL; break; case "xap": filetype = webresource_webresourcetype.Silverlight_XAP; break; case "svg": filetype = webresource_webresourcetype.Vectorformat_SVG; break; } webresource.WebResourceType = filetype; if (webresource.Id == Guid.Empty) { _trace.WriteLine("Creating Webresource '{0}' -> '{1}'", file.file, file.uniquename); // create webresource.Id = _service.Create(webresource); } else { _trace.WriteLine("Updating Webresource '{0}' -> '{1}'", file.file, file.uniquename); // Update _service.Update(webresource); } ; // Add to solution if (Solution != null) { AddWebresourceToSolution(Solution, webresource); } webresourcesToPublish.Add(webresource.Id); } _trace.WriteLine("Deployed {0} webresource(s)", webresources.files.Count); return(webresourcesToPublish); }
private void DeployWebresources(OrganizationServiceContext ctx, ConfigFile config, WebresourceDeployConfig webresources) { var webresourceRoot = Path.Combine(config.filePath, "" + webresources.root); this.Solution = webresources.solution; foreach (var file in webresources.files) { if (file.uniquename == null) { // Make the name uniquename the same as the file name file.uniquename = file.file.Replace("\\", "/"); } if (file.displayname == null) { // make the same as the unique name file.displayname = file.uniquename; } WebResource webresource = ctx.GetWebResource(file.uniquename); if (webresource == null) { webresource = new WebResource(); } var fullPath = Path.Combine(webresourceRoot, file.file); var filecontent = Convert.ToBase64String(File.ReadAllBytes(fullPath)); // Update webresource.Name = file.uniquename; webresource.DisplayName = file.displayname; webresource.Description = file.description; webresource.Content = filecontent; var webResourceFileInfo = new FileInfo(fullPath); WebResourceWebResourceType filetype = WebResourceWebResourceType.Script_JScript; switch (webResourceFileInfo.Extension.ToLower()) { case "html": case "htm": filetype = WebResourceWebResourceType.Webpage_HTML; break; case "js": filetype = WebResourceWebResourceType.Script_JScript; break; case "png": filetype = WebResourceWebResourceType.PNGformat; break; case "gif": filetype = WebResourceWebResourceType.GIFformat; break; case "jpg": case "jpeg": filetype = WebResourceWebResourceType.JPGformat; break; case "css": filetype = WebResourceWebResourceType.StyleSheet_CSS; break; case "ico": filetype = WebResourceWebResourceType.ICOformat; break; case "xml": filetype = WebResourceWebResourceType.Data_XML; break; case "xsl": case "xslt": filetype = WebResourceWebResourceType.StyleSheet_XSL; break; case "xap": filetype = WebResourceWebResourceType.Silverlight_XAP; break; } webresource.WebResourceType = new OptionSetValue((int)filetype); if (webresource.Id == Guid.Empty) { _trace.WriteLine("Creating Webresource '{0}' -> '{1}'", file.file, file.uniquename); // create webresource.Id = _service.Create(webresource); } else { _trace.WriteLine("Updating Webresource '{0}' -> '{1}'", file.file, file.uniquename); // Update _service.Update(webresource); } ; // Add to solution if (Solution != null) { AddWebresourceToSolution(Solution, webresource); } // Publish var publish = new PublishXmlRequest() { ParameterXml = "<importexportxml>" + " <webresources>" + " <webresource>" + webresource.Id.ToString() + "</webresource>" + " </webresources>" + "</importexportxml>" }; } _trace.WriteLine("Deployed {0} webresource(s)", webresources.files.Count); }