Пример #1
0
        private List <string> GetAllForms(string entity, JsForm jsForm)
        {
            var forms = jsForm.GetForms().ToList();

            if (forms.Count == 0)
            {
                return(new List <string>());
            }
            forms = forms.Distinct().ToList();
            return(forms);
        }
        private void GeneratorJsForm(string entity, int i, int count)
        {
            var forms                     = new List <string>();
            var isDebugForm               = true;
            var webApi                    = true;
            var isDebugWebApi             = true;
            var fileTypeScriptDeclaration = $"{currentDirectory}\\{json.rootfolder}\\{entity}.d.ts";

            if (File.Exists(fileTypeScriptDeclaration))
            {
                var lines = File.ReadAllLines(fileTypeScriptDeclaration);
                if (lines.Count() != 0)
                {
                    var json    = lines[lines.Length - 1];
                    var comment = SimpleJson.DeserializeObject <CommentTypeScriptDeclaration>(json.Substring("//".Length).Replace("'", "\""));
                    forms         = comment.JsForm;
                    isDebugForm   = comment.IsDebugForm;
                    webApi        = comment.JsWebApi;
                    isDebugWebApi = comment.IsDebugWebApi;
                }
            }
            if (forms.Count == 0)
            {
                var parts2       = json.rootnamespace.Split(".".ToCharArray());
                var projectName2 = parts2.Length > 1 ? parts2[1] : parts2[0];
                var jsForm2      = new JsForm(XrmHelper.GetIOrganizationService(crmServiceClient), projectName2, entity);
                forms = GetAllForms(entity, jsForm2);
            }
            if (forms.Count == 0)
            {
                return;
            }
            if (File.Exists($"{currentDirectory}\\{json.rootfolder}\\{entity}.js"))
            {
                var text = File.ReadAllText($"{currentDirectory}\\{json.rootfolder}\\{entity}.js");
                text = text.Replace("\r\n", string.Empty);
                if (text.Length == 0 || text == $"//@ts-check///<reference path=\"{entity}.d.ts\" />")
                {
                    Utility.TryDeleteFile($"{currentDirectory}\\{json.rootfolder}\\{entity}.js");
                }
            }
            var parts       = json.rootnamespace.Split(".".ToCharArray());
            var projectName = parts.Length > 1 ? parts[1] : parts[0];
            var jsForm      = new JsForm(XrmHelper.GetIOrganizationService(crmServiceClient), projectName, entity);

            if (json.debug.Length > 0)
            {
                isDebugForm = json.debug == "yes" ? true : false;
            }
            jsForm.GeneratorCode(forms, isDebugForm, webApi, isDebugWebApi);
            if (!File.Exists($"{currentDirectory}\\{json.rootfolder}\\{entity}.js"))
            {
                var text = jsForm.Form;
                text = text.Replace($"[[{entity}]]", $"{entity}.d.ts");
                Utility.ForceWriteAllText($"{currentDirectory}\\{json.rootfolder}\\{entity}.js", text);
            }
            var old = string.Empty;

            if (File.Exists(fileTypeScriptDeclaration))
            {
                old = File.ReadAllText(fileTypeScriptDeclaration).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
            }
            var @new = jsForm.FormCodeTypeScriptDeclaration.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);

            if (old != @new)
            {
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + count.ToString().Length + "}", "", i) + ": ", CliLog.ColorMagenta, "Processing ", CliLog.ColorGreen, entity, ".d.ts");
                Utility.ForceWriteAllText(fileTypeScriptDeclaration, jsForm.FormCodeTypeScriptDeclaration);
            }
            else
            {
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + count.ToString().Length + "}", "", i) + ": ", CliLog.ColorMagenta, "No change ", CliLog.ColorGreen, entity, ".d.ts");
            }
            var fileForm = $"{currentDirectory}\\{json.rootfolder}\\{entity}.form.js";

            old = string.Empty;
            if (File.Exists(fileForm))
            {
                old = File.ReadAllText(fileForm).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
            }
            @new = jsForm.FormCode.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
            if (old != @new)
            {
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + count.ToString().Length + "}", "", i) + ": ", CliLog.ColorMagenta, "Processing ", CliLog.ColorGreen, entity, ".form.js");
                Utility.ForceWriteAllText(fileForm, jsForm.FormCode);
            }
            else
            {
                CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, string.Format("{0,0}{1," + count.ToString().Length + "}", "", i) + ": ", CliLog.ColorMagenta, "No change ", CliLog.ColorGreen, entity, ".form.js");
            }
        }
