コード例 #1
0
 public void Consume(TimeSliceInfo timeSlice)
 {
     List <Summary> summarized = timeSlice.RecordedWindows.GroupBy(q => q.ProgramName)
                                 .Select(g => new Summary()
     {
         ProgramName = g.Key,
         TimeInMs    = g.Count() * timeSlice.TickInMs
     }).ToList();
 }
コード例 #2
0
            public static TimeSliceJSON FromTimeSliceInfo(TimeSliceInfo timeSlice)
            {
                TimeSliceJSON timeSliceJson = new TimeSliceJSON
                {
                    StartTime  = timeSlice.StartTime.ToString("o", CultureInfo.CurrentCulture),
                    TimeLength = timeSlice.LengthInMs,
                    Username   = CollectionConfiguration.Default.Username,
                    Data       = timeSlice.TimeSliceSummary.ToDictionary(p => p.ProgramName, p => p.TimeInMs)
                };

                return(timeSliceJson);
            }
コード例 #3
0
        private void StartNewTimeSlice()
        {
            TimeSliceInfo timeSliceInfo = new TimeSliceInfo
            {
                RecordedWindows = CurrentTimeSlice,
                TickInMs        = CollectTickMs,
                StartTime       = CurrentTimeSliceStart,
                LengthInMs      = 60 * 1000
            };

            Consumer?.Consume(timeSliceInfo);

            CurrentTimeSliceStart = DateTime.Now;
            CurrentTimeSlice.Clear();
        }
コード例 #4
0
        public void Consume(TimeSliceInfo timeSlice)
        {
            TimeSliceJSON timeSliceJson = TimeSliceJSON.FromTimeSliceInfo(timeSlice);

            MemoryStream memoryStream = new MemoryStream();
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(TimeSliceJSON));

            jsonSerializer.WriteObject(memoryStream, timeSliceJson);

            memoryStream.Position = 0;
            StreamReader reader = new StreamReader(memoryStream);
            string       json   = reader.ReadToEnd();

            Console.WriteLine(json);

            StringContent httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            client.PostAsync(CollectionConfiguration.Default.WebService + "/activities/upload", httpContent);
        }