예제 #1
0
        private void GeneratorLateBound()
        {
            CliLog.WriteLine(CliLog.ColorGreen, "START GENERATOR - LATE BOUND - TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            var          entities = new List <string>();
            const string pattern  = "*.generated.cs";
            var          folder   = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}";
            var          files    = Directory.GetFiles(folder, pattern);

            foreach (var file in files)
            {
                var fInfo   = new FileInfo(file);
                var columns = fInfo.Name.Split(".".ToCharArray());
                entities.Add(columns[0]);
            }
            if (entities.Count == 0)
            {
                CliLog.WriteLine(CliLog.ColorRed, "NOT FOUND ENTITIES !!!");
                return;
            }

            CliLog.WriteLine(CliLog.ColorGreen, "Found: ", CliLog.ColorCyan, entities.Count, CliLog.ColorGreen, " entities");
            var i = 1;

            foreach (var entity in entities)
            {
                GeneratorLateBound(entity, i, entities.Count);
                i++;
            }
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "END GENERATOR - LATE BOUND - TASKS");
        }
예제 #2
0
        private void RegisterPluginType(Entity pluginEntity, TypeInfo plugin)
        {
            var fetchData = new
            {
                typename = plugin.FullName
            };
            var fetchXml = $@"
<fetch>
  <entity name='plugintype'>
    <attribute name='plugintypeid' />
    <filter type='and'>
      <condition attribute='typename' operator='eq' value='{fetchData.typename}'/>
    </filter>
  </entity>
</fetch>";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                var pluginType = new Entity("plugintype")
                {
                    ["name"]             = plugin.FullName,
                    ["pluginassemblyid"] = new EntityReference("pluginassembly", Guid.Parse(pluginEntity["pluginassemblyid"].ToString())),
                    ["typename"]         = plugin.FullName,
                    ["friendlyname"]     = plugin.FullName
                };
                CliLog.WriteLine(CliLog.ColorGreen, $"\tRegistering Type: ", CliLog.ColorCyan, $"{plugin.FullName}");
                var pluginTypeId = CrmServiceClient.Create(pluginType);
                pluginType["plugintypeid"] = pluginTypeId;
            }
        }
예제 #3
0
        private Entity RegisterAssembly(FileSystemInfo assemblyFilePath, Assembly assembly, IEnumerable <Type> plugins)
        {
            var assemblyProperties = assembly.GetName().FullName
                                     .Split(",= ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var assemblyName = assembly.GetName().Name;
            var fetchData    = new
            {
                name = assemblyProperties[0]
            };
            var fetchXml         = $@"
<fetch>
  <entity name='pluginassembly'>
    <attribute name='pluginassemblyid' />
    <attribute name='content' />
    <filter type='and'>
      <condition attribute='name' operator='eq' value='{fetchData.name}'/>
    </filter>
  </entity>
</fetch>";
            var rows             = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));
            var pluginAssemblyId = Guid.Empty;
            var existingContent  = string.Empty;

            if (rows.Entities.Count > 0)
            {
                var entity = rows.Entities[0];
                pluginAssemblyId = entity.Id;
                existingContent  = entity.GetAttributeValue <string>("content");
            }
            var content = Convert.ToBase64String(File.ReadAllBytes(assemblyFilePath.FullName));

            if (content == existingContent)
            {
                return(null);
            }
            var plugin = new Entity("pluginassembly")
            {
                ["content"]        = content,
                ["name"]           = assemblyProperties[0],
                ["culture"]        = assemblyProperties[4],
                ["version"]        = assemblyProperties[2],
                ["publickeytoken"] = assemblyProperties[6],
                ["sourcetype"]     = new OptionSetValue(0), /* 0 = database */
                ["isolationmode"]  = new OptionSetValue(2)  /* 2 = sandbox */
            };

            if (pluginAssemblyId == Guid.Empty)
            {
                CliLog.WriteLine(CliLog.ColorGreen, "Registering Assembly: ", CliLog.ColorCyan, $"{assemblyProperties[0]}");
                pluginAssemblyId           = CrmServiceClient.Create(plugin);
                plugin["pluginassemblyid"] = pluginAssemblyId;
            }
            else
            {
                CliLog.WriteLine(CliLog.ColorBlue, "Updating Assembly: ", CliLog.ColorCyan, $"{assemblyProperties[0]}");
                plugin["pluginassemblyid"] = pluginAssemblyId;
                CrmServiceClient.Update(plugin);
            }
            return(plugin);
        }
