예제 #1
0
 private BeaconEntity TrackPageEvent(string id, SpoofedHttpRequestBase spoofedRequest, PageEventType eventType, string page, string contactId, string data = null, string dataKey = null, IDictionary <string, string> extras = null, string monetaryValue = "0")
 {
     return(this.ExecuteTrackingRequest(string.Format("[PageVisit] : Page = {0} : Event = {1} : CID = {2}", page, eventType, contactId), delegate
     {
         if (string.IsNullOrWhiteSpace(id))
         {
             throw HttpExceptionHelper.BadRequest("Bad Request", "No event identifier was specified.");
         }
         PageEventParameters pageEventParameters;
         if (id.IsGuid())
         {
             pageEventParameters = new PageEventParameters(spoofedRequest.Url, new ID(id), eventType, contactId);
         }
         else
         {
             pageEventParameters = new PageEventParameters(spoofedRequest.Url, id, eventType, contactId);
         }
         pageEventParameters.Data = data;
         pageEventParameters.DataKey = dataKey;
         pageEventParameters.Extras = extras;
         if (eventType == PageEventType.Outcome)
         {
             decimal monetaryValue2;
             if (!decimal.TryParse(monetaryValue, out monetaryValue2))
             {
                 throw HttpExceptionHelper.BadRequest("Bad Request", "The outcome monetary value is invalid.");
             }
             pageEventParameters.MonetaryValue = monetaryValue2;
         }
         return this.trackingManager.TrackPageEvent(this.httpContextBase.Request, spoofedRequest, this.httpContextBase.Response, pageEventParameters);
     }));
 }
예제 #2
0
        protected BeaconEntity ExecuteTrackingRequest(string requestInfo, Func <TrackingResult> implementation)
        {
            BeaconEntity result;

            try
            {
                string text;
                if (!this.TryGetSessionId(out text))
                {
                    throw HttpExceptionHelper.BadRequest("Bad Request", "Session could not be initialized with the details provided.");
                }
                TrackingResult trackingResult = implementation();
                if (trackingResult == null)
                {
                    throw HttpExceptionHelper.InternetServerError("Unexpected server error", "Tracking result could not be determined.");
                }
                if (trackingResult.ResultCode != TrackingResultCode.Success)
                {
                    this.logger.Debug(string.Format("[FXM Tracking] [Failed] : Session = {0} : Code : {1} : Message : {2} : {3}", new object[]
                    {
                        text,
                        trackingResult.ResultCode,
                        trackingResult.Message,
                        requestInfo
                    }), null);
                    throw HttpExceptionHelper.BadRequest(trackingResult.ResultCode.ToString(), trackingResult.Message);
                }
                this.logger.Debug((!trackingResult.DoNotTrack) ? string.Format("[FXM Tracking] : Session = {0} : {1}", text, requestInfo) : string.Format("[FXM Tracking] [DoNotTrack] : Session = {0} : {1}", text, requestInfo), null);
                BeaconEntity beaconEntity = (BeaconEntity)trackingResult;
                beaconEntity.SessionId = text;
                result = beaconEntity;
            }
            catch (HttpResponseException exception)
            {
                this.logger.Error(string.Format("[FXM Tracking] [Error] : {0}", requestInfo), exception, typeof(BeaconController));
                throw;
            }
            catch (Exception ex)
            {
                this.logger.Error(string.Format("[FXM Tracking] [Error] : {0}", requestInfo), ex, typeof(BeaconController));
                throw HttpExceptionHelper.InternetServerError("Unexpected server error", ex.Message);
            }
            return(result);
        }
예제 #3
0
        protected SpoofedHttpRequestBase GetSpoofedRequest(string page, string referrer)
        {
            Uri url;

            if (string.IsNullOrWhiteSpace(page) || !Uri.TryCreate(page, UriKind.Absolute, out url))
            {
                throw HttpExceptionHelper.BadRequest("Bad Request", "No valid page was specified.");
            }
            Uri urlReferrer = null;

            if (!string.IsNullOrEmpty(referrer) && !Uri.TryCreate(referrer, UriKind.RelativeOrAbsolute, out urlReferrer))
            {
                throw HttpExceptionHelper.BadRequest("Bad Request", "An invalid referrer was specified.");
            }
            SpoofedHttpRequestBase spoofedHttpRequestBase = new SpoofedHttpRequestBase(this.httpContextBase.Request);

            spoofedHttpRequestBase.SetUrl(url);
            spoofedHttpRequestBase.SetUrlReferrer(urlReferrer);
            return(spoofedHttpRequestBase);
        }