private ProgressEntry GetOrCreateProgressEntry(
        string progressName)
    {
        ProgressEntry result = null;

        if (string.IsNullOrEmpty(progressName))
        {
            throw new ArgumentNullException(
                      progressName,
                      "Progress names must be a non-empty string.");
        }

        if (progressEntries.TryGetValue(progressName, out result))
        {
            // Great! We're done.
        }
        else
        {
            result = new ProgressEntry
            {
                ProgressName         = progressName,
                ProgressValueStorage = 0.0f,
            };

            progressEntries.Add(result.ProgressName, result);
        }

        return(result);
    }
Example #2
0
        public IEnumerable <ProgressEntry> GetProgressEntries(IEnumerable <int> tagsIds, int daysBeforeToday = 7)
        {
            var    result = new List <ProgressEntry>();
            string query  = "select * from ProgressEntries where WhenCreated >= @since";

            using (var conn = new MySqlConnection(_dbConnString)){
                conn.Open();
                var command = new MySqlCommand(query, conn);
                var since   = DateTime.Now.AddDays(-daysBeforeToday).ToString("yyyy-MM-dd");
                command.Parameters.AddWithValue("@since", since);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));
                        var pe = new ProgressEntry()
                        {
                            Id          = reader.GetInt32(reader.GetOrdinal("Id")),
                            Content     = reader.GetString(reader.GetOrdinal("Content")),
                            WhenCreated = reader.GetDateTime(reader.GetOrdinal("WhenCreated"))
                        };

                        result.Add(pe);
                    }
                }
            }

            return(result.OrderByDescending(e => e.WhenCreated));
        }
Example #3
0
            public void Checkpoint(params double?[] values)
            {
                _ectx.AssertValueOrNull(values);
                _ectx.Check(!_isDisposed, "Can't report checkpoints after disposing");
                var entry = new ProgressEntry(true, _headerAndAction.Item1);

                int n    = Utils.Size(values);
                int iSrc = 0;

                for (int iDst = 0; iDst < entry.Metrics.Length && iSrc < n;)
                {
                    entry.Metrics[iDst++] = values[iSrc++];
                }

                for (int iDst = 0; iDst < entry.Progress.Length && iSrc < n;)
                {
                    entry.Progress[iDst++] = values[iSrc++];
                }

                for (int iDst = 0; iDst < entry.ProgressLim.Length && iSrc < n;)
                {
                    var lim = values[iSrc++];
                    if (Double.IsNaN(lim.GetValueOrDefault()))
                    {
                        lim = null;
                    }
                    entry.ProgressLim[iDst++] = lim;
                }

                _ectx.Check(iSrc == n, "Too many values provided in Checkpoint");
                _tracker.Log(this, ProgressEvent.EventKind.Progress, entry);
            }
 protected override void WriteEntry(string key, ProgressEntry entry)
 {
     _storage.AddOrUpdate(key, new ConcurrentBag<ProgressEntry>(new[] { entry }), (s, bag) =>
     {
         bag.Add(entry);
         return bag;
     });
 }
Example #5
0
        private void UpdateSearchEngineProgress(IProgressStatus status)
        {
            var newEntry = new ProgressEntry(DateTime.Now, status.Message);

            _progressTextItems.Add(newEntry);
            txtSearchProgress.AppendText($@"{newEntry.ToString(showTimestampsCheckbox.Checked)}{Environment.NewLine}");
            UpdateTaskbarProgress(TaskbarProgress.TaskbarStates.Normal, status.PercentComplete);
            progressBar.Value = status.PercentComplete;
        }
Example #6
0
            public ProgressEvent(int index, string name, DateTime startTime, EventKind kind)
            {
                Contracts.CheckParam(index >= 0, nameof(index));
                Contracts.CheckNonEmpty(name, nameof(name));

                Index         = index;
                Name          = name;
                StartTime     = startTime;
                EventTime     = DateTime.UtcNow;
                Kind          = kind;
                ProgressEntry = null;
            }
