Esempio n. 1
0
        public virtual void InitializeResxFiles()
        {
            using (var x = SW.Measure())
            {
                string[] types = new string[] { "Columns", "Words", "Pages", "Messages" };

                foreach (string type in types)
                {
                    foreach (var lang in Shell.SupportedLanguages)
                    {
                        var    fileName = type + "." + lang + ".resx";
                        string filePath = Path.Combine(_paths.LocalizationRoot, "Localization", fileName);
                        if (!File.Exists(filePath))
                        {
                            Utils.CreateFolderForFile(filePath);
                            ResxXmlReader reader  = new ResxXmlReader();
                            var           headers = ResHeaderItem.Default;
                            reader.Save(filePath, new ResourceContainer {
                                DataItems = new DataItem[0], Headers = headers
                            });
                            Out.WriteLine($"Created file [{fileName}]");
                        }
                    }
                }
                WriteSuccess(x.Elapsed);
            }
        }
        void UnZip(byte[] bytes, string folder, string name, bool overwrite = false)
        {
            using (var t = SW.Measure())
            {
                string file       = Path.Combine(folder, $"{name}.zip");
                string folderPath = Path.Combine(folder, name);
                bool   write      = true;

                if (Directory.Exists(folderPath))
                {
                    if (overwrite && Utils.DeleteDirectory(folderPath))
                    {
                        write = true;
                    }
                    else
                    {
                        Out.WriteLine(folderPath + " already exists");
                        return;
                    }
                }

                if (write)
                {
                    WriteFileOperation($"Extracting {name} to", folder, false);
                    Utils.CreateFolderForFile(file);
                    File.WriteAllBytes(file, bytes);
                    ZipFile.ExtractToDirectory(file, folderPath);
                    File.Delete(file);
                    WriteSuccess(t.Elapsed, SuccessCol);
                }
                Out.WriteLine();
            }
        }
        public virtual void GenerateMainComponentTemplate(string moduleCode)
        {
            using (var m = SW.Measure())
            {
                using (Out.Set(ConsoleColor.DarkYellow))
                    Out.Write(" Html: ");
                string filePath = _names.GetComponentFilePath(moduleCode, "app") + ".html";

                if (!opts.ReplaceAppComponentHtml && File.Exists(filePath))
                {
                    GotoColumn(SuccessCol);
                    WriteColored("Exists", ConsoleColor.Cyan);
                    return;
                }

                string baseComponent = _unit.TenantRepository.GetSingleValue(d => d.MainComponentBase, d => d.Code == moduleCode);

                string contents = _dbViews.GetMainComponent(baseComponent);


                Utils.CreateFolderForFile(filePath);
                File.WriteAllText(filePath, contents);
                WriteSuccess(m.Elapsed);
            }
        }
        protected bool RenderPage(long id, out RenderedPageResult res)
        {
            using (var x = SW.Measure())
            {
                res = null;
                using (Out.Set(ConsoleColor.Cyan))
                    Out.Write(" Html: ");

                PageDTO p            = _unit.PageRepository.FindSingleForRendering(e => e.Id == id);
                string  templatePath = _names.GetComponentFilePath(p.TenantCode, p.Page.ViewPath) + ".html";
                if (!opts.ReplaceComponentHtml && File.Exists(templatePath))
                {
                    WriteColored("Exists", ConsoleColor.Cyan);
                    return(true);
                }
                res = GetPage(p.Page.Id);
                string template = res.TemplateContent;
                if (template == null)
                {
                    WriteFailed(x.Elapsed);
                    return(false);
                }

                Utils.CreateFolderForFile(templatePath);
                File.WriteAllText(templatePath, template);

                WriteSuccess(x.Elapsed);
            }
            return(true);
        }
