public FileResult Post(List <IFormFile> files) { List <Model> Models = new List <Model>(); long size = files.Sum(f => f.Length); try { var filePath = Path.GetTempFileName(); foreach (var formFile in files) { if (formFile.Length > 0) { using (var reader = new StreamReader(formFile.OpenReadStream())) { string text = reader.ReadToEnd(); reader.Dispose(); string[] models = text.Split(new string[] { "class" }, StringSplitOptions.None); for (int i = 1; i < models.Length; i++) { Model m = new Model(models[i], "Test"); Models.Add(m); } } } } string fileName = "Project.txt"; byte[] bytes = new byte[0]; MemoryStream ms = new MemoryStream(); TextWriter tw = new StreamWriter(ms); List <string> downloads = new List <string>(); foreach (Model m in Models) { tw.WriteLine(APIControllerGenerator.Generate(m)); tw.WriteLine(RepositoryGenerator.Generate(m)); tw.WriteLine(ServiceGenerator.Generate(m)); tw.WriteLine(TableGenerator.Generate(m, Models)); } tw.Flush(); bytes = ms.ToArray(); ms.Dispose(); return(File(bytes, "application/x-msdownload", fileName)); } catch (Exception ex) { return(File("", "")); } }
/// <summary> /// Генерация и регистрация репозриторя. /// </summary> /// <param name="container">Unity-container.</param> /// <param name="repositoryInterfaceType">Тип интерфейса репозитория.</param> private static void RegisterRepository(this IUnityContainer container, Type repositoryInterfaceType) { var factoryGenerator = new RepositoryGenerator(); var concreteFactoryType = factoryGenerator.Generate(repositoryInterfaceType); container.RegisterType( repositoryInterfaceType, new TransientLifetimeManager(), new InjectionFactory( c => { var activator = new RepositoryActivator(); return(activator.CreateInstance(c, concreteFactoryType)); })); }