Exemplo n.º 1
0
 public MenuBarViewModel()
 {
     SelectedColor = new SolidColorBrush(Color.FromRgb(5, 156, 250));
     MovingMode    = false;
     ViewModelMediator.RegisterToViewModelEvent(ViewModelMediator.ViewModelEvent.DrawingStarted, DrawingStartedEventhandler);
     ViewModelMediator.RegisterToViewModelEvent(ViewModelMediator.ViewModelEvent.DrawingEnded, DrawingEndedEventhandler);
 }
        public void GetStocksTest()
        {
            MockDataManager mDm = new MockDataManager();

            mDm.ExchangesConfigured.Add("ABC");
            mDm.ExchangesConfigured.Add("DEF");
            mDm.Stocks.Add(new StockData()
            {
                CompanyNameShort = "TCS", Exchange = "NSE", value = 200, hi52 = 300, lo52 = 100, percentChanged = 1
            });
            mDm.Stocks.Add(new StockData()
            {
                CompanyNameShort = "ONGC", Exchange = "NSE", value = 210, hi52 = 310, lo52 = 110, percentChanged = 2
            });
            mDm.Stocks.Add(new StockData()
            {
                CompanyNameShort = "KSCL", Exchange = "NSE", value = 220, hi52 = 320, lo52 = 120, percentChanged = 3
            });
            ViewModelMediator.GetMediator().dataManager = mDm;
            mDm.stockDataBL = new MockStockDataBusinessLogic();
            mDm.ExchangesConfigured.Add("NSE");

            StockListViewModel listVm = new StockListViewModel();

            listVm.SelectedExchange = "NSE";
            Thread.Sleep(10000);
            Assert.IsTrue(listVm.StockDetailsList.Count == 3);
        }
Exemplo n.º 3
0
 public CanvasViewModel()
 {
     Shapes = new ObservableCollection <ShapeViewModel>();
     Shapes.CollectionChanged += Shapes_CollectionChanged;
     ViewModelMediator.RegisterToViewModelEvent(
         ViewModelMediator.ViewModelEvent.SelectedShapeChanged, () => Reset());
     ViewModelMediator.RegisterToViewModelEvent(
         ViewModelMediator.ViewModelEvent.MovingModeChanged, MovingModeChanged);
 }
Exemplo n.º 4
0
 public ShapeViewModel(Shape shape)
 {
     this.shape            = shape;
     shape.StrokeThickness = 2;
     shape.Stroke          = ViewModelMediator.SelectedColor;
     shapeBrush            = shape.Stroke;
     ViewModelMediator.RegisterToViewModelEvent(
         ViewModelMediator.ViewModelEvent.DrawingEnded, DrawingEndedEventHandler);
     ViewModelMediator.RegisterToViewModelEvent(
         ViewModelMediator.ViewModelEvent.MovingModeChanged, MovingModeChanged);
 }
Exemplo n.º 5
0
        public void ConfiguredExchangesInitTest()
        {
            MockDataManager mDm = new MockDataManager();

            ViewModelMediator.GetMediator().dataManager = mDm;
            mDm.stockDataBL = new MockStockDataBusinessLogic();
            mDm.ExchangesConfigured.Add("NSE");
            ExchangeTabViewModel vm = new ExchangeTabViewModel();

            Assert.AreEqual(vm.ListOfExchanges.Count, 1);
            Assert.AreSame(vm.ListOfExchanges[0], "NSE");
        }
        public MainWindow()
        {
            InitializeComponent();
            ViewModelMediator mediator = new ViewModelMediator();

            DataContext = mediator;

            CommandBinding commandBinding = new CommandBinding();

            commandBinding.Command   = ApplicationCommands.Open;
            commandBinding.Executed += mediator.OpenAssembly;
            menuItem_Open.CommandBindings.Add(commandBinding);
        }
        public void InitTest()
        {
            MockDataManager mDm = new MockDataManager();

            mDm.ExchangesConfigured.Add("ABC");
            mDm.ExchangesConfigured.Add("DEF");
            ViewModelMediator.GetMediator().dataManager = mDm;
            mDm.stockDataBL = new MockStockDataBusinessLogic();
            mDm.ExchangesConfigured.Add("NSE");
            StockListViewModel listVm = new StockListViewModel();

            listVm.SelectedExchange = "NSE";
            Assert.IsTrue(listVm.StockDetailsList.Count > 0);
            Assert.IsTrue(listVm.ListOfAllCompanies.Count > 0);
        }
