Ejemplo n.º 1
0
        public Boolean UpdateDAL(GenerateSettings settings)
        {
            bool resultCode = true;

            db = new DalGenerator();

            resultCode = updDALEntries(settings);

            if (resultCode == true)
            {
                if (settings.WebApiCreation == true)
                {
                    resultCode = updApi(settings);
                    if (resultCode == true)
                    {
                        if (settings.SDKCreation == true)
                        {
                            resultCode = updSdk(settings);
                            if (resultCode == true)
                            {
                                if (settings.WebCreation == true)
                                {
                                    resultCode = updWeb(settings);
                                }
                            }
                        }
                    }
                }
            }

            return(resultCode);
        }
Ejemplo n.º 2
0
        public Boolean createDAL(GenerateSettings settings)
        {
            bool resultCode = true;

            CoreHelper.NewJson(settings.BaseDirectory, settings.CoreSdkVer);

            db         = new DalGenerator();
            resultCode = CoreHelper.CreateNewCoreProject(settings.BaseDirectory, settings.DalSpaceName, "classlib");

            if (resultCode == true)
            {
                resultCode = CoreHelper.AddProjectToSolution(settings.BaseDirectory, settings.DalSpaceName + @"/" + settings.DalSpaceName + @".csproj", settings.SolutionName);

                if (resultCode == true)
                {
                    foreach (var item in settings.DalRefferences)
                    {
                        resultCode = CoreHelper.AddRefferenceToProject(settings.BaseDirectory, settings.DalSpaceName + @"/" + settings.DalSpaceName + @".csproj", item);
                    }
                    foreach (var item in settings.DalPackages)
                    {
                        resultCode = CoreHelper.AddPackageToProject(settings.BaseDirectory, settings.DalSpaceName + @"/" + settings.DalSpaceName + @".csproj", item);
                    }
                    resultCode = CoreHelper.AddProjectToSolution(settings.BaseDirectory, settings.DalSpaceName + @"/" + settings.DalSpaceName + @".csproj", settings.SolutionName);
                }

                resultCode = generateDALEntries(settings);
            }
            if (resultCode == true)
            {
                if (settings.WebApiCreation == true)
                {
                    //Create Web Api ,
                    resultCode = CoreHelper.CreateNewCoreProject(settings.BaseDirectory, settings.WebApiFolder, "webapi ");
                    //CoreHelper.BuildProject(settings.BaseDirectory + @"\" + settings.DalSpaceName);
                    if (resultCode == true)
                    {
                        foreach (var item in settings.WebApiRefferences)
                        {
                            resultCode = CoreHelper.AddRefferenceToProject(settings.BaseDirectory, settings.WebApiFolder + @"/" + settings.WebApiFolder + @".csproj", item);
                        }
                        foreach (var item in settings.WebApiPackages)
                        {
                            resultCode = CoreHelper.AddPackageToProject(settings.BaseDirectory, settings.WebApiFolder + @"/" + settings.WebApiFolder + @".csproj", item);
                        }
                        resultCode = CoreHelper.AddProjectToSolution(settings.BaseDirectory, settings.WebApiFolder + @"/" + settings.WebApiFolder + @".csproj", settings.SolutionName);
                        resultCode = createApi(settings);
                    }
                }
            }



            return(resultCode);
        }
Ejemplo n.º 3
0
        private bool createApi(GenerateSettings settings)
        {
            bool resultCode = true;

            var ctrlDir = settings.BaseDirectory + @"\" + settings.WebApiFolder;

            var db = new DalGenerator();

            var apiEntries = db.FrameworkTemplates.Where(o => o.StepNo == 1).OrderBy(o => o.CallPriority).ToList();

            foreach (var item in apiEntries)
            {
                if (item.PerModel == true)
                {
                    foreach (var modelEntry in settings.ModelNames)
                    {
                        var baseDir = ctrlDir + item.RelativePath;
                        if (!System.IO.Directory.Exists(baseDir))
                        {
                            System.IO.Directory.CreateDirectory(baseDir);
                        }
                        var fileCnt = System.Text.Encoding.Default.GetString(item.TemplateContent);
                        fileCnt = clearEntry(fileCnt, settings, modelEntry);
                        var fileName = settings.BaseDirectory + @"\" + settings.WebApiFolder + item.RelativePath + clearEntry(item.TemplateCodeFile, settings, modelEntry);
                        System.IO.File.WriteAllText(fileName, fileCnt);
                    }
                }
                else
                {
                    var baseDir = ctrlDir + item.RelativePath;
                    if (!System.IO.Directory.Exists(baseDir))
                    {
                        System.IO.Directory.CreateDirectory(baseDir);
                    }
                    var fileCnt = System.Text.Encoding.Default.GetString(item.TemplateContent);
                    fileCnt = clearEntry(fileCnt, settings);
                    var fileName = settings.BaseDirectory + @"\" + settings.WebApiFolder + item.RelativePath + clearEntry(item.TemplateCodeFile, settings);
                    System.IO.File.WriteAllText(fileName, fileCnt);
                }
            }


            if (settings.SDKCreation == true)
            {
                if (resultCode == true)
                {
                    //Create SDk ,
                    resultCode = CoreHelper.CreateNewCoreProject(settings.BaseDirectory, settings.SDKFolder, "classlib");
                    if (resultCode == true)
                    {
                        foreach (var item in settings.SDKRefferences)
                        {
                            resultCode = CoreHelper.AddRefferenceToProject(settings.BaseDirectory, settings.SDKFolder + @"/" + settings.SDKFolder + @".csproj", item);
                        }
                        foreach (var item in settings.SDKPackages)
                        {
                            resultCode = CoreHelper.AddPackageToProject(settings.BaseDirectory, settings.SDKFolder + @"/" + settings.SDKFolder + @".csproj", item);
                        }
                        resultCode = CoreHelper.AddProjectToSolution(settings.BaseDirectory, settings.SDKFolder + @"/" + settings.SDKFolder + @".csproj", settings.SolutionName);
                        resultCode = createSdk(settings);
                    }
                }
            }
            return(resultCode);
        }
