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);
            }
        }
Пример #2
0
        public HttpResponseMessage GetProfileName([FromUri] BaseRequest request)
        {
            string result = null;

            if (request == null || !ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            LogRequest(request);
            ulong temp = 0;

            try
            {
                request.Uid = request.Uid.Trim();
                NeeoUser user = new NeeoUser(request.Uid);
                result = user.GetUserProfileName();
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (ApplicationException appExp)
            {
                return(SetCustomResponseMessage("", (HttpStatusCode)(CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))));
            }
            catch (Exception exp)
            {
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Пример #3
0
        public HttpResponseMessage SyncAvatarTimestamp([FromBody] SyncDataDTO syncData)
        {
            LogRequest(syncData);
            if (!ModelState.IsValid || syncData == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            if (syncData.Contacts.Count > 0)
            {
                var user = new NeeoUser(syncData.Uid);
                try
                {
                    var result = user.GetContactsAvatarTimestamp(syncData.MapModel());
                    return(Request.CreateResponse(HttpStatusCode.OK, result.ConvertAll((MapcontactStatusToContactAvatarTimestampDTO))));
                }
                catch (ApplicationException appExp)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
                catch (Exception exp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
        /*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);
        }
Пример #5
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;
            //}
        }
Пример #6
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;
            //}
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="fID"></param>
        /// <param name="recipientCount"></param>
        /// <returns></returns>
        public static bool Share(NeeoUser user, string fileID, ushort recipientCount)
        {
            DbManager dbManager = new DbManager();

            if (dbManager.UpdateFileSharedDateWithRecipientCount(user.UserID, fileID, recipientCount))
            {
                return(true);
            }
            throw new ApplicationException(HttpStatusCode.NotFound.ToString("D"));
        }
 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, ""));
     }
 }
Пример #9
0
        public HttpResponseMessage CallingTone([FromBody] Models.CallingTone callingTone)
        {
            callingTone.Uid = callingTone.Uid.Trim();
            #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 ===> " + JsonConvert.SerializeObject(callingTone));
            }

            #endregion

            if (ModelState.IsValid)
            {
                try
                {
                    if (Enum.IsDefined(typeof(Common.CallingTone), callingTone.Tone))
                    {
                        NeeoUser user = new NeeoUser(callingTone.Uid.Trim());
                        if (user.UpdateSettings((Common.CallingTone)callingTone.Tone, ToneType.CallingTone))
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ""));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest));
                    }
                }
                catch (ApplicationException appException)
                {
                    return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt32(appException.Message), ""));
                }
                catch (Exception exception)
                {
                    Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().GetType().Name);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ""));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Пример #10
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);

            //}
        }
Пример #11
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);

            //}
        }
Пример #12
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);
            }
        }
Пример #14
0
        public async Task <HttpResponseMessage> Get([FromUri] AvatarRequest avatarRequest)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request"));
            }
            try
            {
                return(await Task <HttpResponseMessage> .Factory.StartNew(() =>
                {
                    NeeoFileInfo fileInfo = null;
                    ulong avatarUpdatedTimeStamp = 0;
                    int dimension = Convert.ToInt32(avatarRequest.Dimension);
                    NeeoUser user = new NeeoUser(avatarRequest.Uid);
                    switch (user.GetAvatarState(avatarRequest.Timestamp, false, out avatarUpdatedTimeStamp, out fileInfo))
                    {
                    case AvatarState.Modified:
                        var response = Request.CreateResponse(HttpStatusCode.OK);
                        response.Headers.Add("ts", avatarUpdatedTimeStamp.ToString());
                        response.Content =
                            new ByteArrayContent(MediaUtility.ResizeImage(fileInfo.FullPath, dimension, dimension));
                        //response.Content = new StreamContent(new FileStream(fileInfo.FullPath,FileMode.Open));
                        response.Content.Headers.ContentType =
                            new MediaTypeHeaderValue(
                                MimeTypeMapping.GetMimeType(fileInfo.Extension).GetDescription());
                        return response;

                    case AvatarState.NotModified:
                        return Request.CreateResponse(HttpStatusCode.NotModified);

                    default:
                        return Request.CreateResponse(HttpStatusCode.BadRequest);
                    }
                }));
            }
            catch (AggregateException aggregateException)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, aggregateException.Message, aggregateException, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
            }
            catch (Exception exception)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
            }
            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
        }
        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);
            }
        }
Пример #16
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;
            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);
            }
        }
Пример #17
0
        /// <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);
            }
        }
Пример #18
0
        public async Task <HttpResponseMessage> GetChatBackup([FromUri] string sender)
        {
            try
            {
                NeeoUser neeoUser           = new NeeoUser(sender);
                var      operationCompleted = await System.Threading.Tasks.Task.Run(() => neeoUser.GetXMLChatBackup(sender));

                return(Request.CreateResponse(HttpStatusCode.OK, operationCompleted));
            }
            catch (ApplicationException applicationException)
            {
                return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(applicationException.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(applicationException.Message)]));
            }
            catch (Exception exception)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
        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);
        }
Пример #20
0
        /// <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);
        }
Пример #21
0
        public HttpResponseMessage GetUserAvatar([FromUri] GetUserAvatarRequest request)
        {
            if (request == null || !ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            LogRequest(request);
            ulong temp = 0;


            //uID = HttpUtility.UrlEncode(uID);
            request.Uid = request.Uid.Trim();
            NeeoUser     user     = new NeeoUser(request.Uid);
            NeeoFileInfo filePath = null;
            ulong        avatarTimeStamp;

            switch (user.GetAvatarState(request.Ts, out avatarTimeStamp, out filePath))
            {
            case AvatarState.NotExist:
                return(Request.CreateResponse(HttpStatusCode.NotFound));

            case AvatarState.Modified:
                string url = NeeoUrlBuilder.BuildAvatarUrl(request.Uid, request.Ts, request.Dim);
                return(RedirectServiceToUrl(url, avatarTimeStamp));

            case AvatarState.NotModified:
                return(Request.CreateResponse(HttpStatusCode.NotModified));

            default:
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }


            //}
            //else
            //{
            //    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //}
        }
Пример #22
0
        public McrData GetMcrDetails(string userID, bool flush)
        {
            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(NeeoUser.GetMcrDetails(userID, flush));
                }
                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(null);
            }
            else
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                return(null);
            }
            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //       return null;
            //   }
        }
Пример #23
0
 /// <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);
     }
 }
Пример #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static List <GroupInfo> GetUserGroupsDetails(NeeoUser user)
        {
            string[]         delimeter          = { "," };
            DbManager        dbManager          = new DbManager();
            DataTable        dtUserGroupDetails = dbManager.GetUserGroupsDetails(user.UserJid);
            List <GroupInfo> groupList          = new List <GroupInfo>();

            if (dtUserGroupDetails.Rows.Count > 0)
            {
                groupList =
                    dtUserGroupDetails.AsEnumerable()
                    .Select(dr => new GroupInfo()
                {
                    Id           = dr.Field <string>("name"),
                    Subject      = dr.Field <string>("subject"),
                    Owner        = dr.Field <string>("admin"),
                    Creator      = dr.Field <string>("creatorId"),
                    Participants = dr.Field <string>("participants").EndsWith(delimeter[0]) ? dr.Field <string>("participants").Substring(0, dr.Field <string>("participants").Length - 1).Split(delimeter, StringSplitOptions.None) : null,
                    CreationDate = dr.Field <string>("creationDate")
                })
                    .ToList();
            }
            return(groupList);
        }
Пример #25
0
        public async Task <HttpResponseMessage> UpdateUserPersonalData([FromBody] UserPersonalData model)
        {
            try
            {
                LogRequest(model);
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                NeeoUser currentUser        = new NeeoUser(model.username);
                bool     operationCompleted = await System.Threading.Tasks.Task.Run(() => currentUser.UpdateUserPersonalData(model));

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (ApplicationException applicationException)
            {
                return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(applicationException.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(applicationException.Message)]));
            }
            catch (Exception exception)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Пример #26
0
        public async Task <HttpResponseMessage> CreateXMLChatBackup([FromBody] ChatBackupDTO chatBackupDTO)
        {
            NeeoUser neeoUser = new NeeoUser("0");

            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                bool operationCompleted = await System.Threading.Tasks.Task.Run(() => neeoUser.CreateXMLChatBackup(chatBackupDTO.sender, chatBackupDTO.messagesXml));

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (ApplicationException applicationException)
            {
                return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(applicationException.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(applicationException.Message)]));
            }
            catch (Exception exception)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Пример #27
0
        public async Task <HttpResponseMessage> GetLastSeen(BaseRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            try
            {
                NeeoUser user   = new NeeoUser(request.Uid.Trim());
                var      result = await user.GetLastSeenTimeAsync();

                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (ApplicationException applicationException)
            {
                return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(applicationException.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(applicationException.Message)]));
            }
            catch (Exception exception)
            {
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, 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);
        }
Пример #29
0
        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 }
            }));
        }
        public HttpResponseMessage GetCapability([FromBody] CapabilityRequest capabilityRequest)
        {
            //capabilityRequest.Uid = (capabilityRequest.Uid != null) ? capabilityRequest.Uid.Trim() : capabilityRequest.Uid;
            #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 ===> " + JsonConvert.SerializeObject(capabilityRequest));
            }

            #endregion

            //#region user authentication

            //IEnumerable<string> headerValues;
            //string keyFromClient = "";
            //if (Request.Headers.TryGetValues("key", out headerValues))
            //{
            //    keyFromClient = headerValues.First();
            //}

            //if (!NeeoUtility.AuthenticateUserRequest(capabilityRequest.UID, keyFromClient))
            //else
            //{
            //    return Request.CreateResponse(HttpStatusCode.Unauthorized);
            //}
            if (ModelState.IsValid)
            {
                ulong temp = 0;
                if (ulong.TryParse(capabilityRequest.Uid, out temp) && capabilityRequest.Cap > 0 && capabilityRequest.Cap < 128)
                {
                    NeeoUser neeoUser = new NeeoUser(capabilityRequest.Uid.Trim());
                    try
                    {
                        Dictionary <string, string> contactsAppVersionDictionary = neeoUser.GetContactsAppVersion(capabilityRequest.Contacts);
                        Capability capability = null;
                        Dictionary <string, Capability> contactsAppCapabilities = new Dictionary <string, Capability>();
                        foreach (var item in contactsAppVersionDictionary)
                        {
                            capability = new Capability(VersionCapability.GetVersionCapability(item.Value.ToUpper()));
                            capability.SetRequestedCapabilities(capabilityRequest.Cap);
                            contactsAppCapabilities.Add(item.Key, capability);
                            capability = null;
                        }

                        CapabilityResponse capabilityResponse = new CapabilityResponse()
                        {
                            UID = capabilityRequest.Uid, ContactsAppCapabilities = contactsAppCapabilities
                        };
                        return(Request.CreateResponse(HttpStatusCode.OK, capabilityResponse));
                    }
                    catch (ApplicationException appEx)
                    {
                        return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(appEx.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(appEx.Message)]));
                    }
                    catch (Exception appEx)
                    {
                        return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(appEx.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(appEx.Message)]));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, NeeoDictionaries.HttpStatusCodeDescriptionMapper[(int)HttpStatusCode.BadRequest]));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, NeeoDictionaries.HttpStatusCodeDescriptionMapper[(int)HttpStatusCode.BadRequest]));
            }
        }