static void Main(string[] args)
        {
            PersonelAggregate aggregate = new PersonelAggregate();

            aggregate.Add(new Personel {
                Id = 1, Adi = "Hasan", SoyAdi = "Sancaktar"
            });
            aggregate.Add(new Personel {
                Id = 2, Adi = "Ali", SoyAdi = "Kap"
            });
            aggregate.Add(new Personel {
                Id = 3, Adi = "Müco", SoyAdi = "Murat"
            });
            aggregate.Add(new Personel {
                Id = 4, Adi = "Bunyo", SoyAdi = "Gürmüc"
            });
            aggregate.Add(new Personel {
                Id = 5, Adi = "Ercan", SoyAdi = "Sakal"
            });

            IIterator iterasyon = aggregate.CreateIterator();

            while (iterasyon.HasItem())
            {
                Console.WriteLine($"ID : {iterasyon.CurrentItem().Id}\nAdı : {iterasyon.CurrentItem().Adi}\nSoyadı : {iterasyon.CurrentItem().SoyAdi}\n*****");
                iterasyon.NextItem();
            }

            Console.Read();
        }
Exemple #2
0
        private Student SearchStudentById(string id)
        {
            Student   result   = null;
            IIterator iterator = studentList.createIterator();

            while (!iterator.IsDone())
            {
                if (iterator.CurrentItem().Id == id)
                {
                    result = iterator.CurrentItem() as Student;
                }
                iterator.Next();
            }
            return(result);
        }
Exemple #3
0
        private Lecturer SearchLecturerById(string id)
        {
            Lecturer  result   = null;
            IIterator iterator = lecturerList.createIterator();

            while (!iterator.IsDone())
            {
                if (iterator.CurrentItem().Id == id)
                {
                    result = iterator.CurrentItem() as Lecturer;
                }
                iterator.Next();
            }
            return(result);
        }
Exemple #4
0
 public void PrintItems(IIterator <Item> iterator)
 {
     for (iterator.First(); !iterator.IsDone(); iterator.Next())
     {
         iterator.CurrentItem().Print();
     }
 }
        static void Main()
        {
            var myMatrix = new Matrix <double>(3, 3);

            helper.PrintColorText("Filling Matrix:\n\n", "cyan");

            for (int i = 0; i < myMatrix.Rows; i++)
            {
                for (int j = 0; j < myMatrix.Cols; j++)
                {
                    myMatrix[i, j] = (i + 1) * (j + 1);
                    helper.PrintColorText(myMatrix[i, j].ToString() + "\n", "green");
                }
            }

            Console.WriteLine();

            IIterator iterator = myMatrix.GetIterator();

            helper.PrintColorText("Iterationg Matrix in reverse:\n\n", "cyan");

            while (!iterator.IsDone())
            {
                helper.PrintColorText(iterator.CurrentItem().ToString() + "\n", "green");
                iterator.Next();
            }

            Console.WriteLine();
        }
