Exemple #1
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);
            }
        }
Exemple #2
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));
            }
        }
        /// <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);
            }
        }
Exemple #4
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);
        }
        /*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);
        }
Exemple #6
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;
            //}
        }
Exemple #7
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;
            //}
        }
Exemple #8
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);

            //}
        }
Exemple #9
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);

            //}
        }
Exemple #10
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);

            //}
        }
Exemple #11
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);
            }
        }
Exemple #12
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);
            }
        }
Exemple #13
0
        /// <summary>
        /// Deletes user account and its all data from Neeo.
        /// </summary>
        /// <param name="uID">A string containing the user id. </param>


        #endregion

        public void UnregisterUser(string uID)
        {
            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, 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
            try
            {
                NeeoActivation.DeleteUserAccount(uID);
            }
            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
            //{
            //    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //}
        }
        public string GetMcrCount(string userID)
        {
            userID = (userID != null) ? userID.Trim() : userID;
            //         #region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( userID, keyFromClient))
            //{
            //#endregion

            ulong temp;

            if (!NeeoUtility.IsNullOrEmpty(userID) && ulong.TryParse(userID, out temp))
            {
                try
                {
                    return(NeeoVoipApi.GetMcrCount(userID));
                }
                catch (ApplicationException applicationException)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(applicationException.Message)));
                }
                catch (Exception exception)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception);
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError);
                }
                return("");
            }
            else
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                return("");
            }
            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //       return "";
            //   }
        }
Exemple #15
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);
     }
 }
        /// <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);
        }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uID"></param>
        /// <param name="gID"></param>
        /// <param name="reqType"></param>
        public void GetGroupIcon(string uID, string gID, string reqType = "GET")
        {
            #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
                {
                    if (!NeeoGroup.GroupIconExists(gID))
                    {
                        NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotFound);
                    }
                    else
                    {
                        string url =
                            NeeoUrlBuilder.BuildFileUrl(ConfigurationManager.AppSettings[NeeoConstants.FileServerUrl], gID,
                                                        FileCategory.Group, MediaType.Image);
                        RedirectServiceToUrl(url);
                    }
                }
                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);

            //}
        }
Exemple #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uID"></param>
        /// <param name="data"></param>
        /// <param name="mimeType"></param>
        /// <param name="recipientCount"></param>
        /// <returns></returns>
        public string UploadFile(string uID, string data, ushort mimeType, ushort recipientCount)
        {
            #region log user request and response

            /***********************************************
            *  To log user request
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                    "Request ===> senderID : " + uID + ", fileData : " + data);
            }

            #endregion

            string result = null;


            if (!NeeoUtility.IsNullOrEmpty(uID) && Enum.IsDefined(typeof(MimeType), mimeType) && (recipientCount > 0 && recipientCount < 255) &&
                !NeeoUtility.IsNullOrEmpty(data))
            {
                NeeoUser sender = new NeeoUser(uID);

                try
                {
                    File file = new File()
                    {
                        Data = data, FileOwner = uID, MediaType = MediaType.Image, MimeType = (MimeType)mimeType
                    };
                    if (sender.UploadFile(file, FileClassfication.SharedFile, recipientCount))
                    {
                        result = file.FileUrl;
                    }

                    #region log user request and response

                    /***********************************************
                    *  To log user response
                    ***********************************************/
                    if (_logRequestResponse)
                    {
                        LogManager.CurrentInstance.InfoLogger.LogInfo(
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                            "Response ===> " + result);
                    }

                    #endregion

                    return(result);
                }
                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
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            return(null);
        }
