コード例 #1
0
        /// <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;
            }
        }
コード例 #2
0
        /// <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"));
                }
            }
        }