Exemplo n.º 1
0
        public LogCollector(MyQueue <string> paths, MyQueue <EventItem> events)
        {
            /*
             *    LogCollectorConfig config = LogCollectorConfig.GetSection(ConfigurationUserLevel.None);
             *    Console.WriteLine(config.ExampleAttribute);
             *    config.ExampleAttribute = "B";
             *    config.Class1.Add(new Class1Element());
             *    config.Save();
             */
            workers = new IWorkingElement[1 + NUM_READERS + NUM_PROCESSORS];
            int p = 0;

            workers[p] = new DirectoryScanner("Scanner", paths, inFiles);
            p++;
            for (int i = 0; i < NUM_READERS; i++)
            {
                workers[p] = new FileReader("FR-" + i, inFiles, rows, outFiles);
                p++;
            }
            for (int i = 0; i < NUM_PROCESSORS; i++)
            {
                workers[p] = new RowProcessor("RP-" + i, rows, events);
                p++;
            }
        }
Exemplo n.º 2
0
        public void AddToDataTableTest()
        {
            var feedFilePlan = new FeedFilePlan {
                TransformMaps = new [] {
                    new TransformMapping {
                        DestCol = "intColumn",
                        SrcColumns = "0",
                        Type = "int",
                    },
                    new TransformMapping {
                        DestCol = "strColumn",
                        SrcColumns = "1",
                    },
                    new TransformMapping {
                        DestCol = "boolColumn",
                        SrcColumns = "2",
                        Type = "bool",
                    },
                    new TransformMapping {
                        DestCol = "floatColumn",
                        SrcColumns = "3",
                        Type = "float",
                    },
                },
            };
            var dataTable = new DataTable ();
            dataTable.Columns.Add (FeedProcessor.LoadNumberString, typeof(Int32));
            dataTable.Columns.Add (FeedProcessor.DataSourceCodeString, typeof(String));
            dataTable.Columns.Add ("intColumn", typeof(int));
            dataTable.Columns.Add ("strColumn", typeof(string));
            dataTable.Columns.Add ("boolColumn", typeof(bool));
            dataTable.Columns.Add ("floatColumn", typeof(float));

            var row = new Dictionary<string, string> {
                { "intColumn", "42" },
                { "strColumn", "foo" },
                { "boolColumn", "true" },
                { "floatColumn", "10.0" },
            };

            var rowProcessor = new RowProcessor ();
            rowProcessor.AddRowToDataTable (feedFilePlan, 1, "TST", row, dataTable);

            Assert.AreEqual (1, dataTable.Rows.Count);
            var dataRow = dataTable.Rows [0];
            Assert.IsNotNull (dataRow);

            var intVal = (int)dataRow ["intColumn"];
            var stringVal = (string)dataRow ["strColumn"];
            var boolVal = (bool)dataRow ["boolColumn"];
            var floatVal = (float)dataRow ["floatColumn"];

            Assert.AreEqual (42, intVal);
            Assert.AreEqual ("foo", stringVal);
            Assert.AreEqual (true, boolVal);
            Assert.AreEqual (10.0f, floatVal);
        }
Exemplo n.º 3
0
        public static void Read(RowProcessor proc, System.IO.StreamReader file, string sep, bool hasHeader)
        {
            string[] header = null;
            string[] read   = null;
            string   data;

            if (hasHeader)
            {
                if ((data = file.ReadLine()) != null)
                {
                    header = data.Split(sep[0]);
                }
            }

            while ((data = file.ReadLine()) != null)
            {
                read = data.Split(sep[0]);
                proc.ProcessRow(header, read);
            }
        }
Exemplo n.º 4
0
    public static void DeserializeWithHeader(TextReader textReader, RowProcessor rowProcessor)
    {
        Dictionary <string, string> keyedRow = new Dictionary <string, string>();

        string[] header = new string[] {};
        int      index;
        bool     initialized = false;
        int      maxLength   = 0;

        for (List <string> rawRow = ParseRow(textReader, ',', '"', maxLength); rawRow != null; rawRow = ParseRow(textReader, ',', '"', maxLength))
        {
            index = 0;

            if (!initialized)
            {
                header = rawRow.ToArray();
            }
            else
            {
                keyedRow = new Dictionary <string, string>();

                foreach (string match in rawRow)
                {
                    keyedRow.Add(header[index], match);

                    ++index;
                }
            }

            if (initialized)
            {
                rowProcessor(keyedRow);
            }
            else
            {
                initialized = true;
            }

            maxLength = (maxLength > rawRow.Count ? maxLength : rawRow.Count);
        }
    }
