Beispiel #1
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);
            }
        }
Beispiel #2
0
 private void PlaySoundFile(FrameworkElement element)
 {
     AlertOptions.PlaySoundFile(element.ToolTip?.ToString(), ref this.mediaPlayer);
 }