public FileImportUploadFileService(UserConnection userConnection, FileUploader fileUploader, IFileUploadInfo fileUploadInfo) : base(userConnection) { _fileUploader = fileUploader; _fileUploadInfo = fileUploadInfo; }
/// <summary> /// Sets custom columns to <paramref name="entity"/> according to <paramref name="fileUploadInfo"/>. /// </summary> /// <param name="entity">File entity.</param> /// <param name="fileUploadInfo">File upload information.</param> protected virtual void SetCustomColumns(Entity entity, IFileUploadInfo fileUploadInfo) { entity.SetColumnValue("Id", fileUploadInfo.FileId); entity.SetColumnValue("Name", fileUploadInfo.FileName); entity.SetColumnValue("TypeId", fileUploadInfo.TypeId); entity.SetColumnValue("Version", fileUploadInfo.Version); }
/// <summary> /// Uploads file. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <param name="isSetCustomColumns">Is set custom columns.</param> /// <returns>Is operation successful.</returns> public virtual bool UploadFile(IFileUploadInfo fileUploadInfo, bool isSetCustomColumns) { UploadFile(new FileUploadConfig(fileUploadInfo) { SetCustomColumnsFromConfig = isSetCustomColumns }); return(true); }
/// <summary> /// Sets custom columns to <paramref name="entity"/> according to <paramref name="fileUploadInfo"/>. /// </summary> /// <param name="entity">File entity.</param> /// <param name="fileUploadInfo">File upload information.</param> protected override void SetCustomColumns(Entity entity, IFileUploadInfo fileUploadInfo) { base.SetCustomColumns(entity, fileUploadInfo); if (fileUploadInfo is CaseFileEntityUploadInfo caseFileInfo) { entity.SetColumnValue("IsNeedToNotify", caseFileInfo.IsNeedToNotify); } }
/// <summary> /// Saves file content into database. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <param name="isSetCustomColumns">Is set custom culumns.</param> protected void Save(IFileUploadInfo fileUploadInfo, bool isSetCustomColumns = true) { Entity entity = GetFileEntity(fileUploadInfo); if (isSetCustomColumns) { SetCustomColumns(entity, fileUploadInfo); } entity.Save(); }
/// <summary> /// Make copy from source <see cref="IFileUploadInfo"/>. /// </summary> /// <param name="source">Source file upload information.</param> /// <param name="parentColumnValue">Parent column value uniqueidentifier.</param> /// <param name="content">File content <see cref="FileUploadInfo.Content"/>.</param> /// <returns>File info for CaseFile <see cref="CaseFileEntityUploadInfo"/>.</returns> public static CaseFileEntityUploadInfo CopyFromFileUploadInfo(IFileUploadInfo source, Guid parentColumnValue, Stream content) { var fileEntityInfo = new CaseFileEntityUploadInfo(TargetFileSchemaName, Guid.NewGuid(), source.FileName) { ParentColumnName = TargetSchema, ParentColumnValue = parentColumnValue, TotalFileLength = source.TotalFileLength, Content = content }; return(fileEntityInfo); }
/// <summary> /// Uploads file. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <param name="isSetCustomColumns">Is set custom culumns.</param> /// <returns>Is operation successful.</returns> public virtual bool UploadFile(IFileUploadInfo fileUploadInfo, bool isSetCustomColumns) { if (CheckMaxFileSize(fileUploadInfo.TotalFileLength)) { throw new MaxFileSizeExceededException(UserConnection.Workspace.ResourceStorage); } if (!fileUploadInfo.IsChunkedUpload || fileUploadInfo.IsFirstChunk) { Save(fileUploadInfo, isSetCustomColumns); } else { AppendData(fileUploadInfo); } return(true); }
/// <summary> /// Returns file entity. /// </summary> /// <param name="fileUploadInfo">File upload info.</param> /// <returns>File entity.</returns> private Entity GetFileEntity(IFileUploadInfo fileUploadInfo) { EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(fileUploadInfo.EntitySchemaName); Entity entity = entitySchema.CreateEntity(UserConnection); entity.UseAdminRights = false; if (!entity.FetchFromDB(fileUploadInfo.FileId)) { entity.SetDefColumnValues(); EntitySchemaColumn column = entitySchema.Columns.FindByName(fileUploadInfo.ParentColumnName); entity.SetColumnValue(column.ColumnValueName, fileUploadInfo.ParentColumnValue); } entity.SetStreamValue(fileUploadInfo.ColumnName, fileUploadInfo.Content); entity.SetColumnValue("Size", fileUploadInfo.TotalFileLength); return(entity); }
/// <summary> /// Saves file content into database. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <param name="isSetCustomColumns">Is set custom columns.</param> protected void Save(IFileUploadInfo fileUploadInfo, bool isSetCustomColumns = true) { Entity entity = GetFileEntity(fileUploadInfo); if (isSetCustomColumns) { SetCustomColumns(entity, fileUploadInfo); } Dictionary <string, object> additionalParams = fileUploadInfo.AdditionalParams; if (!additionalParams.IsNullOrEmpty() && additionalParams.Keys.Count > 0) { SetAdditionalColumns(entity, additionalParams); } entity.Save(); }
public string Upload(Stream fileContent) { IFileUploadInfo fileUploadInfo = ClassFactory.Get <FileUploadInfo>( new ConstructorArgument("fileContent", fileContent), #if NETSTANDARD2_0 // TODO CRM-46497 new ConstructorArgument("request", HttpContext.Current.Request), #else new ConstructorArgument("request", new System.Web.HttpRequestWrapper(System.Web.HttpContext.Current.Request)), #endif new ConstructorArgument("storage", UserConnection.Workspace.ResourceStorage)); if (FileRepository.UploadFile(fileUploadInfo)) { return("Ok"); } return(string.Empty); }
public ConfigurationServiceResponse SaveFile(Stream fileContent) { IFileUploadInfo fileUploadInfo = GetFileUploadInfo(fileContent); decimal maxFileSize = GetMaxFileSizeFromSysSettings(); var uploadSettings = new FileUploadConfig(fileUploadInfo) { SetCustomColumnsFromConfig = false, MaxFileSize = maxFileSize }; var response = new ConfigurationServiceResponse(); try { FileUploader.UploadFile(uploadSettings); } catch (MaxFileSizeExceededException ex) { response.Exception = ex; response.Success = false; } return(response); }
public void GetFile(string entitySchemaUId, string fileId) { using (var memoryStream = new MemoryStream()) { SetOutgoingResponseContentType(); IFileUploadInfo fileInfo = FileRepository.LoadFile(new Guid(entitySchemaUId), new Guid(fileId), new BinaryWriter(memoryStream)); if (fileInfo == null) { return; } SetOutgoingResponseContentLength(Convert.ToInt32(fileInfo.TotalFileLength)); string contentDisposition = GetResponseContentDisposition(fileInfo.FileName); CurrentContext.Response.AddHeader("Content-Disposition", contentDisposition); MimeTypeResult mimeTypeResult = MimeTypeDetector.GetMimeType(fileInfo.FileName); CurrentContext.Response.ContentType = mimeTypeResult.HasError ? "application/octet-stream" : mimeTypeResult.Type; memoryStream.Flush(); memoryStream.WriteTo(CurrentContext.Response.OutputStream); } }
public BaseResponse UploadReportTemplate(Stream fileContent) { HttpContext httpContext = HttpContextAccessor.GetInstance(); string reportId = httpContext.Request.QueryString["reportId"]; Guid report = new Guid(reportId); IFileUploadInfo fileUploadInfo = GetFileUploadInfo(fileContent); decimal maxFileSize = GetMaxFileSizeFromSysSettings(); var uploadSettings = new FileUploadConfig(fileUploadInfo) { SetCustomColumnsFromConfig = false, MaxFileSize = maxFileSize }; try { FileUploader.UploadFile(uploadSettings); if (IsLastChunk(uploadSettings.ByteRange)) { Stream template = ReportWorker.ValidateTemplate(uploadSettings.FileId); ReportWorker.SaveTemplate(template, report); SetResponseHttpStatus(HttpStatusCode.Created); } } catch (ArgumentException ex) { SetResponseHttpStatus(HttpStatusCode.InternalServerError); return(GetResponse(false, (int)HttpStatusCode.NotAcceptable)); } catch (ItemNotFoundException ex) { SetResponseHttpStatus(HttpStatusCode.InternalServerError); return(GetResponse(false, (int)HttpStatusCode.NotFound)); } catch (MaxFileSizeExceededException ex) { SetResponseHttpStatus(HttpStatusCode.LengthRequired); return(GetResponse(false, (int)HttpStatusCode.LengthRequired, ConvertBytesToMb(uploadSettings.MaxFileSize))); } catch (Exception ex) { SetResponseHttpStatus(HttpStatusCode.InternalServerError); return(GetResponse(false, (int)HttpStatusCode.MethodNotAllowed)); } return(GetResponse(true, null)); }
/// <summary> /// Uploads file. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <param name="isSetCustomColumns">Is set custom culumns.</param> /// <returns>Is operation successful.</returns> public virtual bool UploadFile(IFileUploadInfo fileUploadInfo, bool isSetCustomColumns) { var uploader = ClassFactory.Get <FileUploader>(new ConstructorArgument("userConnection", UserConnection)); return(uploader.UploadFile(fileUploadInfo, isSetCustomColumns)); }
/// <summary> /// Appends file content into database. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> private void AppendData(IFileUploadInfo fileUploadInfo) { DBLobUtilities.AppendBlob(UserConnection, fileUploadInfo.EntitySchemaName, fileUploadInfo.ColumnName, fileUploadInfo.FileId, fileUploadInfo.Content); }
/// <summary> /// Uploads file. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <returns>Is operation successful.</returns> public virtual bool UploadFile(IFileUploadInfo fileUploadInfo) { return(UploadFile(fileUploadInfo, true)); }
public virtual string Upload(IFileUploadInfo fileUploadInfo) { UploadFile(fileUploadInfo); return("Ok"); }
public WordReportingDesignService(UserConnection userConnection, IFileUploadInfo fileUploadInfo) : base(userConnection) { }
/// <summary> /// Uploads file. /// </summary> /// <param name="fileUploadInfo">File upload information.</param> /// <param name="isSetCustomColumns">Is set custom columns.</param> /// <returns>Is operation successful.</returns> public override bool UploadFile(IFileUploadInfo fileUploadInfo, bool isSetCustomColumns) { var uploader = new CaseFileUploader(UserConnection); return(uploader.UploadFile(fileUploadInfo, isSetCustomColumns)); }
/// <summary> /// Creates instance of type <see cref="FileUploadConfig"/>. /// </summary> /// <param name="fileUploadInfo"><see cref="IFileUploadInfo"/></param> public FileUploadConfig(IFileUploadInfo fileUploadInfo) { fileUploadInfo.CheckArgumentNull(nameof(fileUploadInfo)); _fileUploadInfo = fileUploadInfo; }