Ejemplo n.º 4
0
        private bool updDALEntries(GenerateSettings settings)
        {
            bool resultCode = true;

            var db = new DalGenerator();

            //Get Data from Data Project.
            var frameworkEntries = db.FrameworkTemplates.Where(o => o.StepNo == 0).Where(o => o.Ovveride == true).OrderBy(o => o.CallPriority).ToList();

            foreach (FrameworkTemplate item in frameworkEntries.Where(o => o.Mode < 4).OrderBy(o => o.CallPriority))
            {
                if (item.Mode != 1 && item.Mode != 3)
                {
                    //DbContext
                    var DalBaseDir = settings.BaseDirectory + @"\" + settings.DalSpaceName;
                    if (System.IO.Directory.Exists(DalBaseDir + item.RelativePath))
                    {
                        System.IO.Directory.CreateDirectory(DalBaseDir + item.RelativePath);
                    }
                    var fileCnt  = System.Text.Encoding.Default.GetString(item.TemplateContent);
                    var fileName = settings.BaseDirectory + @"\" + settings.DalSpaceName + item.RelativePath + clearEntry(item.TemplateCodeFile, settings);
                    fileCnt = clearEntry(fileCnt, settings);
                    var defaultdbSets = "public virtual DbSet<#Model#> #Model# { get; set; }";
                    var allDbSets     = "";
                    foreach (var modelEntry in settings.ModelNames)
                    {
                        allDbSets += defaultdbSets.Replace("#Model#", modelEntry) + Environment.NewLine;
                    }
                    fileCnt = fileCnt.Replace("#public virtual DbSet<#Model#> #Model# { get; set; }#", allDbSets);

                    System.IO.File.WriteAllText(fileName, fileCnt);
                }
                else
                {
                    if (item.PerModel == false)
                    {
                        var DalBaseDir = settings.BaseDirectory + @"\" + settings.DalSpaceName;
                        if (System.IO.Directory.Exists(DalBaseDir + item.RelativePath))
                        {
                            System.IO.Directory.CreateDirectory(DalBaseDir + item.RelativePath);
                        }
                        var fileCnt = System.Text.Encoding.Default.GetString(item.TemplateContent);
                        fileCnt = clearEntry(fileCnt, settings);
                        var fileName = settings.BaseDirectory + @"\" + settings.DalSpaceName + item.RelativePath + clearEntry(item.TemplateCodeFile, settings);
                        System.IO.File.WriteAllText(fileName, fileCnt);
                    }
                    else
                    {
                        var DalBaseDir = settings.BaseDirectory + @"\" + settings.DalSpaceName;

                        foreach (var modelEntry in settings.ModelNames)
                        {
                            var fileCnt      = System.Text.Encoding.Default.GetString(item.TemplateContent);
                            var relativePath = clearEntry(item.RelativePath, settings, modelEntry);
                            if (System.IO.Directory.Exists(DalBaseDir + relativePath))
                            {
                                System.IO.Directory.CreateDirectory(DalBaseDir + relativePath);
                            }
                            fileCnt = clearEntry(fileCnt, settings, modelEntry);
                            var fileName = settings.BaseDirectory + @"\" + settings.DalSpaceName + relativePath + clearEntry(item.TemplateCodeFile, settings, modelEntry);
                            System.IO.File.WriteAllText(fileName, fileCnt);
                        }
                    }
                }
            }

            var privateObjects = "";
            var publicObjects  = "";

            foreach (var item in frameworkEntries.Where(o => o.Mode == 4).OrderBy(o => o.CallPriority))
            {
                if (item.TemplateCodeFile.StartsWith("private"))
                {
                    var privateContent = System.Text.Encoding.Default.GetString(item.TemplateContent);
                    foreach (var modelEntry in settings.ModelNames)
                    {
                        privateObjects += clearEntry(privateContent, settings, modelEntry) + Environment.NewLine;
                    }
                }
                if (item.TemplateCodeFile.StartsWith("public"))
                {
                    var publicContent = System.Text.Encoding.Default.GetString(item.TemplateContent);
                    foreach (var modelEntry in settings.ModelNames)
                    {
                        publicObjects += clearEntry(publicContent, settings, modelEntry) + Environment.NewLine;
                    }
                }
            }

            var finalDalItem = frameworkEntries.Where(o => o.Mode == 5).FirstOrDefault();
            var finalCnt     = System.Text.Encoding.Default.GetString(finalDalItem.TemplateContent);

            finalCnt = clearEntry(finalCnt, settings);
            finalCnt = finalCnt.Replace("#PrivateObjects#", privateObjects);
            finalCnt = finalCnt.Replace("#PublicObjects#", publicObjects);
            var finalfileName = settings.BaseDirectory + @"\" + settings.DalSpaceName + finalDalItem.RelativePath + clearEntry(finalDalItem.TemplateCodeFile, settings);

            System.IO.File.WriteAllText(finalfileName, finalCnt);

            return(resultCode);
        }