Пример #1
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);
        }
Пример #2
0
 public BeaconEntity StopTracking(string contactId = "", bool killContact = false, string endTime = "")
 {
     if (this.httpContextBase != null && this.httpContextBase.Session != null)
     {
         string arg;
         if (!this.TryGetSessionId(out arg))
         {
             HttpExceptionHelper.InternetServerError("Unexpected server error", "Session could not be initialized.");
         }
         this.logger.Debug(string.Format("[StopTracking]: CID: {0} SID: {1}", contactId, arg), null);
         HttpRequestBase httpRequestBase = this.httpContextBase.Request;
         if (!base.Request.Headers.Referrer.Host.Equals(base.Request.RequestUri.Host))
         {
             SpoofedHttpRequestBase spoofedHttpRequestBase = new SpoofedHttpRequestBase(this.httpContextBase.Request);
             spoofedHttpRequestBase.SetUrl(base.Request.Headers.Referrer);
             httpRequestBase = spoofedHttpRequestBase;
             IDomainMatcher domainMatcher;
             Language       language;
             if (!this.trackingManager.DomainIsValid(httpRequestBase, out domainMatcher, out language))
             {
                 throw new HttpResponseException(HttpStatusCode.BadRequest);
             }
             TrackPageVisitArgs args = new TrackPageVisitArgs(this.sitecoreContext, this.trackerProvider, this.httpContextBase.Request, this.httpContextBase.Response, httpRequestBase, new PageVisitParameters(this.httpContextBase.Request.Url, null, contactId), domainMatcher, false);
             InitializeTrackingCookieProcessor initializeTrackingCookieProcessor = new InitializeTrackingCookieProcessor();
             initializeTrackingCookieProcessor.Process(args);
             InitializeExternalTrackingProcessor initializeExternalTrackingProcessor = new InitializeExternalTrackingProcessor();
             initializeExternalTrackingProcessor.Process(args);
             InitializeContextSiteProcessor initializeContextSiteProcessor = new InitializeContextSiteProcessor();
             initializeContextSiteProcessor.Process(args);
         }
         else
         {
             Tracker.Initialize();
             Tracker.Current.Session.SetClassification(0, 0, false);
         }
         if (!string.IsNullOrWhiteSpace(endTime))
         {
             DateTime           dateTime    = DateTime.Parse(endTime, DateTimeFormatInfo.InvariantInfo);
             CurrentInteraction interaction = this.trackerProvider.Current.Interaction;
             Assert.IsNotNull(interaction, "interaction");
             TimeSpan t = DateTime.UtcNow - DateUtil.ToUniversalTime(dateTime);
             interaction.EndDateTime    = dateTime;
             interaction.StartDateTime -= t;
             Page[] pages = interaction.Pages;
             for (int i = 0; i < pages.Length; i++)
             {
                 Page page = pages[i];
                 page.DateTime -= t;
             }
         }
         this.httpContextBase.Session.Abandon();
         this.httpContextBase.Response.Cookies.Clear();
         if (killContact)
         {
             DateTime expires = new DateTime(1979, 1, 1, 0, 0, 0, DateTimeKind.Utc);
             string[] allKeys = this.httpContextBase.Request.Cookies.AllKeys;
             for (int j = 0; j < allKeys.Length; j++)
             {
                 string     text   = allKeys[j];
                 HttpCookie cookie = new HttpCookie(text)
                 {
                     Expires = expires,
                     Value   = string.Empty,
                     Domain  = this.httpContextBase.Request.Cookies.GetSafely(text).Domain
                 };
                 this.httpContextBase.Response.Cookies.Add(cookie);
             }
             this.httpContextBase.Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE")
             {
                 Domain  = "." + this.httpContextBase.Request.Url.Host,
                 Value   = string.Empty,
                 Expires = expires
             });
         }
     }
     return(new BeaconEntity
     {
         Id = "TBC",
         ContactId = string.Empty,
         SessionId = string.Empty,
         Url = string.Empty
     });
 }