Esempio n. 1
0
 public HttpResponseMessage SaveSession(AdSession Session)
 {
     if (Session.AdId != 0)
     {
         var httpContext = (HttpContextWrapper)Request.Properties["MS_HttpContext"];
         Session.UserIp = httpContext.Request.UserHostAddress;
         Session.UserLocale = httpContext.Request.UserLanguages[0];
         Session.UserLocation = "123";
         foreach (var activity in Session.Activities)
         {
             foreach (var click in activity.Clicks)
             {
                 click.ClickText = Generator.GenerateClickName(click);
                 click.ClickStamp = Generator.GenerateClickStamp(click);
             }
         }
         service.SaveAdSession(Session, true);
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     return Request.CreateResponse(HttpStatusCode.InternalServerError);
 }
Esempio n. 2
0
        public string GenerateStats(int AdID, string beginDate, string endDate)
        {
            DatabaseService.DBServiceClient db = new DatabaseService.DBServiceClient();
            SimpleAdModel ad = db.GetAdById(AdID);
            DateTime bDate = DateTime.Parse(beginDate);
            DateTime eDate = DateTime.Parse(endDate);
            for (DateTime curDate = bDate; curDate.CompareTo(eDate) < 0; curDate = curDate.AddDays(1))
            {
                Random r = new Random(Guid.NewGuid().GetHashCode());
                int sessionCount = r.Next(10);
                for (int i = 0; i < sessionCount; i++)
                {
                    AdSession session = new AdSession
                    {
                        ActiveMilliseconds = r.Next(500),
                        AdId = AdID,
                        DateTimeStart = curDate,
                        DateTimeEnd = curDate.AddSeconds(r.Next(180)),
                        UserBrowser = StubUtils.GenerateBrowser(),
                        UserIp = StubUtils.GenerateIP(),
                        UserLocale = StubUtils.GenerateLocale(),
                        UserLocation = "TestLocation"
                    };
                    int ActivityCount = r.Next(5);
                    for (int j = 0; j < ActivityCount; j++)
                    {
                        NodeLink randomLink = ad.StateGraph.ElementAt(r.Next(ad.StateGraph.Count));
                        int rndNode = randomLink.V1;
                        int rndNodeNext = randomLink.V2;
                        int rand = r.Next(10);
                        if (rand > 5)
                        {
                            rndNode = randomLink.V2;
                            rndNodeNext = randomLink.V1;
                        }
                        Activity act = new Activity
                        {
                            StartTime = curDate,
                            EndTime = curDate,
                            CurrentStateName = ad.AdStates.First(a => a.VideoUnitId == rndNode).Name
                        };
                        for (int k = 0; k < 1; k++)
                        {

                            
                            Click c = new Click
                            {
                                ClickTime = curDate,
                                ClickType = "action-next",
                                ClickZone = "SubZone",
                                ClickCurrentStage = rndNode,
                                ClickNextStage = rndNodeNext,
                                ClickNextTime = randomLink.T
                            };
                            c.ClickText = Generator.GenerateClickName(c);
                            c.ClickStamp = Generator.GenerateClickStamp(c);
                            act.Clicks.Add(c);
                        };
                        session.Activities.Add(act);
                    }
                    db.SaveAdSession(session, true);
                }
            }
            return "success";
        }