Exemple #1
0
        public static NetBroadcast.BroadcastData      GetBroadcastDataFromRow(TableRow row)
        {
            string fromAddress = "";
            Dictionary <string, string> dict = new Dictionary <string, string> ();

            TableEntry entryIP = row.FindEntryByColumnName("IP");

            if (entryIP)
            {
                fromAddress = entryIP.entryText;
            }

            for (int i = 0; i < row.Table.columns.Count; i++)
            {
                var column = row.Table.columns [i];
                if (column.columnName == "IP")
                {
                    continue;
                }
                var entry = row.Entries [i];
                dict.AddOrSet(column.columnName, entry.entryText);
            }


            var broadcastData = new NetBroadcast.BroadcastData(fromAddress, dict);

            return(broadcastData);
        }
Exemple #2
0
        public static void    HandleBroadcastData(Table table, NetBroadcast.BroadcastData data)
        {
            EnsureColumnsMatchBroadcastData(table, data);

            // try to find this server in a table
            TableRow rowWithServer = FindRowWithServer(table, data);

            if (rowWithServer)
            {
                // this server already exists in table
                // update it's values

                PopulateTableRow(rowWithServer, data);
            }
            else
            {
                // this server doesn't exist
                // add it to table

                rowWithServer = table.AddRow();

                table.UpdateRow(rowWithServer);

                PopulateTableRow(rowWithServer, data);
            }

            table.UpdateTable();
        }
Exemple #3
0
        public static void    EnsureColumnsMatchBroadcastData(Table table, NetBroadcast.BroadcastData broadcastData)
        {
            var newColumnNames = new List <string>(1 + broadcastData.KeyValuePairs.Count);

            newColumnNames.Add("IP");
            newColumnNames.AddRange(broadcastData.KeyValuePairs.Select(pair => pair.Key));


            bool sameColumns = table.columns.Select(c => c.columnName).SequenceEqual(newColumnNames);

//			for (int i = 0; i < table.columns.Count; i++) {
//				if (table.columns [i].columnName != newColumnNames [i]) {
//					sameColumns = false;
//					break;
//				}
//			}

            if (!sameColumns)
            {
                // we'll make this easy: rebuild the whole table :D

                // first, save all table data
                var allData = new List <NetBroadcast.BroadcastData> (table.RowsCount);
                foreach (var row in table.GetAllRows().WhereAlive())
                {
                    allData.Add(GetBroadcastDataFromRow(row));
                }

                // now rebuild the table

                table.Clear();
                table.DestroyHeader();

                // create new columns
                var newColumns = new List <Table.Column>();
                foreach (var columnName in newColumnNames)
                {
                    var column = new Table.Column();
                    column.columnName = columnName;
                    newColumns.Add(column);
                }
                table.columns = newColumns;
                table.CreateHeader();

                // adjust column widths
                AdjustColumnWidths(table);

                // restore saved data
                foreach (var rowData in allData)
                {
                    var row = table.AddRow();
                    PopulateTableRow(row, rowData);
                }

                // update table
                table.UpdateTable();
            }
        }
Exemple #4
0
        public static void    PopulateTableRow(TableRow row, NetBroadcast.BroadcastData data)
        {
            PopulateTableEntry(row, "IP", data.FromAddress);

            foreach (var pair in data.KeyValuePairs)
            {
                PopulateTableEntry(row, pair.Key, pair.Value);
            }
        }
Exemple #5
0
        public static TableRow        FindRowWithServer(Table table, NetBroadcast.BroadcastData broadcastData)
        {
            TableEntry entry = table.GetAllEntriesInColumn("IP").FirstOrDefault(e => e.entryText == broadcastData.FromAddress);

            if (entry)
            {
                return(entry.TableRow);
            }

            return(null);
        }
Exemple #6
0
 void OnReceivedBroadcast(NetBroadcast.BroadcastData data)
 {
     m_dataToAddToTable.Add(data);
 }