Exemple #19
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)
        {
            userID = (userID != null) ? userID.Trim() : userID;


            #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 : " + userID + ", timeStamp : " + timeStamp +
                    ", requiredDimension : " + requiredDimension);
            }

            #endregion
            //        #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 = 0;

            if (NeeoUtility.IsNullOrEmpty(userID) || !ulong.TryParse(userID, out temp))
            {
                NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.BadRequest);
            }
            else
            {
                userID = HttpUtility.UrlEncode(userID);
                NeeoUser     user     = new NeeoUser(userID);
                NeeoFileInfo fileInfo = null;
                ulong        avatarTimeStamp;
                switch (user.GetAvatarState(timeStamp, out avatarTimeStamp, out fileInfo))
                {
                case AvatarState.NotExist:
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotFound);
                    break;

                case AvatarState.Modified:
                    string url = NeeoUrlBuilder.BuildAvatarUrl(userID, timeStamp, requiredDimension);
                    RedirectServiceToUrl(url, avatarTimeStamp);
                    break;

                case AvatarState.NotModified:
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.NotModified);
                    break;
                }
            }
            //}
            //else
            //{
            //    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //}
        }
Exemple #20
0
        /// <summary>
        /// Updates user's device token into the database for push notifications.
        /// </summary>
        /// <param name="opID">an short integer specifying the type of the operation to be performed.</param>
        /// <param name="uID">A string containing phone number as user id.</param>
        /// <param name="deviceToken">A 64-character string indicating the user's device token.</param>
        /// <returns>true if the device token is successfully updated in database; otherwise, false.</returns>
        public bool DeviceToken(short opID, string uID, UserAgent client)
        {
            uID = (uID != null) ? uID.Trim() : uID;
            const string deletionValue = "-1";

            #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 ===> opID : " + opID + ", userID : " + uID + ", client : " + JsonConvert.SerializeObject(client));
            }

            #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 (client != null)
            {
                OperationType operationType = (OperationType)opID;
                if ((Enum.IsDefined(typeof(DevicePlatform), client.DP) &&
                     Enum.IsDefined(typeof(PushNotificationSource), client.Pns) &&
                     !NeeoUtility.IsNullOrEmpty(client.DToken) && !NeeoUtility.IsNullOrEmpty(uID) &&
                     !NeeoUtility.IsNullOrEmpty(client.DVenID) && Enum.IsDefined(typeof(OperationType), opID) &&
                     operationType == OperationType.Update))
                {
                    //do nothing
                }
                else if ((Enum.IsDefined(typeof(DevicePlatform), client.DP) &&
                          Enum.IsDefined(typeof(PushNotificationSource), client.Pns) && !NeeoUtility.IsNullOrEmpty(uID) &&
                          !NeeoUtility.IsNullOrEmpty(client.DVenID) && Enum.IsDefined(typeof(OperationType), opID) &&
                          operationType == OperationType.Delete))
                {
                    client.DToken = deletionValue;
                }
                else
                {
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                    return(false);
                }
                NeeoUser user = new NeeoUser(uID.Trim());
                try
                {
                    return(user.UpdateUserDeviceInfo(null,
                                                     new DeviceInfo()
                    {
                        DeviceToken = client.DToken?.Trim(),
                        DeviceTokenVoIP = client.DTokenVoIP?.Trim(),
                        PushNotificationSource = (PushNotificationSource)client.Pns,
                        DeviceVenderID = client.DVenID,
                        DevicePlatform = (DevicePlatform)client.DP
                    }, true));
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                    return(false);
                }
                catch (Exception exp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError);
                    return(false);
                }
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(false);
            //}
            //else
            //{
            //    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //    return false;
            //}
        }