Example #7
0
            public void Log(ProgressChannel source, ProgressEvent.EventKind kind, ProgressEntry entry)
            {
                _ectx.AssertValue(source);
                _ectx.AssertValueOrNull(entry);

                if (kind == ProgressEvent.EventKind.Start)
                {
                    _ectx.Assert(entry == null);
                    lock (_lock)
                    {
                        // Figure out an appropriate name.
                        int    i             = 1;
                        var    name          = source.Name;
                        string nameCandidate = name;
                        while (!_namesUsed.Add(nameCandidate))
                        {
                            i++;
                            nameCandidate = string.Format("{0} #{1}", name, i);
                        }
                        var newInfo = new CalculationInfo(++_index, nameCandidate, source);
                        _infos.Add(newInfo);
                        _pendingEvents.Enqueue(new ProgressEvent(newInfo.Index, newInfo.Name, newInfo.StartTime, ProgressEvent.EventKind.Start));
                        return;
                    }
                }

                // Not a start event, so we won't modify the _infos.
                CalculationInfo info;

                lock (_lock)
                {
                    info = _infos.FirstOrDefault(x => x.Channel == source);
                    if (info == null)
                    {
                        throw _ectx.Except("Event sent after the calculation lifetime expired.");
                    }
                }
                switch (kind)
                {
                case ProgressEvent.EventKind.Stop:
                    _ectx.Assert(entry == null);
                    info.IsFinished = true;
                    _pendingEvents.Enqueue(new ProgressEvent(info.Index, info.Name, info.StartTime, ProgressEvent.EventKind.Stop));
                    break;

                default:
                    _ectx.Assert(entry != null);
                    _ectx.Assert(kind == ProgressEvent.EventKind.Progress);
                    _ectx.Assert(!info.IsFinished);
                    _pendingEvents.Enqueue(new ProgressEvent(info.Index, info.Name, info.StartTime, entry));
                    break;
                }
            }
Example #8
0
        public void CreateProgressEntry(ProgressEntry entry)
        {
            string query = "insert into ProgressEntries (Content) values (@content)";

            using (var conn = new MySqlConnection(_dbConnString))
            {
                conn.Open();
                var command = new MySqlCommand(query, conn);
                command.Parameters.AddWithValue("@content", entry.Content);
                command.ExecuteNonQuery();
            }
        }
Example #9
0
        public void UpdateProgressEntry(ProgressEntry entry)
        {
            string query = "update ProgressEntries set Content = @content where Id = @id";

            using (var conn = new MySqlConnection(_dbConnString))
            {
                conn.Open();
                var command = new MySqlCommand(query, conn);
                command.Parameters.AddWithValue("@id", entry.Id);
                command.Parameters.AddWithValue("@content", entry.Content);
                command.ExecuteNonQuery();
            }
        }
Example #10
0
            public ProgressEvent(int index, string name, DateTime startTime, ProgressEntry entry)
            {
                Contracts.CheckParam(index >= 0, nameof(index));
                Contracts.CheckNonEmpty(name, nameof(name));
                Contracts.CheckValue(entry, nameof(entry));

                Index         = index;
                Name          = name;
                StartTime     = startTime;
                EventTime     = DateTime.UtcNow;
                Kind          = EventKind.Progress;
                ProgressEntry = entry;
            }
Example #11
0
                /// <summary>
                /// Pull the current progress by invoking the fill delegate, if any.
                /// </summary>
                public ProgressEntry GetProgress()
                {
                    // Make sure we get header and action from the same pair, even if outdated.
                    var cache      = _headerAndAction;
                    var fillAction = cache.Item2;
                    var entry      = new ProgressEntry(false, cache.Item1);

                    if (fillAction == null)
                    {
                        Contracts.Assert(entry.Header.MetricNames.Length == 0 && entry.Header.UnitNames.Length == 0);
                    }
                    else
                    {
                        fillAction(entry);
                    }
                    return(entry);
                }
