Exemplo n.º 1
0
 public void CreateWebserviceFile(string filePath, string folderPath, string moduleName, string extension, string baseFolderPath, Dictionary <string, string> columnlist)
 {
     if (File.Exists(filePath))
     {
         try
         {
             string destinationPath = folderPath + "/Webservice/";
             ModuleHelper.CreateDirectory(destinationPath);
             string code = string.Empty;
             destinationPath += moduleName + extension;
             using (StreamWriter sw = new StreamWriter(destinationPath))
             {
                 using (StreamReader rdr = new StreamReader(filePath))
                 {
                     code = rdr.ReadToEnd();
                 }
                 string webserviceCode = ModuleHelper.WebServiceCode(columnlist, moduleName).ToString();
                 code = code.Replace("ModuleName", moduleName.Replace("Edit", ""));
                 code = code.Replace("//Methodshere", webserviceCode);
                 code = code.Replace("//references", "using SageFrame." + moduleName + ";");
                 sw.Write(code);
             }
         }
         catch (Exception ex)
         {
             ShowMessage("", ex.ToString(), "", SageMessageType.Error);
             ProcessException(ex);
         }
     }
 }
Exemplo n.º 2
0
 public void CreateJsFile(string filePath, string folderPath, string moduleName, string extension, string baseFolderPath)
 {
     if (File.Exists(filePath))
     {
         try
         {
             string destinationPath = folderPath + "/js/";
             ModuleHelper.CreateDirectory(destinationPath);
             string code = string.Empty;
             destinationPath += moduleName + extension;
             using (StreamWriter sw = new StreamWriter(destinationPath))
             {
                 using (StreamReader rdr = new StreamReader(filePath))
                 {
                     code = rdr.ReadToEnd();
                 }
                 code = code.Replace("ModuleName", moduleName);
                 code = code.Replace("FolderPath", baseFolderPath);
                 sw.Write(code);
             }
         }
         catch (Exception ex)
         {
             ShowMessage("", ex.ToString(), "", SageMessageType.Error);
             ProcessException(ex);
         }
     }
 }
Exemplo n.º 3
0
 public void CreateCssFile(string folderPath, string moduleName, string extension)
 {
     try
     {
         folderPath = folderPath + moduleName + "/css/";
         folderPath = Server.MapPath(folderPath);
         ModuleHelper.CreateDirectory(folderPath);
         string destinationPath = folderPath + moduleName + extension;
         File.Create(destinationPath);
     }
     catch (Exception ex)
     {
         ShowMessage("", ex.ToString(), "", SageMessageType.Error);
         ProcessException(ex);
     }
 }
Exemplo n.º 4
0
    public string SqlFileCreate(string moduleFolderPath, string moduleName, List <string> storeprocedureList)
    {
        string SqlFilePath = Server.MapPath(moduleFolderPath + moduleName + "/Script");

        ModuleHelper.CreateDirectory(SqlFilePath);
        string        sqldestinationPath = SqlFilePath + "/" + moduleName + ".sql";
        StringBuilder procedure          = new StringBuilder();

        using (StreamWriter sw = new StreamWriter(sqldestinationPath))
        {
            foreach (string storeprocedure in storeprocedureList)
            {
                procedure.Append("GO");
                procedure.Append(Environment.NewLine);
                procedure.Append(storeprocedure);
                procedure.Append(Environment.NewLine);
            }
            sw.Write(procedure.ToString());
        }
        return(procedure.ToString());
    }
