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();
 }
            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);
            }
        private void StartNewTimeSlice()
        {
            TimeSliceInfo timeSliceInfo = new TimeSliceInfo
            {
                RecordedWindows = CurrentTimeSlice,
                TickInMs        = CollectTickMs,
                StartTime       = CurrentTimeSliceStart,
                LengthInMs      = 60 * 1000
            };

            Consumer?.Consume(timeSliceInfo);

            CurrentTimeSliceStart = DateTime.Now;
            CurrentTimeSlice.Clear();
        }
        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);
        }