Example #12
0
            private static void processItems(List <uint> items, ProgressEntry <uint> entry)
            {
                if (entry?.Content is null)
                {
                    return;
                }

                uint itm = entry.Content;

                if (entry.Cancel)
                {
                    items.Remove(itm);
                    return;
                }

                items.Add(itm);
                items.Sort();
            }
    private void SetProgressValueInternal(
        string progressName,
        float newValue)
    {
        ProgressEntry progressEntry = GetOrCreateProgressEntry(progressName);

        if (newValue != progressEntry.ProgressValueStorage)
        {
            var eventArgs = new ProgressChangedEventArgs();

            eventArgs.ProgressName = progressName;

            eventArgs.OldValueAsBool  = progressEntry.ProgressValueAsBool;
            eventArgs.OldValueAsFloat = progressEntry.ProgressValueAsFloat;
            eventArgs.OldValueAsInt   = progressEntry.ProgressValueAsInt;

            // Now that the old values have been recorded, actualize the progress-change.
            progressEntry.ProgressValueStorage = newValue;

            eventArgs.NewValueAsBool  = progressEntry.ProgressValueAsBool;
            eventArgs.NewValueAsFloat = progressEntry.ProgressValueAsFloat;
            eventArgs.NewValueAsInt   = progressEntry.ProgressValueAsInt;

            if (DebugEnabled)
            {
                Debug.LogFormat(
                    "Changing progress [{0}] from [{1:F2}] to [{2:F2}].",
                    eventArgs.ProgressName,
                    eventArgs.OldValueAsFloat,
                    eventArgs.NewValueAsFloat);
            }

            if (ProgressChanged != null)
            {
                ProgressChanged(this, eventArgs);
            }
        }
    }
Example #14
0
            private ProgressEntry BuildJointEntry(ProgressEntry rootEntry)
            {
                if (_maxSubId == 0 || _subChannels.Count == 0)
                {
                    return(rootEntry);
                }

                // REVIEW: consider caching the headers, in case the sub-reporters haven't changed.
                // This is not anticipated to be a perf-critical path though.
                var hProgress   = new List <string>();
                var hMetrics    = new List <string>();
                var progress    = new List <double?>();
                var progressLim = new List <double?>();
                var metrics     = new List <double?>();

                hProgress.AddRange(rootEntry.Header.UnitNames);
                hMetrics.AddRange(rootEntry.Header.MetricNames);
                progress.AddRange(rootEntry.Progress);
                progressLim.AddRange(rootEntry.ProgressLim);
                metrics.AddRange(rootEntry.Metrics);

                foreach (var subChannel in _subChannels.Values.ToArray().OrderBy(x => x.Level))
                {
                    var entry = subChannel.GetProgress();
                    hProgress.AddRange(entry.Header.UnitNames);
                    hMetrics.AddRange(entry.Header.MetricNames);
                    progress.AddRange(entry.Progress);
                    progressLim.AddRange(entry.ProgressLim);
                    metrics.AddRange(entry.Metrics);
                }

                var jointEntry = new ProgressEntry(false, new ProgressHeader(hMetrics.ToArray(), hProgress.ToArray()));

                progress.CopyTo(jointEntry.Progress);
                progressLim.CopyTo(jointEntry.ProgressLim);
                metrics.CopyTo(jointEntry.Metrics);
                return(jointEntry);
            }
Example #15
0
 public void CreateProgressEntry(ProgressEntry progressEntry)
 {
     _repo.CreateProgressEntry(progressEntry);
 }
Example #16
0
 private ProgressInfo(string title, bool cancel = false)
 {
     Title = new ProgressEntry <string> (title, cancel);
 }
 protected abstract void WriteEntry(string key, ProgressEntry entry);
Example #18
0
 public void UpdateProgressEntry(ProgressEntry progressEntry)
 {
     _repo.UpdateProgressEntry(progressEntry);
 }
 protected override void WriteEntry(string key, ProgressEntry entry)
 {
     var path = GetCommandStatePath(key);
     File.AppendAllText(path, JsonConvert.SerializeObject(entry) + ",");
 }