Esempio n. 1
0
        private void UpdateDependency(Dependency dependency, int j, int count)
        {
            var           len          = count.ToString().Length;
            List <string> dependencies = dependency.dependencies;

            dependencies            = dependencies.Distinct().ToList();
            dependency.dependencies = dependencies;
            var dependencyXml = GetDependencyXml(dependency.dependencies, out var foundDependencies);

            foreach (var webResourceName in dependency.webresources)
            {
                var    fetchXml = $@"
<fetch>
  <entity name='webresource'>
    <attribute name='dependencyxml' />
    <filter type='and'>
      <condition attribute='name' operator='eq' value='{webResourceName}'/>
    </filter>
  </entity>
</fetch>";
                var    rows     = crmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));
                string existingDependencyXml;
                if (rows.Entities.Count > 0)
                {
                    existingDependencyXml = rows.Entities[0].GetAttributeValue <string>("dependencyxml");
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorBlue, string.Format("{0,0}{1," + len + "}", "", j) + ": ", CliLog.ColorMagenta, "Not existing", CliLog.ColorGreen, " Webresource ", CliLog.ColorCyan, webResourceName);
                    return;
                }
                if (existingDependencyXml != dependencyXml)
                {
                    var webResourceId = rows.Entities[0].Id;
                    var entity        = new Entity("webresource", webResourceId)
                    {
                        ["dependencyxml"] = dependencyXml
                    };
                    CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorBlue, string.Format("{0,0}{1," + len + "}", "", j), ": ", CliLog.ColorMagenta, "Updating ", CliLog.ColorCyan, webResourceName, CliLog.ColorGreen, " dependencies");
                    foreach (var d in foundDependencies)
                    {
                        CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorCyan, "\t" + d);
                    }
                    crmServiceClient.Update(entity);
                    if (!WebResourcesToPublish.Contains(webResourceId))
                    {
                        WebResourcesToPublish.Add(webResourceId);
                    }
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorBlue, string.Format("{0,0}{1," + len + "}", "", j) + ": ", CliLog.ColorCyan, webResourceName, CliLog.ColorGreen, " dependencies");
                    foreach (var d in foundDependencies)
                    {
                        CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorCyan, "\t" + d);
                    }
                }
            }
        }
Esempio n. 2
0
        private void PublishWebResources()
        {
            var guids        = WebResourcesToPublish.Select(g => g.ToString());
            var webresources = string.Join("</webresource><webresource>", guids);
            var publish      = new PublishXmlRequest
            {
                ParameterXml =
                    "<importexportxml><webresources>" +
                    "<webresource>" + webresources + "</webresource>" +
                    "</webresources></importexportxml>"
            };

            CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, "Publishing WebResources");
            crmServiceClient.Execute(publish);
            CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, "Published WebResources");
        }
        private void PublishWebResources()
        {
            var guids        = WebResourcesToPublish.Select(g => g.ToString());
            var webresources = string.Join("</webresource><webresource>", guids);
            var publish      = new PublishXmlRequest
            {
                ParameterXml =
                    "<importexportxml><webresources>" +
                    "<webresource>" + webresources + "</webresource>" +
                    "</webresources></importexportxml>"
            };

            CliLog.WriteLine();
            CliLog.WriteLine(ConsoleColor.Red, "PUBLISHING WEBRESOURCES");
            crmServiceClient.Execute(publish);

            CliLog.WriteLine();
            CliLog.WriteLine(ConsoleColor.Red, "PUBLISHED WEBRESOURCES");
        }
