/// <summary> /// Updates user's profile picture stores in the user's profile directory. /// </summary> /// <param name="fileData">A string containing base64-encoded file data.</param> /// <param name="senderID">A string containing sender user id. It is required only while uploading offline file.</param> /// <returns>true if user's profile picture is successfully updated; otherwise false. </returns> public string UploadImageFile(string fileData, FileClassfication fileClassfication, string senderID) { string result = null; string fileName = null; string directoryPath = null; switch (fileClassfication) { case FileClassfication.Profile: fileName = NeeoUtility.ConvertToFileName(_userID); directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile); if (Directory.Exists(directoryPath)) { result = File.SaveFile(fileName, fileData, directoryPath).ToString(); } else { throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D")); } break; case FileClassfication.Offline: string timeStamp = NeeoUtility.GetTimeStamp(DateTime.UtcNow).ToString(); fileName = NeeoUtility.GetFileNameInOfflineFileFormat(senderID, _userID, timeStamp); directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirOffline); if (Directory.Exists(directoryPath)) { if (File.SaveFile(fileName, fileData, directoryPath)) { result = NeeoUtility.GenerateImageUrl(_userID, timeStamp, fileClassfication, 0, senderID); } } else { throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D")); } break; case FileClassfication.Album: fileName = NeeoUtility.GetTimeStamp(DateTime.UtcNow).ToString(); directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirAlbum); if (Directory.Exists(directoryPath)) { result = File.SaveFile(NeeoUtility.ConvertToFileName(fileName), fileData, directoryPath).ToString(); } else { throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D")); } break; } return(result); }
/// <summary> /// Gets the path of the user's profile picture if it exists. /// </summary> /// <returns>path of the file if it exists; otherwise empty string will be returned.</returns> public string GetAvatar() { string fileName = NeeoUtility.ConvertToFileName(_userID); string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile); if (Directory.Exists(userDirectoryPath)) { return(File.GetFilePath(fileName, userDirectoryPath)); } else { return(""); } }
/// <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); } }
/// <summary> /// Setup user account along with user registration on XMPP server. /// </summary> /// <param name="phoneNumber">A string containing user's phone number.</param> /// <param name="devicePlatform">An integer specifying user's platform</param> /// <param name="deviceVenderID">A string containing device specific vender id.</param> /// <returns>true if account is successfully setup; otherwise, false.</returns> public static bool SetupUserWithRegistration(string phoneNumber, DevicePlatform devicePlatform, string deviceVenderID, string applicationID) { bool isAccountCreated = false; bool isDirectoryStructureCreated = false; DbManager dbManager = new DbManager(); if (!dbManager.CheckUserAlreadyRegistered(phoneNumber)) { try { if (dbManager.StartTransaction()) { dbManager.DeleteUserFromBlockList(phoneNumber); User.CreateUserDirectoryStructure(phoneNumber); isDirectoryStructureCreated = true; RegisterUserOnXmpp(phoneNumber, deviceVenderID, applicationID); isAccountCreated = true; dbManager.UpdateUserDeviceInfo(phoneNumber, deviceVenderID, devicePlatform); dbManager.CommitTransaction(); return(true); } else { return(false); } } catch (ApplicationException appExp) { dbManager.RollbackTransaction(); if (isAccountCreated) { DeleteUserOnXmpp(phoneNumber); } if (isDirectoryStructureCreated) { User.DeleteUserDirectoryStructure(phoneNumber); } throw; } catch (System.UnauthorizedAccessException unAuthExp) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, unAuthExp.Message, unAuthExp); throw new ApplicationException(CustomHttpStatusCode.FileSystemException.ToString("D")); } catch (System.Security.SecurityException secExp) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, secExp.Message, secExp); throw new ApplicationException(CustomHttpStatusCode.FileSystemException.ToString("D")); } catch (Exception exp) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp); throw new ApplicationException(CustomHttpStatusCode.UnknownError.ToString("D")); } } else { try { if (dbManager.StartTransaction()) { dbManager.DeleteUserFromBlockList(phoneNumber); dbManager.UpdateUserDeviceInfo(phoneNumber, deviceVenderID, devicePlatform); ChangeUserDeviceKey(phoneNumber, deviceVenderID, applicationID); dbManager.CommitTransaction(); User.DeleteFile(phoneNumber, FileClassfication.Profile, NeeoUtility.ConvertToFileName(phoneNumber)); return(true); } else { return(false); } } catch (ApplicationException appExp) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, appExp + " NeeoActivation file - 192"); dbManager.RollbackTransaction(); throw; } catch (System.UnauthorizedAccessException unAuthExp) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, unAuthExp.Message, unAuthExp); throw new ApplicationException(CustomHttpStatusCode.FileSystemException.ToString("D")); } catch (System.Security.SecurityException secExp) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, secExp.Message, secExp); throw new ApplicationException(CustomHttpStatusCode.FileSystemException.ToString("D")); } catch (Exception exp) { dbManager.RollbackTransaction(); LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp); throw new ApplicationException(CustomHttpStatusCode.UnknownError.ToString("D")); } } }
/// <summary> /// Updates user information into the database and the profile picture. /// </summary> /// <param name="userID">A string containing phone number as user id.</param> /// <param name="name">A string containing the name of the user.</param> /// <param name="fileData">A base64 encoded string containing the file data.</param> /// <returns>true if information is successfully updated; otherwise, false.</returns> public bool UpdateUserInformation(string userID, string name, string fileData) { bool isCompletedSuccessfully = false; #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 + ", name : " + name + ", fileData : " + fileData); } #endregion if (!NeeoUtility.IsNullOrEmpty(userID)) { if (name != null) { NeeoUser user = new NeeoUser(userID); try { using (TransactionScope scope = new TransactionScope()) { if (user.UpdateUsersDisplayName(name)) { if (!NeeoUtility.IsNullOrEmpty(fileData)) { File file = new File() { FileName = NeeoUtility.ConvertToFileName(userID), Data = fileData, FileOwner = userID, MediaType = MediaType.Image, MimeType = MimeType.Image_jpeg }; if (user.UploadFile(file, FileClassfication.Profile)) { isCompletedSuccessfully = true; scope.Complete(); } } else { isCompletedSuccessfully = true; scope.Complete(); } } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser); } } return(isCompletedSuccessfully); } 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(isCompletedSuccessfully); } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } } else { NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments); } return(isCompletedSuccessfully); }
/// <summary> /// /// </summary> /// <param name="avatarTimeStamp"></param> /// <returns></returns> public AvatarState GetAvatarState(ulong avatarTimeStamp) { string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile); if (Directory.Exists(userDirectoryPath)) { DirectoryInfo dirInfo = new DirectoryInfo(userDirectoryPath); FileInfo fileInfo = dirInfo.GetFiles().SingleOrDefault(x => x.Name == NeeoUtility.ConvertToFileName(_userID)); if (fileInfo != null) { if (NeeoUtility.GetTimeStamp(fileInfo.CreationTimeUtc) == avatarTimeStamp) { return(AvatarState.NotModified); } else { return(AvatarState.Modified); } } else { return(AvatarState.NotExist); } } else { return(AvatarState.NotExist); } }