Exemple #21
0
        /// <summary>
        /// Removes user's device token from database to stop push notifications.
        /// </summary>
        /// <param name="userID">A string containing phone number as user id.</param>
        /// <returns>true if the device token is successfully removed; otherwise, false.</returns>

        /*public bool RemoveUserDeviceToken(string userID)
         * {
         *  if (!NeeoUtility.IsNullOrEmpty(userID))
         *  {
         *      NeeoUser user = new NeeoUser(userID);
         *      try
         *      {
         *          if (user.UpdateUserDeviceToken(null))
         *          {
         *              return true;
         *          }
         *          else
         *          {
         *              SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser);
         *              return false;
         *          }
         *      }
         *      catch (ApplicationException appExp)
         *      {
         *          SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
         *          return false;
         *      }
         *      catch (Exception exp)
         *      {
         *          LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
         *          SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError);
         *          return false;
         *      }
         *  }
         *  else
         *  {
         *      SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
         *      return false;
         *  }
         * }
         */
        #endregion

        #endregion

        #region Checking Application Operatibility

        /// <summary>
        /// Checks application operatibility and update the user device information in the database for a register user.
        /// </summary>
        /// <param name="uID">A string containing phone number as user id.</param>
        /// <param name="client">An object containing the client information.</param>
        public string CheckAppCompatibility(string uID, UserAgent client)
        {
            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, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> uID : " + uID + ", client : " + JsonConvert.SerializeObject(client));
            }

            #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 (client != null)
            {
                ulong tempPhoneNumber = 0;
                if (Enum.IsDefined(typeof(DevicePlatform), client.DP) && !NeeoUtility.IsNullOrEmpty(client.OsVer) &&
                    !NeeoUtility.IsNullOrEmpty(client.AppVer) && !NeeoUtility.IsNullOrEmpty(client.DVenID))
                {
                    switch (CheckCompatibility(client))
                    {
                    case AppCompatibility.Incompatible:
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.Incompatible);
                        break;

                    case AppCompatibility.IncompatibleAppVersion:
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.Incompatible);
                        break;

                    case AppCompatibility.IncompatibleOsVersion:
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.Incompatible);
                        break;

                    case AppCompatibility.Compatible:

                        if (!NeeoUtility.IsNullOrEmpty(uID))
                        {
                            if (ulong.TryParse(uID, out tempPhoneNumber))
                            {
                                NeeoUser user = new NeeoUser(uID);

                                try
                                {
                                    if (!user.UpdateUserDeviceInfo(client.AppVer,
                                                                   new DeviceInfo()
                                    {
                                        DevicePlatform = (DevicePlatform)client.DP,
                                        DeviceVenderID = client.DVenID,
                                        OsVersion = client.OsVer
                                    }, false))
                                    {
                                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser);
                                    }
                                }
                                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
                            {
                                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                }
            }
            else
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }

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

            //}
            return("OK");
        }
Exemple #22
0
        /// <summary>
        /// Updates user information into the database and the profile picture.
        /// </summary>
        /// <param name="userID">A string containing phone number as user id.</param>
        /// <param name="name">A string containing the name of the user.</param>
        /// <param name="fileData">A base64 encoded string containing the file data.</param>
        /// <returns>
        /// true if information is successfully updated; otherwise, false.
        /// </returns>
        public bool UpdateUserInformation(string userID, string name, string fileData)
        {
            userID   = (userID != null) ? userID.Trim() : userID;
            name     = (name != null) ? name.Trim() : name;
            fileData = (fileData != null) ? fileData.Trim() : fileData;
            bool  isUpdated = false;
            ulong temp      = 0;

            #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 : " + userID + ", name : " + name);
            }

            #endregion

            //#region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //if (NeeoUtility.AuthenticateUserRequest(userID, keyFromClient))
            //{
            //#endregion

            if (NeeoUtility.IsNullOrEmpty(userID) || !ulong.TryParse(userID, out temp))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            else if (NeeoUtility.IsNullOrEmpty(name))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            else
            {
                NeeoUser user = new NeeoUser(userID);
                try
                {
                    isUpdated = user.UpdateUserProfile(name, new LibNeeo.IO.File()
                    {
                        Data = fileData
                    });
                    #region old impl
                    //using (TransactionScope scope = new TransactionScope())
                    //{
                    //    if (!user.UpdateUsersDisplayName(name))
                    //    {
                    //        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser);
                    //    }
                    //    else if (NeeoUtility.IsNullOrEmpty(fileData))
                    //    {
                    //        isCompleted = true;
                    //        scope.Complete();
                    //    }
                    //    else
                    //    {
                    //        LibNeeo.IO.File file = new LibNeeo.IO.File()
                    //        {
                    //            Data = fileData,
                    //            FileOwner = userID,
                    //            MediaType = MediaType.Image,
                    //            MimeType = MimeType.Image_jpeg
                    //        };
                    //        if (user.SaveFile(file, FileCategory.Profile))
                    //        {
                    //            isCompleted = true;
                    //            scope.Complete();
                    //        }
                    //    }
                    //}
                    #endregion
                }
                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.ServerInternalError);
                }
            }
            return(isUpdated);
            //}
            //else
            //{
            //   NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //    return false;
            //}
        }
