Exemple #1
0
        public HttpResponseMessage GetProfileName([FromUri] BaseRequest request)
        {
            string result = null;

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

            try
            {
                request.Uid = request.Uid.Trim();
                NeeoUser user = new NeeoUser(request.Uid);
                result = user.GetUserProfileName();
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (ApplicationException appExp)
            {
                return(SetCustomResponseMessage("", (HttpStatusCode)(CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))));
            }
            catch (Exception exp)
            {
                LogManager.CurrentInstance.ErrorLogger.LogError(
                    MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Exemple #2
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 #3
0
        /// <summary>
        /// Gets the user's name and avatar base on the User ID.
        /// </summary>
        /// <param name="uID">A string containing the user id.</param>
        /// <returns>It returns the avatar and name in header.</returns>
        /// SyncProfile
        public HttpResponseMessage PostSyncProfile(string uID)
        {
            uID = (uID != null) ? uID.Trim() : uID;
            Stream resultStream = null;

            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    MethodBase.GetCurrentMethod().DeclaringType, 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;


            if (NeeoUtility.IsNullOrEmpty(uID) || !ulong.TryParse(uID, out temp))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            else
            {
                uID = uID.Trim();
                NeeoUser user = new NeeoUser(uID);

                try
                {
                    Request.Headers.Add("name", user.GetUserProfileName());
                    resultStream = user.GetAvatarStream();
                    return(Request.CreateResponse(HttpStatusCode.OK, resultStream));
                }
                catch (ApplicationException appExp)
                {
                    return(SetCustomResponseMessage("", (HttpStatusCode)(CustomHttpStatusCode)(Convert.ToInt32(appExp.Message))));
                }
                catch (Exception exp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                    return(Request.CreateResponse(HttpStatusCode.Ambiguous));
                }
            }

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