Esempio n. 5
0
        public SyncResult SyncTenants(long src, long tar)
        {
            var con = GetService <MoldsterContext>();
            var wt  = new ConsoleService(_output);

            using (var s = SW.Measure())
            {
                var d = con.SyncTenants(src, tar);
                if (d != null)
                {
                    _output.WriteLine();
                    using (_output.Set(ConsoleColor.DarkCyan))
                    {
                        _output.WriteLine("Synced tenant '" + d.SourceTenant + "' to '" + d.TargetTenant + "'");
                    }
                    _output.WriteLine("------------------------------------");
                    _output.WriteLine();

                    _output.Write("Added Pages : ");

                    _output.GotoColumn(5);
                    _output.WriteLine(d.AddedPages.ToString());

                    _output.Write("Added Controls : ");
                    _output.GotoColumn(5);
                    _output.WriteLine(d.AddedPageControls.ToString());

                    _output.Write("Updated Pages : ");
                    _output.GotoColumn(5);
                    _output.WriteLine(d.UpdatedPages.ToString());

                    _output.Write("Updated Controls : ");
                    _output.GotoColumn(5);
                    _output.WriteLine(d.UpdatedPageControls.ToString());

                    _output.Write("Added Navigation Pages : ");
                    _output.GotoColumn(5);
                    _output.WriteLine(d.NavigationPages.ToString());

                    _output.WriteLine();
                }
                _output.Write("Updating viewparams");
                SubmitResult res = _pages.UpdateTemplatePagesViewParamsJson(tar);
                wt.GotoColumn(wt.SuccessCol);
                if (res.IsSuccess)
                {
                    wt.WriteSuccess();
                    _output.Write("Affected : " + res.AffectedRows);
                }
                else
                {
                    wt.WriteFailed();
                }
                _output.WriteLine();
                return(d);
            }
        }
        public string RenderPartial(HttpContext context, string viewName, object model = null, Dictionary <string, object> viewData = null)
        {
            ActionContext actionContext = new ActionContext(context, new RouteData(), new ActionDescriptor());


            using (var sw = new StringWriter())
            {
                using (var c = SW.Measure())
                {
                    ViewEngineResult viewResult = _razorViewEngine.FindView(actionContext, viewName, false);

                    if (viewResult.View == null)
                    {
                        throw new Exception($"{viewName} does not match any available view");
                    }

                    var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());

                    if (model != null)
                    {
                        viewDictionary.Model = model;
                    }

                    if (viewData != null)
                    {
                        foreach (var item in viewData)
                        {
                            viewDictionary[item.Key] = item.Value;
                        }
                    }

                    var opts = new HtmlHelperOptions();

                    var viewContext = new ViewContext(
                        actionContext,
                        viewResult.View,
                        viewDictionary,
                        new TempDataDictionary(actionContext.HttpContext, _tempDataProvider),
                        sw,
                        opts
                        );

                    var t = RenderAsync(viewResult, viewContext);
                    t.Wait();
                    if (t.Result.Code != 200)
                    {
                        throw new CodeShellHttpException(t.Result);
                    }
                    return(sw.ToString());
                }
            }
        }
Esempio n. 7
0
 public int RunCommand(string folder, string command, string arguments = null, bool useShell = false)
 {
     using (var x = SW.Measure())
     {
         var p = GetCommandProcess(folder, command, arguments, useShell);
         p.Start();
         p.WaitForExit();
         Out.WriteLine();
         WriteSuccess(x.Elapsed);
         Out.WriteLine();
         return(p.ExitCode);
     }
 }
        public bool ProcessForTenant(long id, long tenantId)
        {
            using (var x = SW.Measure())
            {
                CollectTemplateData(id);
                UpdateTemplatePages(id, tenantId);
                using (Out.Set(ConsoleColor.Cyan))
                {
                    Out.Write(" " + x.Elapsed.TotalSeconds.ToString("F4"));
                }
            }

            return(true);
        }