Exemple #23
0
        /*They will be deprecated in future.*/

        /// <summary>
        /// Sends activation code to the phone number provided in <paramref name="phoneNumber"/>.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="phoneNumber">A phone number on which activation code has to be sent.</param>
        /// <param name="devicePlatform">Platform of the user's device.</param>
        /// <param name="activationCode">A code that has to be sent on the give phone number.</param>
        /// <param name="isResend">A bool value indicating this is a resending code request if true,otherwise false (default value). </param>
        /// <param name="isRegenerated">A bool value indicating this is a regenerated code sending request if true,otherwise false (default value). </param>
        /// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>

        public int SendActivationCode(string phoneNumber, short devicePlatform, string activationCode, bool isResend, bool isRegenerated)
        {
            phoneNumber    = (phoneNumber != null) ? phoneNumber.Trim() : phoneNumber;
            activationCode = (activationCode != null) ? activationCode.Trim() : activationCode;
            int smsSendingResult = (int)SmsSendingStatus.SendingFailed;

            #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 ===> phoneNumber : " + phoneNumber + ", devicePlatform : " + devicePlatform +
                    ", activationCode : " + activationCode + ", isResend : " + isResend + ", isRegenerated : " +
                    isRegenerated);
            }

            #endregion

            //#region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( phoneNumber, keyFromClient))
            //{
            //#endregion

            DevicePlatform userDevicePlatform = (DevicePlatform)devicePlatform;
            uint           tempActivationCode = 0;
            ulong          tempPhoneNumber    = 0;
            if (!NeeoUtility.IsNullOrEmpty(phoneNumber) && !NeeoUtility.IsNullOrEmpty(activationCode) && Enum.IsDefined(typeof(DevicePlatform), devicePlatform) && uint.TryParse(activationCode, out tempActivationCode) && ulong.TryParse(phoneNumber, out tempPhoneNumber))
            {
                try
                {
                    if (NeeoUtility.IsPhoneNumberInInternationalFormat(phoneNumber))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(smsSendingResult);
                    }
                    if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber)) && _numberValidityCheck)
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(smsSendingResult);
                    }
                    smsSendingResult = NeeoActivation.SendActivationCodeToUnBlockedUser(phoneNumber, userDevicePlatform, activationCode, isResend, isRegenerated);
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }
                return(smsSendingResult);
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(smsSendingResult);

            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //       return smsSendingResult;
            //   }
        }
