Exemplo n.º 1
0
        private void CloseLogger()
        {
            if (this.logger != null)
            {
                DateTime utcNow    = this.stateManager.LastUpdated;
                TimeSpan monitored = this.stateManager.Monitored;

                using (this.logger.BeginBatch())
                {
                    foreach (var group in this.logRows.GroupBy(row => row.PeerGroupId))
                    {
                        int      numFails        = group.Count();
                        TimeSpan totalFailLength = TimeSpan.FromTicks(group.Sum(row => row.Length.Ticks));
                        decimal  percentFailTime = Math.Round((decimal)(100 * totalFailLength.TotalSeconds / monitored.TotalSeconds), 2);
                        this.logger.AddLogSummary(
                            group.First().PeerGroupName,
                            utcNow,
                            numFails,
                            ConvertUtility.RoundToSeconds(totalFailLength),
                            percentFailTime,
                            ConvertUtility.RoundToSeconds(group.Min(row => row.Length)),
                            ConvertUtility.RoundToSeconds(group.Max(row => row.Length)),
                            ConvertUtility.RoundToSeconds(TimeSpan.FromMilliseconds(group.Average(row => row.Length.TotalMilliseconds))));
                    }

                    this.logger.AddLogEnd(utcNow, ConvertUtility.RoundToSeconds(monitored));
                }

                this.logger = null;
            }
        }
Exemplo n.º 2
0
        private void UpdateLogRows(IEnumerable <PeerGroupState> peerGroupStates)
        {
            List <PeerGroupState> failedChanged = new List <PeerGroupState>(0);

            HashSet <Guid> currentPeerGroups = new HashSet <Guid>(this.failedPeerGroupToLogRowMap.Comparer);

            foreach (PeerGroupState peerGroupState in peerGroupStates)
            {
                PeerGroup peerGroup   = peerGroupState.PeerGroup;
                Guid      peerGroupId = peerGroup.Id;

                if (this.failedPeerGroupToLogRowMap.TryGetValue(peerGroupId, out LogRow row))
                {
                    row.Update(peerGroupState);
                    if (!peerGroupState.IsFailed)
                    {
                        this.failedPeerGroupToLogRowMap.Remove(peerGroupId);
                        this.logger?.AddFailureEnd(row.PeerGroupName, row.FailEnded.Value, row.FailureId, ConvertUtility.RoundToSeconds(row.Length));
                        failedChanged.Add(peerGroupState);
                    }
                }
                else if (peerGroupState.IsFailed)
                {
                    LogRow previous = this.logRows.FirstOrDefault(r => r.PeerGroupId == peerGroupId);
                    row = new LogRow(this.failureId++);
                    row.Update(peerGroupState, previous);
                    this.logRows.Insert(0, row);
                    this.failedPeerGroupToLogRowMap.Add(peerGroupId, row);
                    TimeSpan?sincePrevious = row.SincePrevious != null?ConvertUtility.RoundToSeconds(row.SincePrevious.Value) : (TimeSpan?)null;

                    this.logger?.AddFailureStart(row.PeerGroupName, row.FailStarted, row.FailureId, sincePrevious);
                    failedChanged.Add(peerGroupState);
                }

                currentPeerGroups.Add(peerGroupId);
            }

            foreach (Guid peerGroupId in this.failedPeerGroupToLogRowMap.Keys.Where(key => !currentPeerGroups.Contains(key)).ToArray())
            {
                this.failedPeerGroupToLogRowMap.Remove(peerGroupId);
            }

            foreach (var group in failedChanged.GroupBy(g => g.IsFailed))
            {
                AlertOptions alertOptions = group.Key ? this.appOptions.FailureOptions : this.appOptions.ReconnectOptions;

                StringBuilder sb = new StringBuilder("The following peer groups ");
                sb.Append(group.Key ? "are no longer connected:" : "have reconnected:");
                sb.AppendLine();
                foreach (PeerGroupState peerGroupState in group)
                {
                    sb.AppendLine(peerGroupState.PeerGroup.Name);
                }

                alertOptions.Alert(this, sb.ToString(), this.notifyIcon, ref this.mediaPlayer);
            }
        }
Exemplo n.º 3
0
        public void AddSimpleEntry(string peerGroupName, DateTime startedUtc, DateTime?endedUtc, TimeSpan?sincePrevious, string comment)
        {
            using (this.BeginBatch())
            {
                this.TryAddHeader(
                    Entry.Simple, PeerGroupColumn, "LocalStart", LengthColumn, "LocalEnd", SincePreviousColumn, CommentColumn, "UtcStart", "UtcEnd");
                TimeSpan?length = endedUtc != null?ConvertUtility.RoundToSeconds(endedUtc.Value - startedUtc) : (TimeSpan?)null;

                this.AddValues(peerGroupName, startedUtc.ToLocalTime(), length, endedUtc?.ToLocalTime(), sincePrevious, comment, startedUtc, endedUtc);
            }
        }
Exemplo n.º 4
0
        private void UpdateStates(StateSnapshot states)
        {
            this.UpdateStatusRows(states);
            this.UpdateLogRows(states.AllPeerGroups);

            // This isn't a dependency property, so we can't bind to it. We have to manually update it.
            TimeSpan monitored = this.stateManager.Monitored;

            monitored = ConvertUtility.RoundToSeconds(monitored);
            this.monitoredTime.Text = monitored.ToString();
        }
Exemplo n.º 5
0
        private void UpdateStates(StateSnapshot states)
        {
            this.UpdateStatusRows(states);
            this.UpdateLogRows(states.AllPeerGroups);

            // This isn't a dependency property, so we can't bind to it. We have to manually update it.
            TimeSpan monitored = this.stateManager.Monitored;

            monitored = ConvertUtility.RoundToSeconds(monitored);
            this.monitoredTime.Text = monitored.ToString();

            // Optionally, simulate a failure when ScrollLock is toggled on.
            this.simulateFailure = this.CommonOptions.ScrollLockSimulatesFailure && Keyboard.IsKeyToggled(Key.Scroll);
        }