Пример #3
0
        private void GeneratorJsForm(string entity, int i, int count)
        {
            if (GeneratorJson.usetypescriptdeclaration == "true")
            {
                var forms                     = new List <string>();
                var isDebugForm               = true;
                var webApi                    = true;
                var isDebugWebApi             = true;
                var fileTypeScriptDeclaration = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.d.ts";
                if (File.Exists(fileTypeScriptDeclaration))
                {
                    var lines = File.ReadAllLines(fileTypeScriptDeclaration);
                    if (lines.Count() != 0)
                    {
                        var json    = lines[lines.Length - 1];
                        var comment = SimpleJson.DeserializeObject <CommentIntellisense>(json.Substring("//".Length).Replace("'", "\""));
                        forms         = comment.JsForm;
                        isDebugForm   = comment.IsDebugForm;
                        webApi        = comment.JsWebApi;
                        isDebugWebApi = comment.IsDebugWebApi;
                    }
                }
                if (forms.Count == 0)
                {
                    var parts2       = GeneratorJson.rootnamespace.Split(".".ToCharArray());
                    var projectName2 = parts2.Length > 1 ? parts2[1] : parts2[0];
                    var jsForm2      = new JsForm(CrmServiceClient.OrganizationServiceProxy, projectName2, entity);
                    forms = GetAllForms(entity, jsForm2);
                }
                if (forms.Count == 0)
                {
                    return;
                }
                if (File.Exists($"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.js"))
                {
                    var text = File.ReadAllText($"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.js");
                    text = text.Replace("\r\n", string.Empty);
                    if (text.Length == 0 || text == $"//@ts-check///<reference path=\"{entity}.d.ts\" />")
                    {
                        Utility.TryDeleteFile($"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.js");
                    }
                }
                var parts       = GeneratorJson.rootnamespace.Split(".".ToCharArray());
                var projectName = parts.Length > 1 ? parts[1] : parts[0];
                var jsForm      = new JsForm(CrmServiceClient.OrganizationServiceProxy, projectName, entity);
                jsForm.GeneratorCode(forms, isDebugForm, webApi, isDebugWebApi);
                if (!File.Exists($"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.js"))
                {
                    var text = jsForm.Form;
                    text = text.Replace($"[[{entity}]]", $"{entity}.d.ts");
                    File.WriteAllText($"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.js", text, System.Text.Encoding.UTF8);
                }
                var old = string.Empty;
                if (File.Exists(fileTypeScriptDeclaration))
                {
                    old = File.ReadAllText(fileTypeScriptDeclaration).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                }
                var @new = jsForm.FormCodeIntellisense2.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".d.ts");
                    if (Utility.CanWriteAllText(fileTypeScriptDeclaration))
                    {
                        File.WriteAllText(fileTypeScriptDeclaration, jsForm.FormCodeIntellisense2, System.Text.Encoding.UTF8);
                    }
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".d.ts");
                }
                var fileForm = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.form.js";
                old = string.Empty;
                if (File.Exists(fileForm))
                {
                    old = File.ReadAllText(fileForm).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                }
                @new = jsForm.FormCode.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".form.js");
                    if (Utility.CanWriteAllText(fileForm))
                    {
                        File.WriteAllText(fileForm, jsForm.FormCode, System.Text.Encoding.UTF8);
                    }
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".form.js");
                }
            }
            else
            {
                var fileIntellisense = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.intellisense.js";
                var lines            = File.ReadAllLines(fileIntellisense);
                var json             = lines[lines.Length - 1];
                var comment          = SimpleJson.DeserializeObject <CommentIntellisense>(json.Substring("//".Length).Replace("'", "\""));
                var parts            = GeneratorJson.rootnamespace.Split(".".ToCharArray());
                var projectName      = parts.Length > 1 ? parts[1] : parts[0];
                var jsForm           = new JsForm(CrmServiceClient.OrganizationServiceProxy, projectName, entity);
                jsForm.GeneratorCode(comment.JsForm, comment.IsDebugForm, comment.JsWebApi, comment.IsDebugWebApi);
                var fileForm = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.form.js";

                var old  = File.ReadAllText(fileIntellisense).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                var @new = jsForm.FormCodeIntellisense.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".intellisense.js");
                    File.WriteAllText(fileIntellisense, jsForm.FormCodeIntellisense, System.Text.Encoding.UTF8);
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".intellisense.js");
                }

                old  = File.ReadAllText(fileForm).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                @new = jsForm.FormCode.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".form.js");
                    File.WriteAllText(fileForm, jsForm.FormCode, System.Text.Encoding.UTF8);
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".form.js");
                }
            }
        }