Exemplo n.º 5
0
    public void CreateModule(bool adminModule, Dictionary <string, string> columnlist, List <string> storeprocedureList, Dictionary <string, string> updateList, bool autoIncrement)
    {
        string moduleName       = txtModuleName.Text;
        string moduleFolderPath = "/Modules/";

        if (adminModule)
        {
            moduleFolderPath += "Admin/";
        }
        //Generates the library files: Info , Controller and the dataprovider and compiled it.
        bool isNewModule        = true;
        bool compilationsuccess = GenerateandCompileLibrary(moduleFolderPath, moduleName, columnlist, updateList, isNewModule, autoIncrement);

        if (compilationsuccess)
        {
            string moduleDescription    = txtModuleDescription.Text;
            bool   includeCSS           = chkCss.Checked;
            bool   includeJS            = chkJS.Checked;
            bool   includeEditModule    = chkEdit.Checked;
            bool   includeSettingModule = chkSetting.Checked;
            bool   includeWebService    = chkWebService.Checked;

            string baseFolderPath = moduleFolderPath + moduleName;
            string folderpath     = Server.MapPath(baseFolderPath);
            ModuleHelper.CreateDirectory(folderpath);

            string filePathFront         = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/ModuleName.ascx");
            string filePathBehind        = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/ModuleName.ascx.cs");
            string fileNameFrontEdit     = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/ModuleNameEdit.ascx");
            string fileNameBehindEdit    = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/ModuleNameEdit.ascx.cs");
            string fileNameFrontSetting  = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/ModuleNameSetting.ascx");
            string fileNameBehindSetting = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/ModuleNameSetting.ascx.cs");

            //Creates file for View and its compulsory
            CreateFile(filePathFront, folderpath, moduleName, ".ascx", baseFolderPath, false, false);
            CreateFile(filePathBehind, folderpath, moduleName, ".ascx.cs", baseFolderPath, includeCSS, includeJS);
            //Creates file for Edit if the user wants
            if (includeEditModule)
            {
                CreateFile(fileNameFrontEdit, folderpath, moduleName + "Edit", ".ascx", baseFolderPath, false, includeJS);
                CreateFile(fileNameBehindEdit, folderpath, moduleName + "Edit", ".ascx.cs", baseFolderPath, includeCSS, includeJS);
            }
            //Creates file for Settings if the user wants
            if (includeSettingModule)
            {
                CreateFile(fileNameFrontSetting, folderpath, moduleName + "Setting", ".ascx", baseFolderPath, includeCSS, false);
                CreateFile(fileNameBehindSetting, folderpath, moduleName + "Setting", ".ascx.cs", baseFolderPath, includeCSS, false);
            }
            //Creates css file for the module if the user wants
            if (includeCSS)
            {
                CreateCssFile(moduleFolderPath, moduleName, ".css");
            }
            //Creates Js file for the module if the user wants
            if (includeJS)
            {
                string jsRawFile = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/js/module.js");
                CreateJsFile(jsRawFile, folderpath, moduleName, ".js", baseFolderPath);
                CreateJsFile(jsRawFile, folderpath, moduleName + "Edit", ".js", baseFolderPath);
                //Creates webservice file for the module if the user wants
                if (includeWebService)
                {
                    string webServiceRawFile = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/webservice/WebService.asmx");
                    CreateWebserviceFile(webServiceRawFile, folderpath, moduleName, ".asmx", baseFolderPath, columnlist);
                }
            }
            //SQL file write
            string procedure = SqlFileCreate(moduleFolderPath, moduleName, storeprocedureList);
            RegisterModule(moduleName, moduleFolderPath.Remove(0, 1), procedure);
        }
    }
