Exemplo n.º 1
0
        public static ExperienceLogResponse LogInitialEvent(int employerId)
        {
            var experienceResponse = new ExperienceLogResponse();
            var experienceLog      = new ExperienceLogRequest()
            {
                EmployerId = employerId,
                EventName  = "StartWebsite",
                LogComment = string.Format("Animations Website launched ")
            };

            var requestUrl = string.Format("v1/Animation/Experience/LogInitial/{0}",
                                           "AnzovinHandshakeId".GetConfigurationValue());

            try {
                using (var client = BaseService.GetClient()) {
                    var response = client.PostAsJsonAsync(requestUrl, experienceLog).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        experienceResponse = response.Content.ReadAsAsync <ExperienceLogResponse>().Result;
                    }
                }
            }
            catch (Exception exc) {
                HelperService.LogAnonEvent(ExperienceEvents.Error,
                                           exc.InnerException == null ?
                                           exc.Message :
                                           exc.InnerException.InnerException == null ?
                                           exc.InnerException.Message : exc.InnerException.InnerException.Message);
                experienceResponse.ExperienceUserId = Guid.NewGuid().ToString();
            }
            return(experienceResponse);
        }
Exemplo n.º 2
0
        public HttpResponseMessage LogExperienceEvent(string hsId, [FromBody] ExperienceLogRequest eventLogRequest)
        {
            HttpResponseMessage hrm = Request.CreateResponse(HttpStatusCode.Unauthorized);

            if (ValidateConsumer.IsValidConsumer(hsId))
            {
                hrm = Request.CreateErrorResponse(
                    HttpStatusCode.NoContent, "Unexpected Error");

                if (eventLogRequest.EmployerId > 0)
                {
                    AppendClientVersion(eventLogRequest);

                    using (GetEmployerConnString gecs = new GetEmployerConnString(eventLogRequest.EmployerId))
                    {
                        using (InsertExperienceLog iel = new InsertExperienceLog())
                        {
                            iel.ExperienceEventId   = eventLogRequest.EventId;
                            iel.ExperienceEventDesc = eventLogRequest.EventName;
                            if (Request.CCHID() > 0)
                            {
                                iel.CCHID = Request.CCHID();
                            }
                            if (eventLogRequest.CchId > 0)
                            {
                                iel.CCHID = eventLogRequest.CchId;
                            }
                            if (!string.IsNullOrEmpty(eventLogRequest.ContentId))
                            {
                                int contentId = eventLogRequest.ContentId.GetContentId();
                                if (contentId > 0)
                                {
                                    iel.ContentId = contentId;
                                }
                                else
                                {
                                    iel.ContentId = int.Parse(eventLogRequest.ContentId);
                                }
                            }
                            iel.ExperienceUserId = eventLogRequest.ExperienceUserId;
                            iel.Comment          = eventLogRequest.LogComment;
                            iel.DeviceId         = eventLogRequest.DeviceId;
                            iel.ClientVersion    = eventLogRequest.ClientVersion;

                            iel.PostData(gecs.ConnString);
                            if (iel.PostReturn == 1)
                            {
                                hrm = Request.CreateResponse(HttpStatusCode.OK);
                            }
                            else
                            {
                                hrm = Request.CreateErrorResponse(HttpStatusCode.NoContent,
                                                                  "Insert Experience Event Procedure Failed.");
                            }
                        }
                    }
                }
            }
            return(hrm);
        }
Exemplo n.º 3
0
 private void AppendClientVersion(ExperienceLogRequest request)
 {
     if (Request.Headers.Contains("X-Client-Version"))
     {
         request.ClientVersion = Request.Headers.GetValues("X-Client-Version").FirstOrDefault();
     }
 }
Exemplo n.º 4
0
        public static async Task LogAnonEvent(ExperienceLogRequest experienceLog)
        {
            var requestUrl = string.Format("v1/Animation/Experience/LogAnonEvent/{0}",
                                           "AnzovinHandshakeId".GetConfigurationValue());

            using (var client = BaseService.GetClient()) {
                var response = await client.PostAsJsonAsync(
                    requestUrl, experienceLog);
            }
        }
Exemplo n.º 5
0
        public static async Task LogUserEvent(ExperienceLogRequest experienceLog, string authHash)
        {
            var requestUrl = string.Format("v1/Animation/Experience/LogUserEvent/{0}",
                                           "AnzovinHandshakeId".GetConfigurationValue());

            using (var client = BaseService.GetClient()) {
                if (!client.DefaultRequestHeaders.Contains("AuthHash"))
                {
                    client.DefaultRequestHeaders.Add("AuthHash", authHash);
                }
                var response = await client.PostAsJsonAsync(
                    requestUrl, experienceLog);
            }
        }