Exemple #24
0
        /// <summary>
        /// Sends activation code to the phone number provided in <paramref name="ph"/>. It is a wrapping method with short parameter name.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ph">A phone number on which activation code has to be sent.</param>
        /// <param name="dP">Platform of the user's device.</param>
        /// <param name="actCode">A code that has to be sent on the give phone number.</param>
        /// <param name="isRes">A bool value indicating this is a resending code request if true,otherwise false (default value). </param>
        /// <param name="isReg">A bool value indicating this is a regenerated code sending request if true,otherwise false (default value). </param>
        /// <param name="appKey">A string containing the appKey(For Android).</param>
        /// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>
        public int SendActCode(string ph, short dP, string actCode, bool isRes, bool isReg, string appKey, short sType)
        {
            #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 ===> phoneNumber : " + ph + ", devicePlatform : " + dP +
                    ", activationCode : " + actCode + ", isResend : " + isRes + ", isRegenerated : " + isReg + ", appKey : " + appKey + ", serviceType: " + sType);
            }

            #endregion

            //return this.SendActivationCode(ph, dP, actCode, isRes, isReg);
            ph      = (ph != null) ? ph.Trim() : ph;
            actCode = (actCode != null) ? actCode.Trim() : actCode;
            appKey  = appKey?.Trim();

            int                codeSendingResult  = (int)SmsSendingStatus.SendingFailed;
            DevicePlatform     userDevicePlatform = (DevicePlatform)dP;
            CodeSendingService codeSendingService = (CodeSendingService)sType;
            uint               tempActivationCode = 0;
            ulong              tempPhoneNumber    = 0;
            if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(actCode) && Enum.IsDefined(typeof(DevicePlatform), dP) && Enum.IsDefined(typeof(CodeSendingService), sType) && uint.TryParse(actCode, out tempActivationCode) && ulong.TryParse(ph, out tempPhoneNumber))
            {
                try
                {
                    if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(codeSendingResult);
                    }
                    if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(codeSendingResult);
                    }

                    if (codeSendingService == CodeSendingService.Call)
                    {
                        codeSendingResult = NeeoActivation.CallForActivationCode(ph, userDevicePlatform, actCode);
                    }
                    else
                    {
                        codeSendingResult = NeeoActivation.SendActivationCode(ph, userDevicePlatform, actCode, appKey);
                    }
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }

                return(codeSendingResult);
            }

            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(codeSendingResult);
        }
Exemple #25
0
        ///// <summary>
        ///// Sends activation code to the phone number provided in <paramref name="ph"/>. It is a wrapping method with short parameter name.
        ///// </summary>
        ///// <remarks>
        ///// </remarks>
        ///// <param name="ph">A phone number on which activation code has to be sent.</param>
        ///// <param name="dP">Platform of the user's device.</param>
        ///// <param name="actCode">A code that has to be sent on the give phone number.</param>
        ///// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>
        //public int SendCodeTest(string ph, short dP, string actCode)
        //{
        //    #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 ===> phoneNumber : " + ph + ", devicePlatform : " + dP +
        //            ", activationCode : " + actCode);
        //    }

        //    #endregion

        //    //return this.SendActivationCode(ph, dP, actCode, isRes, isReg);
        //    ph = (ph != null) ? ph.Trim() : ph;
        //    actCode = (actCode != null) ? actCode.Trim() : actCode;

        //    int smsSendingResult = (int)SmsSendingStatus.SendingFailed;
        //    DevicePlatform userDevicePlatform = (DevicePlatform)dP;
        //    uint tempActivationCode = 0;
        //    ulong tempPhoneNumber = 0;
        //    if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(actCode) && Enum.IsDefined(typeof(DevicePlatform), dP))
        //    {
        //        try
        //        {
        //            if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
        //            {
        //                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
        //                return smsSendingResult;
        //            }
        //            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
        //            {
        //                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
        //                return smsSendingResult;
        //            }
        //            smsSendingResult = NeeoActivation.SendActivationCodeTest(ph, userDevicePlatform, actCode);
        //        }
        //        catch (ApplicationException appExp)
        //        {
        //            NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
        //        }

        //        return smsSendingResult;
        //    }
        //    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
        //    return smsSendingResult;
        //}

        /// <summary>
        /// Registers and configures user account. It is a wrapping method with short parameter name.
        /// </summary>
        /// <param name="ph">A string containing phone number for registering account.</param>
        /// <param name="client">An object containing the client information.</param>
        /// <returns>true if the account is successfully registered on the server; otherwise, false.</returns>
        public bool RegisterAppUser(string ph, UserAgent client)

        {
            ph = (ph != null) ? ph.Trim() : ph;
            #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 ===> phoneNumber : " + ph + ", client : " + JsonConvert.SerializeObject(client));
            }

            #endregion

            //        #region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( ph, keyFromClient))
            //{
            //#endregion

            if (client != null)
            {
                ulong tempPhoneNumber = 0;

                if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(client.DVenID) && !NeeoUtility.IsNullOrEmpty(client.AppID) && Enum.IsDefined(typeof(DevicePlatform), client.DP) && Enum.IsDefined(typeof(PushNotificationSource), client.Pns) && ulong.TryParse(ph, out tempPhoneNumber) && !NeeoUtility.IsNullOrEmpty(client.AppVer) && !NeeoUtility.IsNullOrEmpty(client.OsVer) && !NeeoUtility.IsNullOrEmpty(client.DM))
                {
                    try
                    {
                        if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
                        {
                            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                            return(false);
                        }
                        if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
                        {
                            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                            return(false);
                        }
                        if (NeeoActivation.SetupUserAccount(ph, client.AppID, client.AppVer, new DeviceInfo()
                        {
                            DeviceModel = client.DM, DevicePlatform = (DevicePlatform)client.DP, DeviceVenderID = client.DVenID, DeviceToken = client.DToken?.Trim(), PushNotificationSource = (PushNotificationSource)client.Pns, OsVersion = client.OsVer, DeviceTokenVoIP = client.DTokenVoIP?.Trim()
                        }))
                        {
                            return(true);
                        }
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.TransactionFailure);
                        return(false);
                    }
                    catch (ApplicationException appExp)
                    {
                        NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                        return(false);
                    }
                }
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(false);

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

            //       return false;
            //   }
        }
