public UploadAsyncResponse Post(UploadImageAsyncRequest request) { UploadAsyncResponse res = new UploadAsyncResponse(); Log.Info("Inside ImageAsyncUpload"); IUploadImageRequest req = null; if (request.ImageInfo.FileCategory == EbFileCategory.Dp) { req = new UploadDpRequest(); } else if (request.ImageInfo.FileCategory == EbFileCategory.Images) { req = new UploadImageRequest(); } else if (request.ImageInfo.FileCategory == EbFileCategory.SolLogo) { req = new UploadLogoRequest(); } else if (request.ImageInfo.FileCategory == EbFileCategory.LocationFile) { req = new UploadLocRequest(); } try { string context = string.IsNullOrEmpty(request.ImageInfo.Context) ? StaticFileConstants.CONTEXT_DEFAULT : request.ImageInfo.Context; req.Byte = request.ImageByte; req.FileCategory = request.ImageInfo.FileCategory; req.SolutionId = request.SolutionId; req.SolnId = request.SolnId; req.UserId = (req is UploadDpRequest) ? request.UserIntId : request.UserId; req.UserAuthId = request.UserAuthId; req.BToken = (!String.IsNullOrEmpty(this.Request.Authorization)) ? this.Request.Authorization.Replace("Bearer", string.Empty).Trim() : String.Empty; req.RToken = (!String.IsNullOrEmpty(this.Request.Headers["rToken"])) ? this.Request.Headers["rToken"] : String.Empty; req.SubscriptionId = (!String.IsNullOrEmpty(this.Request.Headers[TokenConstants.SSE_SUBSCRIP_ID])) ? this.Request.Headers[TokenConstants.SSE_SUBSCRIP_ID] : String.Empty; req.ImageRefId = GetFileRefId(request.UserId, request.ImageInfo.FileName, request.ImageInfo.FileType, request.ImageInfo.MetaDataDictionary.ToJson(), request.ImageInfo.FileCategory, request.ImageInfo.Context); this.MessageProducer3.Publish(req); res.FileRefId = req.ImageRefId; } catch (Exception e) { Log.Info("Exception:" + e.ToString()); res.FileRefId = 0; res.ResponseStatus.Message = e.Message; } return(res); }
public EbMqResponse Post(UploadDpRequest request) { this.ServerEventClient.BearerToken = request.BToken; this.ServerEventClient.RefreshToken = request.RToken; this.ServerEventClient.RefreshTokenUri = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_GET_ACCESS_TOKEN_URL); try { this.EbConnectionFactory = new EbConnectionFactory(request.SolnId, this.Redis); string filestore_sid = this.EbConnectionFactory.FilesDB.UploadFile(request.ImageRefId.ToString(), request.Byte, request.FileCategory, request.InfraConID); DbParameter[] parameters = { this.EbConnectionFactory.DataDB.GetNewParameter("refid", EbDbTypes.Int32, request.ImageRefId), this.EbConnectionFactory.DataDB.GetNewParameter("filestoreid", EbDbTypes.String, filestore_sid), this.EbConnectionFactory.DataDB.GetNewParameter("length", EbDbTypes.Int64, request.Byte.Length), this.EbConnectionFactory.DataDB.GetNewParameter("imagequality_id", EbDbTypes.Int32, ImageQuality.original), this.EbConnectionFactory.DataDB.GetNewParameter("filedb_con_id", EbDbTypes.Int32, this.EbConnectionFactory.FilesDB.UsedConId), this.EbConnectionFactory.DataDB.GetNewParameter("imgmanpserid", EbDbTypes.Int32, 0), this.EbConnectionFactory.DataDB.GetNewParameter("is_image", EbDbTypes.Boolean, true), this.EbConnectionFactory.DataDB.GetNewParameter("userid", EbDbTypes.Int32, request.UserId) }; var iCount = this.EbConnectionFactory.DataDB.DoQuery(this.EbConnectionFactory.DataDB.EB_DPUPDATESQL, parameters); if (iCount.Rows.Capacity > 0) { this.ServerEventClient.Post <NotifyResponse>(new NotifyUserIdRequest { Msg = request.ImageRefId, Selector = StaticFileConstants.UPLOADSUCCESS, ToUserAuthId = request.UserAuthId, }); } if (this.EbConnectionFactory.ImageManipulate != null) { string Clodinaryurl = this.EbConnectionFactory.ImageManipulate[0].GetImgSize (request.Byte, request.ImageRefId.ToString(), ImageQuality.small); if (!string.IsNullOrEmpty(Clodinaryurl)) { using (var client = new HttpClient()) { var response = client.GetAsync(Clodinaryurl).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; request.ImgManpSerConId = this.EbConnectionFactory.ImageManipulate[0].InfraConId; byte[] smallByte = responseContent.ReadAsByteArrayAsync().Result; string fStoreIdSmall = this.EbConnectionFactory.FilesDB.UploadFile(request.ImageRefId.ToString(), smallByte, request.FileCategory, request.InfraConID); DbParameter[] smallImgParams = { this.EbConnectionFactory.DataDB.GetNewParameter("refid", EbDbTypes.Int32, request.ImageRefId), this.EbConnectionFactory.DataDB.GetNewParameter("filestoreid", EbDbTypes.String, fStoreIdSmall), this.EbConnectionFactory.DataDB.GetNewParameter("length", EbDbTypes.Int64, request.Byte.Length), this.EbConnectionFactory.DataDB.GetNewParameter("imagequality_id", EbDbTypes.Int32, ImageQuality.small), this.EbConnectionFactory.DataDB.GetNewParameter("filedb_con_id", EbDbTypes.Int32, this.EbConnectionFactory.FilesDB.UsedConId), this.EbConnectionFactory.DataDB.GetNewParameter("imgmanpserid", EbDbTypes.Int32, request.ImgManpSerConId), this.EbConnectionFactory.DataDB.GetNewParameter("is_image", EbDbTypes.Boolean, true), this.EbConnectionFactory.DataDB.GetNewParameter("userid", EbDbTypes.Int32, request.UserId) }; var iSmallCount = this.EbConnectionFactory.DataDB.DoQuery(EbConnectionFactory.DataDB.EB_DPUPDATESQL, smallImgParams); } } } } } catch (Exception e) { if (request.ImgQuality == ImageQuality.original) { this.ServerEventClient.Post <NotifyResponse>(new NotifyUserIdRequest { Msg = request.ImageRefId, Selector = StaticFileConstants.UPLOADFAILURE, ToUserAuthId = request.UserAuthId, }); } Log.Error("UploadImage:" + e.ToString()); MqResponse.IsError = true; MqResponse.ErrorString = e.ToString(); } return(MqResponse); }