示例#1
0
        public static void TestFlyweight()
        {
            Console.WriteLine("----------------------Flyweight----------------------");
            BoxFactory boxFactory          = new BoxFactory();
            Box        blackRectangularBox = boxFactory.CreateBox("rectangular");

            blackRectangularBox.Display("Black");

            Box blackRoundBox = boxFactory.CreateBox("round");

            blackRoundBox.Display("Black");

            Box redRoundBox = boxFactory.CreateBox("round");

            redRoundBox.Display("Red");

            Box unsharedBox = new UnsharedBox(10, 20, 15);

            unsharedBox.Display("Green");

            Console.WriteLine("Changing boxes width to be 100:");
            blackRectangularBox.Width = 100;
            blackRoundBox.Width       = 100;

            blackRectangularBox.Display("Black");
            blackRoundBox.Display("Black");
            redRoundBox.Display("Red");
            unsharedBox.Display("Green");

            Console.WriteLine("---------------------------------------------------\n");
        }
示例#2
0
 public ConfigurationInterceptor(Type interfaceType, IoHandler ioHandler, string prefix = null)
 {
     _boxes         = BoxFactory.Discover(interfaceType, ioHandler.ValueHandler);
     _interfaceType = interfaceType;
     _ioHandler     = ioHandler;
     _prefix        = prefix;
 }
示例#3
0
        private static void FlyWeight()
        {
            BoxFactory boxFactory = new BoxFactory();

            Box blackBox1 = boxFactory.Get(BoxColor.Black);
            Box blackBox2 = boxFactory.Get(BoxColor.Black);
        }
示例#4
0
        public IEnumerable <Box> AddFromJsonString(string definitionJson)
        {
            var jboxes = JArray.Parse(definitionJson);

            BoxFactory.AddFromJson(this.rootBox, jboxes);
            return(this.rootBox.Children.Values);
        }
示例#5
0
 public InterfaceInterceptor(Type interfaceType, IoHandler ioHandler, string prefix = null)
 {
     _boxes     = BoxFactory.Discover(interfaceType, ioHandler.ValueHandler, prefix);
     _ioHandler = ioHandler;
     _prefix    = prefix;
     _reader    = new DynamicReader(prefix, ioHandler);
     _writer    = new DynamicWriter(prefix, ioHandler);
 }
示例#6
0
 public InterfaceInterceptor(Type interfaceType, IoHandler ioHandler, string prefix = null)
 {
     _boxes     = BoxFactory.Discover(interfaceType, ioHandler.ValueHandler, prefix);
     _ioHandler = ioHandler;
     _prefix    = prefix;
     _reader    = new DynamicReader(prefix, ioHandler);
     _writer    = new DynamicWriter(prefix, ioHandler);
     _isInpc    = interfaceType.GetInterface(nameof(INotifyPropertyChanged)) != null;
 }
示例#7
0
        public void BoxFactoryShouldDeliverFiveBoxes()
        {
            // Arrange
            var boxFactory = new BoxFactory();

            // Act
            var numberOfContainingBoxes = boxFactory.CreateBoxWithContainingBoxes(5);

            // Assert
            Assert.AreEqual(5, numberOfContainingBoxes.GetNumberOfContaintingBoxes);
        }
示例#8
0
        public IEnumerable <Box> AddFromXmlString(string definitionXml)
        {
            var setting = new XmlReaderSettings();

            setting.IgnoreComments   = true;
            setting.IgnoreWhitespace = true;
            using (var sr = new StringReader(definitionXml))
                using (var xr = XmlReader.Create(sr, setting))
                {
                    BoxFactory.AddFromXml(this.rootBox, xr);
                }
            return(this.rootBox.Children.Values);
        }
示例#9
0
文件: Board.cs 项目: cheng93/Sudoku
        private void CreateUnits()
        {
            var boxFactory    = new BoxFactory();
            var columnFactory = new ColumnFactory();
            var rowFactory    = new RowFactory();

            for (int i = 0; i < 9; i++)
            {
                _boxes[i]   = boxFactory.Factory(_cells, i);
                _columns[i] = columnFactory.Factory(_cells, i);
                _rows[i]    = rowFactory.Factory(_cells, i);
            }
        }
示例#10
0
        /// <summary>
        ///  抽象工厂类
        /// </summary>
        public void CreateBinFile()
        {
            // box 找码逻辑
            AbstractFactory boxfactory = new BoxFactory();
            BInFile         boxbinFile = boxfactory.CreateBinFile();

            boxbinFile.CreateBinFile();

            // os 找码逻辑
            AbstractFactory osfactory = new OsFactory();
            BInFile         osbinFile = osfactory.CreateBinFile();

            osbinFile.CreateBinFile();
        }
示例#11
0
    // Get an exact same object as this one.
    public override Component Clone()
    {
        BoxDescription boxDescription = BoxFactory.GetBoxDescription(Description.BackImage, Description.Size);
        HiddenObject   hiddenObject   = new HiddenObject {
            Image = HiddenObject.Image
        };
        BoxState boxState = new BoxState {
            State = State.State
        };
        ImageBinder imageBinder = new ImageBinder();
        BoxFactory  boxFactory  = BoxFactory.GetInstance();
        string      image       = (string)CurrentImage.Clone();

        return(new Box {
            Description = boxDescription, HiddenObject = hiddenObject,
            State = boxState, ImageBinder = imageBinder,
            BoxFactory = boxFactory, CurrentImage = image, Position = this.Position,
            IsEnabled = this.IsEnabled
        });
    }
示例#12
0
    // Initialize a new game environment
    public void NewGame()
    {
        Time      = TimeSpan.Zero;
        HighScore = 0;
        Player    = new Player {
            Name = "Player 1", Score = 0
        };
        ProjetPictue.Program.GeneratePhotos();
        GameController = GameController.GetInstance();

        Box box = new Box
        {
            Position     = 1,
            CurrentImage = "",
            State        = new BoxState(),
            IsEnabled    = true,
            ImageBinder  = new ImageBinder(),
            Description  = BoxFactory.GetInstance().GetBoxDescription("images/card2.png", new System.Drawing.Size(79, 66)),
            HiddenObject = new HiddenObject(),
            BoxFactory   = BoxFactory.GetInstance()
        };

        GameController.Grid.Add(box);

        for (int i = 1; i < 5 * 8; i++)
        {
            Box box2 = (Box)box.Clone();
            box2.Position = i + 1;
            GameController.Grid.Add(box2);
        }

        GameController.Grid.Draw();

        ShowImages(null, null);
        timer          = new System.Timers.Timer();
        timer.Interval = 5000;
        timer.Elapsed += ShowImages;
        timer.Start();
    }
示例#13
0
 // Start is called before the first frame update
 void Start()
 {
     boxFactory = new SampleBoxFactory();
 }
示例#14
0
 public OpenCommand(Context context)
 {
     this.context = context;
     this.Box     = BoxFactory.Create();
 }
示例#15
0
        public void Return_Not_Null_When_Provider_Exist()
        {
            IBoxProvider box = new BoxFactory().GetBoxProvider(Store.PizzeriaA);

            Assert.IsNotNull(box);
        }