public void ExecuteTest()
        {
            _command.Execute();
            List <Shape> list = (List <Shape>)_target.GetField("_shapes");

            Assert.AreEqual(1, list.Count);
        }
Пример #2
0
        public void ExecuteTest()
        {
            Model       m = new Model();
            DrawCommand d = new DrawCommand(m, new Rectangle());

            d.Execute();
            Assert.IsTrue(true);
        }
Пример #3
0
 private void drawCanvas_MouseMove(object sender, MouseEventArgs e)
 {
     if (_drag)
     {
         ICommand cmd = new DrawCommand(drawCanvas, e.Location);
         _oneStroke.Push(cmd);
         cmd.Execute();
     }
 }
Пример #4
0
 private void DrawCanvas1_MouseMove(object sender, MouseEventArgs e)
 {
     if (drag)
     {
         ICommand cmd = new DrawCommand(drawCanvas1, e.Location);
         commands.Append(cmd);
         cmd.Execute();
     }
 }
Пример #5
0
 public void ExecuteTest()
 {
     model.CurrentMode  = 0;
     model.CurrentState = new DrawingState(model);
     model.PressPointer(90, 150);
     model.ReleasePointer(190, 250);
     drawCommand = new DrawCommand(model, model.GetTotalShapes[0]);
     drawCommand.CancelExecute();
     drawCommand.Execute();
     Assert.AreEqual(1, model.GetTotalShapes.Count);
 }
Пример #6
0
 public void Update()
 {
     // 左ボタンクリック
     if (Input.GetMouseButton(0))
     {
         Vector3 mousePosition = Input.mousePosition;
         Debug.Log("LeftClick:" + mousePosition);
         Command cmd = new DrawCommand(canvas, mousePosition);
         history.append(cmd);
         cmd.Execute();
     }
 }
Пример #7
0
 private void pic_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         //当条件满足时,触发添加命令,
         //在当前鼠标位置再画一个点的命令
         //将这个命令添加到命令列表中
         //执行这个命令
         CommandPattern.Command.ICommand cmd = new DrawCommand(canvas, e.Location);
         history.Append(cmd);
         cmd.Execute();//执行的是具体命令表 MacroCommand中的方法
     }
 }
Пример #8
0
        public CodingViewModel()
        {
            Content             = Properties.Resources.Startin_Text;
            Encoded             = new BitArray(0);
            canExecuteOnEncoded = this.WhenAnyValue(x => x.IsEncoded, x => x == true);

            EncodeCommand = ReactiveCommand <Unit, Unit> .Create(() =>
            {
                Tree          = new HuffmanTree(content);
                encodedValues = Tree.GetCodes();
                Encoded       = Tree.Encode(Content);
                CreateStatsTable();
                CalculateEntropy();
                CalculateAverageWordLenth();
                NumberOfInputBits = Content.Length * 8;
                CalculateNumberOfOutputBits();
                TreeHight = Tree.Height;
                Nodes     = Tree.Nodes;
                IsEncoded = true;
                DrawCommand.Execute().Subscribe();
                SetEncodedValue();
            }, this.WhenAnyValue(c => c.Content, (c) => (!String.IsNullOrWhiteSpace(c) && (c.Any(x => x != c[0])))));

            DecodeCommand = ReactiveCommand.Create(() =>
            {
                Content = Tree.Decode(Encoded);
            }, canExecuteOnEncoded.Merge(this.WhenAnyValue(c => c.Encoded.Length, (c) => c > 0)));

            DrawCommand = ReactiveCommand <Unit, bool> .Create(() =>
            {
                return(true);
            }, this.WhenAnyValue(e => e.IsEncoded, e => e == true));

            ExportToXmlCommand = ReactiveCommand.Create(() =>
            {
                SaveFileDialog dialog = new SaveFileDialog()
                {
                    Filter = "text|*.xml"
                };
                string filePath;
                if (dialog.ShowDialog() == true)
                {
                    filePath = dialog.FileName;
                    try
                    {
                        WriteToXmlFile(filePath, Tree);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }, canExecuteOnEncoded);

            ExportToJsonCommand = ReactiveCommand.Create(() =>
            {
                SaveFileDialog dialog = new SaveFileDialog()
                {
                    Filter = "text|*.json"
                };
                string filePath;
                if (dialog.ShowDialog() == true)
                {
                    filePath = dialog.FileName;
                    try
                    {
                        WriteToJsonFIle(filePath);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }, canExecuteOnEncoded);

            ImportJson = ReactiveCommand.CreateFromTask(async() =>
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter         = "text|*.json";
                string content        = string.Empty;
                if (dialog.ShowDialog() == true)
                {
                    content = File.ReadAllText(dialog.FileName);
                }
                if (string.IsNullOrEmpty(content))
                {
                    return;
                }
                ReadJson(content);
            });

            ImportXml = ReactiveCommand.CreateFromTask(async() =>
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter         = "text|*.xml";
                string filePath       = string.Empty;
                if (dialog.ShowDialog() == true)
                {
                    filePath = dialog.FileName;
                }
                if (filePath == null)
                {
                    return;
                }
                ReadXml(filePath);
            });
        }
Пример #9
0
        public Map()
        {
            _selectObjectCommand = ReactiveCommand.Create <object>(x => { SelectedObject = x; });
            DrawCommand          = ReactiveCommand.Create(() =>
            {
                Children.Clear();
                if (SimulationService == null)
                {
                    return;
                }
                foreach (var cityRoad in SimulationService.CityMap.Roads)
                {
                    Children.Add(CreateElementForRoad(cityRoad));
                }
                foreach (var cityPlace in SimulationService.CityMap.Places)
                {
                    Children.Add(CreateElementForPlace(cityPlace));
                    Children.Add(LabelPlace(cityPlace));
                }

                RenderTransform = new TransformGroup
                {
                    Children = new Transforms {
                        new TranslateTransform(500, 500), new ScaleTransform(0.5, 0.5)
                    }
                };
            });
            this.WhenAnyValue(x => x.SimulationService)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x =>
            {
                if (x == null)
                {
                    return;
                }
                DrawCommand.Execute(null);
                RecolorRoads();
                x.MinuteInterval
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ =>
                {
                    RecolorRoads();
                    MoveVehicles();
                });
                x.DayInterval
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ =>
                {
                    foreach (var vehicleView in Children.OfType <Button>()
                             .Where(x => x.DataContext is IVehicle)
                             .ToArray())
                    {
                        Children.Remove(vehicleView);
                    }

                    foreach (var vehicle in SimulationService.Solutions.Select(x => x.Vehicle))
                    {
                        Children.Add(CreateElementForVehicle(vehicle));
                    }
                });
            });
        }