コード例 #1
0
        public HttpResponseMessage Post(GenerateFile model)
        {
            ModelInfo modelInfo = model.ModelInfo;
            int       id        = model.TemplateId;

            GetMicrosoftDatabaseSchemaDetails microsoftDatabaseSchemaDetails = new GetMicrosoftDatabaseSchemaDetails();
            List <IModelInfoTemplate>         templates = templateFactory.GetModelInfoTemplates(modelInfo);
            IModelInfoTemplate template = templates.FirstOrDefault(c => c.GetClassId() == id);

            string documentText = "Error no template found!";

            if (template != null)
            {
                documentText = template.TransformText();
            }

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(Encoding.ASCII.GetBytes(documentText))
            };

            result.Content.Headers.ContentDisposition =
                new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = "CertificationCard.cs"
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

            return(result);
        }
コード例 #2
0
        public HttpResponseMessage Post(AppInfo generateAllFiles)
        {
            Dictionary <string, string> filesDictionary = new Dictionary <string, string>();

            string baseFolder = AppDomain.CurrentDomain.BaseDirectory + "/Download/";

            foreach (ModelInfo tableInfo in generateAllFiles.TableInfomation)
            {
                //if (!tableInfo.Required)
                //    continue;
                // create a folder
                string innerFolder   = tableInfo.TableName + "ServiceTests";
                string currentFolder = baseFolder + innerFolder;
                System.IO.Directory.CreateDirectory(currentFolder);
                GetMicrosoftDatabaseSchemaDetails DbSchema          = new GetMicrosoftDatabaseSchemaDetails();
                List <IModelInfoTemplate>         allLogicTemplates = testsTemplateFactory.GetModelInfoTemplates(tableInfo);

                foreach (IModelInfoTemplate logicTemplate in allLogicTemplates)
                {
                    IModelInfoTemplate template  = allLogicTemplates.FirstOrDefault(c => c.GetClassId() == logicTemplate.GetClassId());
                    string             classText = template.TransformText();
                    // create a file in the folder
                    var    fileName = template.GetClassName() + ".cs";
                    string path     = currentFolder + "/" + fileName;

                    using (FileStream fs = System.IO.File.Create(path))
                    {
                        Byte[] info = new UTF8Encoding(true).GetBytes(classText);
                        // Add some information to the file.
                        fs.Write(info, 0, info.Length);
                    }

                    filesDictionary.Add(path, innerFolder + "/" + fileName);
                }
            }

            string zipFolder = baseFolder + "/Tests.zip";

            if (System.IO.File.Exists(zipFolder))
            {
                System.IO.File.Delete(zipFolder);
            }
            ZipArchive zip = ZipFile.Open(zipFolder, ZipArchiveMode.Create);

            foreach (var file in filesDictionary)
            {
                zip.CreateEntryFromFile(file.Key, file.Value.Replace("_", ""));
            }
            zip.Dispose();

            // return File(zipFolder,"application/zip", "bundle.zip");

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(zipFolder, FileMode.Open, FileAccess.Read);

            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/octet-stream");
            return(result);
        }
コード例 #3
0
        public ActionResult DefineApplication(ServerModel model)
        {
            // 1. Test view model
            if (!ModelState.IsValid)
            {
                return(View("Index", model));
            }

            string[] reqList = null;
            if (model.RequiredList != null)
            {
                reqList = model.RequiredList.ToLower().Split(',').ToList().Select(c => c.Trim()).ToArray();
            }

            var result = _microsoftDatabaseSchemaDetails.GetTableDefinition(GetConnectionString(model), reqList); // getting the database mode 3 seconds


            // 2. Test Service result for getting schema data
            if (!result.Success)
            {
                Danger(string.Join("<br/>", result.Messages.Where(c => c.SeverityLevel == "error").Select(cc => cc.MessageText)));
                return(View("Index", model));
            }

            List <ModelInfo> tableInfomation = result.Data;

            _appInfo.TableInfomation = tableInfomation;

            // Custom Logic templates
            List <IModelInfoTemplate> templates = customLogicTemplateFactory.GetModelInfoTemplates(null);

            _appInfo.Templates = templates.Select(c => new TempalateClassModel
            {
                ClassId   = c.GetClassId(),
                ClassName = c.GetClassName()
            }).ToList();

            List <IModelInfoTemplate> templatesFront = AngularFrontEndTemplateFactory.GetModelInfoTemplates(null);

            _appInfo.FrontEndTemplates = templatesFront.Select(c => new TempalateClassModel
            {
                ClassId   = c.GetClassId(),
                ClassName = c.GetClassName()
            }).ToList();

            return(View(_appInfo));
        }