Example #1
0
        public ActionResult Output(string input1, string input2)
        {
            ProjectVariable myProjectVariable = new ProjectVariable();

            myProjectVariable.SetInput1(input1);
            myProjectVariable.SetInput2(input2);
            return(View(myProjectVariable));
        }
        public ActionResult TestFormResult(string test, string test2)
        {
            ProjectVariable projectVariable = new ProjectVariable();

            projectVariable.Test  = test;
            projectVariable.Test2 = test2;
            return(View(projectVariable));
        }
Example #3
0
        private DALClass getNewDAL(ProjectVariable nameSpace)
        {
            ConnectionString readConn = new ConnectionString(1, "Reader", "db_reader");
            ConnectionString editConn = new ConnectionString(2, "Editor", "db_editor");
            DALClass         dal      = new DALClass();

            dal.NameSpaceName            = nameSpace;
            dal.Name                     = nameSpace + "DAL";
            dal.ReadOnlyConnectionString = readConn;
            dal.EditOnlyConnectionstring = editConn;

            return(dal);
        }
Example #4
0
        public IActionResult Upload(IFormFile fupFile, string name, string uniquekey)
        {
            // Import Stats
            DateTime startImport = DateTime.Now;
            long     lineCreated = 0;
            // end stats


            Project thisProject = new Project()
            {
                Key = uniquekey
            };
            List <ProjectFile> thisFiles = new List <ProjectFile>();

            string uploadFolder  = Path.GetFullPath("Uploads") + "\\" + uniquekey + "\\";
            string filePath      = uploadFolder + fupFile.FileName;
            string nameSpaceName = getCleanNameSpace(fupFile.FileName);

            // create directory for upload
            Directory.CreateDirectory(uploadFolder);
            //
            string saveFolderPath = Path.GetFullPath("Projects") + @"\" + thisProject.Key;

            // copy uploaded file to upload directory.
            using (FileStream fs = new FileStream(filePath, FileMode.Create)) {
                fupFile.CopyTo(fs);
                fs.Close();
            }
            List <string>       messages        = new List <string>();
            List <ProjectClass> classes         = SQLScriptConversion.generateObjects(filePath, ref messages);
            ProjectVariable     nameSpaceObject = new ProjectVariable(1, nameSpaceName);

            StaticVariables.Instance.NameSpaceNames.Append(nameSpaceObject);
            DALClass dalClassObject = getNewDAL(nameSpaceObject);

            if (!Directory.Exists(saveFolderPath))
            {
                // no directory; create it
                Directory.CreateDirectory(saveFolderPath);
            }
            StringBuilder sprocScripts = new StringBuilder();
            StringBuilder dalFunctions = new StringBuilder();

            foreach (ProjectClass pClass in classes)
            {
                String fileName = pClass.Name.Capitalized() + ".cs";
                pClass.DALClassVariable  = dalClassObject;
                pClass.NameSpaceVariable = nameSpaceObject;
                string classContent = ClassGenerator.getEntireClass(pClass, name, CodeGeneration.Language.CSharp, CodeGeneration.Format.ASPX, ref messages);
                // save file to project folder.
                using (StreamWriter sw = new StreamWriter(saveFolderPath + @"\" + fileName, false)) {
                    lineCreated += classContent.Count('\n');
                    sw.Write(classContent);
                }

                thisFiles.Add(new ProjectFile()
                {
                    Name    = fileName, PhysicalPath = saveFolderPath + @"\",
                    Project = thisProject
                });

                sprocScripts.Append(StoredProcsGenerator.getSprocText(pClass, name, ref messages));
                dalFunctions.Append(DALGenerator.getDALFunctions(pClass, CodeGeneration.Language.CSharp));
            }

            // Save SProcs file
            string sprocFileName = "StoredProcedures.sql";

            using (StreamWriter sw = new StreamWriter(saveFolderPath + @"\" + sprocFileName, false)) {
                string sprocString = sprocScripts.ToString();
                lineCreated += sprocString.Count('\n');
                sw.Write(sprocString);
                thisFiles.Add(new ProjectFile()
                {
                    Name    = sprocFileName, PhysicalPath = saveFolderPath + @"\",
                    Project = thisProject
                });
            }

            // Save DAL file
            string dalContent  = DALGenerator.getDALText("ReadOnlyConnectionString", "EditOnlyConnectionString", dalClassObject, dalFunctions, CodeGeneration.Language.CSharp);
            string dalFileName = dalClassObject.Name + ".cs";

            using (StreamWriter sw = new StreamWriter(saveFolderPath + @"\" + dalFileName, false)) {
                lineCreated += dalContent.Count('\n');
                sw.Write(dalContent);
                thisFiles.Add(new ProjectFile()
                {
                    Name    = dalFileName, PhysicalPath = saveFolderPath + @"\",
                    Project = thisProject
                });
            }

            TimeSpan timeTaken = DateTime.Now - startImport;

            thisProject.Files = thisFiles;
            thisProject.ConversionMessages = messages;
            thisProject.LinesGenerated     = lineCreated;
            thisProject.TimeTaken          = timeTaken;
            string projName = nameSpaceName + ".proj";

            using (StreamWriter sw = new StreamWriter(saveFolderPath + @"\" + projName, false)) {
                string projJSON = System.Text.Json.JsonSerializer.Serialize(thisProject);
                sw.Write(projJSON);
            }
            //return View(thisProject);

            //https://stackoverflow.com/questions/13510204/json-net-self-referencing-loop-detected
            TempData["CurrentProject"] = Newtonsoft.Json.JsonConvert.SerializeObject(thisProject,
                                                                                     new Newtonsoft.Json.JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });
            return(RedirectToAction("List", new { uniquekey = thisProject.Key }));
        }