Esempio n. 4
0
        private void DeployWebResource(WebResourceFile webResourceFile, int current, int totalWebResources)
        {
            var len = totalWebResources.ToString().Length;

            if (webResourceFile.uniquename.StartsWith("/"))
            {
                webResourceFile.uniquename = webResourceFile.uniquename.Substring(1);
            }

            var fetchData = new
            {
                name  = webResourceFile.uniquename,
                name2 = webResourceFile.uniquename.Substring(0, webResourceFile.uniquename.LastIndexOf('.'))
            };
            var fetchXml      = $@"
<fetch>
  <entity name='webresource'>
    <attribute name='content' />
    <attribute name='webresourceid' />
    <attribute name='name' />
    <attribute name='iscustomizable' />
    <attribute name='ismanaged' />
    <filter type='or'>
      <condition attribute='name' operator='eq' value='{fetchData.name}'/>
      <condition attribute='name' operator='eq' value='{fetchData.name2}'/>
    </filter>
  </entity>
</fetch>";
            var rows          = crmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));
            var content       = string.Empty;
            var webResourceId = Guid.Empty;

            if (rows.Entities.Count > 0)
            {
                if (rows.Entities.Count == 1)
                {
                    var entity         = rows.Entities[0];
                    var ismanaged      = entity.GetAttributeValue <bool?>("ismanaged");
                    var iscustomizable = entity.GetAttributeValue <BooleanManagedProperty>("iscustomizable");
                    if (ismanaged.HasValue && ismanaged.Value == true)
                    {
                        if (iscustomizable?.Value == false)
                        {
                            CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + len + "}", "", current) + ": ", CliLog.ColorRed, "Update webresource failed because the setting webresource.iscustomizable = false - ", CliLog.ColorGreen, webResourceFile.uniquename);
                            return;
                        }
                    }
                    webResourceId = entity.Id;
                    content       = entity?["content"]?.ToString();
                }
                else
                {
                    foreach (var entity in rows.Entities)
                    {
                        if (entity.GetAttributeValue <string>("name") != fetchData.name)
                        {
                            continue;
                        }
                        var ismanaged      = entity.GetAttributeValue <bool?>("ismanaged");
                        var iscustomizable = entity.GetAttributeValue <BooleanManagedProperty>("iscustomizable");
                        if (ismanaged.HasValue && ismanaged.Value == true)
                        {
                            if (iscustomizable?.Value == false)
                            {
                                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + len + "}", "", current) + ": ", CliLog.ColorRed, "Update webresource failed because the setting webresource.iscustomizable = false - ", CliLog.ColorGreen, webResourceFile.uniquename);
                                return;
                            }
                        }
                        webResourceId = entity.Id;
                        content       = entity?["content"]?.ToString();
                        break;
                    }
                }
            }
            var fileContent = Convert.ToBase64String(File.ReadAllBytes(webResourceFile.file));

            if (fileContent == content)
            {
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + len + "}", "", current) + ": ", CliLog.ColorMagenta, "No Change ", CliLog.ColorGreen, webResourceFile.file.Substring(currentDirectory.Length + 1));
                AddWebResourceToSolution(new Entity("webresource")
                {
                    ["name"]          = webResourceFile.uniquename,
                    ["webresourceid"] = webResourceId
                });
                return;
            }
            var webResource = new Entity("webresource")
            {
                ["name"]        = webResourceFile.uniquename,
                ["displayname"] = webResourceFile.displayname,
                ["description"] = webResourceFile.version,
                ["content"]     = fileContent
            };
            var webResourceFileInfo = new FileInfo(webResourceFile.file);
            var fileType            = WebResourceWebResourceType.ScriptJScript;

            switch (webResourceFileInfo.Extension.ToLower().TrimStart('.'))
            {
            case "html":
            case "htm":
                fileType = WebResourceWebResourceType.WebpageHtml;
                break;

            case "js":
                fileType = WebResourceWebResourceType.ScriptJScript;
                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.StyleSheetCss;
                break;

            case "ico":
                fileType = WebResourceWebResourceType.IcoFormat;
                break;

            case "xml":
                fileType = WebResourceWebResourceType.DataXml;
                break;

            case "xsl":
            case "xslt":
                fileType = WebResourceWebResourceType.StyleSheetXsl;
                break;

            case "xap":
                fileType = WebResourceWebResourceType.SilverlightXap;
                break;

            case "resx":
                fileType = WebResourceWebResourceType.StringResx;
                break;

            case "svg":
                fileType = WebResourceWebResourceType.SvgFormat;
                break;
            }
            webResource["webresourcetype"] = new OptionSetValue((int)fileType);
            if (fileType == WebResourceWebResourceType.StringResx)
            {
                var fileName = webResourceFileInfo.Name.Substring(0, webResourceFileInfo.Name.Length - webResourceFileInfo.Extension.Length);
                var arr      = fileName.Split(".".ToCharArray());
                if (int.TryParse(arr[arr.Length - 1], out var languagecode))
                {
                    var req = new RetrieveProvisionedLanguagesRequest();
                    var res = (RetrieveProvisionedLanguagesResponse)crmServiceClient.Execute(req);
                    if (res.RetrieveProvisionedLanguages.Contains(languagecode))
                    {
                        webResource["languagecode"] = languagecode;
                    }
                    else
                    {
                        throw new Exception($"Language code not found: {languagecode}");
                    }
                }
            }
            if (webResourceId == Guid.Empty)
            {
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + len + "}", "", current), ": ", CliLog.ColorMagenta, "Creating", CliLog.ColorGreen, " WebResource ", CliLog.ColorCyan, webResourceFile.file, CliLog.ColorGreen, " to ", CliLog.ColorCyan, webResourceFile.uniquename);
                webResourceId = crmServiceClient.Create(webResource);
                webResource["webresourceid"] = webResourceId;
            }
            else
            {
                webResource["webresourceid"] = webResourceId;
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + len + "}", "", current), ": ", CliLog.ColorMagenta, "Updating", CliLog.ColorBlue, " WebResource ", CliLog.ColorCyan, webResourceFile.file, CliLog.ColorGreen, " to ", CliLog.ColorCyan, webResourceFile.uniquename);
                crmServiceClient.Update(webResource);
            }
            WebResourcesToPublish.Add(webResourceId);
            AddWebResourceToSolution(webResource);
        }