/// <summary>
        /// Sends push notifications with message and badge count to the user device specified with device token.
        /// </summary>
        /// <param name="nType">An integer containing specifying notification type.</param>
        /// <param name="dp">An integer containing specifying device platform.</param>
        /// <param name="dToken">A string containing the device token of the user device to whom message has to be delivered.</param>
        /// <param name="data">A dictionary having notification data.</param>
        public void SendNotification(short nType, short dp, string dToken, Dictionary <string, string> data)
        {
            NotificationType notificationType = (NotificationType)nType;
            DevicePlatform   devicePlatform   = (DevicePlatform)dp;

            if (Enum.IsDefined(typeof(NotificationType), nType) && Enum.IsDefined(typeof(DevicePlatform), dp) && !NeeoUtility.IsNullOrEmpty(dToken))
            {
                try
                {
                    NotificationManager notificationManager = new NotificationManager();
                    notificationManager.SendNotification(notificationType, devicePlatform, dToken, data);
                }
                catch (ApplicationException appExp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "notificationType:" + notificationType + ", devicePlatform:" + devicePlatform + ", deviceToken:" + dToken + ", data:" + JsonConvert.SerializeObject(data) + ", error:" + appExp.Message);
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)Convert.ToInt32(appExp.Message));
                }
                catch (Exception exp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "notificationType:" + notificationType + ", devicePlatform:" + devicePlatform + ", deviceToken:" + dToken + ", data:" + JsonConvert.SerializeObject(data) + ", error:" + exp.Message, exp);
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError);
                }
            }
            else
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public bool UpdateUserProfile(string name, LibNeeo.IO.File file)
        {
            bool isCompleted = false;

            if (!UpdateUsersDisplayName(name))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser);
            }
            else if (file == null)
            {
                isCompleted = true;
            }
            else
            {
                file.Info = new NeeoFileInfo()
                {
                    Name = _userID, Creator = _userID, MediaType = MediaType.Image, MimeType = MimeType.ImageJpeg
                };

                if (FileManager.Save(file, FileCategory.Profile))
                {
                    isCompleted = true;
                }
            }
            return(isCompleted);
        }
Beispiel #3
0
        public HttpResponseMessage UserLogin([FromBody] tokenModel currentModel)
        {
            string token = "";

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            if (NeeoUtility.IsPhoneNumberInInternationalFormat(currentModel.uID))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(currentModel.uID)))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (NeeoActivation.CheckUserAlreadyRegistered(currentModel.uID))
            {
                token = GenerateToken(currentModel.uID);
                return(Request.CreateResponse(HttpStatusCode.OK, token));
            }
            else
            {
                token = "-1";
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, token));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Deletes user's profile picture stored in the user profile directory. It is an instance method.
        /// </summary>
        /// <returns>true if user's profile picture is successfully deleted; otherwise false.</returns>
        public bool DeleteFile(FileClassfication fileClassfication, string fileName)
        {
            bool   result        = false;
            string directoryPath = null;

            switch (fileClassfication)
            {
            case FileClassfication.Profile:
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile);
                break;

            case FileClassfication.Offline:
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirOffline);
                break;

            case FileClassfication.Album:
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirAlbum);
                break;
            }

            if (Directory.Exists(directoryPath))
            {
                result = File.DeleteFile(fileName, directoryPath);
            }
            else
            {
                throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D"));
            }
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Creates user's directories based on his/her phone number. It is a static method.
        /// </summary>
        /// <param name="phoneNumber">A string containing user's phone number.</param>
        public static void CreateUserDirectoryStructure(string phoneNumber)
        {
            string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(phoneNumber));

            if (!Directory.Exists(userDirectoryPath))
            {
                DirectoryInfo dirInfo = Directory.CreateDirectory(userDirectoryPath);
                dirInfo.CreateSubdirectory(_dirProfile);
                dirInfo.CreateSubdirectory(_dirOffline);
                dirInfo.CreateSubdirectory(_dirAlbum);
            }
            else
            {
                if (!Directory.Exists(Path.Combine(userDirectoryPath, _dirProfile)))
                {
                    DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(userDirectoryPath, _dirProfile));
                }
                if (!Directory.Exists(Path.Combine(userDirectoryPath, _dirOffline)))
                {
                    DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(userDirectoryPath, _dirOffline));
                }
                if (!Directory.Exists(Path.Combine(userDirectoryPath, _dirAlbum)))
                {
                    DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(userDirectoryPath, _dirAlbum));
                }
            }
        }
Beispiel #6
0
        /// <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);
            }
        }
        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);
        }