Exemplo n.º 6
0
        public HttpResponseMessage LogInitialExperience(string hsId, [FromBody] ExperienceLogRequest eventLogRequest)
        {
            HttpResponseMessage hrm = Request.CreateResponse(HttpStatusCode.Unauthorized);

            if (ValidateConsumer.IsValidConsumer(hsId))
            {
                hrm = Request.CreateErrorResponse(
                    HttpStatusCode.NoContent, "Unexpected Error");

                if (eventLogRequest.EmployerId > 0)
                {
                    AppendClientVersion(eventLogRequest);

                    using (GetEmployerConnString gecs = new GetEmployerConnString(eventLogRequest.EmployerId))
                    {
                        try
                        {
                            using (InsertExperienceLog iel = new InsertExperienceLog())
                            {
                                ExperienceLogResponse elr = new ExperienceLogResponse
                                {
                                    ExperienceUserId = Guid.NewGuid().ToString()
                                };
                                iel.ExperienceEventId   = eventLogRequest.EventId;
                                iel.ExperienceEventDesc = eventLogRequest.EventName;
                                iel.ExperienceUserId    = elr.ExperienceUserId;
                                iel.Comment             = eventLogRequest.LogComment;
                                iel.DeviceId            = eventLogRequest.DeviceId;
                                iel.ClientVersion       = eventLogRequest.ClientVersion;

                                iel.PostData(gecs.ConnString);
                                hrm = Request.CreateResponse(HttpStatusCode.OK, elr);
                            }
                        }
                        catch (Exception exc)
                        {
                            hrm = Request.CreateErrorResponse(HttpStatusCode.NoContent, String.Format("Insert Experience Event Procedure Failed: {0}", exc.Message));
                        }
                    }
                }
            }
            return(hrm);
        }
        public void CanLogInitialExperience()
        {
            var ctx = UnitTestContext.Get(EnvironmentHelper.GetEnvironment(),
                                          "*****@*****.**");

            var experienceLogRequest = new ExperienceLogRequest {
                EmployerId = 21,
                EventName  = "Unit Test",
                LogComment = "confirming route works.",
                DeviceId   = "0"
            };

            var urlResult = ApiUtil.PostJson <HttpResponseMessage>(ctx,
                                                                   String.Format("Animation/Experience/LogInitial/{0}", ctx.Employer.HandshakeId),
                                                                   experienceLogRequest);

            Assert.IsNotNull(urlResult);
            Assert.AreEqual(HttpStatusCode.OK, urlResult.Item1);
        }
Exemplo n.º 8
0
        public static void LogUserEvent(ExperienceEvents experienceEvent, string message)
        {
            var experienceLog = new ExperienceLogRequest {
                EventId          = Convert.ToInt32(experienceEvent),
                EmployerId       = CampaignSessionModel.Current.EmployerId,
                ExperienceUserId = CampaignSessionModel.Current.ExperienceUserId,
                CchId            = CampaignSessionModel.Current.CchId
            };

            switch (experienceEvent)
            {
            case ExperienceEvents.AuthenticationSuccess:
                experienceLog.LogComment = string.Format("Authentication for {0} successful",
                                                         message);
                break;

            case ExperienceEvents.StartAnimation:
                experienceLog.LogComment = string.Format("Start Animation {0} ",
                                                         message);
                experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.EndAnimation:
                experienceLog.LogComment = string.Format("End Animation {0} ",
                                                         message);
                experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.StartQuiz:
                experienceLog.LogComment = string.Format("Start Quiz {0}", message);
                experienceLog.ContentId  = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.EndQuiz:
                experienceLog.LogComment = string.Format("End Quiz {0}", message);
                experienceLog.ContentId  = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.HelpfulYes:
                experienceLog.LogComment = string.Format("Animation {0} WAS Helpful",
                                                         message);
                experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.HelpfulNo:
                experienceLog.LogComment = string.Format("Animation {0} WAS NOT Helpful",
                                                         message);
                experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.ReplayAnimation:
                experienceLog.LogComment = string.Format("Replay Animation {0}", message);
                experienceLog.ContentId  = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.GoToCch:
                experienceLog.LogComment = string.Format("Go to CCH Website");
                experienceLog.ContentId  = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.GoToPlan:
                experienceLog.LogComment = string.Format("Go to Employer Plan Website");
                experienceLog.ContentId  = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.Error:
                experienceLog.LogComment = string.Format("Unexpected Error: {0}", message);
                break;

            default:
                experienceLog.LogComment = string.Format("Invalid Action");
                break;
            }
            var authHash = CampaignSessionModel.Current.AuthorizationHash;

            try {
                Task.Run(() => WebApiService.LogUserEvent(experienceLog, authHash));
            } catch (Exception ex) {
                throw new Exception(string.Format("Error in LogUserEvent.  ExperienceLogRequest values {0}",
                                                  experienceLog.GetValuesFoLog()), ex);
            }
        }
