Пример #1
0
        public override void Display()
        {
            CompositeLetterIterator i = new CompositeLetterIterator(this);

            for (i.First(); !i.IsDone(); i.Next())
            {
                i.CurrentItem().Display();
            }
        }
Пример #2
0
        private void GetLetters_Click(object sender, EventArgs e)
        {
            Handler h1 = new CheckingEmailAddress();
            Handler h2 = new CheckingEmailSubject();
            Handler h3 = new CheckingEmailText();

            h1.SetSuccessor(h2);
            h2.SetSuccessor(h3);

            List <string> lines = File.ReadAllLines("input.txt", Encoding.GetEncoding(1251)).ToList();

            if (lines.Count > 3)
            {
                CompositeLetter compLet = new CompositeLetter();
                for (int j = 0; j < lines.Count; j += 3)
                {
                    List <string> l = new List <string>();
                    l.Add(lines[j]);
                    l.Add(lines[j + 1]);
                    l.Add(lines[j + 2]);
                    Letter letter = new Letter();
                    letter.SetLetter(l);
                    compLet.Add(letter);
                }

                CompositeLetterIterator i = new CompositeLetterIterator(compLet);
                for (i.First(); !i.IsDone(); i.Next())
                {
                    h1.HandleRequest(i.CurrentItem());
                }
                compLet.Display();
            }
            else
            {
                Letter letter = new Letter();
                letter.SetLetter(lines);
                h1.HandleRequest(letter);
                letter.Display();
            }
        }