public FichierEntete Add(IFormFile file, Guid documentId, Guid userId) { if (file.Length > 0) { var fileName = Path.GetFileName(file.FileName); var fileExtension = Path.GetExtension(fileName); var newFileName = String.Concat(fileName, fileExtension); var protector = _protectorProvider.CreateProtector("LazyDocs.Fichier", userId.ToString()); var fichier = new EntityFile() { DocumentId = documentId, Name = newFileName, Type = fileExtension, UserId = userId, CreateDate = DateTime.Now, Size = file.Length, Encrypted = true }; using (var target = new MemoryStream()) { file.CopyTo(target); fichier.File = protector.Protect(target.ToArray()); } this._context.Files.Add(fichier); this._context.SaveChanges(); return(fichier.ToFichierEntete()); } return(null); }
public Generator(List<DbTableInfo> tables, EntityFile file, string dirTemplate) { this.tables = tables; this.file = file; this.dirTemplate = dirTemplate; entities = new Dictionary<string, EntityInfo>(); }
public virtual EntityFileOperationResult SaveAs(EntityFile file) { EntityFileOperationResult result = new EntityFileOperationResult(); string virtualPath = Path.Combine(this._commerceDataDir.DataVirtualFolder, file.CommerceName, "Images", file.FileName); string physicalPath = Kooboo.Web.Url.UrlUtility.MapPath(virtualPath); byte[] data = new byte[file.Data.Length]; file.Data.Read(data, 0, data.Length); FileStream fs = new FileStream(physicalPath, FileMode.Create); try { fs.Write(data, 0, data.Length); fs.Flush(); fs.Close(); } catch (Exception ex) { fs.Close(); throw ex; } result.PhysicalPath = physicalPath; result.VirtualPath = virtualPath; return(result); }
public DataLite(IHttpContextAccessor context, ILoggerFactory loggerFactory) { this.logger = loggerFactory.CreateLogger("RequestInfoLogger"); this.context = context.HttpContext; Initializing(this.context.Session.GetString("StorageName")); Accounts = new EntityAccount(Connection); Files = new EntityFile(Connection); }
public static FichierEntete ToFichierEntete(this EntityFile entity) { return(new FichierEntete() { Id = entity.Id, Type = entity.Type, Name = entity.Name, CreateDate = entity.CreateDate }); }
public static EntityFileModel Map(EntityFile objModel) { return(new EntityFileModel { Id = objModel.Id, SectionId = objModel.SectionId, EntityId = objModel.EntityId, FileId = objModel.FileId, Section = SectionMap.Map(objModel.Section) }); }
public ActionResult <EntityFile> PostEntityFile([FromBody] EntityFile entityFile) { using (_unitOfWork) { _unitOfWork.Create(); entityFile.Id = Guid.NewGuid(); _unitOfWork.EntityFile.Add(entityFile); _unitOfWork.Commit(); return(Ok(entityFile)); } }
public void SplitsFolderName() { var entityId = Guid.NewGuid(); var fileId = Guid.NewGuid(); var file = new EntityFile(1, "AccountFile", entityId, fileId, 1, new byte[] { 0 }); Assert.NotNull(file); Assert.NotNull(file.FolderNames); Assert.NotEmpty(file.FolderNames); Assert.Equal("AccountFile", file.FolderNames[0]); Assert.Equal(entityId.ToString(), file.FolderNames[1]); Assert.Equal(fileId.ToString(), file.FolderNames[2]); }
public void CreatesRemoteFolderPath() { var entityId = Guid.NewGuid(); var fileId = Guid.NewGuid(); var file = new EntityFile(1, "AccountFile", entityId, fileId, 1, new byte[] { 0 }); var remoteFolderPath = file.GetRemoteFolderPath(); Assert.NotNull(file); Assert.NotNull(file.Entity); Assert.NotNull(file.EntityId); Assert.NotNull(file.FileId); Assert.Equal($"AccountFile/{entityId.ToString()}/{fileId.ToString()}/", remoteFolderPath); }
/// <summary> /// Помещает файл в файловое хранилище. /// </summary> /// <param name="entityFile">Выгружаемый файл</param> /// <param name="allFiles">Все файлы сущности</param> public async Task <bool> PutWithHttp(EntityFile entityFile, IEnumerable <EntityFile> allFiles) { if (entityFile?.Data == null || !(entityFile.FolderNames?.Count > 0)) { return(false); } try { using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(UserName, Password), PreAuthenticate = true }) using (var client = new HttpClient(handler) { BaseAddress = new Uri(ServerUrl) }) { var requestMessage = new HttpRequestMessage(HttpMethod.Put, new Uri(ServerUrl + entityFile.GetRemotePath())) { Content = new ByteArrayContent(entityFile.Data), Version = HttpVersion.Version11, Headers = { { HttpRequestHeader.Translate.ToString(), "f" }, { HttpRequestHeader.ContentType.ToString(), "application/octet-stream" }, { HttpRequestHeader.ContentLength.ToString(), entityFile.Data.ToString() } } }; var result = await client.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead); var entityFiles = allFiles.ToList(); Log.Info(Utils.ShowPercentProgress("Выгружаем файлы", entityFiles.IndexOf(entityFile), entityFiles.Count)); Log.Info($"Файл: #{entityFile.Number.ToString()} {entityFile.Entity}/{entityFile.EntityId}/{entityFile.FileId}/{entityFile.Version} {entityFile.Data.Length / 1024.0:####0.######} КБ ({entityFile.Data.Length / (1024.0 * 1024.0):####0.######} МБ) {result.StatusCode.ToString()}"); return(true); } } catch (WebException ex) { Console.WriteLine(ex.Message); Log.Debug(ex); return(false); } catch (Exception ex) { ExceptionHandler.LogExceptionToConsole(ex); throw ex; } }
public void Test_Save() { EntityFile entityFile = new EntityFile() { FileName = "image1.png", Data = new MemoryStream(new byte[] { 0, 1, 2, 3 }), ContentType = "image" }; var result = entityFileProvider.Save(entityFile, "Tests"); var expectedPhysicalPath = Path.Combine(commerceDataDir.DataPhysicalPath, "Tests", entityFile.FileName); var expectedVirtualPath = UrlUtility.Combine(commerceDataDir.DataVirutalPath, "Tests", entityFile.FileName); Assert.AreEqual(expectedPhysicalPath, result.PhysicalPath); Assert.AreEqual(expectedVirtualPath, result.VirtualPath); }
public void Creates() { var entityId = Guid.NewGuid(); var fileId = Guid.NewGuid(); var file = new EntityFile(1, "AccountFile", entityId, fileId, 1, new byte[] { 0 }); Assert.NotNull(file); Assert.NotNull(file.Entity); Assert.Equal("AccountFile", file.Entity); Assert.NotNull(file.EntityId); Assert.False(Guid.Empty == Guid.Parse(file.EntityId)); Assert.NotNull(file.FileId); Assert.False(Guid.Empty == Guid.Parse(file.FileId)); Assert.NotNull(file.Version); Assert.True(file.Version == "1"); Assert.NotNull(file.Data); Assert.NotEmpty(file.Data); Assert.True(file.Data.Length == 1); }
public async Task GenerateEntities(EntityGenerationRequest request) { var connectionString = string.Format(@"Data Source={0};Initial Catalog={1};User Id={2};Password={3};", request.Server, request.Database, request.Username, request.Password); var generator = CodeFirstGenerator.Load(connectionString, request.EntityDefinitions.ToDictionary(def => def.TableName, def => def.EntityName)); bool makePartialClasses = false; EntityFile entityFile = FilePathSplitter.DetermineEntityFile(request.OutputPath); var projectDirectoryPaths = Directory.GetFiles(entityFile.EntityOutputPath, "*.csproj"); if (projectDirectoryPaths.Length == 1) { var projectDirectoryPath = projectDirectoryPaths.Single(); var project = new Project(projectDirectoryPath); var serverPath = FilePathSplitter.DetermineServerPath(request.OutputPath); foreach (var entityDefinition in request.EntityDefinitions.Where(table => !generator.IsManyToManyMappingTable(table.TableName))) { var tryToSave = _SearchForExistingTableName(entityDefinition.TableName, serverPath); if (tryToSave) { var pocoEntity = EntityGeneratorEngine.GeneratePocoEntity(request.Namespace, entityDefinition.TableName, entityDefinition.EntityName, makePartialClasses, generator); _SaveOutput(request.OutputPath, Path.Combine(entityDefinition.EntityName + ".cs"), entityFile.EntityOutputPathPrefix, pocoEntity, project); var mapping = EntityGeneratorEngine.GenerateMapping(request.Namespace + ".Mapping", entityDefinition.TableName, entityDefinition.EntityName, generator); _SaveOutput(request.OutputPath, Path.Combine("Mapping", entityDefinition.EntityName + "Map.cs"), entityFile.EntityOutputPathPrefix, mapping, project); } } if (project.IsDirty) { _SortProjectDirectory(projectDirectoryPath); } ProjectCollection.GlobalProjectCollection.UnloadProject(project); } }
public async Task <IActionResult> PutEntityFile([FromRoute] Guid id, [FromBody] EntityFile entityFile) { using (_unitOfWork) { _unitOfWork.Create(); if (entityFile == null) { return(NotFound()); } if (id != entityFile.Id) { return(BadRequest()); } _unitOfWork.EntityFile.Update(entityFile); _unitOfWork.Commit(); return(Ok(entityFile)); } }
public Guid AddDocument(IFormCollection fileCollection, Guid userId) { if (fileCollection == null) { return(Guid.Empty); } var document = new EntityDocument(); document.UserId = userId; document.Files = new List <EntityFile>(); document.CreateDate = DateTime.Now; foreach (var file in fileCollection.Files) { if (file.Length > 0) { var fileName = Path.GetFileName(file.FileName); var fileExtension = Path.GetExtension(fileName); var newFileName = String.Concat(fileName, fileExtension); var fichier = new EntityFile() { Name = newFileName, Type = fileExtension, UserId = document.UserId, CreateDate = DateTime.Now }; using (var target = new MemoryStream()) { file.CopyTo(target); fichier.File = target.ToArray(); } document.Files.Add(fichier); } } this._context.Documents.Add(document); this._context.SaveChanges(); return(document.Id); }
public FileUtil(EnumTipoArquivo tipoArquivo) { EntityFile = new EntityFile(tipoArquivo); Path = EntityFile.Path; }
public void SetNames(EntityFile file, string tableName) { var v = file.Variables; EntityName = v.EntityName.Replace("[EntityName]", tableName); if (NameCase != EnumNameCase.None) { var names = EntityName.Split(new char[] { '_', ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < names.Length; i++) { if (NameCase == EnumNameCase.Lower) names[i] = names[i].ToUpper(); if (NameCase == EnumNameCase.Upper) names[i] = names[i].ToUpper(); if (NameCase == EnumNameCase.Camel) names[i] = names[i].Substring(0, 1).ToLower() + names[i].Substring(1, names[i].Length - 1); if (NameCase == EnumNameCase.Pascal) names[i] = names[i].Substring(0, 1).ToUpper() + names[i].Substring(1, names[i].Length - 1).ToLower(); } EntityName = string.Join("", names); } var fv = file.Variables; IRepositoryName = fv.IRepositoryName.Replace("[EntityName]", EntityName); RepositoryName = fv.RepositoryName.Replace("[EntityName]", EntityName); IBusinessName = fv.IBusinessName.Replace("[EntityName]", EntityName); BusinessName = fv.BusinessName.Replace("[EntityName]", EntityName); ConfigurationName = fv.ConfigurationName.Replace("[EntityName]", EntityName); ConnectionString = fv.ConnectionString; ContextName = fv.ContextName; }