Exemple #6
0
        private void SearchStudent()
        {
            Console.WriteLine("Enter the name of the student to search:");
            string    keyword  = Console.ReadLine();
            IIterator iterator = studentList.createIterator();

            while (!iterator.IsDone())
            {
                if (iterator.CurrentItem().Name.IndexOf(keyword, StringComparison.Ordinal) > -1)
                {
                    Console.WriteLine(iterator.CurrentItem().Display());
                }
                iterator.Next();
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemple #7
0
 // Metoda vezme instanci iterátoru a postará se o výpis všech prvků
 // Zároveň se zde ukazuje klasické využití iterátorových funkcí v cyklu for
 // pro průchod všemi prvky
 static void printAllUsingIterator(IIterator <int> iterator)
 {
     for (iterator.First(); !iterator.IsDone(); iterator.Next())
     {
         Console.Write(iterator.CurrentItem());
     }
     Console.WriteLine();
 }
Exemple #8
0
 static void PrintItems(IIterator iterator)
 {
     while (!iterator.IsDone())
     {
         Console.WriteLine($"Current item is {iterator.CurrentItem()}");
         iterator.Next();
     }
 }
Exemple #9
0
        private void SearchLecturer()
        {
            Console.WriteLine("Input search text:");
            string    keyword  = Console.ReadLine();
            IIterator iterator = lecturerList.createIterator();

            while (!iterator.IsDone())
            {
                if (iterator.CurrentItem().Name.IndexOf(keyword, StringComparison.Ordinal) > -1)
                {
                    Console.WriteLine(iterator.CurrentItem().Display());
                }
                iterator.Next();
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemple #10
0
        /*
         * Method: EvaluateStack()
         * Purpose: Evaluate a stack from [0] - [2] (3 elements)
         * Parameters: HeavyObjectList
         * Returns: double
         */
        public double EvaluateStack(HeavyObjectList input)
        {
            //rewards points based on the postition the heaviest object is one.
            //input[0] should be the heaviest in the stack  for it to be a bottomweight stack
            //create a list that will hold the volume and mass of each object
            List <float> mass = new List <float>();

            for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next())
            {
                mass.Add(i.CurrentItem().Mass);
            }
            //after loading the mass of each object into a list, we can now see if the heaviest in index [0]
            //with the mass , then sort, then reverse,because sort is ascending order and I want descending
            mass.Sort();
            mass.Reverse();

            //lets see the stack first has the heaviest object on the bottom.
            float total = 0.0f;

            if (mass[0] == input.At(0).Mass)
            {
                //if we have the heaviest at the bottom
                //im going to add all the values up and divide by the number of elements
                foreach (float value in mass)
                {
                    total = total + value;
                }
                float count = total / input.Length();
                return((float)Math.Round(count));
            }
            else if (mass[1] == input.At(0).Mass)
            {
                //if we have the second heaviest object on the bottom
                //use this algorithm
                //total the massess like before
                foreach (float value in mass)
                {
                    total = total + value;
                }
                //this time we are going to return a value that is the total divided by the #elements + 2
                float count = total / (input.Length() + 2);
                return((float)Math.Round(count));
            }
            else
            {
                //the bottom is basically at the top
                //total the massess like before
                foreach (float value in mass)
                {
                    total = total + value;
                }
                //this time we are going to return a value that is the total divided by the #elements + 4
                float count = total / (input.Length() + 4);
                return((float)Math.Round(count));
            }
        }
Exemple #11
0
        /// <summary>
        /// you get all informations in  department
        /// </summary>
        /// <returns> informations string </returns>
        public override string ToString()
        {
            string superString = null;

            superString  = "\n------------------------------\n";
            superString += "\n**Deparment Name : " + this.name + "**\n";
            superString += "\n------------------------------\n";

            superString += "\n**All Students in department**\n";
            if (this.students.Count == 0)
            {
                superString += "\n-----------Empty----------\n";
            }
            foreach (Student item in this.students)
            {
                superString += item.ToString();
            }



            superString += "\n**All Lecturer in department**\n";
            if (this.lecturers.Count == 0)
            {
                superString += "\n-----------Empty----------\n";
            }
            foreach (Lecturer item in this.lecturers)
            {
                superString += item.ToString();
            }

            superString += "\n--------------------------------" + this.name.ToUpper() + " IN LESSONS-------------------------------\n";
            //I'm going to use to get to Iterator degin pattern lessons
            LessonAggregate aggregate = new LessonAggregate();

            if (lessons.Count == 0)
            {
                superString += "\n-----------Empty----------\n";
            }

            foreach (Lesson item in lessons)
            {
                aggregate.Add(item);
            }

            IIterator iterator = aggregate.CreateIterator();

            while (iterator.HasItem())
            {
                superString += iterator.CurrentItem().ToString();
                iterator.NextItem();
            }
            superString += "\n\n\n";
            return(superString);
        }
Exemple #12
0
 public void Play()
 {
     if (singleton.SoundWaveOut.PlaybackState == PlaybackState.Paused)
     {
         command.Play();
     }
     else if (singleton.SoundWaveOut.PlaybackState == PlaybackState.Playing)
     {
         command.Pause();
     }
     else
     {
         SoundSingleton.GetInstance().StopWaveOut();
         if (File.Exists(iterator.CurrentItem().Path))
         {
             command.Init(iterator.CurrentItem().Path);
             command.Play();
             string name = Path.GetFileName(iterator.CurrentItem().Path).Split('.')[0];
         }
     }
 }
Exemple #13
0
        //适用性:
        //1.访问一个聚合对象的内容而无需暴露它的内部表示。
        //2.支持对聚合对象的多种遍历。
        //3.为遍历不同的聚合结构提供一个统一的接口(即, 支持多态迭代)。
        public void Test()
        {
            IList     list      = new ConcreteList();
            IIterator iIterator = list.GetIterator();

            while (iIterator.MoveNext())
            {
                Console.WriteLine($"Item is {iIterator.CurrentItem().ToString()}");
                iIterator.Next();
            }

            Console.ReadLine();
        }
Exemple #14
0
        static void Main(string[] args)
        {
            IList <string> list = new List <string>()
            {
                "Катя", "Маша", "Петя", "Саша"
            };
            IAgregator <string> myList   = new MyList <string>(list);
            IIterator <string>  iterator = new MyListIterator <string>(myList);

            for (IIterator <string> i = iterator; !i.IsDone(); i.Next())
            {
                Console.WriteLine(i.CurrentItem());
            }

            Console.ReadKey();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            IAggregate aggregate = new ConcreateAggregate("Item1", "Item2", "Item3", "Item4");
            IIterator  iterator  = aggregate.CreateIterator();

            if (iterator.IsDone())
            {
                iterator.First();
            }
            while (!iterator.IsDone())
            {
                Console.WriteLine(iterator.CurrentItem());
                iterator.Next();
            }

            Console.ReadKey();
        }
Exemple #16
0
        static void Main(string[] args)
        {
            ConcreteAgregate agregate = new ConcreteAgregate();

            agregate.Add("Marcin");
            agregate.Add("Tomasz");
            agregate.Add("Paweł");
            agregate.Add("Krzysztof");
            agregate.Add("Piotr");


            IIterator iterator = agregate.GetIterator();

            while (!iterator.IsDone())
            {
                Console.WriteLine(iterator.CurrentItem());

                iterator.Next();
            }
        }
        private void SaveSettingsToFile()
        {
            using (FileStream fs = File.Open("settings.dat", FileMode.Create))
            {
                try
                {
                    using (BinaryWriter w = new BinaryWriter(fs))
                    {
                        w.Write(settings.StepDelay);
                        w.Write(settings.RetryStepDelay);
                        w.Write(settings.MaximumNumberOfRetries);
                        int rowsCount    = instance.GetMatrixRowCount();
                        int columnsCount = instance.GetMatrixColumnCount();
                        w.Write(rowsCount);
                        w.Write(columnsCount);
                        w.Write(settings.RowDeviation);
                        w.Write(settings.ColumnDeviation);
                        IIterator instanceIterator = instance.Iterator();
                        instanceIterator.First();
                        while (!instanceIterator.IsDone())
                        {
                            ExportPointMatrixItem item = instanceIterator.CurrentItem();
                            w.Write(item.PointDescription);
                            w.Write(item.IsAvaliable);
                            instanceIterator.Next();
                        }
                        w.Close();
                    }
#if DEBUG
                    Console.WriteLine("写入文件完成");
#endif
                }
                catch (IOException e)
                {
#if DEBUG
                    Console.WriteLine("写入文件发生 IO 错误: " + e.Message);
#endif
                }
            }
        }
        public void Start()
        {
            ConcreteAggregate a = new ConcreteAggregate();

            a[0] = "First element";
            a[1] = "Second element";
            a[2] = "Third element";

            IIterator i = a.CreateIterator();

            Console.WriteLine("Collection is:");

            object item = i.First();

            while (item != null)
            {
                Console.WriteLine($"- {item}");
                item = i.Next();
            }

            Console.WriteLine($"\nCurrent item: {i.CurrentItem()}");
            Console.WriteLine($"Is done: {i.IsDone()}");
        }
Exemple #19
0
        /*
         * Method: EvaluateStack()
         * Purpose: Evaluate a stack from [0] - [2] (3 elements)
         * Parameters: HeavyObjectList
         * Returns: double
         */
        public double EvaluateStack(HeavyObjectList input)
        {
            //opposite of a pyramid, we need to look at mass and volume.
            //logically for a topple, the smallest shape  should logically be on the bottom with the largest shape on top
            //looking at density. (least, middle, most) will topple but also (small,medium,large) shape
            //create a list to make the ideal senario
            List <float> topple = new List <float>();

            for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next())
            {
                topple.Add(i.CurrentItem().Density);
            }
            topple.Sort(); //this should give us a least,meduim,most denisty structure with least at [0];

            //similar to the other structures, we can see if the list[0] is the same as topple[0] for the ideal toople structure
            if (input.At(0).Density == topple[0]) //if the bottom is the most dense
            {
                //we need to find the second most dense and see if it is in the middle
                if (input.At(1).Density == topple[1])
                {
                    //this gaurentees that we have a toople (because there us only 3 elements in every list, this would not work in a real world situation where there could be mutliple lists with different lengths).
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length();
                    return((float)Math.Round(count));
                }
                else //heavy,least,meduim
                {
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 15;
                    return((float)Math.Round(count));
                }
            }
            else if (input.At(0).Density == topple[1]) // we have a medium,heavy,least or meduim, least, heavy, more chance of topple than the previous else above
            {
                if (input.At(1).Density == topple[0])
                {
                    //medium,heavy,least
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 35;
                    return((float)Math.Round(count));
                }
                else //we have a medium,least,heavy
                {
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 25; //almost equal posiblity of it toppling wth senario (heavy,least,meduim)
                    return((float)Math.Round(count));
                }
            }
            else
            {
                //we have a least,meduim,heavy or least,heavy,medium
                if (input.At(1).Density == topple[1]) //meduim in the middle
                {
                    //least,meduim,heavy, proabbly wont topple at all
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 55;
                    return((float)Math.Round(count));
                }
                else
                {
                    //least,heavy,medium
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = (float)Math.Round(total / input.Length() + 85);
                    return(count);
                }
            }
        }
Exemple #20
0
 public object CurrentItem()
 {
     return(_myIt.CurrentItem());
 }
        static void Main(string[] args)
        {
            /************************ 1- FACTORY PATTERN  **************************/
            Console.WriteLine("\n" + "/******************Factory Pattern Çalıştı**************/" + "\n");
            Creater creater  = new Creater();
            Calisan calisan1 = creater.FactoryMethod(Calisanlar.Personel);
            Calisan calisan2 = creater.FactoryMethod(Calisanlar.Sofor);

            calisan1.calisan();
            calisan2.calisan();

            /************************ 2- SINGLETON PATTERN  **************************/
            Console.WriteLine("\n" + "/******************Singleton Pattern Çalıştı**************/" + "\n");

            Depo depo1 = Depo.Depo_Nesnesi;

            depo1.Sicaklik = 5;
            Console.WriteLine("Depo1 nesnesi üretildi Depo1 Sıcaklık: " + depo1.Sicaklik + "\n");
            Depo depo2 = Depo.Depo_Nesnesi;

            depo2.Sicaklik = -10;
            Console.WriteLine("Depo2 nesnesi üretildi Depo2 Sıcaklık: " + depo2.Sicaklik + "\n");

            if (depo1 == depo2)
            {
                Console.WriteLine("Nesneler singleton pattern ile üretildiği için depo1 depo2'deki değişiklikten etkilendi.\n  Depo1 Sıcaklık: " + depo1.Sicaklik + "\n" + "  Depo2 Sıcaklık: " + depo2.Sicaklik);
            }

            else
            {
                Console.WriteLine("Nesneler farklıdır");
            }

            /************************ 3-PROTOTYPE PATTERN  **************************/
            Console.WriteLine("\n" + "/******************Prototype Pattern Çalıştı**************/" + "\n");

            Kontrol kontrol1 = new Kontrol();

            kontrol1.MaxKapasite = 3000;
            kontrol1.MaxSicaklik = -3;
            Console.WriteLine("Kontrol1 oluşturuldu.\n");
            Console.WriteLine("Kontrol1 MaxKapasitesi: " + kontrol1.MaxKapasite + "  Kontrol1 MaxSıcaklık: " + kontrol1.MaxSicaklik + "\n\n");
            Kontrol kontrol2 = kontrol1.DeepCopy();

            kontrol2.MaxKapasite = 2000;
            kontrol2.MaxSicaklik = 0;

            Console.WriteLine("DeepCopy ile Kontrol2 oluşturuldu ve kontrol1 etkilenmedi." + "\n" + "Kontrol2 MaxKapasitesi: " + kontrol2.MaxKapasite + "  Kontrol2 MaxSıcaklık: " + kontrol2.MaxSicaklik + "\n" + "Kontrol1 MaxKapasitesi: " + kontrol1.MaxKapasite + "  Kontrol1 MaxSıcaklık: " + kontrol1.MaxSicaklik + "\n");
            var kontrol3 = kontrol1.ShallowCopy();

            Console.WriteLine("ShallowCopy ile Kontrol3 oluşturuldu ." + "\n" + "Kontrol3 MaxKapasitesi: " + kontrol3.MaxKapasite + "  Kontrol3 MaxSıcaklık: " + kontrol3.MaxSicaklik);


            /************************ 4- OBJECT POOL PATTERN  **************************/
            Console.WriteLine("\n" + "/******************Object Pool Pattern Çalıştı**************/" + "\n");

            Console.WriteLine("Havuzun boyutu {0}", ClientPool.Instance.Size);

            Console.WriteLine("Client sınıfı ediniyoruz.");
            var client1 = ClientPool.Instance.AcquireObject();

            client1.Connect();

            Console.WriteLine("Client'ı geri bırakıyoruz");
            if (client1 != null)
            {
                ClientPool.Instance.ReleaseObject(client1);
            }

            var clients = new List <Client>();

            for (int i = 0; i < ClientPool.Instance.Size; i++)
            {
                clients.Add(ClientPool.Instance.AcquireObject());
            }

            Console.WriteLine("Uygun olan tüm Client nesneleri listeye eklendi.");

            var nullClient = ClientPool.Instance.AcquireObject();

            if (nullClient == null)
            {
                Console.WriteLine("Daha fazla Client sınıfı bulunmamaktadır.");
            }

            Console.WriteLine("Havuzun boyutunu arttırıyoruz");
            ClientPool.Instance.IncreaseSize();

            Console.WriteLine("Yeni bir Client sınıfı ediniyoruz.");
            var newClient = ClientPool.Instance.AcquireObject();

            newClient.Connect();

            Console.WriteLine("Edindiğimiz sınıfı geri veriyoruz.");
            if (newClient != null)
            {
                ClientPool.Instance.ReleaseObject(newClient);
            }

            Console.WriteLine("Listedeki tüm Client sınıflarını geri bırakıyoruz.");

            foreach (var item in clients)
            {
                ClientPool.Instance.ReleaseObject(item);
            }

            /************************ 5-ABSTRACT FACTORY PATTERN  **************************/
            Console.WriteLine("\n" + "/******************Abstract Factory Pattern Çalıştı**************/" + "\n");

            IUrunFactory factory = new YesilFactory();

            Console.WriteLine("YeşilFactory çalıştı.\n");
            var YesilElma = factory.Elma();
            var YesilErik = factory.Erik();

            Console.WriteLine(YesilErik.ErikFeature());
            Console.WriteLine(YesilElma.ElmaFeature());

            IUrunFactory factory2 = new KırmızıFactory();

            Console.WriteLine("\nKırmızıFactory çalıştı.\n");
            var KırmızıElma = factory2.Elma();
            var KırmızıErik = factory2.Erik();

            Console.WriteLine(KırmızıErik.ErikFeature());
            Console.WriteLine(KırmızıElma.ElmaFeature());

            /************************ 6- BUILDER PATTERN  **************************/
            Console.WriteLine("\n" + "/******************Builder Pattern Çalıştı**************/" + "\n");

            UrunBuilder urun = new ElmaBuilder();
            UrunUret    uret = new UrunUret();

            uret.Uret(urun);

            Console.WriteLine(urun.Urun.ToString());

            urun = new ErikBuilder();
            uret.Uret(urun);
            Console.WriteLine(urun.Urun.ToString());

            /************************ 7-ITERATOR PATTERN  **************************/
            Console.WriteLine("\n" + "/****************** Iterator Pattern Çalıştı**************/" + "\n");
            PersonelAggregate aggregate = new PersonelAggregate();

            aggregate.Add(new Personel {
                Id = 1, Adi = "Personel1", SoyAdi = "Soyad1"
            });
            aggregate.Add(new Personel {
                Id = 2, Adi = "Personel2", SoyAdi = "Soyad2"
            });

            IIterator iterasyon = aggregate.CreateIterator();

            while (iterasyon.HasItem())
            {
                Console.WriteLine($"ID : {iterasyon.CurrentItem().Id}\nAdı : {iterasyon.CurrentItem().Adi}\nSoyadı : {iterasyon.CurrentItem().SoyAdi}\n");
                iterasyon.NextItem();
            }


            /************************ 8-OBSERVER PATTERN  **************************/
            Console.WriteLine("\n" + "/****************** Observer Pattern Çalıştı**************/" + "\n");
            urunKabul kabul    = new SebzeKabul();
            ICalisan  yonetici = new Yonetici();

            kabul.Bilgilendir(new Yonetici("Murat Bey"));
            kabul.YeniBilgilendirme(new Urun2("Soğan", 5000));

            // Murat bey oluşturulduğu için bundan sonrakilerde otomatik bilgilendirilcek !!!

            kabul.Bilgilendir(new Yonetici("Sinan Bey"));
            kabul.YeniBilgilendirme(new Urun2("Havuç", 750));

            /************************ 9-MEMENTO PATTERN  **************************/
            Console.WriteLine("\n" + "/****************** Memento Pattern Çalıştı**************/" + "\n");

            KontrolSistemi sistem = new KontrolSistemi();

            sistem.MaxSicaklik = -10;
            sistem.MaxKapasite = 2300;
            sistem.DepoId      = 1;
            Console.WriteLine(sistem.ToString());

            Caretaker Taker = new Caretaker();

            Taker.Memento = sistem.Kaydet();

            sistem.MaxSicaklik = -12;
            sistem.MaxKapasite = 1850;
            sistem.DepoId      = 1;
            Console.WriteLine(sistem.ToString());
            sistem.OncekiniYukle(Taker.Memento);

            Console.WriteLine("\n Sistem önceki durumuna geri döndü.\n" + sistem.ToString());

            /************************ 10-CHAIN OF RESPONSİBİLİTY PATTERN  **************************/
            Console.WriteLine("\n" + "/****************** ChainofResponsibility Pattern Çalıştı**************/" + "\n");

            Calisan dep1 = new Sofor();
            Calisan dep2 = new Personel();

            dep1.Sonraki = dep2;

            dep1.calisan("Şöför");
            dep2.calisan("Personel");
            dep2.calisan("Müdür");


            /************************ 11-DECORATOR PATTERN  **************************/
            Console.WriteLine("\n" + "/****************** Decorator Pattern Çalıştı**************/" + "\n");

            Arac arac = new Arac()
            {
                Model = "Astra", Km = 100, Yakıt = 120
            };

            arac.DetayYaz();
            KmDecorator kmdeco = new KmDecorator(arac);

            kmdeco.DetayYaz();

            KmDecorator kmdeco2 = new KmDecorator(arac);

            kmdeco2.DetayYaz();

            Console.WriteLine("\n\n 11 Adet pattern çalıştı.");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // Create our HeavyObjects (DO NOT MODIFY THESE VALUES)
            HeavyObject lightest      = new HeavyObject(10, 10, 1, 1);
            HeavyObject medium        = new HeavyObject(7, 7, 2, 5);
            HeavyObject heavyAndSmall = new HeavyObject(5, 5, 5, 50);

            // Create lists of the HeavyObjects and print them for debug purposes
            HeavyObjectList listA = new HeavyObjectList();

            listA.Add(heavyAndSmall);
            listA.Add(medium);
            listA.Add(lightest);
            Console.WriteLine($"Testing First() method in ListA:");
            IIterator iterator = listA.CreateIterator();

            iterator.First().Print();
            Console.WriteLine("\nItems in ListA:");
            for (IIterator i = listA.CreateIterator(); !i.IsDone(); i.Next())
            {
                i.CurrentItem().Print();
            }

            Console.WriteLine();

            HeavyObjectList listB = new HeavyObjectList();

            listB.Add(medium);
            listB.Add(lightest);
            listB.Add(heavyAndSmall);
            iterator = listB.CreateIterator();
            Console.WriteLine($"Testing First() method in ListB:");
            iterator.First().Print();
            Console.WriteLine("\nItems in ListB:");
            for (IIterator i = listB.CreateIterator(); !i.IsDone(); i.Next())
            {
                i.CurrentItem().Print();
            }
            Console.WriteLine();

            HeavyObjectList listC = new HeavyObjectList();

            listC.Add(lightest);
            listC.Add(medium);
            listC.Add(heavyAndSmall);
            iterator = listC.CreateIterator();
            Console.WriteLine($"Testing First() method in listC.");
            iterator.First().Print();
            Console.WriteLine("\nItems in ListC:");
            for (IIterator i = listC.CreateIterator(); !i.IsDone(); i.Next())
            {
                i.CurrentItem().Print();
            }
            Console.WriteLine();

            // Create our Flyweight Factory and create the Flyweights out of it
            FlyweightFactory fw           = new FlyweightFactory();
            StackingStrategy bottomWeight = fw.GetFlyweight("bottomWeight");
            StackingStrategy pyramid      = fw.GetFlyweight("pyramid");
            StackingStrategy topple       = fw.GetFlyweight("topple");


            // Print results
            Console.WriteLine("BottomWeight - ListA: " + bottomWeight.EvaluateStack(listA));
            Console.WriteLine("BottomWeight - ListB: " + bottomWeight.EvaluateStack(listB));
            Console.WriteLine("BottomWeight - ListC: " + bottomWeight.EvaluateStack(listC));
            Console.WriteLine();

            Console.WriteLine("Pyramid - ListA: " + pyramid.EvaluateStack(listA));
            Console.WriteLine("Pyramid - ListB: " + pyramid.EvaluateStack(listB));
            Console.WriteLine("Pyramid - ListC: " + pyramid.EvaluateStack(listC));
            Console.WriteLine();

            Console.WriteLine("Topple - ListA: " + topple.EvaluateStack(listA));
            Console.WriteLine("Topple - ListB: " + topple.EvaluateStack(listB));
            Console.WriteLine("Topple - ListC: " + topple.EvaluateStack(listC));
        }
Exemple #23
0
        public static List <IProcessItem> GenerateProcessQueue(
            ExportPointMatrix matrix,
            TargetRectangle rectangle,
            WindowHandle handle,
            SettingComponent settings)
        {
            List <IProcessItem> queue = new List <IProcessItem>();
            IProcessItem        procItem;

            switch (settings.ProcessType)
            {
            case ProcessTypeFlags.MAINBOARD_FIND_HANDLE:
                procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, false);
                queue.Add(procItem);
                procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.MAINBOARD_FIND_RECTANGLE:
                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0);
                queue.Add(procItem);
                procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                queue.Add(procItem);
                procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "GXWND", 1);
                queue.Add(procItem);
                procItem = new ProcessItem_GetControlRectangle(handle);
                queue.Add(procItem);
                procItem = new ProcessItem_CalcRectExportPointMatrix(matrix, rectangle, settings.RowDeviation, settings.ColumnDeviation);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.MAINBOARD_CHECK_POSITION:
            {
                IIterator matrixPointIterator = matrix.Iterator();
                for (; !matrixPointIterator.IsDone(); matrixPointIterator.Next())
                {
                    ExportPointMatrixItem item = matrixPointIterator.CurrentItem();
                    if (!item.IsAvaliable)
                    {
                        continue;          // 没被选中忽略
                    }
                    else
                    {
                        procItem = new ProcessItem_MouseMove(item.PointX, item.PointY);
                        queue.Add(procItem);
                    }
                }
            }
            break;

            case ProcessTypeFlags.OVERWRITE_PARENT_WND:
                procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_WINDOW:
                procItem = new ProcessItem_FindWindow(handle, settings.StringParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_WINDOW_EX:
                procItem = new ProcessItem_FindWindowEx(handle, settings.StringParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_WINDOW_BY_NAME:
                procItem = new ProcessItem_FindWindowByName(handle, settings.StringParam, settings.IntParam, false);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_CONTROL_BY_CLASSNAME:
                procItem = new ProcessItem_FindCtrlByCtrlClass(handle, settings.StringParam, settings.IntParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_CONTROL_BY_NAME:
                procItem = new ProcessItem_FindCtrlByCtrlName(handle, settings.StringParam, settings.IntParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.GET_WINDOW_RECTANGLE:
                procItem = new ProcessItem_GetControlRectangle(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.CALCULATE_RECTANGLE_EXPORT_POINT_MATRIX:
                procItem = new ProcessItem_CalcRectExportPointMatrix(matrix, rectangle, settings.RowDeviation, settings.RowDeviation);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.SET_COMBOBOX_CURSEL:
                procItem = new ProcessItem_SetComboBoxCrusel(handle, settings.IntParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.SET_TEXTBOX_VALUE:
                procItem = new ProcessItem_SetTextBoxValue(handle, settings.StringParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.CONTROL_MOUSE_LBUTTON_CLICK:
                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.MOUSE_LBUTTON_CLICK:
                procItem = new ProcessItem_NormMouseLeftButtonClick();
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.DEFAULT:
            {
                IIterator matrixPointIterator = matrix.Iterator();
                for (; !matrixPointIterator.IsDone(); matrixPointIterator.Next())
                {
                    ExportPointMatrixItem item = matrixPointIterator.CurrentItem();
                    // 判断该位置是否被选中
                    if (!item.IsAvaliable)
                    {
                        continue;          // 没被选中忽略
                    }
                    else
                    // 开始执行既定步骤
                    {
                        // 鼠标移动到该位置
                        procItem = new ProcessItem_MouseMove(item.PointX, item.PointY);
                        queue.Add(procItem);
                        // 鼠标点击该位置
                        procItem = new ProcessItem_NormMouseLeftButtonClick();
                        queue.Add(procItem);
                        /* 弹出图片详情后 */
                        // 获取主窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 找到 Plate 1 控件句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 找到 Process... 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Process...", 0);
                        queue.Add(procItem);
                        // 点击 Process 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);

                        /* 弹出 Image Stitching 后 */
                        // 获取 Image Stitching 窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, "Image Stitching", 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 ComboBox 句柄
                        procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "ComboBox", 0);
                        queue.Add(procItem);
                        // 设置 ComboBox 选项为第 1 个
                        procItem = new ProcessItem_SetComboBoxCrusel(handle, 0);
                        queue.Add(procItem);
                        // 获取 Edit 句柄
                        procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "Edit", 0);
                        queue.Add(procItem);
                        // 设置 Edit 值为 50.00
                        procItem = new ProcessItem_SetTextBoxValue(handle, "50.00");
                        queue.Add(procItem);
                        // 获取 OK 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "OK", 0);
                        queue.Add(procItem);
                        // 点击 OK 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);

                        /* 弹出 Image Processing 窗口后 */

                        for (int i = 0; i < 3; i++)
                        {
                            // 找到 Image Processing 窗口句柄
                            procItem = new ProcessItem_FindWindowByName(handle, "Image Processing", 0, true);
                            queue.Add(procItem);
                            procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                            queue.Add(procItem);
                            // 分别选择不同选项
                            switch (i)
                            {
                            case 0:             // DAPI + GFP, 无需操作复选框
                                break;

                            case 1:             // DAPI, 取消选中 GFP
                                                // 获取 GFP 复选框句柄
                                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[GFP 469,525]", 0);
                                queue.Add(procItem);
                                // 点击 GFP 按钮
                                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                                queue.Add(procItem);
                                break;

                            case 2:             // GFP, 取消选中 DAPI
                                                // 获取 DAPI 复选框句柄
                                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[DAPI 377,447]", 0);
                                queue.Add(procItem);
                                // 点击 DAPI 复选框
                                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                                queue.Add(procItem);
                                // 获取 GFP 复选框句柄
                                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[GFP 469,525]", 0);
                                queue.Add(procItem);
                                // 点击 GFP 复选框
                                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                                queue.Add(procItem);
                                break;
                            }
                            // 获取 Save Image Set 按钮句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save Image Set", 0);
                            queue.Add(procItem);
                            // 点击 Save Image Set 按钮
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);

                            /* 弹出 Image Save Options 窗口后 */
                            // 获取 Save Image Options 窗口句柄
                            procItem = new ProcessItem_FindWindowByName(handle, "Image Save Options", 0, true);
                            queue.Add(procItem);
                            procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                            queue.Add(procItem);
                            // 获取 Save picture for presentation 单选框句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save picture for presentation", 0);
                            queue.Add(procItem);
                            // 点击 Save picture for presentation 单选框
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);
                            // 获取 Save entire image (1 camera pixel resolution) 单选框句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save entire image (1 camera pixel resolution)", 0);
                            queue.Add(procItem);
                            // 点击 Save entire image (1 camera pixel resolution) 单选框
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);
                            // 获取 OK 按钮句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "OK", 0);
                            queue.Add(procItem);
                            // 点击 OK 按钮
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);

                            /* 弹出 Save As Picture 窗口后 */
                            // 获取 Save As Picture 窗口句柄
                            procItem = new ProcessItem_FindWindowByName(handle, "Save As Picture", 0, false);
                            queue.Add(procItem);
                            procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                            queue.Add(procItem);
                            // 获取文件名输入框
                            // 获取文件名输入框的句柄
                            procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "Edit", 0);
                            queue.Add(procItem);
                            // 设置文件名(eg. ExpHlp_Expo_PosA1_DAPI_GFP_2017100112)
                            StringBuilder sb = new StringBuilder();
                            sb.AppendFormat("ExpHlp_Expo_Pos{0}_", item.PointDescription);
                            switch (i)
                            {
                            case 0:
                                // DAPI + GFP
                                sb.Append("DAPI_GFP_");
                                break;

                            case 1:
                                // DAPI
                                sb.Append("DAPI_");
                                break;

                            case 2:
                                // GFP
                                sb.Append("GFP_");
                                break;
                            }
                            sb.Append(DateTime.Now.ToString("yyyyMMddHHmm"));
                            procItem = new ProcessItem_SetTextBoxValue(handle, sb.ToString());
                            queue.Add(procItem);
                            // 获取 保存 按钮的句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "保存", 0);
                            queue.Add(procItem);
                            // 点击 保存 按钮
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);
                        }

                        /* 执行完成 Image Processing 窗口操作后 */
                        // 找到 Image Processing 窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, "Image Processing", 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 Close 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Close", 0);
                        queue.Add(procItem);
                        // 点击 Close 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);
                        // 获取主窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 Plate 1 控件句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 Close 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Close", 1);
                        queue.Add(procItem);
                        // 点击 Close 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);
                    }
                }
            }
            break;
            }
            return(queue);
        }
