private void SendGroupInviteNotification(NotificationModel notificationModel) { ulong tempNumber; if (NeeoUtility.IsNullOrEmpty(notificationModel.DToken) || notificationModel.Dp == null || notificationModel.IMTone == null || NeeoUtility.IsNullOrEmpty(notificationModel.Alert) || NeeoUtility.IsNullOrEmpty(notificationModel.RName) || NeeoUtility.IsNullOrEmpty(notificationModel.ReceiverID) || !ulong.TryParse(notificationModel.ReceiverID, out tempNumber)) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } var receiver = new NeeoUser(notificationModel.ReceiverID) { DeviceToken = notificationModel.DToken.Trim(), ImTone = notificationModel.IMTone.GetValueOrDefault(), OfflineMsgCount = notificationModel.Badge, DevicePlatform = notificationModel.Dp.GetValueOrDefault(), PnSource = notificationModel.PnSource.HasValue ? notificationModel.PnSource.Value : PushNotificationSource.Default }; if (receiver.DevicePlatform == DevicePlatform.iOS) { _services.ApnsService.Send(new List <NeeoUser>() { receiver }, notificationModel); } else if (receiver.DevicePlatform == DevicePlatform.Android) { _services.GcmService.Send(new List <NeeoUser>() { receiver }, notificationModel); } }
private void SendGroupImNotification(NotificationModel notificationModel) { if (NeeoUtility.IsNullOrEmpty(notificationModel.SenderID) || notificationModel.RID == 0 || NeeoUtility.IsNullOrEmpty(notificationModel.RName) || NeeoUtility.IsNullOrEmpty(notificationModel.Alert) || notificationModel.MessageType == null) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } List <NeeoUser> lstgroupParticipant = NeeoGroup.GetGroupParticipants(notificationModel.RID, notificationModel.SenderID, (int)notificationModel.MessageType); if (lstgroupParticipant.Count == 0) { return; } var taskUpdateOfflineCount = Task.Factory.StartNew(() => { const string delimeter = ","; LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Group participants - " + JsonConvert.SerializeObject(lstgroupParticipant), System.Reflection.MethodBase.GetCurrentMethod().Name); IEnumerable <string> userList = from item in lstgroupParticipant where item.PresenceStatus == Presence.Offline select item.UserID; string userString = string.Join(delimeter, userList); //lstgroupParticipant.Where(i => i.PresenceStatus == Presence.Offline).Select(a => a.UserID) // .Aggregate((current, next) => current + delimeter + next); LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "User list - " + userString, System.Reflection.MethodBase.GetCurrentMethod().Name); if (NeeoUtility.IsNullOrEmpty(userString)) { return; } var dbManager = new DbManager(); dbManager.UpdateUserOfflineCount(userString, delimeter); }); var taskSendiOSNotification = Task.Factory.StartNew(() => { var iosUserList = lstgroupParticipant.Where( x => x.DevicePlatform == DevicePlatform.iOS && x.PresenceStatus == Presence.Offline).ToList(); _services.ApnsService.Send(iosUserList, notificationModel); }); var taskSendAndroidNotification = Task.Factory.StartNew(() => { var androidUserList = lstgroupParticipant.Where( x => x.DevicePlatform == DevicePlatform.Android && x.PresenceStatus == Presence.Offline).ToList(); _services.GcmService.Send(androidUserList, notificationModel); }); Task.WaitAll(taskUpdateOfflineCount, taskSendiOSNotification, taskSendAndroidNotification); }
/*They will be deprecated in future.*/ /// <summary> /// Lookup the user's contacts on the server for existance. /// </summary> /// <param name="userID">A string containing the user id.</param> /// <param name="contacts">A array of type 'Contact' containing the contacts.</param> /// <returns>A list containing user's contacts those are application users.</returns> public List <ContactDetails> SyncUpContacts(string userID, Contact[] contacts) { #region log user request and response /*********************************************** * To log user request ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Request ===> User ID : " + userID + "- Contact List :" + JsonConvert.SerializeObject(contacts)); } #endregion if (!NeeoUtility.IsNullOrEmpty(userID) && contacts != null) { if (contacts.Length > 0) { NeeoUser user = new NeeoUser(userID); try { var response = user.GetContactsRosterState(contacts, false, true); #region log user request and response /*********************************************** * To log user response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Response==> User ID : " + userID + "- Contact List :" + JsonConvert.SerializeObject(response)); } #endregion return(response); } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); } catch (Exception exp) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError); } } else { return(new List <ContactDetails>()); } } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } return(null); }
/// <summary> /// Gets the user's name base on the User ID. /// </summary> /// <param name="uID">A string containing the user id.</param> /// <returns>It returns the profile name.</returns> public string GetProfileName(string uID) { uID = (uID != null) ? uID.Trim() : uID; string result = null; #region log user request and response /*********************************************** * To log user request and response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Request ===> userID : " + uID); } #endregion // #region Verify User //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; //string keyFromClient = request.Headers["key"]; //if (NeeoUtility.AuthenticateUserRequest(uID, keyFromClient)) //{ // #endregion ulong temp = 0; uID = uID.Trim(); try { if (NeeoUtility.IsNullOrEmpty(uID) || !ulong.TryParse(uID, out temp)) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.BadRequest); } else { NeeoUser user = new NeeoUser(uID); result = user.GetUserProfileName(); } } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); } catch (Exception exp) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError); } return(result); //} //else //{ // NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized); // return result; //} }
/// <summary> /// Seting custome status code in service response header /// </summary> /// <param name="code">An enumeration representing custome status code.</param> //protected void SetServiceResponseHeaders(CustomHttpStatusCode code) //{ // OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse; // response.StatusCode = (System.Net.HttpStatusCode)code; // if (NeeoDictionaries.HttpStatusCodeDescriptionDictionary.ContainsKey((int)code)) // response.StatusDescription = NeeoDictionaries.HttpStatusCodeDescriptionDictionary[(int)code]; //} #endregion #region User Verification /// <summary> /// Verify user account information based on user's information hash. /// </summary> /// <param name="uID">string containing the user id.</param> /// <param name="hash">string containing the user's information hash.</param> /// <returns>Returns true if hash codes are same else returns false.</returns> public bool VerifyUser(string uID, string hash) { uID = (uID != null) ? uID.Trim() : uID; #region log user request and response /*********************************************** * To log user request and response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, " ===> " + "Request ===> userID : " + uID + ", hash : " + hash, System.Reflection.MethodBase.GetCurrentMethod().Name); } #endregion // #region Verify User //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; //string keyFromClient = request.Headers["key"]; //if (NeeoUtility.AuthenticateUserRequest(uID, keyFromClient)) //{ // #endregion try { if (!(NeeoUtility.IsNullOrEmpty(uID) && NeeoUtility.IsNullOrEmpty(hash))) { NeeoUser user = new NeeoUser(uID.Trim()); return(user.VerifyUser(hash)); } return(false); } catch (ApplicationException appExp) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, " ===> " + "Request ===> userID : " + uID + ", hash : " + hash + " ===> " + appExp.Message, System.Reflection.MethodBase.GetCurrentMethod().Name); if (appExp.Message == CustomHttpStatusCode.InvalidUser.ToString("D")) { return(false); } NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); return(false); } catch (Exception exp) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, " ===> " + "Request ===> userID : " + uID + ", hash : " + hash + " ===> " + exp.Message, exp, System.Reflection.MethodBase.GetCurrentMethod().Name); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError); return(false); } // } //else //{ // NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized); // return false; //} }
public bool Valid() { if (NeeoUtility.IsNullOrEmpty(UserID) || NeeoUtility.IsNullOrEmpty(AppID) || NeeoUtility.IsNullOrEmpty(SpamUserID) || UserID == SpamUserID) { return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="pushEnabled"></param> public static void UpdateUserAccount(string username, string password, PushEnabled pushEnabled, UserStatus userStatus) { RequestMode requestMode = RequestMode.Set; if (_voipServerUrl == null) { _voipServerUrl = ConfigurationManager.AppSettings[NeeoConstants.VoipServerUrl]; } RestRequest request = new RestRequest(); request.AddQueryParameter("mode", requestMode.ToString("G").ToLower()); request.AddQueryParameter("mob", username); if (password != null) { request.AddQueryParameter("pass", password); } if (pushEnabled != Voip.PushEnabled.NotSpecified) { request.AddQueryParameter("pushEnabled", pushEnabled.ToString("D")); } if (userStatus != Voip.UserStatus.NotSpecified) { request.AddQueryParameter("status", userStatus.ToString("D")); } try { ExecuteRequest(request, requestMode); } catch (ApplicationException firstAppException) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, firstAppException.Message); try { if (!NeeoUtility.IsNullOrEmpty(password)) { ExecuteBackupPolicy(firstAppException.Message, request, requestMode); } else { throw new ApplicationException(CustomHttpStatusCode.ServerInternalError.ToString("D")); } } catch (ApplicationException secondAppException) { throw new Exception(secondAppException.Message); } } }
public HttpResponseMessage ResetCount([FromBody] ResetCountRequest request) { if (ModelState.IsValid) { ulong temp = 0; if (!NeeoUtility.IsNullOrEmpty(request.uID) && ulong.TryParse(request.uID, out temp)) { request.uID = request.uID.Trim(); try { if (NeeoUser.ResetOfflineMessageCount(request.uID)) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return (Request.CreateResponse( (HttpStatusCode)Convert.ToInt32(CustomHttpStatusCode.UnknownError.ToString("D")))); } } catch (ApplicationException appExp) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "user id = " + request.uID + ", error:" + appExp.Message, System.Reflection.MethodBase.GetCurrentMethod().Name); return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt32(appExp.Message), "")); } catch (Exception exp) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "user id = " + request.uID + ", error:" + exp.Message, exp, System.Reflection.MethodBase.GetCurrentMethod().Name); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "")); } } else { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "user id = " + request.uID , System.Reflection.MethodBase.GetCurrentMethod().Name); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "")); } } else { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "user id = " + request.uID , System.Reflection.MethodBase.GetCurrentMethod().Name); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "")); } }
/// <summary> /// /// </summary> /// <param name="uID"></param> /// <param name="gID"></param> public void DeleteGroupIcon(string uID, string gID) { #region log user request and response /*********************************************** * To log user request ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Request ===> senderID : " + uID + ", groupID : " + gID); } #endregion //#region Verify User //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; //string keyFromClient = request.Headers["key"]; //if (NeeoUtility.AuthenticateUserRequest(uID, keyFromClient)) //{ // #endregion ulong temp = 0; if (NeeoUtility.IsNullOrEmpty(uID) || !ulong.TryParse(uID, out temp) || NeeoUtility.IsNullOrEmpty(gID)) { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } else { uID = uID.Trim(); gID = gID.ToLower(); try { NeeoGroup.DeleteGroupIcon(groupID: gID, userID: uID); } catch (Exception exception) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name, exception); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError); } } //} //else //{ // NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode) HttpStatusCode.Unauthorized); //} }
/// <summary> /// /// </summary> /// <param name="uID"></param> /// <param name="fileID"></param> public void Acknowledgement(string uID, string fileID) { ulong temp = 0; uID = (uID != null) ? uID.Trim() : uID; fileID = (fileID != null) ? fileID.Trim() : fileID; #region log user request and response /*********************************************** * To log user request ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Request ===> senderID : " + uID + ", fileID : " + fileID); } #endregion //#region Verify User // var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; // string keyFromClient = request.Headers["key"]; // if (NeeoUtility.AuthenticateUserRequest(uID, keyFromClient)) // { // #endregion if (NeeoUtility.IsNullOrEmpty(uID) && !ulong.TryParse(uID, out temp) && NeeoUtility.IsNullOrEmpty(fileID)) { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } else { NeeoUser user = new NeeoUser(uID); try { if (!SharedMedia.UpdateDownloadCount(user, fileID)) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotFound); } } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); } } //} //else //{ // NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized); //} }
/// <summary> /// Generates link for the file with required parameters. /// </summary> /// <param name="userID">A string containing the user id.</param> /// <param name="fileName">A string containing the file name.</param> /// <param name="fileClassfication">An enum that is specifying the file classification.</param> /// <param name="requiredDimension">An unsigned integer specifying the required dimensions.</param> /// <param name="senderID">A string containing sender user id. Required only getting url of offline file.</param> /// <remarks>Dimensions should be greater than 0 and less than the actual dimension of the file. If dimension is 0 or greater than the actual dimension of the image, image with actual dimensions will be returned.</remarks> /// <returns>A string containing the url for getting the file.</returns> public static string BuildFileUrl(string fileServer, string fileName, FileCategory fileClassfication, MediaType mediaType) { string fileStorePort = ConfigurationManager.AppSettings[NeeoConstants.FileStorePort]; string imageHandler = ConfigurationManager.AppSettings[NeeoConstants.ImageHandler]; string webProtocol = ConfigurationManager.AppSettings[NeeoConstants.WebProtocol]; string idQString = "?id=" + fileName; string fileClassificationQString = "&fc=" + fileClassfication.ToString("D"); string mediaTypeQString = "&mt=" + mediaType.ToString("D"); string signatureQString = "&sig=" + NeeoUtility.GenerateSignature(fileName + fileClassfication.ToString("D") + mediaType.ToString("D")); string url = webProtocol + "://" + fileServer + (NeeoUtility.IsNullOrEmpty(fileStorePort) == false ? (":" + fileStorePort + "/") : "/") + imageHandler + idQString + fileClassificationQString + mediaTypeQString + signatureQString; return(url); }
/// <summary> /// Checks the file transfer support on receiver side. /// </summary> /// <param name="sUID">A string containing the sender user id.</param> /// <param name="rUID">A string containing the receiver user id.</param> public void CheckSupport(string sUID, string rUID) { #region log user request and response /*********************************************** * To log user request ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "CheckSupport -- Request ===> senderID : " + sUID + ", receiverID : " + rUID); } #endregion ulong temp = 0; sUID = (sUID != null) ? sUID.Trim() : sUID; rUID = (rUID != null) ? rUID.Trim() : rUID; // #region Verify User //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; //string keyFromClient = request.Headers["key"]; //if (NeeoUtility.AuthenticateUserRequest(sUID, keyFromClient)) //{ // #endregion if (NeeoUtility.IsNullOrEmpty(sUID) && !ulong.TryParse(sUID, out temp) && NeeoUtility.IsNullOrEmpty(rUID) && !ulong.TryParse(rUID, out temp)) { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } else { try { NeeoUser senderUser = new NeeoUser(sUID); if (!senderUser.IsFileTransferSupported(rUID)) { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.FileTransferNotSupported); } } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); } } //} //else //{ // NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized); //} }
/// <summary> /// Processes the http request to send the required response. /// </summary> /// <remarks>It is used to send image data to the requester if the request </remarks> /// <param name="context">An object holding http context object for setting up response header on sending response.</param> public void ProcessRequest(HttpContext context) { _httpContext = context; LibNeeo.IO.File file = null; ulong timeStamp = 0; short fileClass = 0; if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["id"]) && !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["sig"]) && !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["fc"]) && !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["mt"])) { string fileID = HttpUtility.UrlEncode(context.Request.QueryString["id"].ToString()); FileCategory fileCategory = (FileCategory)Convert.ToInt16(context.Request.QueryString["fc"]); MediaType mediaType = (MediaType)Convert.ToInt16(context.Request.QueryString["mt"]); if (NeeoUtility.GenerateSignature(fileID + fileCategory.ToString("D") + mediaType.ToString("D")) == context.Request.QueryString["sig"].ToString()) { file = GetRequestedFile(fileID, fileCategory, mediaType); if (file != null) { SetResponseWithFileData(file); } else { Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "File ID: " + fileID + ", File Category: Shared, Status: File does not exists."); } } } else if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["id"]) && !NeeoUtility.IsNullOrEmpty(context.Request.QueryString["sig"])) { // This part is to give backward compatibility for shared file service given with release 3 string fileID = HttpUtility.UrlEncode(context.Request.QueryString["id"].ToString()); if (NeeoUtility.GenerateSignature(fileID) == context.Request.QueryString["sig"].ToString()) { file = GetRequestedFile(fileID, FileCategory.Shared, MediaType.Image); if (file != null) { SetResponseWithFileData(file); } else { Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "File ID: " + fileID + ", File Category: Group, Status: File does not exists."); } } } SetResponseHeaders((int)HttpStatusCode.BadRequest); }
/// <summary> /// Delete the user's profile picture from the server. /// </summary> /// <param name="userID">A string containing phone number as user id.</param> /// <returns>true if the profile picture is successfully deleted from the server; otherwise, false.</returns> public bool DeleteAvatar(string userID) { #region log user request and response /*********************************************** * To log user request and response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Request ===> userID : " + userID); } #endregion if (!NeeoUtility.IsNullOrEmpty(userID)) { try { NeeoUser user = new NeeoUser(userID); if (user.DeleteUserAvatar(NeeoUtility.ConvertToFileName(userID))) { return(true); } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.FileSystemException); return(false); } } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); } catch (Exception exp) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError); } return(false); } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); return(false); } }
private void SendCallNotification(NotificationModel notificationModel) { ulong tempNumber; if (NeeoUtility.IsNullOrEmpty(notificationModel.CallerID) || !ulong.TryParse(notificationModel.CallerID, out tempNumber) || NeeoUtility.IsNullOrEmpty(notificationModel.ReceiverID) || !ulong.TryParse(notificationModel.ReceiverID, out tempNumber)) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } // Get the name of the user from data base. var dbManager = new DbManager(); var userInfo = dbManager.GetUserInforForNotification(notificationModel.ReceiverID, notificationModel.CallerID, false); if (NeeoUtility.IsNullOrEmpty(userInfo[NeeoConstants.ReceiverDeviceToken]) || NeeoUtility.IsNullOrEmpty(userInfo[NeeoConstants.CallerName])) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } notificationModel.Alert = NotificationAppConfiguration.IncomingCallText.Replace("[" + NeeoConstants.CallerName + "]", userInfo[NeeoConstants.CallerName]); var receiver = new NeeoUser(notificationModel.ReceiverID) { CallingTone = (CallingTone)Convert.ToInt16(userInfo[NeeoConstants.ReceiverCallingTone]), DevicePlatform = (DevicePlatform)Convert.ToInt16(userInfo[NeeoConstants.ReceiverUserDeviceplatform]), DeviceToken = userInfo[NeeoConstants.ReceiverDeviceToken].Trim(), PnSource = (PushNotificationSource)Convert.ToInt32(userInfo[NeeoConstants.PushNotificationSource]) }; if (receiver.DevicePlatform == DevicePlatform.iOS) { _services.ApnsService.Send(new List <NeeoUser>() { receiver }, notificationModel); } else if (receiver.DevicePlatform == DevicePlatform.Android) { _services.GcmService.Send(new List <NeeoUser>() { receiver }, notificationModel); } }
/// <summary> /// Generates link for the file with required parameters. /// </summary> /// <param name="userID">A string containing the user id.</param> /// <param name="avatarTimeStamp">An unsigned long integer containing the avatar time stamp.</param> /// <param name="requiredDimension">An unsigned integer specifying the required dimensions.</param> /// <remarks>Dimensions should be greater than 0 and less than the actual dimension of the file. If dimension is 0 or greater than the actual dimension of the image, image with actual dimensions will be returned.</remarks> /// <returns>A string containing the url for getting user avatar.</returns> public static string BuildAvatarUrl(string userID, ulong avatarTimeStamp, uint requiredDimension) { string fileServerUrl = ConfigurationManager.AppSettings[NeeoConstants.FileServerUrl]; string fileStorePort = ConfigurationManager.AppSettings[NeeoConstants.FileStorePort]; string avatarHandler = ConfigurationManager.AppSettings[NeeoConstants.AvatarHandler]; string webProtocol = ConfigurationManager.AppSettings[NeeoConstants.WebProtocol]; string uIDQString = "?uid=" + userID; string imgTimeStampQString = "&ts=" + avatarTimeStamp; string imgRequiredDimensionQString = "&dim=" + requiredDimension; string url = webProtocol + "://" + fileServerUrl + (NeeoUtility.IsNullOrEmpty(fileStorePort) == false ? (":" + fileStorePort + "/") : "/") + avatarHandler + uIDQString + imgTimeStampQString; if (requiredDimension > 0) { url = url + imgRequiredDimensionQString; } return(url); }
private void SendMcrNotification(NotificationModel notificationModel) { ulong tempNumber; if (NeeoUtility.IsNullOrEmpty(notificationModel.CallerID) || !ulong.TryParse(notificationModel.CallerID, out tempNumber) || NeeoUtility.IsNullOrEmpty(notificationModel.ReceiverID) || !ulong.TryParse(notificationModel.ReceiverID, out tempNumber) || notificationModel.McrCount == 0) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } var dbManager = new DbManager(); var userInfo = dbManager.GetUserInforForNotification(notificationModel.ReceiverID, notificationModel.CallerID, true, notificationModel.McrCount); if (NeeoUtility.IsNullOrEmpty(userInfo[NeeoConstants.ReceiverDeviceToken])) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } notificationModel.Alert = NotificationAppConfiguration.McrText.Replace("[" + NeeoConstants.CallerName + "]", userInfo[NeeoConstants.CallerName]); var receiver = new NeeoUser(notificationModel.ReceiverID) { DevicePlatform = (DevicePlatform)Convert.ToInt16(userInfo[NeeoConstants.ReceiverUserDeviceplatform]), DeviceToken = userInfo[NeeoConstants.ReceiverDeviceToken].Trim(), PnSource = (PushNotificationSource)Convert.ToInt32(userInfo[NeeoConstants.PushNotificationSource]), OfflineMsgCount = Convert.ToInt32(userInfo[NeeoConstants.OfflineMessageCount]) }; if (receiver.DevicePlatform == DevicePlatform.iOS) { _services.ApnsService.Send(new List <NeeoUser>() { receiver }, notificationModel); } else if (receiver.DevicePlatform == DevicePlatform.Android) { _services.GcmService.Send(new List <NeeoUser>() { receiver }, notificationModel); } }
/// <summary> /// /// </summary> /// <param name="uName"></param> /// <param name="contacts"></param> public void SendInvitation(string uName, string contacts, string languageCode) { string invitationText; string[] delimeter = { "," }; invitationText = InvitationMessage.GetLocalizedMessage(languageCode); _invitationSenderKey = _invitationSenderKey ?? ConfigurationManager.AppSettings[NeeoConstants.InvitationSenderKey]; string[] contactsArray = contacts.Split(delimeter, StringSplitOptions.None); ulong temp = 0; DbManager dbManager = new DbManager(); string profileName = dbManager.GetUserProfileName(_userID); string msgBody = invitationText.Replace(_invitationSenderKey, (NeeoUtility.IsNullOrEmpty(uName) ? (NeeoUtility.IsNullOrEmpty(profileName) ? "(" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")" : (profileName + " (" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")")) : (uName + " (" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")"))); for (int i = 0; i < contactsArray.Length; i++) { if (ulong.TryParse(contactsArray[i], out temp)) { try { //SmsManager.SendThroughSecondaryApi(NeeoUtility.FormatAsIntlPhoneNumber(contactsArray[i]),msgBody.Replace("!", Environment.NewLine)); PowerfulPal.Sms.SmsManager.GetInstance().Twilio.SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(contactsArray[i]) }, msgBody.Replace("!", Environment.NewLine), languageCode != "en"); } catch (ApplicationException appEx) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + " ===> uid : " + _userID + " ===> contact : " + contactsArray[i] + " is invalid."); } } else { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + " ===> uid : " + _userID + " ===> contact : " + contactsArray[i] + " is invalid."); } } }
/// <summary> /// Processes the http request to send the required response. /// </summary> /// <remarks>It is used to send image data to the requester if the request </remarks> /// <param name="context">An object holding http context object for setting up response header on sending response.</param> public void ProcessRequest(HttpContext context) { _httpContext = context; NeeoFileInfo fileInfo = null; ulong avatarTimeStamp = 0; ulong avatarUpdatedTimeStamp = 0; uint requiredDimension = 0; if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["uid"])) { string uID = HttpUtility.UrlEncode(context.Request.QueryString["uid"].ToString()); NeeoUser user = new NeeoUser(uID); if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["ts"])) { if (!ulong.TryParse(context.Request.QueryString["ts"], out avatarTimeStamp)) { SetResponseHeaders((int)HttpStatusCode.BadRequest); } } switch (user.GetAvatarState(avatarTimeStamp, out avatarUpdatedTimeStamp, out fileInfo)) { case AvatarState.NotExist: SetResponseHeaders((int)HttpStatusCode.BadRequest); break; case AvatarState.Modified: if (!NeeoUtility.IsNullOrEmpty(context.Request.QueryString["dim"])) { UInt32.TryParse(context.Request.QueryString["dim"], out requiredDimension); } SetResponseWithFileData(fileInfo.FullPath, avatarUpdatedTimeStamp, requiredDimension); break; case AvatarState.NotModified: SetResponseHeaders((int)HttpStatusCode.NotModified); break; } } else { SetResponseHeaders((int)HttpStatusCode.BadRequest); } }
/// <summary> /// Gets the user's avatar base on the previous time stamp of the avatar. /// </summary> /// <param name="userID">A string containing the user id.</param> /// <param name="timeStamp">An integer containing the time stamp that has to be matched with the existing image. It is optional.</param> /// <param name="requiredDimension">An integer specifying the dimension of the image required. It is optional.</param> public void GetUserAvatar(string userID, ulong timeStamp, uint requiredDimension) { #region log user request and response /*********************************************** * To log user request and response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Request ===> userID : " + userID + ", timeStamp : " + timeStamp + ", requiredDimension : " + requiredDimension); } #endregion if (!NeeoUtility.IsNullOrEmpty(userID)) { userID = HttpUtility.UrlEncode(userID); NeeoUser user = new NeeoUser(userID); string filePath = ""; ulong avatarTimeStamp; switch (user.GetAvatarState(timeStamp, out avatarTimeStamp, out filePath)) { case AvatarState.NotExist: NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotFound); break; case AvatarState.Modified: string url = NeeoUtility.GenerateAvatarUrl(userID, timeStamp, requiredDimension); RedirectServiceToUrl(url, avatarTimeStamp); break; case AvatarState.NotModified: NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotModified); break; } } else { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.BadRequest); } }
private void SendUpdateProfilePicNotification(NotificationModel notificationModel) { ulong tempNumber; if (NeeoUtility.IsNullOrEmpty(notificationModel.SenderID) || !ulong.TryParse(notificationModel.SenderID, out tempNumber)) { throw new ApplicationException(CustomHttpStatusCode.InvalidArguments.ToString("D")); } // Get the name of the user from data base. List <NeeoUser> userRoasterList = NeeoUser.GetUserRoster(notificationModel.SenderID); if (userRoasterList.Count == 0) { return; } notificationModel.Alert = "Update"; var taskSendiOSNotification = Task.Factory.StartNew(() => { var iosUserList = userRoasterList.Where( x => x.DevicePlatform == DevicePlatform.iOS && x.PresenceStatus == Presence.Offline).ToList(); _services.ApnsService.Send(iosUserList, notificationModel); }); var taskSendAndroidNotification = Task.Factory.StartNew(() => { var androidUserList = userRoasterList.Where( x => x.DevicePlatform == DevicePlatform.Android //&& x.PresenceStatus == Presence.Offline ).ToList(); _services.GcmService.Send(androidUserList, notificationModel); }); Task.WaitAll(taskSendiOSNotification, taskSendAndroidNotification); }
public HttpResponseMessage Delete(string uId, string gID) { #region log user request and response /*********************************************** * To log user request ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Request ===> senderID : " + uId + ", groupID : " + gID); } #endregion ulong temp = 0; if (NeeoUtility.IsNullOrEmpty(uId) || !ulong.TryParse(uId, out temp) || NeeoUtility.IsNullOrEmpty(gID)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } else { uId = uId.Trim(); gID = gID.ToLower(); try { NeeoGroup.DeleteGroupIcon(groupID: gID, userID: uId); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception exception) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } } }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="file"></param> /// <param name="fileCategory"></param> /// <param name="recipientCount"></param> /// <param name="isOverloaded"></param> /// <returns></returns> public static bool Save(NeeoUser user, File file, FileCategory fileCategory, ushort recipientCount = 0, bool isOverloaded = true) { bool isOperationCompleted = false; file.Info.Name = NeeoUtility.IsNullOrEmpty(file.Info.Name) ? Guid.NewGuid().ToString("N") : file.Info.Name; var server = FileServerManager.GetInstance().SelectServer(); DbManager dbManager = new DbManager(); file.Info.FullPath = server.GetServerNetworkPath(); try { //file.Info.CreationTimeUtc = DateTime.UtcNow; FileManager.Save(file, FileCategory.Shared); if (dbManager.StartTransaction()) { if (dbManager.InsertSharedFileInformation(file.Info.Name, file.Info.Creator, Convert.ToUInt16(file.Info.MediaType), Convert.ToUInt16(file.Info.MimeType), Path.Combine(file.Info.FullPath, file.Info.FullName), file.Info.CreationTimeUtc, recipientCount, file.Info.Length, file.Info.Hash)) { file.Info.Url = NeeoUrlBuilder.BuildFileUrl(server.LiveDomain, file.Info.Name, FileCategory.Shared, file.Info.MediaType); dbManager.CommitTransaction(); isOperationCompleted = true; } else { dbManager.RollbackTransaction(); } } } catch (ApplicationException appException) { dbManager.RollbackTransaction(); throw; } catch (Exception exception) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError(MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); throw new ApplicationException(CustomHttpStatusCode.ServerInternalError.ToString("D")); } return(isOperationCompleted); }
public string GetMcrCount(string userID) { userID = (userID != null) ? userID.Trim() : userID; // #region Verify User //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; //string keyFromClient = request.Headers["key"]; // if (NeeoUtility.AuthenticateUserRequest( userID, keyFromClient)) //{ //#endregion ulong temp; if (!NeeoUtility.IsNullOrEmpty(userID) && ulong.TryParse(userID, out temp)) { try { return(NeeoVoipApi.GetMcrCount(userID)); } catch (ApplicationException applicationException) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(applicationException.Message))); } catch (Exception exception) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError); } return(""); } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); return(""); } //} // else // { // NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized); // return ""; // } }
/// <summary> /// /// </summary> /// <param name="uID"></param> /// <param name="fileID"></param> public void Acknowledgement(string uID, string fileID) { if (!NeeoUtility.IsNullOrEmpty(uID) && !NeeoUtility.IsNullOrEmpty(fileID)) { NeeoUser user = new NeeoUser(uID); try { if (!user.UpdateSharedFileDownloadCount(fileID)) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotFound); } } catch (ApplicationException appExp) { NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))); } } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } }
/// <summary> /// Updates an existing user on the XMPP server. /// </summary> /// <param name="userID">A string containing the username.</param> /// <param name="password">[Optional].A string containing the password. Pass null if not required. </param> /// <param name="name">[Optional].A string containing the name for the account. Pass null if not required.</param> /// <param name="email">[Optional].A string containing the user's email id. Pass null if not required.</param> public static void UpdateUser(string userID, string password, string name, string email) { LoadVariables(); string url = UserServiceUrl + "/" + userID; RestRequest request = new RestRequest(url); request.Method = Method.PUT; request.AddHeader("Content-Type", "application/xml"); request.AddHeader("Authorization", _adminKey); string RequestBody = string.Format(@"<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <user>"); if (NeeoUtility.IsNullOrEmpty(userID)) { throw new ApplicationException(HttpStatusCode.BadRequest.ToString("D")); } RequestBody = RequestBody + "<username>" + userID + "</username>"; if (password != null) { RequestBody = RequestBody + "<password>" + password + "</password>"; } if (name != null) { RequestBody = RequestBody + "<name>" + name + "</name>"; } if (email != null) { RequestBody = RequestBody + "<email>" + email + "</email>"; } RequestBody = RequestBody + "</user>"; request.AddParameter("application/xml", RequestBody, ParameterType.RequestBody); ExecuteRequest(request); }
public HttpResponseMessage Get([FromUri] GetGroupIconRequest request) { LogRequest(request); ulong temp = 0; if (NeeoUtility.IsNullOrEmpty(request.Uid) || !ulong.TryParse(request.Uid, out temp) || NeeoUtility.IsNullOrEmpty(request.gID)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } else { request.Uid = request.Uid.Trim(); request.gID = request.gID.ToLower(); try { if (NeeoGroup.GroupIconExists(request.gID.ToLower())) { string url = NeeoUrlBuilder.BuildFileUrl(ConfigurationManager.AppSettings[NeeoConstants.FileServerUrl], request.gID, FileCategory.Group, MediaType.Image); return(RedirectServiceToUrl(url)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch (Exception exception) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } } }
/// <summary> /// Gets avatar timestamps details for the user's provided contacts. /// </summary> /// <param name="uID">A string containing the user id.</param> /// <param name="contacts">A string containing the ',' separated contacts.</param> /// <returns>A list containing user's contacts avatar timestamp.</returns> public List <ContactAvatarTimestamp> GetContactAvatarTimestamp(string uID, string contacts) { #region log user request and response /*********************************************** * To log user response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Response==> User ID : " + uID + "- Contact List :" + contacts); } #endregion if (!NeeoUtility.IsNullOrEmpty(uID) && !NeeoUtility.IsNullOrEmpty(contacts)) { NeeoUser user = new NeeoUser(uID.Trim()); var result = user.GetContactsAvatarTimestamp(contacts); #region log user request and response /*********************************************** * To log user response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "Response==> User ID : " + uID + "- Contact List :" + JsonConvert.SerializeObject(result)); } #endregion return(result); } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } return(null); }
public async Task <HttpResponseMessage> Put([FromUri] string type, [FromUri] string sessionID) { long startingPosition = 0; try { if (type != "resumable" || NeeoUtility.IsNullOrEmpty(sessionID)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var session = await UploadSessionManager.ValidateSessionAsync(sessionID); if (session == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } session.FileInfo.Extension = MimeTypeMapping.GetMimeTypeDetail(session.FileInfo.MimeType.GetDescription()).Extension; long? contentLength = Request.Content.Headers.ContentLength; string contentType = Request.Content.Headers.ContentType == null ? null : Request.Content.Headers.ContentType.ToString(); if (Request.Content.Headers.Contains("Content-Range")) { var contentRange = Request.Content.Headers.GetValues("Content-Range").First(); if (contentRange == "bytes */*") { var file = SharedMedia.GetMedia(session.FileInfo.Name, session.FileInfo.MediaType); if (file != null) { var response = Request.CreateResponse((HttpStatusCode)308); response.Headers.Add("Range", "bytes=0-" + file.Info.Length); response.ReasonPhrase = "Resumable Incomplete"; return(response); } else { var response = Request.CreateResponse((HttpStatusCode)308); response.Headers.Add("Range", "bytes=0-0"); response.ReasonPhrase = "Resumable Incomplete"; return(response); } } else { var delimeter = new char[] { '-', '/', ' ' }; var rangeValues = contentRange.Split(delimeter); if (rangeValues.Length != 4) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (Convert.ToInt64(rangeValues[2]) != session.FileInfo.Length) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } startingPosition = Convert.ToInt64(rangeValues[1]); } } if (contentLength == null || contentLength > (long)session.FileInfo.Length) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } using (var stream = await Request.Content.ReadAsStreamAsync()) { var newFile = new File() { Info = session.FileInfo, FileStream = new FileDataStream() { Stream = stream, Postion = startingPosition } }; if (SharedMedia.Save(new NeeoUser(session.FileInfo.Creator), newFile, FileCategory.Shared, 0)) { // check the length of the file with the database then delete it. await UploadSessionManager.DeleteSessionAsync(sessionID); var response = new HttpResponseMessage(HttpStatusCode.Created); response.Headers.Location = new Uri(newFile.Info.Url); return(response); } } return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } catch (Exception exception) { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public async Task <HttpResponseMessage> UploadDataAsync(ApiController controller) { if (controller.Request.Content.Headers.ContentType == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (Request.Content.Headers.ContentType.ToString().Split(new char[] { ';' })[0] != "application/json") { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var requestBody = await Request.Content.ReadAsStringAsync(); var fileRequest = JsonConvert.DeserializeObject <UploadFileRequest>(requestBody); controller.Validate(fileRequest); if (!ModelState.IsValid) { return(controller.Request.CreateResponse(HttpStatusCode.BadRequest)); } if (!NeeoUtility.IsNullOrEmpty(fileRequest.FId)) { Guid resultingGuid; if (!Guid.TryParse(fileRequest.FId, out resultingGuid)) { LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" + "fID : " + fileRequest.FId + " is not parseable."); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } fileRequest.FId = resultingGuid.ToString("N").ToLower(); } NeeoUser sender = new NeeoUser(fileRequest.Uid); File uploadedFile = FileFactory.Create(fileRequest.MimeType.GetDescription()); uploadedFile.Info.Name = fileRequest.FId; uploadedFile.Info.Creator = fileRequest.Uid; uploadedFile.Data = fileRequest.Data; //LibNeeo.IO.File uploadingFile = new LibNeeo.IO.File() //{ // Info = new NeeoFileInfo() // { // MediaType = MediaType.Image, // MimeType = fileRequest.MimeType, // Extension = "jpg" // }, // Data = fileRequest.Data //}; SharedMedia.Save(sender, uploadedFile, FileCategory.Shared, 0); #region log user request and response /*********************************************** * To log user response ***********************************************/ if (_logRequestResponse) { LogManager.CurrentInstance.InfoLogger.LogInfo( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Response ===> " + uploadedFile.Info.Url); } #endregion log user request and response return(Request.CreateResponse(HttpStatusCode.OK, new Dictionary <string, string>() { { "UploadFileResult", uploadedFile.Info.Url } })); }