Exemplo n.º 5
0
        public static int addRowsWithDataGrid(
            DataGridView dataGrid, 
            DataGridRowValidator validate, RowProcessor rowProc, ErrorCallBack callback)
        {
            DataGridViewRow lastRow = dataGrid.Rows[dataGrid.Rows.Count - 1];
            string missingCol;

            foreach (DataGridViewRow r in dataGrid.Rows)
            {
                if (validate(r, out missingCol))
                {
                    rowProc(r.Cells);
                }
                else if (r != lastRow && dataGrid.AllowUserToAddRows)
                {
                    callback(missingCol);
                    return -1;
                }
            }

            return dataGrid.Rows.Count - (dataGrid.AllowUserToAddRows ? 1 : 0);
        }
Exemplo n.º 6
0
 public static void DeserializeWithHeader(string path, RowProcessor rowProcessor)
 {
     DeserializeWithHeader(new StreamReader(path), rowProcessor);
 }
Exemplo n.º 7
0
        protected virtual void ReadHotfixes <T>(IDictionary <int, T> storage, DBReader dbReader, RowProcessor processor = null) where T : class, new()
        {
            var fieldCache = typeof(T).GetFields().Select(x => new FieldCache <T>(x)).ToArray();

            if (processor == null)
            {
                processor = DefaultProcessor;
            }

            // Id fields need to be excluded if not inline
            if (dbReader.Flags.HasFlagExt(DB2Flags.Index))
            {
                fieldCache[dbReader.IdFieldIndex].IndexMapField = true;
            }

            // TODO verify hotfixes need to be applied sequentially
            var records = _reader.GetRecords(dbReader.TableHash).OrderBy(x => x.PushId);

            // Check if there are any valid cached records with data, don't remove row if so.
            // Example situation: Blizzard has invalidated TACTKey records in the same DBCache as valid ones.
            // Without the below check, valid cached TACTKey records would be removed by the invalidated records afterwards.
            // This only seems to be relevant for cached tables and specifically TACTKey, BroadcastText/ItemSparse only show up single times it seems.
            var shouldDelete = dbReader.TableHash != 3744420815 || !records.Any(r => r.IsValid && r.PushId == -1 && r.DataSize > 0);

            foreach (var row in records)
            {
                var operation = processor(row, shouldDelete);

                if (operation == RowOp.Add)
                {
                    T entry = new T();
                    row.GetFields(fieldCache, entry);
                    storage[row.RecordId] = entry;
                }
                else if (operation == RowOp.Delete)
                {
                    storage.Remove(row.RecordId);
                }
            }
        }
Exemplo n.º 8
0
 public void ApplyHotfixes <T>(IDictionary <int, T> storage, DBReader dbReader, RowProcessor processor) where T : class, new()
 => ReadHotfixes(storage, dbReader, processor);
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new instance of EntityHandler.
 /// </summary>
 /// <param name="entity">The Entity Type that objects returned from handle() are created from.</param>
 /// <param name="processor">The RowProcessor implementation to use when converting rows into entities.</param>
 public EntityHandler(Entity entity, RowProcessor processor)
 {
     this.entType   = entity;
     this.processor = processor;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new instance of PageInfoHandler.
 /// </summary>
 /// <param name="type">The type that objects returned from handle() are created from.</param>
 public PageFilterHandler(Type type)
 {
     this.type      = type;
     this.processor = new BasicRowProcesor();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new instance of BeanHandler.
 /// </summary>
 /// <param name="type">The type that objects returned from handle() are created from.</param>
 /// <param name="processor">The RowProcessor implementation to use when converting rows into beans.</param>
 public BeanHandler(Type type, RowProcessor processor)
 {
     this.type      = type;
     this.processor = processor;
 }
Exemplo n.º 12
0
        public void RowTransformationTest()
        {
            var rowProcessor = new RowProcessor {
                MethodResolvers = methodResolver
            };

            var result = rowProcessor.TransformRow (1, "ARC", 0, feedFilePlan, new[] {
                "Sterling",
                "Archer",
                "40",
                "85",
                "2",
                "anotherIgnoredValue"
            });

            Assert.IsTrue (result.Keys.Count == 4);
            Assert.IsTrue (result.ContainsKey ("FirstName"));
            Assert.IsTrue (result.ContainsKey ("LastName"));
            Assert.IsTrue (result.ContainsKey ("ComputedValue"));
            Assert.IsTrue (result.ContainsKey ("FullName"));

            Assert.AreEqual ("Sterling", result ["FirstName"]);
            Assert.AreEqual ("Archer", result ["LastName"]);
            Assert.AreEqual ("42", result ["ComputedValue"]);
            Assert.AreEqual ("Mr. Sterling Archer, the world's most dangerous spy.",
                result ["FullName"]);
        }