コード例 #1
0
        /*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);
        }
コード例 #2
0
        public HttpResponseMessage SyncUpContacts(ContactSyncRequest request)
        {
            Dictionary <string, object> responseData = new Dictionary <string, object>();

            responseData.Add("SyncUpContactsResult", null);

            if (request != null)
            {
                request.userID = (request.userID != null) ? request.userID.Trim() : request.userID;

                #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 : " +
                        request.userID + "- Contact List :" + JsonConvert.SerializeObject(request.contacts));
                }

                #endregion

                //#region user authentication

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

                //if (NeeoUtility.AuthenticateUserRequest(syncRequest.userID, keyFromClient))
                //{
                //    #endregion

                if (!NeeoUtility.IsNullOrEmpty(request.userID) && request.contacts != null)
                {
                    if (request.contacts.Length > 0)
                    {
                        NeeoUser user = new NeeoUser(request.userID);
                        try
                        {
                            var response = user.GetContactsRosterState(request.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 : " + request.userID + "- Contact List :" +
                                    JsonConvert.SerializeObject(response));
                            }

                            #endregion

                            responseData["SyncUpContactsResult"] = response;
                            return(Request.CreateResponse(HttpStatusCode.OK, responseData));
                        }
                        catch (ApplicationException appExp)
                        {
                            return(SetCustomResponseMessage(responseData,
                                                            (HttpStatusCode)(Convert.ToInt32(appExp.Message))));
                        }
                        catch (Exception exp)
                        {
                            LogManager.CurrentInstance.ErrorLogger.LogError(
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                            return(Request.CreateResponse(HttpStatusCode.InternalServerError, responseData));
                        }
                    }
                }
            }
            return(SetCustomResponseMessage(responseData, HttpStatusCode.BadRequest));

            //}
            //else
            //{
            //    return Request.CreateResponse(HttpStatusCode.Unauthorized, responseData);
            //}
        }