Пример #4
0
        private void GeneratorJsForm(string entity, int i, int count)
        {
            if (GeneratorJson.usetypescriptdeclaration == "true")
            {
                var fileTypeScriptDeclaration = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.d.ts";
                var lines       = File.ReadAllLines(fileTypeScriptDeclaration);
                var json        = lines[lines.Length - 1];
                var comment     = SimpleJson.DeserializeObject <CommentIntellisense>(json.Substring("//".Length).Replace("'", "\""));
                var parts       = GeneratorJson.rootnamespace.Split(".".ToCharArray());
                var projectName = parts.Length > 1 ? parts[1] : parts[0];
                var jsForm      = new JsForm(CrmServiceClient.OrganizationServiceProxy, projectName, entity);
                jsForm.GeneratorCode(comment.JsForm, comment.IsDebugForm, comment.JsWebApi, comment.IsDebugWebApi);
                var old  = File.ReadAllText(fileTypeScriptDeclaration).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                var @new = jsForm.FormCodeIntellisense2.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".d.ts");
                    if (Utility.CanWriteAllText(fileTypeScriptDeclaration))
                    {
                        File.WriteAllText(fileTypeScriptDeclaration, jsForm.FormCodeIntellisense, System.Text.Encoding.UTF8);
                    }
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".d.ts");
                }
                var fileForm = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.form.js";
                old  = File.ReadAllText(fileForm).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                @new = jsForm.FormCode.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".form.js");
                    if (Utility.CanWriteAllText(fileForm))
                    {
                        File.WriteAllText(fileForm, jsForm.FormCode, System.Text.Encoding.UTF8);
                    }
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".form.js");
                }
            }
            else
            {
                var fileIntellisense = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.intellisense.js";
                var lines            = File.ReadAllLines(fileIntellisense);
                var json             = lines[lines.Length - 1];
                var comment          = SimpleJson.DeserializeObject <CommentIntellisense>(json.Substring("//".Length).Replace("'", "\""));
                var parts            = GeneratorJson.rootnamespace.Split(".".ToCharArray());
                var projectName      = parts.Length > 1 ? parts[1] : parts[0];
                var jsForm           = new JsForm(CrmServiceClient.OrganizationServiceProxy, projectName, entity);
                jsForm.GeneratorCode(comment.JsForm, comment.IsDebugForm, comment.JsWebApi, comment.IsDebugWebApi);
                var fileForm = $"{CurrentDirectory}\\{GeneratorJson.rootfolder}\\{entity}.form.js";

                var old  = File.ReadAllText(fileIntellisense).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                var @new = jsForm.FormCodeIntellisense.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".intellisense.js");
                    File.WriteAllText(fileIntellisense, jsForm.FormCodeIntellisense, System.Text.Encoding.UTF8);
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".intellisense.js");
                }

                old  = File.ReadAllText(fileForm).Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                @new = jsForm.FormCode.Replace(" ", string.Empty).Replace("\r\n", string.Empty).Replace("\t", string.Empty);
                if (old != @new)
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": Processing ", CliLog.ColorGreen, entity, ".form.js");
                    File.WriteAllText(fileForm, jsForm.FormCode, System.Text.Encoding.UTF8);
                }
                else
                {
                    CliLog.WriteLine(CliLog.ColorCyan, string.Format("{0,0}|{1," + count.ToString().Length + "}", "", i) + ": No change ", CliLog.ColorGreen, entity, ".form.js");
                }
            }
        }