예제 #4
0
        public static void Main(string[] args)
        {
            CliLog.WriteLine(CliLog.COLOR_GREEN, new String('*', CliLog.STAR_LENGTH));
            CliLog.WriteLine(CliLog.COLOR_GREEN, "PL.DynamicsCrm.DevKit.Cli ", CliLog.COLOR_RED, "1.0.2");
            CliLog.WriteLine(CliLog.COLOR_GREEN, new String('*', CliLog.STAR_LENGTH));
            CommandLineArgs arguments = null;

#if !DEBUG
            try
            {
#endif
            arguments = CommandLine.Parse <CommandLineArgs>();
            Run(arguments);
#if DEBUG
            CliLog.WriteLine(CliLog.COLOR_RED, "!!! FINISHED !!!");
            Console.ReadKey();
#endif
#if !DEBUG
        }
        catch (Exception e)
        {
            CliLog.WriteLine(CliLog.COLOR_ERROR, $"Reading arguments fail:\r\n{e.Message}");
            Console.ReadKey();
            return;
        }
#endif
        }
예제 #5
0
        internal void Run()
        {
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            if (GeneratorJson.rootnamespace.Length == 0 || GeneratorJson.rootnamespace == "???")
            {
                throw new Exception("No rootnamespace found. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (GeneratorJson.rootfolder == "???")
            {
                throw new Exception("No rootfolder found. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (GeneratorJson.crmversion.Length == 0 || GeneratorJson.crmversion == "???")
            {
                throw new Exception("No crmversion found. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (GeneratorJson.usetypescriptdeclaration != "true" && GeneratorJson.usetypescriptdeclaration != "false")
            {
                throw new Exception("No usetypescriptdeclaration found. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }

            if (GeneratorJson.type.ToLower() == "csharp" || GeneratorJson.type.ToLower() == "c#")
            {
                GeneratorLateBound();
            }
            else if (GeneratorJson.type.ToLower() == "jsform")
            {
                GeneratorJsForm();
            }
            else if (GeneratorJson.type.ToLower() == "jswebapi")
            {
                GeneratorWebApi();
            }

            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
        }
        private void Packger(string solutionFile)
        {
            var command = CreateCommandArgs(solutionFile);
            var path    = "\"" + GetParentFolder(CurrentDirectory) + $@"\packages\Microsoft.CrmSdk.CoreTools.{Version}\content\bin\coretools\SolutionPackager.exe" + "\"";

            CliLog.WriteLine(CliLog.ColorGreen, "Executing Solution Packager");
            CliLog.WriteLine(CliLog.ColorCyan, "\t" + path);
            CliLog.WriteLine(CliLog.ColorCyan, "\t" + command);
            CliLog.WriteLine(CliLog.ColorGreen, "");
            var process = new Process
            {
                StartInfo = new ProcessStartInfo(path)
                {
                    Arguments              = $"{command}",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            process.Start();
            while (!process.StandardOutput.EndOfStream)
            {
                var line = process.StandardOutput.ReadLine();
                CliLog.WriteLine(CliLog.ColorWhite, line);
            }
            process.WaitForExit();
            CliLog.WriteLine(CliLog.ColorGreen, "Executed Solution Packager");
        }
        private void DownloadEntityList()
        {
            var fetchData = new
            {
                adx_websiteid = WebSiteId
            };
            var fetchXml = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
  <entity name='adx_entitylist'>
    <attribute name='adx_registerstartupscript'/>
    <attribute name='adx_name'/>
    <order attribute='adx_name' descending='false'/>
    <filter type='and'>
      <condition attribute='adx_websiteid' operator='eq' value='{fetchData.adx_websiteid}'/>
    </filter>
  </entity>
</fetch>
";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                return;
            }
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            var folder = Path.Combine(CurrentDirectory, "Entity List");

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            var total = rows.Entities.Count;
            var len   = total.ToString().Length;
            var i     = 1;

            CliLog.WriteLine(CliLog.ColorGreen, "Processing Entity List ...");
            CliLog.WriteLine(CliLog.ColorGreen, "Found: ", CliLog.ColorRed, total, CliLog.ColorGreen, " entity list");
            foreach (var entity in rows.Entities)
            {
                var name = entity.GetAttributeValue <string>("adx_name");
                if (name == null)
                {
                    continue;
                }
                var file      = Path.Combine(folder, $"{name}.js");
                var shortFile = file.Substring(CurrentDirectory.Length + 1);
                if (File.Exists(file))
                {
                    Utility.TryDeleteFile(file);
                }
                var script = entity.GetAttributeValue <string>("adx_registerstartupscript") ?? string.Empty;
                DownloadedFiles.Add(file);
                File.WriteAllText(file, script);
                CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + len + "}", "", i) + ": ", CliLog.ColorWhite, "Downloaded: ", CliLog.ColorGreen, shortFile);
                i++;
            }
        }
        private void DownloadWebPage()
        {
            var fetchData = new
            {
                adx_websiteid = WebSiteId
            };
            var fetchXml = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
  <entity name='adx_webpage'>
    <attribute name='adx_webpageid'/>
    <attribute name='adx_name'/>
    <attribute name='adx_customjavascript'/>
    <attribute name='adx_customcss'/>
    <attribute name='adx_copy'/>
    <attribute name='adx_summary'/>
    <order attribute='adx_name' descending='false'/>
    <filter type='and'>
      <condition attribute='adx_websiteid' operator='eq' value='{fetchData.adx_websiteid}'/>
      <condition attribute='adx_rootwebpageid' operator='not-null'/>
    </filter>
  </entity>
</fetch>
";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                return;
            }
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            var folder = Path.Combine(CurrentDirectory, "Web File");

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            var total = rows.Entities.Count();
            var len   = total.ToString().Length;
            var i     = 1;

            CliLog.WriteLine(CliLog.ColorGreen, "Processing Web Page ...");
            CliLog.WriteLine(CliLog.ColorGreen, "Found: ", CliLog.ColorRed, total, CliLog.ColorGreen, " web page");
            var rows2 = (from entity in rows.Entities
                         select new
            {
                adx_name = entity.GetAttributeValue <string>("adx_name") ?? string.Empty,
                adx_customjavascript = entity.GetAttributeValue <string>("adx_customjavascript") ?? string.Empty,
                adx_customcss = entity.GetAttributeValue <string>("adx_customcss") ?? string.Empty,
                adx_copy = entity.GetAttributeValue <string>("adx_copy") ?? string.Empty,
                adx_summary = entity.GetAttributeValue <string>("adx_summary") ?? string.Empty
            }).ToList();

            foreach (var row in rows2)
            {
                i++;
            }
        }
예제 #9
0
        private void RegisterWorkflowType(Entity workflowEntity, TypeInfo workflow)
        {
            var workflowAttributes = workflow.GetCustomAttributesData()
                                     .Where(a => a.AttributeType.Name == typeof(CrmPluginRegistrationAttribute).Name).ToList();

            if (!workflowAttributes.Any())
            {
                return;
            }
            foreach (var workflowAttribute in workflowAttributes)
            {
                var attribute = workflowAttribute.CreateFromData();
                var fetchData = new
                {
                    typename = workflow.FullName
                };
                var fetchXml   = $@"
<fetch>
  <entity name='plugintype'>
    <all-attributes />
    <filter type='and'>
      <condition attribute='typename' operator='eq' value='{fetchData.typename}'/>
    </filter>
  </entity>
</fetch>";
                var rows       = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));
                var pluginType = new Entity("plugintype")
                {
                    ["name"]                      = attribute.Name,
                    ["friendlyname"]              = attribute.FriendlyName,
                    ["pluginassemblyid"]          = new EntityReference("pluginassembly", Guid.Parse(workflowEntity["pluginassemblyid"].ToString())),
                    ["typename"]                  = workflow.FullName,
                    ["workflowactivitygroupname"] = attribute.GroupName,
                    ["description"]               = attribute.Description
                };
                if (rows.Entities.Count == 0)
                {
                    CliLog.WriteLine(CliLog.ColorRed, "\tRegistering", CliLog.ColorGreen, " Type: ", CliLog.ColorCyan, $"{workflow.FullName}");
                    CrmServiceClient.Create(pluginType);
                }
                else
                {
                    var check = rows.Entities[0];
                    if (!IsChangedPluginType(check, pluginType))
                    {
                        CliLog.WriteLine(CliLog.ColorRed, "\tNo Change", CliLog.ColorGreen, " Type: ", CliLog.ColorCyan, $"{workflow.FullName}");
                    }
                    else
                    {
                        pluginType["plugintypeid"] = rows.Entities[0].Id;
                        CliLog.WriteLine(CliLog.ColorRed, "\tUpdating", CliLog.ColorGreen, " Type: ", CliLog.ColorCyan, $"{workflow.FullName}");
                        CrmServiceClient.Update(pluginType);
                    }
                }
            }
        }
예제 #10
0
        private void GeneratorWebApi()
        {
            CliLog.WriteLine(CliLog.ColorGreen, "START GENERATOR - JS WEBAPI - TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));

            var entities = new List <string>();

            string[] files;
            var      folder = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}";

            if (GeneratorJson.entities == null || GeneratorJson.entities.Count == 0)
            {
                var pattern = "*.webapi.js";
                files = Directory.GetFiles(folder, pattern);
            }
            else
            {
                if (GeneratorJson.entities.Count == 1 && GeneratorJson.entities[0].ToLower() == "all")
                {
                    files = GetAllEntitiesForWebApi();
                }
                else
                {
                    files = GeneratorJson.entities.Select(e => $"{folder}{e}.webapi.js").ToArray();
                }
            }

            foreach (var file in files)
            {
                var fInfo   = new FileInfo(file);
                var columns = fInfo.Name.Split(".".ToCharArray());
                entities.Add(columns[0]);
            }
            if (entities.Count == 0)
            {
                CliLog.WriteLine(CliLog.ColorRed, "NOT FOUND ENTIIES !!!");
                return;
            }
            CliLog.WriteLine(CliLog.ColorGreen, "Found: ", CliLog.ColorCyan, entities.Count, CliLog.ColorGreen, " entities");
            var i = 1;

            foreach (var entity in entities)
            {
#if DEBUG
                if (entity != "abiz_Sla")
                {
                    continue;
                }
#endif
                GeneratorJsWebApi(entity, i, entities.Count);
                i++;
            }
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "END GENERATOR - JS WEBAPI - TASKS");
        }
        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);

            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.ColorCyan, string.Format("{0,0}|{1," + len + "}", "", j) + ": ", CliLog.ColorRed, "No Change ", CliLog.ColorGreen, webResourceName);
                    return;
                }
                if (existingDependencyXml != dependencyXml)
                {
                    var webResourceId = rows.Entities[0].Id;
                    var entity        = new Entity("webresource", webResourceId)
                    {
                        ["dependencyxml"] = dependencyXml
                    };
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + len + "}", "", j), ": ", CliLog.ColorRed, "Updated", CliLog.ColorBlue, " Dependency Webresource ", CliLog.ColorCyan, webResourceName);
                    foreach (var d in dependency.dependencies)
                    {
                        CliLog.WriteLine(CliLog.ColorWhite, "\t" + d);
                    }
                    CrmServiceClient.Update(entity);
                    if (!WebResourcesToPublish.Contains(webResourceId))
                    {
                        WebResourcesToPublish.Add(webResourceId);
                    }
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + len + "}", "", j) + ": ", CliLog.ColorRed, "No Change ", CliLog.ColorGreen, webResourceName);
                }
            }
        }
 public void Run()
 {
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, "BEGIN WORKFLOW TASKS");
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
     foreach (var workflowFile in WorkflowFiles)
     {
         RegisterWorkflow(workflowFile);
     }
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, "END WORKFLOW TASKS");
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
 }