Exemplo n.º 9
0
        public static void LogAnonEvent(ExperienceEvents experienceEvent, string message)
        {
            var experienceLog = new ExperienceLogRequest
            {
                EventId          = Convert.ToInt32(experienceEvent),
                EmployerId       = CampaignSessionModel.Current.EmployerId,
                ExperienceUserId = CampaignSessionModel.Current.ExperienceUserId
            };

            switch (experienceEvent)
            {
            case ExperienceEvents.StartIntro:
                experienceLog.LogComment = string.Format("Start Intro Animation {0}",
                                                         message);
                experienceLog.ContentId = CampaignSessionModel.Current.IntroContentId.ToString();
                break;

            case ExperienceEvents.EndIntro:
                experienceLog.LogComment = string.Format("End Intro Animation {0} ",
                                                         message);
                experienceLog.ContentId = CampaignSessionModel.Current.IntroContentId.ToString();
                break;

            case ExperienceEvents.VisitResourcePage:
                experienceLog.LogComment = string.Format("Visit Resource Page {0} ", message);
                experienceLog.ContentId  = CampaignSessionModel.Current.ContentId.ToString();
                break;

            case ExperienceEvents.ExitAndroidApp:
                experienceLog.LogComment = string.Format("Exit Android App");
                break;

            case ExperienceEvents.ExitiOSApp:
                experienceLog.LogComment = string.Format("Exit iOS App");
                break;

            case ExperienceEvents.AuthenticationFail:
                experienceLog.LogComment = string.Format("Authentication {0} failed",
                                                         message);
                break;

            case ExperienceEvents.InvalidQueryParameters:
                experienceLog.LogComment = string.Format("Invalid format for query parameters: {0}", message);
                break;

            case ExperienceEvents.NoQueryParameters:
                experienceLog.LogComment = "Query parameters Not Found";
                break;

            case ExperienceEvents.StartWebsite:
                experienceLog.LogComment = string.Format("Animations Website launched ");
                break;

            case ExperienceEvents.LoadTimer:
                experienceLog.LogComment = string.Format("Load Timer: {0}",
                                                         message);
                break;

            case ExperienceEvents.Info:
                experienceLog.LogComment = string.Format("Info: {0}", message);
                break;

            case ExperienceEvents.Debug:
                experienceLog.LogComment = string.Format("Debug: {0}", message);
                break;

            case ExperienceEvents.Warning:
                experienceLog.LogComment = string.Format("Warning: {0}", message);
                break;

            // Following events require authentication from a Web API client
            //case ExperienceEvents.AuthenticationSuccess:
            //    experienceLog.LogComment = string.Format("Authentication {0} successful",
            //        message);
            //    break;
            //case ExperienceEvents.StartAnimation:
            //    experienceLog.LogComment = string.Format("Start Animation {0} ",
            //        message);
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    break;
            //case ExperienceEvents.EndAnimation:
            //    experienceLog.LogComment = string.Format("End Animation {0} ",
            //        message);
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    break;
            //case ExperienceEvents.StartQuiz:
            //    experienceLog.LogComment = string.Format("Start Quiz {0}", message);
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    break;
            //case ExperienceEvents.EndQuiz:
            //    experienceLog.LogComment = string.Format("End Quiz {0}", message);
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    break;
            //case ExperienceEvents.HelpfulYes:
            //    experienceLog.LogComment = string.Format("Animation {0} WAS Helpful",
            //        message);
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    break;
            //case ExperienceEvents.HelpfulNo:
            //    experienceLog.LogComment = string.Format("Animation {0} WAS NOT Helpful",
            //        message);
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    break;
            //case ExperienceEvents.ReplayAnimation:
            //    experienceLog.LogComment = string.Format("Replay Animation {0}", message);
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    experienceLog.ContentId = CampaignSessionModel.Current.ContentId.ToString();
            //    break;
            //case ExperienceEvents.GoToCch:
            //    experienceLog.LogComment = string.Format("Go to CCH Website");
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    break;
            //case ExperienceEvents.GoToPlan:
            //    experienceLog.LogComment = string.Format("Go to Employer Plan Website");
            //    experienceLog.CchId = CampaignSessionModel.Current.CchId;
            //    break;
            case ExperienceEvents.Error:
                experienceLog.LogComment = string.Format("Unexpected Error: {0}", message);
                break;

            default:
                experienceLog.LogComment = string.Format("Invalid Action");
                break;
            }
            try {
                Task.Run(() => WebApiService.LogAnonEvent(experienceLog));
            } catch (Exception ex) {
                throw new Exception(string.Format("Error in LogAnonEvent.  ExperienceLogRequest values {0}",
                                                  experienceLog.GetValuesFoLog()), ex);
            }
        }