Beispiel #9
0
 private AppCompatibility CheckCompatibility(UserAgent client)
 {
     if ((DevicePlatform)client.DP == DevicePlatform.iOS)
     {
         if (NeeoUtility.GetIntegerValue(client.AppVer) >=
             NeeoUtility.GetIntegerValue(ConfigurationManager.AppSettings[NeeoConstants.IosCriticalVersion]))
         {
             return(AppCompatibility.Compatible);
         }
         return(AppCompatibility.Incompatible);
     }
     if ((DevicePlatform)client.DP == DevicePlatform.Android)
     {
         if (NeeoUtility.GetIntegerValue(client.AppVer) < NeeoUtility.GetIntegerValue(ConfigurationManager.AppSettings[NeeoConstants.AndroidFeatureVersion]))
         {
             return(AppCompatibility.Compatible);
         }
         if (NeeoUtility.GetIntegerValue(client.AppVer) >=
             NeeoUtility.GetIntegerValue(ConfigurationManager.AppSettings[NeeoConstants.AndroidCriticalVersion]))
         {
             return(AppCompatibility.Compatible);
         }
         return(AppCompatibility.Incompatible);
     }
     if ((DevicePlatform)client.DP == DevicePlatform.WindowsMobile)
     {
         if (NeeoUtility.GetIntegerValue(client.AppVer) >=
             NeeoUtility.GetIntegerValue(ConfigurationManager.AppSettings[NeeoConstants.WPCriticalVersion]))
         {
             return(AppCompatibility.Compatible);
         }
         return(AppCompatibility.Incompatible);
     }
     return(AppCompatibility.Incompatible);
 }
Beispiel #10
0
        /// <summary>
        /// Gets the country of the requesting user
        /// </summary>
        /// <returns>A string containing the country code (e.g. PK)</returns>
        public string GetCountry()
        {
            var cip = HttpContext.Current.Request.UserHostAddress;
            var requestMessageProperties      = OperationContext.Current.IncomingMessageProperties;
            var remoteEndpointMessageProperty = requestMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            if (remoteEndpointMessageProperty != null)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().GetType(), "Ip address:" + remoteEndpointMessageProperty.Address);
                try
                {
                    return(GeoLocator.GetLocation(remoteEndpointMessageProperty.Address));
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                    return(null);
                }
            }
            else
            {
                LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), "Endpoint message property is null.");
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError);
                return(null);
            }
        }
        /*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);
        }
Beispiel #12
0
        /// <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;
            //}
        }
Beispiel #13
0
        /// <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;
            //}
        }
Beispiel #14
0
        public bool Valid()
        {
            if (NeeoUtility.IsNullOrEmpty(UserID) || NeeoUtility.IsNullOrEmpty(AppID) || NeeoUtility.IsNullOrEmpty(SpamUserID) || UserID == SpamUserID)
            {
                return(false);
            }

            return(true);
        }
 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, ""));
     }
 }
Beispiel #16
0
        /// <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);
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Call to the given number.
        /// </summary>
        /// <param name="phoneNumber">A string containing the phone number for sending SMS.</param>
        /// <param name="code">A string containing code.</param>
        public void Call(string phoneNumber, string code)
        {
            TwilioClient.Init(_twilioAccountSid, _twilioAuthToken);

            var to   = new PhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber));
            var from = new PhoneNumber(_twilioPhoneNumber);
            var call = Create(to, from,
                              url: new Uri(_twilioSsmlUrl.Replace("{{code}}", code)));

            LogManager.CurrentInstance.InfoLogger.LogInfo(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Twilio voice call - Phone # : \"" + phoneNumber[0] + "\"  is completed with Sid: " + call.Sid);
        }
Beispiel #18
0
        /// <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);
        }
Beispiel #19
0
        /// <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);

            //}
        }
Beispiel #20
0
        /// <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);
        }
Beispiel #22
0
        /// <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);

            //}
        }
Beispiel #23
0
        /// <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("");
            }
        }
Beispiel #24
0
        /// <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);
        }
Beispiel #25
0
 /// <summary>
 /// Deletes user's directories based on his/her phone number. It is an instance method.
 /// </summary>
 /// <param name="phoneNumber">A string containing user's phone number.</param>
 public void DeleteUserDirectoryStructure()
 {
     try
     {
         string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID));
         if (Directory.Exists(userDirectoryPath))
         {
             Directory.Delete(userDirectoryPath, true);
         }
     }
     catch (UnauthorizedAccessException unAuthExp)
     {
         LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, unAuthExp.Message, unAuthExp);
     }
 }
Beispiel #26
0
        /// <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);
        }
Beispiel #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="fileClassfication"></param>
 /// <returns></returns>
 public string GetFileState(string fileName, FileClassfication fileClassfication)
 {
     if (fileClassfication == FileClassfication.Offline)
     {
         string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirOffline);
         if (Directory.Exists(userDirectoryPath))
         {
             DirectoryInfo dirInfo  = new DirectoryInfo(userDirectoryPath);
             FileInfo      fileInfo = dirInfo.GetFiles().SingleOrDefault(x => x.Name == fileName);
             if (fileInfo != null)
             {
                 return(fileInfo.FullName);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     }
     else if (fileClassfication == FileClassfication.Album)
     {
         string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirAlbum);
         if (Directory.Exists(userDirectoryPath))
         {
             DirectoryInfo dirInfo  = new DirectoryInfo(userDirectoryPath);
             FileInfo      fileInfo = dirInfo.GetFiles().SingleOrDefault(x => x.Name == fileName);
             if (fileInfo != null)
             {
                 return(fileInfo.FullName);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
        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);
            }
        }