Exemplo n.º 8
0
        public void LeftMouseDownEventHandler(CanvasPoint mouseCoordinate)
        {
            if (!ViewModelMediator.MovingMode && ViewModelMediator.SelectedShapeType == ShapeType.FreeHand)
            {
                ViewModelMediator.RaiseViewModelEvent(this, ViewModelMediator.ViewModelEvent.DrawingStarted);
                drawn = false;  // new drawing started
                ShapeViewModel shapeVM = CreateShapeVM();
                if (shapeVM.Shape is Polyline polyLine)
                {
                    polyLine.Points.Add(new System.Windows.Point(mouseCoordinate.AbsolutePoint.X, mouseCoordinate.AbsolutePoint.Y));
                }

                Shapes.Add(shapeVM);
            }
        }
Exemplo n.º 9
0
        public void SelectionTest()
        {
            IStockDataBusinessLogic dataBL = new MockStockDataBusinessLogic();
            MockDataManager         mDm    = new MockDataManager();

            ViewModelMediator.GetMediator().dataManager = mDm;
            mDm.stockDataBL = new MockStockDataBusinessLogic();
            mDm.ExchangesConfigured.Add("NSE");
            ExchangeTabViewModel   vm     = new ExchangeTabViewModel();
            MockStockListViewModel listVm = new MockStockListViewModel();

            ViewModelMediator.GetMediator().RegisterForAction("SelectedExchange", false, listVm);
            vm.SelectedExchange = "NSE";
            Assert.AreSame(vm.SelectedExchange, listVm.SelectedExchange);
        }
Exemplo n.º 10
0
        public void LeftMouseUpEventHandler(CanvasPoint mouseCoordinate)
        {
            if (!ViewModelMediator.MovingMode && ViewModelMediator.SelectedShapeType != ShapeType.FreeHand)
            {
                if (firstPoint == null)
                {
                    ViewModelMediator.RaiseViewModelEvent(this, ViewModelMediator.ViewModelEvent.DrawingStarted);
                    drawn = false;  // new drawing started
                    ShapeViewModel shapeVM = CreateShapeVM();
                    firstPoint = mouseCoordinate.AbsolutePoint;

                    if (shapeVM.Shape is Line line)
                    {
                        line.X1 = firstPoint.X;
                        line.Y1 = firstPoint.Y;
                        line.X2 = firstPoint.X;
                        line.Y2 = firstPoint.Y;
                        Shapes.Add(shapeVM);
                    }
                    else
                    {
                        shapeVM.Shape.Width           = 0;
                        shapeVM.Shape.Height          = 2;
                        shapeVM.Shape.RenderTransform = new TranslateTransform(firstPoint.X, firstPoint.Y);
                        Shapes.Add(shapeVM);

                        ShapeViewModel tempLineVM = CreateShapeVM(ShapeType.Line);
                        Line           tempLine   = tempLineVM.Shape as Line;
                        tempLine.X1 = firstPoint.X;
                        tempLine.Y1 = firstPoint.Y;
                        tempLine.X2 = firstPoint.X;
                        tempLine.Y2 = firstPoint.Y;
                        Shapes.Add(tempLineVM);
                    }
                }
                else if (secondPoint == null)
                {
                    secondPoint = mouseCoordinate.AbsolutePoint;
                    if (ViewModelMediator.SelectedShapeType == ShapeType.Line)
                    {
                        Shape shape = Shapes.Last().Shape;
                        (shape as Line).X2 = secondPoint.X;
                        (shape as Line).Y2 = secondPoint.Y;
                        drawn      = true;
                        firstPoint = secondPoint = null;
                        ViewModelMediator.RaiseViewModelEvent(this,
                                                              ViewModelMediator.ViewModelEvent.DrawingEnded);
                    }
                    else
                    {
                        Shapes.Remove(Shapes.Last());
                        Shape shape  = Shapes.Last().Shape;
                        var   angle  = Math.Atan((secondPoint.Y - firstPoint.Y) / (secondPoint.X - firstPoint.X));
                        var   rotate = new RotateTransform(angle * 180 / 3.14);
                        rotate.CenterX        = (firstPoint.X + secondPoint.X) / 2;
                        rotate.CenterY        = (firstPoint.Y + secondPoint.Y) / 2;
                        shape.RenderTransform = rotate;
                    }
                }
                else
                {
                    drawn      = true;
                    firstPoint = secondPoint = null;
                    ViewModelMediator.RaiseViewModelEvent(this,
                                                          ViewModelMediator.ViewModelEvent.DrawingEnded);
                }
            }
        }
 public MediatorWindow()
 {
     InitializeComponent();
     DataContext = new ViewModelMediator();
 }