예제 #13
0
 public void Run()
 {
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, "BEGIN PLUGIN TASKS");
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
     foreach (var pluginFile in PluginFiles)
     {
         RegisterPlugin(pluginFile);
     }
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, "END PLUGIN TASKS");
     CliLog.WriteLine(CliLog.COLOR_MAGENTA, new String('*', CliLog.STAR_LENGTH));
 }
예제 #14
0
        public void PublishWebResources()
        {
            var stringGuids  = WebResourcesToPublish.Select(g => g.ToString());
            var webresources = string.Join("</webresource><webresource>", stringGuids);
            var publish      = new PublishXmlRequest
            {
                ParameterXml =
                    "<importexportxml><webresources>" +
                    "<webresource>" + webresources + "</webresource>" +
                    "</webresources></importexportxml>"
            };

            CliLog.WriteLine(CliLog.COLOR_YELLOW, "Publishing WebResources !!!");
            CrmServiceClient.Execute(publish);
        }
        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.ColorYellow, "Publishing WebResources");
            CrmServiceClient.Execute(publish);
            CliLog.WriteLine(CliLog.ColorYellow, "Published WebResources");
        }
        public void Run()
        {
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "START PROXYTYPES TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));

            if ([email protected] == 0 || ProxyTypeJson.@namespace == "???")
            {
                throw new Exception("No namespae found in proxy type profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (ProxyTypeJson.output.Length == 0 || ProxyTypeJson.output == "???")
            {
                throw new Exception("No output found in proxy type profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }

            var command = CreateCommandArgs();
            var path    = "\"" + GetParentFolder(CurrentDirectory) + $@"\packages\Microsoft.CrmSdk.CoreTools.{Version}\content\bin\coretools\CrmSvcUtil.exe" + "\"";

            CliLog.WriteLine(CliLog.ColorGreen, "Executing CrmSvcUtil");
            CliLog.WriteLine(CliLog.ColorCyan, "\t" + path);
            CliLog.WriteLine(CliLog.ColorCyan, "\t" + HidePassword(command));
            CliLog.WriteLine(CliLog.ColorGreen, "");
            var process = new Process
            {
                StartInfo = new ProcessStartInfo(path)
                {
                    Arguments              = $"{command}",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            process.Start();
            while (!process.StandardOutput.EndOfStream)
            {
                var line = process.StandardOutput.ReadLine();
                CliLog.WriteLine(CliLog.ColorWhite, line);
            }
            process.WaitForExit();
            CliLog.WriteLine(CliLog.ColorGreen, "Executed CrmSvcUtil");

            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "END PROXYTYPES TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
        }
 public void Run()
 {
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     CliLog.WriteLine(CliLog.ColorGreen, "START DOWNLOAD PORTAL WEBRESOURCES TASKS");
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     if (PortalJson.name.Length == 0 || PortalJson.name == "???")
     {
         throw new Exception("No name found in download portal webresources profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
     }
     DownloadEntityForm();
     DownloadEntityList();
     DownloadWebFile();
     DownloadWebPage();
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     CliLog.WriteLine(CliLog.ColorGreen, "END DOWNLOAD PORTAL WEBRESOURCES TASKS");
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
 }
        private string GetSolutionFromCrm()
        {
            CliLog.WriteLine(CliLog.ColorGreen, $"Exporting {SolutionPackagerJson.solutiontype} solution: ", CliLog.ColorCyan, SolutionPackagerJson.solution, CliLog.ColorGreen, " to:");
            var fileName     = FileHandler.FormatSolutionVersionString(SolutionPackagerJson.solution, System.Version.Parse(CrmVersion), SolutionPackagerJson.solutiontype);
            var solutionFile = Path.Combine(CurrentDirectory, SolutionPackagerJson.solutionzipfolder, DateTime.Now.ToString("yyyyMMdd") + "-" + fileName);

            CliLog.WriteLine(CliLog.ColorCyan, "\t" + solutionFile);
            var request = new ExportSolutionRequest
            {
                Managed      = SolutionPackagerJson.solutiontype == "Managed",
                SolutionName = SolutionPackagerJson.solution
            };
            var response = (ExportSolutionResponse)CrmServiceClient.Execute(request);
            var tempFile = FileHandler.WriteTempFile(fileName, response.ExportSolutionFile);

            File.Copy(tempFile, solutionFile, true);
            CliLog.WriteLine(CliLog.ColorGreen, $"Exported {SolutionPackagerJson.solutiontype} solution: ", CliLog.ColorCyan);
            return(solutionFile);
        }
        private void AddWebResourceToSolution(Entity webResource)
        {
            var fetchData = new
            {
                objectid      = Guid.Parse(webResource["webresourceid"].ToString()),
                componenttype = 61,
                uniquename    = WebResourceJson.solution
            };
            var fetchXml = $@"
<fetch>
  <entity name='solutioncomponent'>
    <attribute name='solutioncomponentid' />
    <filter type='and'>
      <condition attribute='objectid' operator='eq' value='{fetchData.objectid}'/>
      <condition attribute='componenttype' operator='eq' value='{fetchData.componenttype}'/>
    </filter>
    <link-entity name='solution' from='solutionid' to='solutionid'>
      <filter type='and'>
        <condition attribute='uniquename' operator='eq' value='{fetchData.uniquename}'/>
      </filter>
    </link-entity>
  </entity>
</fetch>";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count != 0)
            {
                return;
            }
            var request = new AddSolutionComponentRequest
            {
                AddRequiredComponents = true,
                ComponentType         = 61,
                ComponentId           = Guid.Parse(webResource["webresourceid"].ToString()),
                SolutionUniqueName    = WebResourceJson.solution
            };

            CliLog.WriteLine(CliLog.ColorCyan, "|", CliLog.ColorRed, "\tAdding", CliLog.ColorGreen, " WebResource: ", CliLog.ColorCyan,
                             $"{webResource["name"]} ", CliLog.ColorGreen, "to solution: ", CliLog.ColorCyan,
                             $"{WebResourceJson.solution}");
            CrmServiceClient.Execute(request);
        }
예제 #20
0
        public void Run()
        {
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "START DATA PROVIDER TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));

            if (DataProviderJson.solution.Length == 0 || DataProviderJson.solution == "???")
            {
                throw new Exception("No solution found in plugin profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }

            foreach (var pluginFile in DataProviderFiles)
            {
                RegisterDataProvider(pluginFile);
            }

            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "END DATA PROVIDER TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
        }
예제 #21
0
        private void RegisterImage(string message, string imageName, ImageTypeEnum imageType, string imageAttributes, Guid sdkMessageProcessingStepId)
        {
            var image = new Entity("sdkmessageprocessingstepimage");

            image["name"]      = imageName;
            image["imagetype"] = new OptionSetValue((int)imageType);
            image["sdkmessageprocessingstepid"] = new EntityReference("sdkmessageprocessingstep", sdkMessageProcessingStepId);
            image["attributes"]          = imageAttributes.Replace(" ", "");
            image["entityalias"]         = imageName;
            image["messagepropertyname"] = message == "Create" ? "Id" : "Target";
            var fetchData = new
            {
                sdkmessageprocessingstepid = sdkMessageProcessingStepId,
                entityalias = imageName,
                imagetype   = (int)imageType
            };
            var fetchXml = $@"
<fetch>
  <entity name='sdkmessageprocessingstepimage'>
    <attribute name='sdkmessageprocessingstepimageid' />
    <filter type='and'>
      <condition attribute='sdkmessageprocessingstepid' operator='eq' value='{fetchData.sdkmessageprocessingstepid}'/>
      <condition attribute='entityalias' operator='eq' value='{fetchData.entityalias}'/>
      <condition attribute='imagetype' operator='eq' value='{fetchData.imagetype}'/>
    </filter>
  </entity>
</fetch>";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                CliLog.WriteLine(CliLog.COLOR_GREEN, "\t\t\tRegistering Image: ", CliLog.COLOR_CYAN, $"{imageName}");
                CrmServiceClient.Create(image);
            }
            else
            {
                image["sdkmessageprocessingstepimageid"] = rows.Entities[0].Id;
                CliLog.WriteLine(CliLog.COLOR_BLUE, "\t\t\tUpdating Image: ", CliLog.COLOR_CYAN, $"{imageName}");
                CrmServiceClient.Update(image);
            }
        }
 public void Run()
 {
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     CliLog.WriteLine(CliLog.ColorGreen, "START PLUGIN TASKS");
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     if (PluginFiles.Count() == 0)
     {
         throw new Exception("No plugin files found. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
     }
     if (PluginJson.solution.Length == 0 || PluginJson.solution == "???")
     {
         throw new Exception("No solution found in plugin profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
     }
     foreach (var pluginFile in PluginFiles)
     {
         RegisterPlugin(pluginFile);
     }
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     CliLog.WriteLine(CliLog.ColorGreen, "END PLUGIN TASKS");
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
 }
예제 #23
0
 private bool DownloadWebResourceFile(DownloadFile downloadFile, int i, int totalDownloadWebResources)
 {
     if (File.Exists(downloadFile.FileName))
     {
         var len = totalDownloadWebResources.ToString().Length;
         CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + len + "}", "", i) + ": ", CliLog.ColorRed, "Failed: ", CliLog.ColorGreen, downloadFile.Name, CliLog.ColorWhite, " to: ", CliLog.ColorGreen, downloadFile.FileName);
         return(false);
     }
     else
     {
         var directoryName = Path.GetDirectoryName(downloadFile.FileName);
         if (!Directory.Exists(directoryName))
         {
             Directory.CreateDirectory(directoryName ?? throw new InvalidOperationException());
         }
         byte[] decode = Convert.FromBase64String(downloadFile.Content);
         File.WriteAllBytes(downloadFile.FileName, decode);
         downloadedFiles.Add(downloadFile);
         return(true);
     }
 }
예제 #24
0
 public void Run()
 {
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     CliLog.WriteLine(CliLog.ColorGreen, "START WORKFLOW TASKS");
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     if (WorkflowFiles.Count() == 0)
     {
         throw new Exception("No workflow files found. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
     }
     if (WorkflowJson.solution.Length == 0 || WorkflowJson.solution == "???")
     {
         throw new Exception("No solution found in workflow profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
     }
     foreach (var workflowFile in WorkflowFiles)
     {
         RegisterWorkflow(workflowFile);
     }
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
     CliLog.WriteLine(CliLog.ColorGreen, "END WORKFLOW TASKS");
     CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
 }
        private void AddStepToSolution(Entity step)
        {
            var fetchData = new
            {
                objectid      = step["sdkmessageprocessingstepid"].ToString(),
                componenttype = 92,
                uniquename    = PluginJson.solution
            };
            var fetchXml = $@"
<fetch>
  <entity name='solutioncomponent'>
    <attribute name='solutioncomponentid' />
    <filter type='and'>
      <condition attribute='objectid' operator='eq' value='{fetchData.objectid}'/>
      <condition attribute='componenttype' operator='eq' value='{fetchData.componenttype}'/>
    </filter>
    <link-entity name='solution' from='solutionid' to='solutionid'>
      <filter type='and'>
        <condition attribute='uniquename' operator='eq' value='{fetchData.uniquename}'/>
      </filter>
    </link-entity>
  </entity>
</fetch>";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count != 0)
            {
                return;
            }
            var request = new AddSolutionComponentRequest
            {
                AddRequiredComponents = false,
                ComponentType         = 92,
                ComponentId           = Guid.Parse(step["sdkmessageprocessingstepid"].ToString()),
                SolutionUniqueName    = PluginJson.solution
            };

            CliLog.WriteLine(CliLog.ColorRed, "\t\tAdding", CliLog.ColorGreen, " Step: ", CliLog.ColorCyan, $"{step["name"]} ", CliLog.ColorGreen, "to solution: ", CliLog.ColorCyan, $"{PluginJson.solution}");
            CrmServiceClient.Execute(request);
        }
예제 #26
0
        private void UpdateDependency(Dependency dependency)
        {
            var files         = GetWebResourceFilesDependencies(dependency);
            var dependencyXml = GetDependencyXml(dependency.dependencies);

            foreach (var file in files)
            {
                var fetchData = new
                {
                    name = file.uniquename
                };
                var fetchXml = $@"
<fetch>
  <entity name='webresource'>
    <attribute name='dependencyxml' />
    <filter type='and'>
      <condition attribute='name' operator='eq' value='{fetchData.name}'/>
    </filter>
  </entity>
</fetch>";
                var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));
                var existingDependencyXml = string.Empty;
                if (rows.Entities.Count > 0)
                {
                    existingDependencyXml = rows.Entities[0].GetAttributeValue <string>("dependencyxml");
                }
                if (existingDependencyXml != dependencyXml)
                {
                    var webResourceId = rows.Entities[0].Id;
                    var enttiy        = new Entity("webresource", webResourceId);
                    enttiy["dependencyxml"] = dependencyXml;
                    CliLog.WriteLine(CliLog.COLOR_BLUE, "Updated Dependency Webresource ", CliLog.COLOR_CYAN, file.uniquename);
                    CrmServiceClient.Update(enttiy);
                    if (!WebResourcesToPublish.Contains(webResourceId))
                    {
                        WebResourcesToPublish.Add(webResourceId);
                    }
                }
            }
        }
예제 #27
0
        public static void Main(string[] args)
        {
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "PL.DynamicsCrm.DevKit.Cli ", CliLog.ColorRed, Const.Version);
            CliLog.WriteLine(CliLog.ColorGreen, "Path: ", CliLog.ColorWhite, GetCliPath());
            #if DEBUG
            CliLog.WriteLine(CliLog.ColorRed, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorRed, "DEBUG MODE");
            CliLog.WriteLine(CliLog.ColorRed, new string('*', CliLog.StarLength));
            #endif
#if !DEBUG
            try
            {
#endif
            var arguments = CommandLine.Parse <CommandLineArgs>();
            var jsonFile  = Path.Combine(CurrentDirectory, arguments.Json);
            CliLog.WriteLine(CliLog.ColorGreen, "PL.DynamicsCrm.DevKit.Cli.json path: ", CliLog.ColorWhite, jsonFile);
            CliLog.WriteLine(CliLog.ColorGreen, "Arguments: ",
                             CliLog.ColorMagenta, "/conn:", CliLog.ColorCyan, arguments.Connection, " ",
                             CliLog.ColorMagenta, "/json:", CliLog.ColorCyan, arguments.Json, " ",
                             CliLog.ColorMagenta, "/type:", CliLog.ColorCyan, arguments.Type, " ",
                             CliLog.ColorMagenta, "/profile:", CliLog.ColorCyan, arguments.Profile, " ",
                             CliLog.ColorMagenta, "/version:", CliLog.ColorCyan, arguments.Version
                             );
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            Run(arguments);
#if DEBUG
            CliLog.WriteLine(CliLog.ColorRed, "!!! FINISHED !!!");
            Console.ReadKey();
#endif
#if !DEBUG
        }
        catch (Exception e)
        {
            CliLog.WriteLine(CliLog.ColorError, $"{e.Message}");
            Console.ReadKey();
        }
#endif
        }
예제 #28
0
        private void GeneratorLateBound(string entity, int i, int count)
        {
            var lateBound       = new GeneratedCSharpLateBound();
            var rootNameSpace   = GeneratorJson.rootnamespace + ".Shared.Entities";
            var sharedNameSpace = GeneratorJson.rootnamespace + ".";
            var crmVersionName  = (CrmVersionName)int.Parse(GeneratorJson.crmversion);
            var generated       = lateBound.Go(CrmServiceClient.OrganizationServiceProxy, crmVersionName, entity, rootNameSpace, sharedNameSpace);
            var file            = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.generated.cs";

            var old  = File.ReadAllText(file).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
            var @new = generated.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);

            if (old != @new)
            {
                File.WriteAllText(file, generated, System.Text.Encoding.UTF8);
                CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".generated.cs");
            }
            else
            {
                CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".generated.cs");
            }
        }
        public void Run()
        {
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "START SOLUTIONPACKAGER TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));

            if (SolutionPackagerJson.solution.Length == 0 || SolutionPackagerJson.solution == "???")
            {
                throw new Exception("No solution found in solution packager profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (SolutionPackagerJson.solutiontype != "Managed" && SolutionPackagerJson.solutiontype != "Unmanaged")
            {
                throw new Exception("solutiontype should be: Managed/Unmanaged. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (SolutionPackagerJson.folder == "???")
            {
                throw new Exception("No folder found in solution packager profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (SolutionPackagerJson.solutionzipfolder == "???")
            {
                throw new Exception("No solution zip folder found in solution packager profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (SolutionPackagerJson.logfolder == "???")
            {
                throw new Exception("No log folder found in solution packager profile. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }
            if (SolutionPackagerJson.type != "Extract" && SolutionPackagerJson.type != "Pack")
            {
                throw new Exception("type should be: Extract/Pack. Please check PL.DynamicsCrm.DevKit.Cli.json file !!!");
            }

            var solution = GetSolutionFromCrm();

            Packger(solution);

            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
            CliLog.WriteLine(CliLog.ColorGreen, "END SOLUTIONPACKAGER TASKS");
            CliLog.WriteLine(CliLog.ColorGreen, new string('*', CliLog.StarLength));
        }
예제 #30
0
        private void AddAssemblyToSolution(Entity plugin)
        {
            var fetchData = new
            {
                objectid      = plugin["pluginassemblyid"].ToString(),
                componenttype = 91,
                uniquename    = DataProviderJson.solution
            };
            var fetchXml = $@"
<fetch>
  <entity name='solutioncomponent'>
    <attribute name='solutioncomponentid' />
    <filter type='and'>
      <condition attribute='objectid' operator='eq' value='{fetchData.objectid}'/>
      <condition attribute='componenttype' operator='eq' value='{fetchData.componenttype}'/>
    </filter>
    <link-entity name='solution' from='solutionid' to='solutionid'>
      <filter type='and'>
        <condition attribute='uniquename' operator='eq' value='{fetchData.uniquename}'/>
      </filter>
    </link-entity>
  </entity>
</fetch>";
            var rows     = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml));

            if (rows.Entities.Count == 0)
            {
                var request = new AddSolutionComponentRequest
                {
                    AddRequiredComponents = true,
                    ComponentType         = 91,
                    ComponentId           = Guid.Parse(plugin["pluginassemblyid"].ToString()),
                    SolutionUniqueName    = DataProviderJson.solution
                };
                CliLog.WriteLine(CliLog.ColorGreen, "Adding Assembly: ", CliLog.ColorCyan, $"{plugin["name"]} ",
                                 CliLog.ColorGreen, "to solution: ", CliLog.ColorCyan, $"{DataProviderJson.solution}");
                CrmServiceClient.Execute(request);
            }
        }