Exemple #26
0
        /// <summary>
        /// Delete the user's profile picture from the server.
        /// </summary>
        /// <param name="uID">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 uID)
        {
            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);
            }

            #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))
            {
                try
                {
                    NeeoUser user = new NeeoUser(uID);
                    if (user.DeleteUserAvatar())
                    {
                        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);
            }
            //}
            //else
            //{
            //    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //    return false;
            //}
        }
Exemple #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uID"></param>
        /// <param name="data"></param>
        /// <param name="gID"></param>
        public void UploadGroupIcon(string uID, string data, string gID)
        {
            ulong temp = 0;

            uID = (uID != null) ? uID.Trim() : uID;

            #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


            if (NeeoUtility.IsNullOrEmpty(uID) || !ulong.TryParse(uID, out temp) ||
                NeeoUtility.IsNullOrEmpty(data) ||
                NeeoUtility.IsNullOrEmpty(gID))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            else
            {
                gID = gID.ToLower();
                try
                {
                    var file = new LibNeeo.IO.File()
                    {
                        Info = new NeeoFileInfo()
                        {
                            Creator   = uID,
                            MimeType  = MimeType.ImageJpeg,
                            MediaType = MediaType.Image
                        },
                        Data = data,
                    };
                    if (!NeeoGroup.SaveGroupIcon(uID, gID.ToLower(), file))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError);
                    }
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }
                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);

            //}
        }
Exemple #28
0
        /// <summary>
        /// Updates user information into the database and the profile picture.
        /// </summary>
        /// <param name="userID">A string containing phone number as user id.</param>
        /// <param name="name">A string containing the name of the user.</param>
        /// <param name="fileData">A base64 encoded string containing the file data.</param>
        /// <returns>true if information is successfully updated; otherwise, false.</returns>
        public bool UpdateUserInformation(string userID, string name, string fileData)
        {
            bool isCompletedSuccessfully = false;

            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                    "Request ===> userID : " + userID + ", name : " + name +
                    ", fileData : " + fileData);
            }

            #endregion

            if (!NeeoUtility.IsNullOrEmpty(userID))
            {
                if (name != null)
                {
                    NeeoUser user = new NeeoUser(userID);
                    try
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            if (user.UpdateUsersDisplayName(name))
                            {
                                if (!NeeoUtility.IsNullOrEmpty(fileData))
                                {
                                    File file = new File()
                                    {
                                        FileName  = NeeoUtility.ConvertToFileName(userID),
                                        Data      = fileData,
                                        FileOwner = userID,
                                        MediaType = MediaType.Image,
                                        MimeType  = MimeType.Image_jpeg
                                    };
                                    if (user.UploadFile(file, FileClassfication.Profile))
                                    {
                                        isCompletedSuccessfully = true;
                                        scope.Complete();
                                    }
                                }
                                else
                                {
                                    isCompletedSuccessfully = true;
                                    scope.Complete();
                                }
                            }
                            else
                            {
                                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser);
                            }
                        }
                        return(isCompletedSuccessfully);
                    }
                    catch (ApplicationException appExp)
                    {
                        NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                    }
                    catch (Exception exp)
                    {
                        LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError);
                    }
                    return(isCompletedSuccessfully);
                }
                else
                {
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                }
            }
            else
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            return(isCompletedSuccessfully);
        }
