public async Task <HttpResponseMessage> GetCount(BaseRequest request) { if (!ModelState.IsValid || request == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { var result = await Task.Factory.StartNew(() => NeeoVoipApi.GetMcrCount(request.Uid)); return(Request.CreateResponse(HttpStatusCode.OK, new Dictionary <string, string>() { { "GetMcrCountResult", result } })); } catch (ApplicationException applicationException) { return(SetCustomResponseMessage("", (HttpStatusCode)(Convert.ToInt32(applicationException.Message)))); } catch (Exception exception) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
/// <summary> /// /// </summary> /// <param name="flush"></param> /// <returns></returns> public McrData GetMcrDetails(bool flush) { var mcrDetails = NeeoVoipApi.GetMcrDetails(_userID, flush); if (flush == true) { DbManager dbManager = new DbManager(); if (!dbManager.ResetOfflineCount(_userID, OfflineCount.MCR)) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, " ==> " + _userID + " : Mcr count reset operation failed.", System.Reflection.MethodBase.GetCurrentMethod().Name); } } return(mcrDetails); }
/// <summary> /// Updates user's device token in the xmpp database and on voip server. /// </summary> /// <param name="applicationVersion">A string containing the application version.</param> /// <param name="deviceInfo">An object of DeviceInfo class that contains the device inforamtion.</param> /// <param name="isUpdatingDToken">A boolean, if true,shows the user device token is going to update, otherwise false.</param> /// <returns>true if device token is successfully updated; otherwise false;</returns> public bool UpdateUserDeviceInfo(string applicationVersion, DeviceInfo deviceInfo, bool isUpdatingDToken) { DbManager dbManager = new DbManager(); try { if (isUpdatingDToken) { if (dbManager.StartTransaction()) { if (dbManager.UpdateUserDeviceInfo(_userID, null, applicationVersion, deviceInfo, true, false)) { //NeeoVoipApi.UpdateUserAccount(_userID, null, // deviceInfo.DeviceToken == "-1" ? PushEnabled.False : PushEnabled.True, // UserStatus.NotSpecified); NeeoVoipApi.UpdateUserAccount(_userID, null, PushEnabled.True, UserStatus.NotSpecified); dbManager.CommitTransaction(); return(true); } throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D")); } return(false); } if (dbManager.UpdateUserDeviceInfo(_userID, null, applicationVersion, deviceInfo, false, false)) { return(true); } throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D")); } catch (ApplicationException applicationException) { if (isUpdatingDToken) { dbManager.RollbackTransaction(); } throw; } catch (Exception exception) { if (isUpdatingDToken) { dbManager.RollbackTransaction(); } throw; } }
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 ""; // } }
public async Task <HttpResponseMessage> Unblock(UserDTO request) { if (!ModelState.IsValid || request == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { await Task.Factory.StartNew(() => NeeoVoipApi.UnBlockUser(request.Uid, request.UserList)); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (ApplicationException applicationException) { return(SetCustomResponseMessage(null, (HttpStatusCode)(Convert.ToInt32(applicationException.Message)))); } catch (Exception exception) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
/// <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="applicationID">An string containing the application id.</param> /// <param name="applicationVersion">A string containing application version.</param> /// <param name="deviceInfo">An object of DeviceInfo class that contains the device inforamtion.</param> /// <returns>true if account is successfully setup; otherwise, false.</returns> public static bool SetupUserAccount(string phoneNumber, string applicationID, string applicationVersion, DeviceInfo deviceInfo) { bool isAccountCreated = false; bool isDirectoriesCreated = false; DbManager dbManager = new DbManager(); string deviceKey = GenerateDeviceKey(phoneNumber, deviceInfo.DeviceVenderID, applicationID); if (!dbManager.CheckUserAlreadyRegistered(phoneNumber)) { try { if (dbManager.StartTransaction()) { dbManager.DeleteUserFromBlockList(phoneNumber); FileManager.CreateUserDirectory(phoneNumber); isDirectoriesCreated = true; RegisterUserOnXmpp(phoneNumber, deviceKey); isAccountCreated = true; dbManager.UpdateUserDeviceInfo(phoneNumber, applicationID, applicationVersion, deviceInfo, true, true); //NeeoVoipApi.RegisterUser(phoneNumber, deviceKey, deviceInfo.DeviceToken == null ? PushEnabled.False : PushEnabled.True); NeeoVoipApi.RegisterUser(phoneNumber, deviceKey, PushEnabled.True); dbManager.CommitTransaction(); return(true); } else { return(false); } } catch (ApplicationException appExp) { dbManager.RollbackTransaction(); if (isAccountCreated) { DeleteUserOnXmpp(phoneNumber); } if (isDirectoriesCreated) { FileManager.DeleteUserDirectory(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.ServerInternalError.ToString("D")); } } else { try { if (dbManager.StartTransaction()) { dbManager.DeleteUserFromBlockList(phoneNumber); dbManager.UpdateUserDeviceInfo(phoneNumber, applicationID, applicationVersion, deviceInfo, true, true); ChangeUserDeviceKey(phoneNumber, deviceKey); NeeoVoipApi.UpdateUserAccount(phoneNumber, deviceKey, deviceInfo.DeviceToken == null ? PushEnabled.False : PushEnabled.True, UserStatus.NotSpecified); dbManager.CommitTransaction(); //NeeoUser.DeleteUserAvatar(phoneNumber); return(true); } else { return(false); } } catch (ApplicationException appExp) { LogManager.CurrentInstance.ErrorLogger.LogError( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, appExp.Message); 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.ServerInternalError.ToString("D")); } } }
protected void Button1_Click(object sender, EventArgs e) { var _conStr = ConfigurationManager.ConnectionStrings["neeoConnectionString"].ConnectionString; var _con = new SqlConnection(_conStr); try { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Select username from neUserExtension where devicePlatform = 1"; cmd.CommandType = CommandType.Text; cmd.Connection = _con; System.Data.DataTable dtContactsInfo = new System.Data.DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dtContactsInfo); if (dtContactsInfo.Rows.Count > 0) { Response.Write("Count == > " + dtContactsInfo.Rows.Count.ToString() + "<br/>"); for (int i = 0; i < dtContactsInfo.Rows.Count; i++) { try { var mcr = NeeoVoipApi.GetMcrCount(dtContactsInfo.Rows[i]["username"].ToString()); Response.Write(i + " ==> " + dtContactsInfo.Rows[i]["username"].ToString() + " ==> " + mcr + "<br/>"); var _conStrr = ConfigurationManager.ConnectionStrings["neeoConnectionString"].ConnectionString; var _conn = new SqlConnection(_conStrr); SqlCommand cmdd = new SqlCommand(); cmdd.CommandText = "UPDATE [dbo].[neOfflineUserMessageCount] SET [mcrCount] = " + mcr + " WHERE username = '******'"; cmdd.CommandType = CommandType.Text; cmdd.Connection = _conn; using (_conn) { _conn.Open(); cmdd.ExecuteNonQuery(); _conn.Close(); Response.Write(i + " ==> " + dtContactsInfo.Rows[i]["username"].ToString() + " ==> updated" + "<br/>"); } } catch (SqlException sqlEx) { Response.Write(sqlEx.Message + "<br/>"); } catch (ApplicationException applicationException) { Response.Write(applicationException.Message + "<br/>"); } catch (Exception exception) { Response.Write(exception.Message + "<br/>"); } } } } catch (SqlException sqlEx) { Response.Write(sqlEx.Message + "<br/>"); } catch (Exception Ex) { Response.Write(Ex.Message + "<br/>"); } finally { if (_con.State != ConnectionState.Closed) { _con.Close(); } } }