Esempio n. 9
0
        public virtual bool CompareStructures(string db, out string script)
        {
            using (var w = SW.Measure())
            {
                Out.Write(WriteLogMessage($"Comparing {db} to source"));

                script = GetQueryOutput($"exec master.dbo.CompareStructures '[{Environment?.SourceDatabase}]', '[{db}]', '{PrimaryKeyDefinition}'", Environment.ConnectionParams.ConnectionString);
                var lines = script.Split('\n');
                if (lines.Length > 0 && !lines[0].Contains("-- NO ADDED TABLES"))
                {
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 10
0
        public virtual SubmitResult RunUpdateScript(string db, string updateScript, bool showResult = true, string message = null, bool saveFile = true)
        {
            message = message ?? $"Updating {db} Structure ... ";
            var res = new SubmitResult();

            using (var w = SW.Measure())
            {
                Out.Write(WriteLogMessage(message));
                Environment.ConnectionParams.Database = db;
                res = ExecuteBatchNonQuery(updateScript, Environment.ConnectionParams.ConnectionString);
                if (res.IsSuccess)
                {
                    WriteSuccess(w.Elapsed);
                }
                else
                {
                    WriteFailed(w.Elapsed, res);
                }

                Out.WriteLine();
            }

            return(res);
        }
Esempio n. 11
0
        public virtual void SyncLanguages(string lang1, string lang2)
        {
            using (var x = SW.Measure())
            {
                string[] types = new string[] { "Columns", "Words", "Pages", "Messages" };

                foreach (string type in types)
                {
                    string resLang1 = Path.Combine(_paths.LocalizationRoot, "Localization", type + "." + lang1 + ".resx");
                    string resLang2 = Path.Combine(_paths.LocalizationRoot, "Localization", type + "." + lang2 + ".resx");

                    ResxXmlReader reader = new ResxXmlReader();

                    var data1 = new List <DataItem>();
                    var data2 = new List <DataItem>();

                    var headers1 = new ResHeaderItem[0];
                    var headers2 = new ResHeaderItem[0];

                    if (reader.TryRead(resLang1, out ResourceContainer cont1))
                    {
                        cont1.DataItems = cont1.DataItems ?? new DataItem[0];
                        Out.WriteLine("Found " + type + "." + lang1 + ".resx with " + cont1.DataItems.Length + " items");
                        headers1 = cont1.Headers;
                        data1    = new List <DataItem>();
                        data1.AddRange(cont1.DataItems);
                    }

                    if (reader.TryRead(resLang2, out ResourceContainer cont2))
                    {
                        cont2.DataItems = cont2.DataItems ?? new DataItem[0];
                        Out.WriteLine("Found " + type + "." + lang2 + ".resx with " + cont2.DataItems.Length + " items");
                        headers2 = cont2.Headers;
                        data2    = new List <DataItem>();
                        data2.AddRange(cont2.DataItems);
                    }

                    int i = 0;
                    foreach (var item in data1)
                    {
                        if (!data2.Any(d => d.Name == item.Name))
                        {
                            data2.Add(new DataItem
                            {
                                Name  = item.Name,
                                Value = "",
                                Space = item.Space
                            });
                            i++;
                        }
                    }
                    Out.WriteLine($"{lang1} --> {lang2} : Added {i} Entries..");

                    i = 0;
                    foreach (var item in data2)
                    {
                        if (!data1.Any(d => d.Name == item.Name))
                        {
                            data1.Add(new DataItem
                            {
                                Name  = item.Name,
                                Value = type == "Messages" ? LangUtils.IdToPhrase(item.Name) : "",
                                Space = item.Space
                            });
                            i++;
                        }
                    }
                    Out.WriteLine($"{lang2} --> {lang1} : Added {i} Entries..");
                    reader.Save(resLang1, new ResourceContainer {
                        DataItems = data1.ToArray(), Headers = headers1
                    });
                    reader.Save(resLang2, new ResourceContainer {
                        DataItems = data2.ToArray(), Headers = headers2
                    });
                }



                WriteSuccess(x.Elapsed);
            }
        }
        private PublisherResult UploadFtp(UploadConfig env, string tenant, string version)
        {
            using (var m = SW.Measure())
            {
                string path = env.PathOnServer;

                string zipFile = CompressSubModuleScripts(tenant, version);

                string zipFileTarget = Utils.CombineUrl(path, BundleFolder, Path.GetFileName(zipFile));

                WriteFileOperation("Uploading", $"{env.Server}/{zipFileTarget}", false);

                var upl = http.UploadFile(zipFile, zipFileTarget);

                if (!upl.IsSuccess)
                {
                    WriteException(upl.ExceptionMessage, upl.Message, upl.StackTrace);
                    return(upl.MapToResult <PublisherResult>());
                }

                WriteSuccess();
                output.WriteLine();

                string mainFile = GetMainModuleScriptPath(tenant, version);
                if (File.Exists(mainFile))
                {
                    string mainFileTarget = Utils.CombineUrl(path, BundleFolder, Path.GetFileName(mainFile));
                    WriteFileOperation("Uploading", $"{env.Server}/{mainFileTarget}", false);

                    upl = http.UploadFile(mainFile, mainFileTarget);

                    if (!upl.IsSuccess)
                    {
                        WriteException(upl.ExceptionMessage, upl.Message, upl.StackTrace);
                        return(upl.MapToResult <PublisherResult>());
                    }

                    WriteSuccess();
                    output.WriteLine();
                }

                WriteFileOperation("Sending extract command", env.ServerUrl, false);

                var dec = http.HandleRequest(new PublisherRequest
                {
                    Type = ServerRequestTypes.Decompress,
                    DestinationFolder = Path.Combine(BundleFolder, version),
                    FileName          = Path.Combine(BundleFolder, Path.GetFileName(zipFile))
                });

                if (!dec.IsSuccess)
                {
                    WriteException(dec.ExceptionMessage, dec.Message, dec.StackTrace);
                }
                else
                {
                    File.Delete(zipFile);
                    WriteSuccess(m.Elapsed);
                }

                output.WriteLine();
                return(dec.MapToResult <PublisherResult>());
            }
        }