コード例 #1
0
        private static void Main()
        {
            // Facade.
            {
                Console.WriteLine("----    Testing Facade pattern    ----");
                var swimmingPoodSystemsFacade = new SwimmingpoolFacade();
                swimmingPoodSystemsFacade.GoToASwimmingPool();
                Console.WriteLine("----    Testing Facade pattern finished    ----");
                Console.WriteLine(".. press any key to continue testing ..");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Mediator
            {
                Console.WriteLine("----    Testing Mediator pattern    ----");

                var brain = new BrainMediator();
                var ear   = new Ear(brain);
                var face  = new Face(brain);

                brain.Ear  = ear;
                brain.Face = face;

                ear.HearSounds();

                Console.WriteLine("----    Testing Mediator pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Singleton
            {
                Console.WriteLine("----    Testing Singleton pattern    ----");

                var loggerSingleton = LoggerSingleton.GetInstance();
                loggerSingleton.TestId = 7;

                var loggerSingleton2 = LoggerSingleton.GetInstance();

                Console.WriteLine(loggerSingleton2.ToString());

                Console.WriteLine("----    Testing Singleton pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Builder
            {
                Console.WriteLine("----    Testing Builder pattern    ----");

                var gamingBuilder    = new GamingLaptopBuilder();
                var travelingBuilder = new TravelingLaptopBuilder();
                var director         = new BuilderDirector(travelingBuilder);

                var laptop = director.ConstructLaptop();

                Console.WriteLine(laptop.ToString());

                director.ChangeBuilderTo(gamingBuilder);

                var laptop2 = director.ConstructLaptop();

                Console.WriteLine(laptop2.ToString());

                Console.WriteLine("----    Testing Builder pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Factory Method
            {
                Console.WriteLine("----    Testing Factory Method pattern    ----");

                Console.WriteLine(ConcreteFactory.CreateProduct(ProductType.Type2));

                Console.WriteLine("----    Testing Factory Method pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Abstract Factory
            {
                Console.WriteLine("----    Testing Abstract Factory pattern    ----");

                AbstractToysFactory factory = new TeddyToyFactory();
                var createdToy = factory.CreateToy();
                Console.WriteLine(createdToy.ToString());

                Console.WriteLine("----    Testing Abstract Factory pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Prototype
            {
                Console.WriteLine("----    Testing Prototype pattern    ----");

                var prototype = ProtorypeDirector.GetFilledPrototype();
                prototype.Parameter2 = prototype.Parameter2 + " changed!";
                Console.WriteLine(prototype.ToString());

                Console.WriteLine("----    Testing Prototype pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Strategy
            {
                Console.WriteLine("----    Testing Strategy pattern    ----");

                var strategyOne = new StrategyOne();
                var strategyTwo = new StrategyTwo();

                StrategyClient.DoJobUsingSomeStrategy(strategyOne, "data parameter");
                StrategyClient.DoJobUsingSomeStrategy(strategyTwo, "data parameter");

                Console.WriteLine("----    Testing Strategy pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Template Method
            {
                Console.WriteLine("----    Testing Template Method pattern    ----");

                var templateMethodImplementationClassObject = new ConcreteClassWithTemplateMethodUsing();
                templateMethodImplementationClassObject.DoSomeTemplateMethodJob();

                Console.WriteLine("----    Testing Template Method pattern finished    ----");
                Console.ReadKey();
            }

            Console.WriteLine("--------------------------------------------------");

            // Iterator
            {
                Console.WriteLine("----    Testing Iterator pattern    ----");

                var iterator = new EnumerableDataSource(new[] { "one", "two" });

                foreach (var item in iterator)
                {
                    Console.WriteLine(item);
                }

                Console.WriteLine("----    Testing Iterator pattern finished    ----");
                Console.ReadKey();
            }
        }
コード例 #2
0
        /// <summary>
        /// Ths is the main class the manages the interactions between the plot, dataview, mainform, and fragment ladder.
        /// </summary>
        /// <param name="mainForm">This should be the mainform that will contain the fragment ladder, plot and the dataview.</param>
        public Manager(MainForm mainForm)
        {
            //Plot
            m_plot                 = new SLPlot(this);
            m_plot.TopLevel        = false;
            m_plot.Visible         = true;
            m_plot.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            m_plot.Text            = "Plot";

            //Data View
            m_dataView                 = new DataView(this);
            m_dataView.TopLevel        = false;
            m_dataView.Visible         = true;
            m_dataView.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

            //Fragment Ladder
            m_fragLadder                 = new Views.FragmentLadderView.FragmentLadderView(this);
            m_fragLadder.TopLevel        = false;
            m_fragLadder.Visible         = true;
            m_fragLadder.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

            //MainForm
            m_mainForm = mainForm;

            //BuilderDirector
            m_builderDirector = new BuilderDirector();


            //For loading profile settings :
            FileStream reader         = null;
            bool       createFileFlag = false;

            // check to see if data is loaded
            DataLoaded = false;

            /*********************This is to read the UserProfile for spectrumLook**********************/
            try
            {
                reader = new FileStream(System.IO.Directory.GetCurrentDirectory() + "\\UserProfile.spuf", FileMode.Open, FileAccess.Read);
            }
            catch (Exception)
            {
                createFileFlag = true;
            }

            if (reader != null)
            {
                try
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    m_plot.m_options                   = new PlotOptions((PlotOptions)binaryFormatter.Deserialize(reader));
                    m_mainForm.m_currentOptions        = new MainFormOptions((MainFormOptions)binaryFormatter.Deserialize(reader));
                    m_fragLadder.fragmentLadderOptions = new Views.Options.FragmentLadderOptions((Views.Options.FragmentLadderOptions)binaryFormatter.Deserialize(reader));
                }
                catch { }
                finally
                {
                    reader.Close();
                }
            }
            /***************************************************************/
            //This is used to read and write the the .spuf
            m_workFileWriter = new LadderInstanceDictionaryXmlSerializer();

            //Options
            m_options = new OptionsViewController(m_plot.m_options, m_mainForm.m_currentOptions, m_fragLadder.fragmentLadderOptions, System.IO.Directory.GetCurrentDirectory() + "\\UserProfile.spuf", createFileFlag, m_fragLadder);
            m_mainForm.m_currentOptions.toleranceValue = 0.7;

            //attach all of the observers to the subjects
            IObserver tempObserver = m_plot as IObserver;

            m_plot.m_options.Attach(ref tempObserver);

            tempObserver = m_mainForm as IObserver;
            m_mainForm.m_currentOptions.Attach(ref tempObserver);

            tempObserver = m_options as IObserver;
            m_mainForm.m_currentOptions.Attach(ref tempObserver);
            m_plot.m_options.Attach(ref tempObserver);//This is because the plot window depends on the mainFormOptions.

            tempObserver = m_fragLadder as IObserver;
            // Add pre-defined symbols to modifications list
            m_fragLadder.fragmentLadderOptions.Attach(ref tempObserver);
            if (m_fragLadder.fragmentLadderOptions.modificationList.Count == 0)
            {
                m_fragLadder.fragmentLadderOptions.modificationList.Add('*', 79.9663326);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('+', 14.01565);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('@', 15.99492);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('!', 57.02146);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('&', 58.00548);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('#', 71.03711);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('$', 227.127);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('%', 236.127);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('~', 442.225);
                m_fragLadder.fragmentLadderOptions.modificationList.Add('`', 450.274);
            }

            m_plot.m_options.CopyOptions(m_plot.m_options);
            m_options.Hide();
        }