Esempio n. 1
0
        public void ThreeRowsSimpleRunAllNodesMustBeDisposed()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();
            var a = new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{counterWrapper.Counter++}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            });
            var b = new TestActionProcess(p => { p.Item = p.Item += "BBB"; });
            var c = new TestActionProcess(p => { p.Item = p.Item += "CCC"; });

            nodeRegistry.Register("A", new BaseNode <string>(a, definitionA));
            nodeRegistry.Register("B", new BaseNode <string>(b, definitionB));
            nodeRegistry.Register("C", new BaseNode <string>(c, definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            runner.Dispose();
            Assert.IsTrue(a.IsDisposed);
            Assert.IsTrue(b.IsDisposed);
            Assert.IsTrue(c.IsDisposed);
        }
Esempio n. 2
0
        public void Run()
        {
            var provider = new NodeDefinitionProvider("FileWriter");

            provider.Register("FileReader", new NodeDefinition()
            {
                Name = "FileReader"
            });
            provider.Register("FileWriter", new NodeDefinition()
            {
                Name      = "FileWriter",
                DependsOn = new List <string>()
                {
                    "ErrorWriter"
                }
            });
            provider.Register("ErrorWriter", new NodeDefinition()
            {
                Name      = "ErrorWriter",
                DependsOn = new List <string>()
                {
                    "FileReader"
                }
            });
            var input  = @"C:\Temp\My\1.txt";
            var output = @"C:\Temp\My\2.txt";
            var error  = @"C:\Temp\My\errors.txt";

            using (StreamWriter sw = new StreamWriter(input))
            {
                for (int i = 0; i < 100000; i++)
                {
                    if (i % 3000 == 0)
                    {
                        sw.WriteLine($"POOP{i}");
                    }
                    else
                    {
                        sw.WriteLine(i);
                    }
                }
            }
            var nodeRegistry = new NodeRegistry <FileMoverData>();

            nodeRegistry.Register("FileReader", new BaseNode <FileMoverData>(new FileReader(input), provider.GetByName("FileReader")));
            nodeRegistry.Register("FileWriter", new BaseNode <FileMoverData>(new FileWriter(output), provider.GetByName("FileWriter")));
            nodeRegistry.Register("ErrorWriter", new BaseNode <FileMoverData>(new ErrorWriter(error), provider.GetByName("ErrorWriter")));


            var runner = new DataNodeRunner <FileMoverData>(provider, nodeRegistry);

            runner.Run();
            runner.Dispose();
        }