Пример #1
0
        private static Dictionary <string, double> GetDatesSeries(RecordsHolder records)
        {
            var result = new Dictionary <string, double>();

            Record prevRecord = records.Records.Values.ElementAt(0);
            string newKey     = prevRecord.DateTime.ToString("d");
            double newValue   = 0;

            int trackingBorder = 0;

            foreach (var curRecord in records.Records.Values)
            {
                if (curRecord.IsTracking)
                {
                    trackingBorder++;
                }
                else
                {
                    trackingBorder--;
                }

                if (prevRecord.DateTime.Date != curRecord.DateTime.Date)
                {
                    newKey = curRecord.DateTime.ToString("d");
                }

                if (trackingBorder != 1)
                {
                    TimeSpan timeSpan = curRecord.DateTime.Subtract(prevRecord.DateTime);
                    newValue += timeSpan.TotalHours;
                }

                if (trackingBorder == 0)
                {
                    newValue = Math.Round(newValue, 3);
                    if (result.ContainsKey(newKey))
                    {
                        result[newKey] += newValue;
                    }
                    else
                    {
                        result.Add(newKey, newValue);
                    }
                    newValue = 0;
                }

                prevRecord = curRecord;
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeTracker"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private TimeTracker(AsyncPackage package, OleMenuCommandService commandService)
        {
            this.package   = package ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

            Records = new RecordsHolder();

            var menuCommandTrackingId = new CommandID(CommandSet, CommandTrackingId);
            var menuCommandTracking   = new OleMenuCommand(TimeTracking.OnClick, menuCommandTrackingId);

            var menuCommandShowGraphId = new CommandID(CommandSet, CommandShowChartId);
            var menuCommandShowGraph   = new OleMenuCommand(ChartShowing.OnClick, menuCommandShowGraphId);

            commandService.AddCommand(menuCommandTracking);
            commandService.AddCommand(menuCommandShowGraph);
        }