示例#1
0
        private static void ConnectionStatisticsOutput()
        {
            using (var writer = new StreamWriter("result.csv"))
            {
                var nodes = ccManager_.ConnectionsCollection.Select(x => x.Value.Node).Distinct().ToArray().OrderBy(x => x);
                var dates = ccManager_.ConnectionsCollection.Select(x => x.Value.Date).Distinct().ToArray().OrderBy(x => x);

                var sb = new StringBuilder(";");
                foreach (var date in dates)
                {
                    sb.Append(date.Date.ToShortDateString() + ";");
                }
                writer.WriteLine(sb.ToString());

                sb.Clear();
                foreach (var node in nodes)
                {
                    sb.Append(node + ";");
                    foreach (var date in dates)
                    {
                        var hash = ConnectionItem.CalculateHashCode(node, date);
                        if (ccManager_.ConnectionsCollection.ContainsKey(hash))
                        {
                            sb.Append(ccManager_.ConnectionsCollection[hash].States[ConnectionState.Established]);
                        }

                        sb.Append(";");
                    }
                    sb.AppendLine();
                }
                writer.WriteLine(sb.ToString());
            }
        }
        private void Add(DateTime date, ConnectionState state, int channel, string node, string line)
        {
            int hash;

            if (!this.nodeChannelLink_.ContainsKey(channel))
            {
                if (state == ConnectionState.Established)
                {
                    Console.WriteLine(line);
                }
                if (node == string.Empty)
                {
                    hash = ConnectionItem.CalculateHashCode("000000", date);
                }
                else
                {
                    hash = ConnectionItem.CalculateHashCode(node, date);
                    this.nodeChannelLink_.Add(channel, hash);
                }
            }
            else
            {
                hash = this.nodeChannelLink_[channel];
            }

            if (!this.ConnectionsCollection.ContainsKey(hash))
            {
                if (node == string.Empty)
                {
                    node = "000000";
                }
                this.ConnectionsCollection.Add(hash, new ConnectionItem(node, date));
            }

            this.ConnectionsCollection[hash].AddState(state);
        }