示例#1
0
        public static void UpdateLocalFan(Fan fan, TouchpointResponse response)
        {
            var xml = response.ResponseXml;

            if (xml.Contains("<contactid>"))
            {
                fan.TouchpointContactID = xml.ExtractTextBetween("<contactid>", "</contactid>").ToInt();
                if (xml.Contains("<firstname>"))
                {
                    fan.FirstName = xml.ExtractTextBetween("<firstname>", "</firstname>");
                }
                if (xml.Contains("<lastname>"))
                {
                    fan.LastName = xml.ExtractTextBetween("<lastname>", "</lastname>");
                }
                if (xml.Contains("<gender>"))
                {
                    fan.Gender = xml.ExtractTextBetween("<gender>", "</gender>");
                }
                if (xml.Contains("<email>"))
                {
                    fan.Email = xml.ExtractTextBetween("<email>", "</email>");
                }
                if (xml.Contains("<mobile>"))
                {
                    fan.Mobile = xml.ExtractTextBetween("<mobile>", "</mobile>");
                }
                if (xml.Contains("<city>"))
                {
                    fan.City = xml.ExtractTextBetween("<city>", "</city>");
                }
                if (xml.Contains("<postcode>"))
                {
                    fan.PostCode = xml.ExtractTextBetween("<postcode>", "</postcode>");
                }
                if (xml.Contains("<country>"))
                {
                    fan.Country = xml.ExtractTextBetween("<country>", "</country>");
                }
                if (xml.Contains("<birthdate>"))
                {
                    fan.DateOfBirth = xml.ExtractTextBetween("<birthdate>", "</birthdate>").ConvertToDate(null);
                }
                if (xml.Contains("<mobilepermission>"))
                {
                    fan.MobilePermission = xml.ExtractTextBetween("<mobilepermission>", "</mobilepermission>").ToBool();
                }
                if (xml.Contains("<emailpermission>"))
                {
                    fan.EmailPermission = xml.ExtractTextBetween("<emailpermission>", "</emailpermission>").ToBool();
                }
                fan.LastSyncDate = DateTime.Now;
                fan.Save();
            }
        }
示例#2
0
        /// <summary>
        /// Core API calling method
        /// </summary>
        private static TouchpointResponse SendTouchpointRequest(Http.HttpVerbConst httpMethod, string requestUrl, string data)
        {
            string baseUrl    = TouchpointAPIUrl + "rest/core/" + TouchpointAPICompanyID + "/" + TouchpointAPIPartitionID + "/";
            string url        = baseUrl + requestUrl;
            string userAgent  = Web.Request.UserAgent;
            string remoteHost = "127.0.0.1";

            var headers = new WebHeaderCollection();

            headers["X-Touchpoint-API-Version"] = "1.1";
            headers["Remote-Host"] = remoteHost;
            headers["User-Agent"]  = userAgent;

            headers["X-Touchpoint-Application-Key"] = TouchpointAPIKey;
            headers["Authorization"] = GetAuthorization(httpMethod, url, remoteHost, userAgent);
            headers["Accept"]        = "application/xml";

            // call the API
            var xml = Http.Request(httpMethod, url, data, headers);

            bool isDebug = false;

            if (isDebug)
            {
                Web.WriteLine("Touchpoint Request: " + httpMethod + " url:" + url);
                Web.WriteLine("Data: " + bwbXml.PrettyPrintXml(data));
                Web.WriteLine("Response: " + bwbXml.PrettyPrintXml(xml));
            }
            else
            {
                Logging.dlog("Touchpoint Request: " + httpMethod + " url:" + url);
                Logging.dlog("Data: " + data);
                Logging.dlog("Response: " + xml);
            }

            // compose response
            var result = new TouchpointResponse();

            result.RequestUrl  = url;
            result.RequestXml  = data;
            result.ResponseXml = xml;
            if (xml.Contains("<errors>"))
            {
                result.ErrorMessage = xml;
                if (xml.Contains("request.attribute.uniqueconstraint.violated") && xml.Contains("attributeid=email"))
                {
                    result.ErrorMessage = "There seems to be an existing Lion account that uses the email you entered.";
                }
                else if (xml.Contains("failedauthentication.invalidpassword"))
                {
                    result.ErrorMessage = "Your password is incorrect.";
                }
                else if (xml.Contains("failedauthentication.invalidmatchvalue"))
                {
                    result.ErrorMessage = "There does not seem to be an existing Lion account with the email you entered.";
                }
                else if (xml.Contains("failedauthentication.blankpassword"))
                {
                    result.ErrorMessage = "Please enter your password.";
                }
                else if (xml.Contains("failedauthentication.maximumloginattemptsexceeded"))
                {
                    result.ErrorMessage = "Maximum login attempts exceeded. Please wait 15 minutes and try again.";
                }
                else if (xml.Contains("failedauthentication."))
                {
                    result.ErrorMessage = "Failed authentication.";
                }
                else if (xml.Contains("request.attribute.uniqueconstraint.violated") && xml.Contains("attributeid=mobile"))
                {
                    result.ErrorMessage = "There seems to be an existing Lion account that uses the mobile phone number you entered.";
                }
                else if (xml.Contains("request.attribute.invalidvalue") && xml.Contains("attributeid=userpassword"))
                {
                    result.ErrorMessage = "Your password must be at least 6 chars long and contain at least one number and one letter.";
                }
                else if (xml.Contains("message"))
                {
                    result.ErrorMessage = xml.ExtractTextBetween("<message>", "</message>");
                }
                if (result.ErrorMessage.IsBlank() && xml.Contains("errorcode"))
                {
                    result.ErrorMessage = xml.ExtractTextBetween("<errorcode>", "</errorcode>");
                }
                if (result.ErrorMessage.IsBlank())
                {
                    result.ErrorMessage = "Unknown Touchpoint API error";
                }
            }
            if (xml.Contains("<contactid>"))
            {
                result.ContactID = xml.ExtractTextBetween("<contactid>", "</contactid>").ToInt();
            }
            if (xml.Contains("<statuscode>"))
            {
                result.StatusCode = xml.ExtractTextBetween("<statuscode>", "</statuscode>").ToInt();
            }
            return(result);
        }