Exemple #29
0
        /// <summary>
        /// Checks the already uploaded file whether it still exist or not. If exists, its shared date-time and number of recipient information are updated.
        /// </summary>
        /// <param name="userID">A string containing the user id.</param>
        /// <param name="fileID">A string containing the file id.</param>
        /// <param name="recipientCount">An unsigned integer value containing the recipient count.</param>
        /// <returns>If true, file exists and information is updated; otherwise false.</returns>
        public bool ShareFile(string uID, string fID, ushort recipientCount)
        {
            uID = (uID != null) ? uID.Trim() : uID;
            fID = (fID != null) ? fID.Trim() : fID;
            bool   result    = false;
            ulong  temp      = 0;
            string resultUrl = null;

            #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 + ", recipientCount : " + recipientCount.ToString());
            }

            #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) &&
                (recipientCount == 0 || recipientCount >= 255) && NeeoUtility.IsNullOrEmpty(fID))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            else
            {
                NeeoUser user = new NeeoUser(uID);
                try
                {
                    result = SharedMedia.Share(user, fID, recipientCount);
                }
                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;
            //}
        }
Exemple #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uID"></param>
        /// <param name="data"></param>
        /// <param name="mimeType"></param>
        /// <param name="recipientCount"></param>
        /// <returns></returns>
        public string UploadFile(string uID, string fID, string data, ushort mimeType, ushort recipientCount)
        {
            ulong  temp      = 0;
            string resultUrl = null;

            uID = (uID != null) ? uID.Trim() : uID;
            fID = (fID != null) ? fID.Trim() : fID;
            fID = (fID != null) ? fID.Trim() : fID;


            #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 + ", mimeType : " + mimeType.ToString() + ", fID : " + fID + ", recipientCount : " + recipientCount.ToString());
            }

            #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) && !Enum.IsDefined(typeof(MimeType), mimeType) && (recipientCount == 0 || recipientCount >= 255) &&
                NeeoUtility.IsNullOrEmpty(data))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            else
            {
                if (!NeeoUtility.IsNullOrEmpty(fID))
                {
                    Guid resultingGuid;
                    if (!Guid.TryParse(fID, out resultingGuid))
                    {
                        LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" +
                                                                      "fID : " + fID + " is not parseable.");
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                        return(resultUrl);
                    }
                    fID = resultingGuid.ToString("N").ToLower();
                }

                NeeoUser sender = new NeeoUser(uID);
                try
                {
                    LibNeeo.IO.File file = new LibNeeo.IO.File()
                    {
                        Info = new NeeoFileInfo()
                        {
                            Creator = uID, MediaType = MediaType.Image, MimeType = (MimeType)mimeType, Name = fID
                        }, Data = data
                    };
                    if (SharedMedia.Save(sender, file, FileCategory.Shared, recipientCount))
                    {
                        resultUrl = file.Info.Url;
                    }
                    #region log user request and response

                    /***********************************************
                    *  To log user response
                    ***********************************************/
                    if (_logRequestResponse)
                    {
                        LogManager.CurrentInstance.InfoLogger.LogInfo(
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                            "Response ===> " + resultUrl);
                    }

                    #endregion
                }
                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(resultUrl);
            //}
            //else
            //{
            //    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //    return resultUrl;
            //}
        }