Esempio n. 1
0
        public static void Main(string[] args)
        {
            var genomeDatabase          = Generators.PrepareGenomes();
            var simpleDatabase          = Generators.PrepareSimpleDatabase(genomeDatabase);
            var excellDatabase          = Generators.PrepareExcellDatabase(genomeDatabase);
            var overcomplicatedDatabase = Generators.PrepareOvercomplicatedDatabase(genomeDatabase);
            var mediaOutlet             = new MediaOutlet();

            Console.WriteLine("ETAP 1\n");

            Console.WriteLine("Simple database without genomes");
            var it = GetVirusIterator(GetDatabaseIterator(simpleDatabase));

            mediaOutlet.Publish(it);

            Console.WriteLine("Simple database with genomes");
            it = GetVirusIterator(GetDatabaseIterator(simpleDatabase), genomeDatabase);
            mediaOutlet.Publish(it);

            Console.WriteLine("Excell database");
            it = GetVirusIterator(GetDatabaseIterator(excellDatabase), genomeDatabase);
            mediaOutlet.Publish(it);

            Console.WriteLine("Overcomplicated database");
            it = GetVirusIterator(GetDatabaseIterator(overcomplicatedDatabase), genomeDatabase);
            mediaOutlet.Publish(it);

            Console.WriteLine("ETAP 2\n");

            Console.WriteLine("Filter:");
            it = GetVirusIterator(GetDatabaseIterator(excellDatabase), genomeDatabase);
            mediaOutlet.Publish(new FilterIterator(it, new FilterDeathRateGreater(15)));

            Console.WriteLine("Mapping:");
            it = GetVirusIterator(GetDatabaseIterator(excellDatabase), genomeDatabase);
            mediaOutlet.Publish(new FilterIterator(
                                    new ModifierIterator(
                                        it, new ModifierDeathRate(10)),
                                    new FilterDeathRateGreater(15)));

            Console.WriteLine("Concatenate:");
            it = GetVirusIterator(GetDatabaseIterator(excellDatabase), genomeDatabase);
            var it2 = GetVirusIterator(GetDatabaseIterator(overcomplicatedDatabase), genomeDatabase);

            mediaOutlet.Publish(new ConcatenateIterator(it, it2));

            // testing animals
            var tester = new Tester();

            tester.Test();
        }
        public static void Main(string[] args)
        {
            var genomeDatabase          = Generators.PrepareGenomes();
            var simpleDatabase          = Generators.PrepareSimpleDatabase(genomeDatabase);
            var excellDatabase          = Generators.PrepareExcellDatabase(genomeDatabase);
            var overcomplicatedDatabase = Generators.PrepareOvercomplicatedDatabase(genomeDatabase);
            var mediaOutlet             = new MediaOutlet(genomeDatabase);

            Console.WriteLine("------ Simple database ------\n");
            mediaOutlet.Publish(simpleDatabase);
            Console.WriteLine("\n------ Excel database ------\n");
            mediaOutlet.Publish(excellDatabase);
            Console.WriteLine("\n------ Overcomplicated database ------\n");
            mediaOutlet.Publish(overcomplicatedDatabase);

            Console.WriteLine("\n------ Decorators: filter Excel by DeathRate > 15 ------\n");
            Func <VirusData, bool> f = virus => virus.DeathRate > 15;
            IDecorator             filteredByDeathRate = new Filter(excellDatabase, f);

            mediaOutlet.Publish(filteredByDeathRate);


            Console.WriteLine("\n------ Decorators: increased death rate of each Excel virus by 10 and then filtered by DeathRate > 15 ------\n");
            Func <VirusData, VirusData> m  = virus => new VirusData(virus.VirusName, virus.DeathRate + 10, virus.InfectionRate, virus.Genomes);
            IDecorator MappingAndFiltering = new Mapping(excellDatabase, m);

            MappingAndFiltering = new Filter(MappingAndFiltering, f); // or we can declare two different IDecorator objects: IDecorator NotMappingAndFiltering = new Filter(MappingAndFiltering...);
            mediaOutlet.Publish(MappingAndFiltering);

/*            Console.WriteLine("\n------ Decorators: concat excel and overcomplicated databases ------");
 *          IDecorator concat = new Concat(excellDatabase, overcomplicatedDatabase);
 *          mediaOutlet.Publish(concat);*/

            Console.WriteLine();

            // testing animals
            var tester = new Tester();

            tester.Test();
        }