Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var prospect = new SalesProspect
            {
                Name   = "Noel van Halen",
                Phone  = "(412) 256-0990",
                Budget = 2500.0m
            };

            prospect.PrintState();

            var m = new PrespectMemory();

            m.SaveState(prospect.SaveMemento());

            prospect.Name = "Leo Welch";
            m.SaveState(prospect.SaveMemento());
            prospect.PrintState();

            prospect.Phone = "(310) 209-7111";
            m.SaveState(prospect.SaveMemento());
            prospect.PrintState();

            prospect.Budget = 1000000.0m;
            m.SaveState(prospect.SaveMemento());
            prospect.PrintState();

            prospect.RestoreMemento(m.Undo());
            prospect.RestoreMemento(m.Undo());
            prospect.RestoreMemento(m.Undo());
            prospect.PrintState();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var prospect = new SalesProspect
            {
                CustomerNumber = 1,
                Name           = "Erno Perälä",
                Address        = "<unknown>",
                CustomerType   = "Lead"
            };

            Console.WriteLine("Start");
            Console.WriteLine("-----");
            Console.WriteLine("{0}", prospect.ToString());

            var careTaker = new CareTaker();

            careTaker.StoreState(prospect.SaveMemento());

            // change prospect data
            prospect.Address = "Ernolantie 6";
            careTaker.StoreState(prospect.SaveMemento());

            Console.WriteLine("After first change");
            Console.WriteLine("------------------");
            Console.WriteLine("{0}", prospect.ToString());

            // change prospect data again
            prospect.CustomerType = "Prospect";
            careTaker.StoreState(prospect.SaveMemento());

            Console.WriteLine("After second change");
            Console.WriteLine("------------");
            Console.WriteLine("{0}", prospect.ToString());


            // restore to previous state
            prospect.RestoreMemento(careTaker.GetMemento());

            Console.WriteLine("After first restore");
            Console.WriteLine("-------------------");
            Console.WriteLine("{0}", prospect.ToString());

            // restore to previous state
            prospect.RestoreMemento(careTaker.GetMemento());

            Console.WriteLine("After second restore");
            Console.WriteLine("-------------------");
            Console.WriteLine("{0}", prospect.ToString());

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var prospect = new SalesProspect
            {
                CustomerNumber = 1,
                Name = "Erno Perälä",
                Address = "<unknown>",
                CustomerType = "Lead"
            };

            Console.WriteLine("Start");
            Console.WriteLine("-----");
            Console.WriteLine("{0}", prospect.ToString());

            var careTaker = new CareTaker();
            careTaker.StoreState(prospect.SaveMemento());

            // change prospect data
            prospect.Address = "Ernolantie 6";
            careTaker.StoreState(prospect.SaveMemento());

            Console.WriteLine("After first change");
            Console.WriteLine("------------------");
            Console.WriteLine("{0}", prospect.ToString());

            // change prospect data again
            prospect.CustomerType = "Prospect";
            careTaker.StoreState(prospect.SaveMemento());

            Console.WriteLine("After second change");
            Console.WriteLine("------------");
            Console.WriteLine("{0}", prospect.ToString());

            // restore to previous state
            prospect.RestoreMemento(careTaker.GetMemento());

            Console.WriteLine("After first restore");
            Console.WriteLine("-------------------");
            Console.WriteLine("{0}", prospect.ToString());

            // restore to previous state
            prospect.RestoreMemento(careTaker.GetMemento());

            Console.WriteLine("After second restore");
            Console.WriteLine("-------------------");
            Console.WriteLine("{0}", prospect.ToString());

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            SalesProspect s = new SalesProspect();

            s.Name   = "Noel van Halen";
            s.Phone  = "(412) 256-0990";
            s.Budget = 25000.0;

            // Store internal state

            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();

            // Continue changing originator

            s.Name   = "Leo Welch";
            s.Phone  = "(310) 209-7111";
            s.Budget = 1000000.0;

            // Restore saved state

            s.RestoreMemento(m.Memento);

            // Wait for user

            Console.ReadKey();
        }
        /// <summary>
        /// The test first.
        /// </summary>
        private static void TestFirst()
        {
            SalesProspect salesProspect = new SalesProspect
            {
                Name   = "Noel van Halen",
                Phone  = "(412) 256-0990",
                Budget = 25000.0
            };

            // Store internal state
            ProspectMemory prospectMemory =
                new ProspectMemory {
                Memento = salesProspect.SaveMemento()
            };

            // Continue changing originator
            salesProspect.Name   = "Leo Welch";
            salesProspect.Phone  = "(310) 209-7111";
            salesProspect.Budget = 1000000.0;

            // Restore saved state
            salesProspect.RestoreMemento(prospectMemory.Memento);

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 6
0
        internal static void Main()
        {
            var sale = new SalesProspect { Name = "Noel van Halen", Phone = "(412) 256-0990", Budget = 25000.0 };

            // Store internal state
            var memento = sale.SaveMemento();

            // Continue changing originator
            sale.Name = "Leo Welch";
            sale.Phone = "(310) 209-7111";
            sale.Budget = 1000000.0;

            // Restore saved state
            sale.RestoreMemento(memento);
        }
Exemplo n.º 7
0
        internal static void Main()
        {
            var sale = new SalesProspect {
                Name = "Noel van Halen", Phone = "(412) 256-0990", Budget = 25000.0
            };

            // Store internal state
            var memento = sale.SaveMemento();

            // Continue changing originator
            sale.Name   = "Leo Welch";
            sale.Phone  = "(310) 209-7111";
            sale.Budget = 1000000.0;

            // Restore saved state
            sale.RestoreMemento(memento);
        }
Exemplo n.º 8
0
        public static void Main()
        {
            var sale = new SalesProspect { Name = "Noel van Halen", Phone = "(412) 256-0990", Budget = 25000.0 };

            // Store internal state
            var memory = new ProspectMemory();
            Console.WriteLine("\nSaving state --\n");
            memory.Memento = sale.SaveMemento();

            // Continue changing originator
            sale.Name = "Leo Welch";
            sale.Phone = "(310) 209-7111";
            sale.Budget = 1000000.0;

            // Restore saved state
            Console.WriteLine("\nRestoring state --\n");
            sale.RestoreMemento(memory.Memento);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Entry point into console application.
 /// </summary>
 static void Main()
 {
     SalesProspect s = new SalesProspect();
     s.Name = "Noel van Halen";
     s.Phone = "(412) 256-0990";
     s.Budget = 25000.0;
     // Store internal state
     ProspectMemory m = new ProspectMemory();
     m.Memento = s.SaveMemento();
     // Continue changing originator
     s.Name = "Leo Welch";
     s.Phone = "(310) 209-7111";
     s.Budget = 1000000.0;
     // Restore saved state
     s.RestoreMemento(m.Memento);
     // Wait for user
     Console.ReadKey();
 }
Exemplo n.º 10
0
        public static void Main()
        {
            var sale = new SalesProspect {
                Name = "Noel van Halen", Phone = "(412) 256-0990", Budget = 25000.0
            };

            // Store internal state
            var memory = new ProspectMemory();

            Console.WriteLine("\nSaving state --\n");
            memory.Memento = sale.SaveMemento();

            // Continue changing originator
            sale.Name   = "Leo Welch";
            sale.Phone  = "(310) 209-7111";
            sale.Budget = 1000000.0;

            // Restore saved state
            Console.WriteLine("\nRestoring state --\n");
            sale.RestoreMemento(memory.Memento);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            SalesProspect s = new SalesProspect();

            s.Name   = "Maham Nazir";
            s.Phone  = "(+92) 321-2112110";
            s.Budget = 25000.0;

            // Store internal state
            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();

            // Continue changing originator
            s.Name   = "Leo Welch";
            s.Phone  = "(310) 209-7111";
            s.Budget = 1000000.0;

            // Restore saved state
            s.RestoreMemento(m.Memento);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            SalesProspect s = new SalesProspect();

            s.Name   = "Teste";
            s.Phone  = "(00) 00000-0000";
            s.Budget = 25000.0;


            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();

            s.Name   = "Teste 2";
            s.Phone  = "(00) 0000-0000";
            s.Budget = 1000000.0;

            s.RestoreMemento(m.Memento);


            Console.ReadKey();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            SalesProspect salesProspect = new SalesProspect();

            salesProspect.Name   = "Noel van Halen";
            salesProspect.Phone  = "(412) 256-0990";
            salesProspect.Budget = 25000;

            //Store internal state
            ProspectMemory prospectMemory = new ProspectMemory();

            prospectMemory.Memento = salesProspect.SaveMemento();

            salesProspect.Name   = "Leo Welch";
            salesProspect.Phone  = "(310) 209-7111";
            salesProspect.Budget = 1000000;

            //Restore saved state
            salesProspect.RestoreMemento(prospectMemory.Memento);

            Console.ReadKey();
        }
Exemplo n.º 14
0
        public static void Run()
        {
            Console.WriteLine("This real-world code demonstrates the Memento pattern which temporarily saves and then restores the SalesProspect's internal state.\n");
            SalesProspect s = new SalesProspect();

            s.Name   = "Noel van Halen";
            s.Phone  = "(412) 256-0990";
            s.Budget = 25000.0;

            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();

            s.Name   = "Leo Welch";
            s.Phone  = "(310) 209-7111";
            s.Budget = 1000000.0;

            s.RestoreMemento(m.Memento);
            Console.WriteLine("----");

            /*
             * Name:   Noel van Halen
             * Phone:  (412) 256-0990
             * Budget: 25000
             *
             * Saving state --
             *
             * Name:   Leo Welch
             * Phone:  (310) 209-7111
             * Budget: 1000000
             *
             * Restoring state --
             *
             * Name:   Noel van Halen
             * Phone:  (412) 256-0990
             * Budget: 25000
             */
        }