Exemplo n.º 6
0
    public bool GenerateandCompileLibrary(string moduleFolderPath, string moduleName, Dictionary <string, string> columnlist, Dictionary <string, string> updateList, bool isNewModule, bool autoIncrement)
    {
        string filePathInfo         = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/library/ModuleInfo.cs");
        string filePathController   = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/library/ModuleController.cs");
        string filePathDataProvider = Server.MapPath("/Modules/Admin/ModuleMaker/RawModule/library/ModuleDataProvider.cs");
        string bigCode    = string.Empty;
        string code       = string.Empty;
        bool   isCompiled = false;

        try
        {
            string libraryPath = Server.MapPath(moduleFolderPath + moduleName + "/SageFrame." + moduleName);
            ModuleHelper.CreateDirectory(libraryPath);
            string infoPath = libraryPath + "/Info";
            ModuleHelper.CreateDirectory(infoPath);
            string destinationPath = infoPath + "/" + moduleName + "Info.cs";
            using (StreamWriter sw = new StreamWriter(destinationPath))
            {
                using (StreamReader rdr = new StreamReader(filePathInfo))
                {
                    code = rdr.ReadToEnd();
                }
                StringBuilder html = new StringBuilder();
                foreach (KeyValuePair <string, string> datatype in columnlist)
                {
                    html.Append(ModuleHelper.SageProp(datatype.Value, datatype.Key));
                }
                code = code.Replace("//properties", html.ToString());
                string references = "using System;";
                references = "using System;\nusing SageFrame.Web.Utilities;\nusing System.Collections.Generic;\n";
                code       = code.Replace("//references", references);
                code       = code.Replace("ModuleName", moduleName);
                sw.Write(code);
                bigCode = code;
            }
            string contollerPath = libraryPath + "/Controller";
            ModuleHelper.CreateDirectory(contollerPath);
            destinationPath = contollerPath + "/" + moduleName + "Controller.cs";
            using (StreamWriter sw = new StreamWriter(destinationPath))
            {
                using (StreamReader rdr = new StreamReader(filePathController))
                {
                    code = rdr.ReadToEnd();
                }
                string controllerCode = ModuleHelper.ControllerCode(columnlist, moduleName).ToString();
                code     = code.Replace("//properties", controllerCode);
                code     = code.Replace("ModuleName", moduleName);
                bigCode += "\n" + code;
                string references = "using System; using System.Collections.Generic;";
                code = code.Replace("//references", references);
                sw.Write(code);
            }
            string dataProviderPath = libraryPath + "/DataProvider";
            ModuleHelper.CreateDirectory(dataProviderPath);
            destinationPath = dataProviderPath + "/" + moduleName + "DataProvider.cs";
            using (StreamWriter sw = new StreamWriter(destinationPath))
            {
                using (StreamReader rdr = new StreamReader(filePathDataProvider))
                {
                    code = rdr.ReadToEnd();
                }
                string dataProviderCode = ModuleHelper.DataProviderCode(columnlist, moduleName, updateList, autoIncrement).ToString();
                code     = code.Replace("//properties", dataProviderCode);
                code     = code.Replace("ModuleName", moduleName);
                bigCode += "\n" + code;
                string references = "using System;\n using SageFrame.Web.Utilities;\n using System.Collections.Generic;\n";
                code = code.Replace("//references", references);
                sw.Write(code);
            }
        }
        catch (Exception ex)
        {
            ShowMessage("", ex.ToString(), "", SageMessageType.Error);
            ProcessException(ex);
        }
        if (isNewModule)
        {
            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
            //CSharpCodeProvider csp = new CSharpCodeProvider();
            // ICodeCompiler cc = provider.CreateCompiler();
            CompilerParameters cp             = new CompilerParameters();
            string             OutputAssembly = Path.Combine(Server.MapPath("/bin/"), "SageFrame." + moduleName + ".dll");
            cp.OutputAssembly = OutputAssembly;
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + "bin\\SageFrame.Common.dll");
            cp.WarningLevel = 3;
            //cp.CompilerOptions = "/target:library /optimize";
            cp.GenerateExecutable = false;
            cp.GenerateInMemory   = false;
            System.CodeDom.Compiler.TempFileCollection tfc = new TempFileCollection(GetApplicationName, false);
            CompilerResults cr = new CompilerResults(tfc);
            cr = provider.CompileAssemblyFromSource(cp, bigCode);
            if (cr.Errors.Count > 0)
            {
                string error = string.Empty;
                foreach (CompilerError ce in cr.Errors)
                {
                    error += ce.ErrorNumber + ": " + ce.ErrorText;
                }
                ShowMessage("", error, "", SageMessageType.Error);
                isCompiled = false;
            }
            else
            {
                isCompiled = true;
            }
        }
        return(isCompiled);
    }