Exemple #24
0
        /*
         * Method: EvaluateStack()
         * Purpose: Evaluate a stack from [0] - [2] (3 elements)
         * Parameters: HeavyObjectList
         * Returns: double
         */
        public double EvaluateStack(HeavyObjectList input)
        {
            //look at the volume of each box
            List <float> volume = new List <float>();

            for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next())
            {
                volume.Add(i.CurrentItem().Volume);
            }
            volume.Sort();
            volume.Reverse();
            //by reversing after sort we can indicate that we want the most volume at the bottom  to create that Pyramid  shape.
            //test to see if the highest volume, (largest shape) is at the bottom (similar to the bottomweight except were not looking at mass
            if (volume[0] == input.At(0).Volume)
            {
                //now we can test to see if the rest if equal
                //because I know there are three objects in each list.
                int  counter = 0;
                bool isSame  = false;
                foreach (float vol in volume)
                {
                    if (vol == input.At(counter).Volume)
                    {
                        counter++;
                        isSame = true;
                        continue;
                    }
                    else
                    {
                        isSame = false;
                        break; //if the second volumes are not the same to volume stack (which should represent a Pyramid )
                    }
                }
                if (isSame)
                {
                    //return a value based on the volume of each box
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 10); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
                else
                {
                    //because it isnt the same (large, meduim,small)
                    //we must have (large,small,medium) which isnt Pyramid itself
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 20); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
            }
            //the second largest box is now one the bottom
            else if (volume[1] == input.At(0).Volume)
            {
                //the largest box is now in the middle or top
                //lets check where the largest box is
                float largeBox = input.At(1).Volume; //check ot see if this is the largest box
                if (largeBox == volume[0])           //should be teh largest box (medium, large, small)
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 30); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
                else //the largest is on the top, medium,small,large
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 40); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
            }
            //smallest box is on the bottom
            else
            {
                //where is the largest back then
                //in the middle (small,large,medium)
                //check ot see if this is the largest box
                if (volume[0] == input.At(1).Volume)
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 50); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
                else //the largest is on the top, (small,meduim,large)
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 60); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
            }
        }