Example #1
0
        public MainPage()
        {
            InitializeComponent();
            cPage = new NavigationPage(new ChemPage())
            {
                Title           = "Chem",
                IconImageSource = "chem_icon.png"
            };
            _notificator   = DependencyService.Get <IToastNotificator>();
            BindingContext = viewModel = SimpleIoc.Default.GetInstance <ControllerViewModel>();

            viewModel.PropertyChanged += ViewModel_PropertyChanged;
            viewModel.DataInterface.ConnectionChanged += DataInterface_ConnectionChanged;

            MessagingCenter.Subscribe <App>(this, "Starting", (sender) =>
            {
                viewModel.LoadHardwareDefinitionCommand.Execute(true);
            });
            MessagingCenter.Subscribe <App>(this, "Sleeping", (sender) =>
            {
                viewModel.ClosingCommand.Execute(null);
            });
            MessagingCenter.Subscribe <App>(this, "Resume", (sender) =>
            {
                viewModel.LoadHardwareDefinitionCommand.Execute(true);
            });


            //Task.Run(async () => await CheckAndRequestStoragePermission());
        }
        public MainWindow()
        {
            InitializeComponent();

            c = new ControllerViewModel();
            this.DataContext = c;
        }
        public ControllerViewModel GetControllerViewModel()
        {
            ControllerViewModel controller = new ControllerViewModel();



            return(controller);
        }
Example #4
0
        public ControllerMainView()
        {
            InitializeComponent();

            BindingContext = viewModel = SimpleIoc.Default.GetInstance <ControllerViewModel>();

            viewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
Example #5
0
        private void New_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            this.CanSave             = true;
            this.controllerViewModel = ControllerViewModel.New();
            this.controllerViewModel.GameJoinedEvent  += this.GameJoinedEventHandler;
            this.controllerViewModel.ErrorRaisedEvent += this.ErrorRaisedEventHandler;

            this.PlayArea.Initialise(this.controllerViewModel);
            this.PlayArea.StartGame();
        }
Example #6
0
 public void Initialise(ControllerViewModel controllerViewModel)
 {
     this.DataContext = this.controllerViewModel = controllerViewModel;
     this.controllerViewModel.GameJoinedEvent          += this.InitialisePlayerViews;
     this.controllerViewModel.InitialBoardSetupEvent   += this.InitialBoardSetupEventHandler;
     this.controllerViewModel.RobberEvent              += this.RobberEventHandler;
     this.controllerViewModel.RobbingChoicesEvent      += this.RobbingChoicesEventHandler;
     this.controllerViewModel.StartPhaseEvent          += this.StartPhaseEventHandler;
     this.controllerViewModel.PlaceInfrastructureEvent += this.PlaceInfrastructureEventHandler;
 }
Example #7
0
        public MainWindow()
        {
            InitializeComponent();
            TargetPosition = ARM_MID;
            DataContext    = new ControllerViewModel();
            SetDataContextDefaults();
            SetupPhidget();

#if DEBUG
            this.AttachDevTools();
#endif
        }
        public IActionResult Post([FromBody] ControllerViewModel model)
        {
            //Беремо айді користувача з токену
            var user = User.GetUser(_context);

            //Перевіряємо модель
            if (model == null || !ModelState.IsValid)
            {
                return(StatusCode(500, new InternalServerError()));
            }
            if (model.MAC.Length != 12)
            {
                return(StatusCode(500, new InternalServerError("MAC address must has 12 symbols!")));
            }

            var userHasController = _context.UserHasControllers
                                    .Where(p => p.UserId == user.Id)
                                    .Where(p => p.ControllerId == model.Id)
                                    .Where(p => p.IsAdmin)
                                    .FirstOrDefault();

            if (userHasController == null)
            {
                return(Unauthorized(new UnauthorizedError()));
            }

            var controller = _context.Controllers
                             .Where(p => p.MAC == model.MAC && p.Id != model.Id)
                             .FirstOrDefault();

            if (controller != null)
            {
                return(StatusCode(500, new InternalServerError("Controller is ulready exists")));
            }
            controller = _context.Controllers.Find(model.Id);
            if (controller == null)
            {
                return(NotFound(new NotFoundError()));
            }
            //Змінюємо контролер
            controller.MAC    = model.MAC;
            controller.Name   = model.Name;
            controller.Status = model.Status;
            //Зберігаємо зміни
            _context.Controllers.Update(controller);
            _context.SaveChanges();
            //Повертаємо результат
            return(new JsonResult(controller.Adapt <ControllerViewModel>()));
        }
        public MvcActionsDiscoveryService(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
        {
            if (actionDescriptorCollectionProvider == null)
            {
                throw new ArgumentNullException(nameof(actionDescriptorCollectionProvider));
            }

            MvcControllers = new List <ControllerViewModel>();
            var lastControllerName = string.Empty;
            ControllerViewModel currentController = null;

            var actionDescriptors = actionDescriptorCollectionProvider.ActionDescriptors.Items;

            foreach (var actionDescriptor in actionDescriptors)
            {
                if (!(actionDescriptor is ControllerActionDescriptor descriptor))
                {
                    continue;
                }

                var controllerTypeInfo = descriptor.ControllerTypeInfo;
                var actionMethodInfo   = descriptor.MethodInfo;

                if (lastControllerName != descriptor.ControllerName)
                {
                    currentController = new ControllerViewModel
                    {
                        AreaName              = controllerTypeInfo.GetCustomAttribute <AreaAttribute>()?.RouteValue,
                        ControllerAttributes  = GetAttributes(controllerTypeInfo),
                        ControllerDisplayName = controllerTypeInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName,
                        ControllerName        = descriptor.ControllerName,
                    };
                    MvcControllers.Add(currentController);

                    lastControllerName = descriptor.ControllerName;
                }

                currentController?.MvcActions.Add(new ActionViewModel
                {
                    ControllerId      = currentController.ControllerId,
                    ActionName        = descriptor.ActionName,
                    ActionDisplayName = actionMethodInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName,
                    ActionAttributes  = GetAttributes(actionMethodInfo),
                    IsSecuredAction   = IsSecuredAction(controllerTypeInfo, actionMethodInfo)
                });
            }
        }
Example #10
0
        private void Open_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.CheckFileExists = true;
            ofd.Title           = "Select game file to open";
            ofd.Filter          = "Game save files (*.soc)|*.soc";
            var dialogResult = ofd.ShowDialog();

            if (dialogResult != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            this.controllerViewModel = ControllerViewModel.Load(ofd.FileName);
            this.controllerViewModel.GameJoinedEvent += this.GameJoinedEventHandler;
            this.PlayArea.Initialise(this.controllerViewModel);
            this.PlayArea.ContinueGame();
        }
Example #11
0
        public MenuItemsViewModel GetMenuItems()
        {
            var vm          = new MenuItemsViewModel();
            var controllers = _context.Controllers.Where(x => x.Name.Length > 0 && x.Pages.Any(p => p.IsActive)).ToList();

            foreach (var controller in controllers)
            {
                var ctrlModel = new ControllerViewModel
                {
                    Name  = controller.Name,
                    Pages = controller.Pages.Where(p => p.Alias != "Index" && p.Type != 0 && p.IsActive).Select(p => new PageViewModel
                    {
                        Alias      = p.Alias,
                        HeaderName = p.Content.Header,
                        Name       = p.Name,
                        Type       = (int)p.Type
                    })
                            .ToList()
                };
                vm.Controllers.Add(ctrlModel);
            }

            return(vm);
        }
 protected override void OnOpen(OpenEventArgs args)
 {
     StateViewModel.Open(args);
     VideoViewModel.Open(args);
     ControllerViewModel.Open(args);
 }
 internal void ClearDatabase()
 {
     StateViewModel.ClearDatabase();
     ControllerViewModel.ClearDatabase();
 }
Example #14
0
 public NewTodoItemDialog(ControllerViewModel dataContext)
 {
     InitializeComponent();
     this.DataContext = dataContext;
 }
        public void InterSGSerialization()
        {
            while (DataProvider.Instance.Controller != null)
            {
                Thread.Sleep(100);
            }

            // Setup variables
            SettingsProvider.Instance.Settings = new TLCGen.Models.Settings.TLCGenSettingsModel();
            var mainwinvm = new MainWindowViewModel();

            Assert.IsFalse(mainwinvm.HasController);
            Assert.IsTrue(mainwinvm.NewFileCommand.CanExecute(null));
            mainwinvm.NewFileCommand.Execute(null);
            Assert.IsTrue(mainwinvm.HasController);

            var c            = DataProvider.Instance.Controller;
            var controllervm = mainwinvm.ControllerVM;
            var fasentab     = controllervm.FasenTabVM;
            var synctab      = controllervm.CoordinatiesTabVM;

            Assert.IsTrue(c.Fasen.Count == 0);
            Assert.IsTrue(fasentab.AddFaseCommand.CanExecute(null));

            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);

            Assert.IsTrue(c.Fasen.Count == 5);

            Assert.IsTrue(synctab.DisplayType == TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict);
            Assert.IsTrue(synctab.ConflictMatrix != null);
            Assert.IsTrue(synctab.ConflictMatrix.GetLength(0) == 5);
            Assert.IsTrue(synctab.ConflictMatrix.GetLength(1) == 5);

            synctab.ConflictMatrix[0, 1].ConflictValue = "10";
            synctab.ConflictMatrix[1, 0].ConflictValue = "20";
            synctab.ConflictMatrix[2, 4].ConflictValue = "0";
            synctab.ConflictMatrix[4, 2].ConflictValue = "50";
            synctab.ConflictMatrix[3, 2].ConflictValue = "FK";

            Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null);

            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart;

            Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling);

            Assert.IsTrue(synctab.ConflictMatrix[1, 3].AllowCoupling);
            synctab.ConflictMatrix[1, 3].IsCoupled = true;
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart);
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].HasNoCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].HasNoCoupling);

            Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null);

            // Simulate saving and opening
            var ser   = new TLCGen.DataAccess.SerializeT <ControllerModel>();
            var deser = new TLCGen.DataAccess.DeserializeT <ControllerModel>();
            var doc   = ser.SerializeToXmlDocument(c);

            controllervm.HasChanged = false;
            Assert.IsTrue(mainwinvm.CloseFileCommand.CanExecute(null));
            mainwinvm.CloseFileCommand.Execute(null);

            Assert.IsFalse(mainwinvm.HasController);

            mainwinvm.SetController(deser.SerializeFromXmlDocument(doc));
            Assert.IsTrue(mainwinvm.HasController);

            c            = DataProvider.Instance.Controller;
            controllervm = new ControllerViewModel(mainwinvm, c);
            fasentab     = controllervm.FasenTabVM;
            synctab      = controllervm.CoordinatiesTabVM;
            synctab.BuildConflictMatrix();

            Assert.AreEqual("10", synctab.ConflictMatrix[0, 1].ConflictValue);
            Assert.AreEqual("20", synctab.ConflictMatrix[1, 0].ConflictValue);
            Assert.AreEqual("0", synctab.ConflictMatrix[2, 4].ConflictValue);
            Assert.AreEqual("50", synctab.ConflictMatrix[4, 2].ConflictValue);
            Assert.AreEqual("FK", synctab.ConflictMatrix[3, 2].ConflictValue);
            Assert.AreEqual("FK", synctab.ConflictMatrix[2, 3].ConflictValue);

            Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null);

            AssertConfictMatrixModelEqual(10, c, synctab.ConflictMatrix[0, 1]);
            AssertConfictMatrixModelEqual(20, c, synctab.ConflictMatrix[1, 0]);
            AssertConfictMatrixModelEqual(0, c, synctab.ConflictMatrix[2, 4]);
            AssertConfictMatrixModelEqual(50, c, synctab.ConflictMatrix[4, 2]);
            AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]);
            AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]);

            Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling);

            Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart);
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].HasNoCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].HasNoCoupling);

            controllervm.HasChanged = false;
            mainwinvm.CloseFileCommand.Execute(null);
        }
        public void InterSGCouplingMatrixIntegrity()
        {
            while (DataProvider.Instance.Controller != null)
            {
                Thread.Sleep(100);
            }

            // Setup variables
            SettingsProvider.Instance.Settings = new TLCGen.Models.Settings.TLCGenSettingsModel();
            var mainwinvm = new MainWindowViewModel();

            Assert.IsFalse(mainwinvm.HasController);
            Assert.IsTrue(mainwinvm.NewFileCommand.CanExecute(null));
            mainwinvm.NewFileCommand.Execute(null);
            Assert.IsTrue(mainwinvm.HasController);

            var c            = DataProvider.Instance.Controller;
            var controllervm = mainwinvm.ControllerVM;
            var fasentab     = controllervm.FasenTabVM;
            var synctab      = controllervm.CoordinatiesTabVM;

            // Add signal groups
            Assert.IsTrue(c.Fasen.Count == 0);
            Assert.IsTrue(fasentab.AddFaseCommand.CanExecute(null));
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            fasentab.AddFaseCommand.Execute(null);
            Assert.IsTrue(c.Fasen.Count == 5);

            // Check matrix
            Assert.IsTrue(synctab.DisplayType == TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict);
            Assert.IsTrue(synctab.ConflictMatrix != null);
            Assert.IsTrue(synctab.ConflictMatrix.GetLength(0) == 5);
            Assert.IsTrue(synctab.ConflictMatrix.GetLength(1) == 5);

            // Add conflicts
            synctab.ConflictMatrix[0, 1].ConflictValue = "10";
            synctab.ConflictMatrix[1, 0].ConflictValue = "20";
            synctab.ConflictMatrix[2, 4].ConflictValue = "0";
            synctab.ConflictMatrix[4, 2].ConflictValue = "50";
            synctab.ConflictMatrix[3, 2].ConflictValue = "FK";
            Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null);

            // Check properties that set cell availability
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart;
            Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling || synctab.ConflictMatrix[0, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling || synctab.ConflictMatrix[1, 0].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling || synctab.ConflictMatrix[2, 4].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling || synctab.ConflictMatrix[4, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling || synctab.ConflictMatrix[3, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling || synctab.ConflictMatrix[2, 3].IsEnabled);

            // Set a "gelijkstart"
            // ===================
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].AllowCoupling);
            synctab.ConflictMatrix[1, 3].IsCoupled = true;
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart); // Assert symmetry
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].HasNoCoupling);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].HasNoCoupling);

            // Check properties that set cell availability in Conflict Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);

            // Check properties that set cell availability in Voorstart Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);

            // Check properties that set cell availability in Naloop Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop;
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled);

            // Set a "Voorstart"
            // =================
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart;
            Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled);
            synctab.ConflictMatrix[4, 3].IsCoupled = true;
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Assert this cannot be also set on the opposite side
            Assert.IsTrue(synctab.ConflictMatrix[3, 4].HasOppositeVoorstart);

            // Check properties that set cell availability in Conflict Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled);

            // Check properties that set cell availability in Voorstart Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart;
            Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled);

            // Check properties that set cell availability in Naloop Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop;
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 4].IsEnabled);

            // Set a "Naloop"
            // ==============
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop;
            Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled);
            synctab.ConflictMatrix[0, 2].IsCoupled = true;
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled); // Assert this _can_ be also set on the opposite side
            Assert.IsTrue(synctab.ConflictMatrix[0, 2].HasNaloop);
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].HasOppositeNaloop);

            // Check properties that set cell availability in Conflict Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[0, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 0].IsEnabled);

            // Check properties that set cell availability in Gelijkstart Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart;
            Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with gelijkstart
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled);

            // Check properties that set cell availability in Voorstart Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Assert this cannot be also set on the opposite side
            Assert.IsTrue(synctab.ConflictMatrix[3, 4].HasOppositeVoorstart);
            Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with voorstart
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled);

            // Check properties that set cell availability in Naloop Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop;
            Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling || synctab.ConflictMatrix[0, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling || synctab.ConflictMatrix[1, 0].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling || synctab.ConflictMatrix[2, 4].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling || synctab.ConflictMatrix[4, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling || synctab.ConflictMatrix[3, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling || synctab.ConflictMatrix[2, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 4].IsEnabled);

            // Check and save
            Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null);

            // Simulate saving and opening
            // ===========================
            var ser   = new TLCGen.DataAccess.SerializeT <ControllerModel>();
            var deser = new TLCGen.DataAccess.DeserializeT <ControllerModel>();
            var doc   = ser.SerializeToXmlDocument(c);

            controllervm.HasChanged = false;
            Assert.IsTrue(mainwinvm.CloseFileCommand.CanExecute(null));
            mainwinvm.CloseFileCommand.Execute(null);

            Assert.IsFalse(mainwinvm.HasController);

            mainwinvm.SetController(deser.SerializeFromXmlDocument(doc));
            Assert.IsTrue(mainwinvm.HasController);

            c            = DataProvider.Instance.Controller;
            controllervm = new ControllerViewModel(mainwinvm, c);
            fasentab     = controllervm.FasenTabVM;
            synctab      = controllervm.CoordinatiesTabVM;
            synctab.BuildConflictMatrix();

            Assert.AreEqual("10", synctab.ConflictMatrix[0, 1].ConflictValue);
            Assert.AreEqual("20", synctab.ConflictMatrix[1, 0].ConflictValue);
            Assert.AreEqual("0", synctab.ConflictMatrix[2, 4].ConflictValue);
            Assert.AreEqual("50", synctab.ConflictMatrix[4, 2].ConflictValue);
            Assert.AreEqual("FK", synctab.ConflictMatrix[3, 2].ConflictValue);
            Assert.AreEqual("FK", synctab.ConflictMatrix[2, 3].ConflictValue);

            Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart);

            Assert.IsTrue(synctab.ConflictMatrix[4, 3].HasVoorstart);
            Assert.IsTrue(synctab.ConflictMatrix[3, 4].HasOppositeVoorstart);

            Assert.IsTrue(synctab.ConflictMatrix[0, 2].HasNaloop);
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].HasOppositeNaloop);

            Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null);

            AssertConfictMatrixModelEqual(10, c, synctab.ConflictMatrix[0, 1]);
            AssertConfictMatrixModelEqual(20, c, synctab.ConflictMatrix[1, 0]);
            AssertConfictMatrixModelEqual(0, c, synctab.ConflictMatrix[2, 4]);
            AssertConfictMatrixModelEqual(50, c, synctab.ConflictMatrix[4, 2]);
            AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]);
            AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]);

            // Check properties that set cell availability in Conflict Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[0, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 0].IsEnabled);

            // Check properties that set cell availability in Gelijkstart Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart;
            Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with gelijkstart
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled);

            // Check properties that set cell availability in Voorstart Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart;
            Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Assert this cannot be also set on the opposite side
            Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled);  // Naloop can go together with voorstart
            Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled);

            // Check properties that set cell availability in Naloop Tab
            synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop;
            Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling || synctab.ConflictMatrix[0, 1].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling || synctab.ConflictMatrix[1, 0].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling || synctab.ConflictMatrix[2, 4].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling || synctab.ConflictMatrix[4, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling || synctab.ConflictMatrix[3, 2].IsEnabled);
            Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling || synctab.ConflictMatrix[2, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled);
            Assert.IsTrue(synctab.ConflictMatrix[3, 4].IsEnabled);

            controllervm.HasChanged = false;
            mainwinvm.CloseFileCommand.Execute(null);
        }
 public ScheduleEditPage()
 {
     InitializeComponent();
     _notificator   = DependencyService.Get <IToastNotificator>();
     BindingContext = viewModel = SimpleIoc.Default.GetInstance <ControllerViewModel>();
 }
 protected override void OnClosing(ClosingEventArgs args)
 {
     args.CanClose = ControllerViewModel.Close() && StateViewModel.Close() && VideoViewModel.Close();
 }
        public IActionResult Put([FromBody] ControllerViewModel model)
        {
            //Перевіряємо модель
            if (model == null || !ModelState.IsValid)
            {
                return(StatusCode(500, new InternalServerError("Data is incorrect!")));
            }
            var controller = _context.Controllers.Where(p => p.MAC == model.MAC).FirstOrDefault();

            if (controller != null)
            {
                return(StatusCode(500, new InternalServerError("Controller is already exists")));
            }
            if (model.MAC.Length != 12)
            {
                return(StatusCode(500, new InternalServerError("MAC address must has 12 symbols!")));
            }
            //Беремо айді користувача з токену
            var user = User.GetUser(_context);

            if (user == null)
            {
                return(Unauthorized(new UnauthorizedError()));
            }
            //Створюємо контролер
            controller = model.Adapt <Data.Models.Controller>();
            controller.InstalledDate = DateTime.Now;
            controller.PublicKey     = "jak to bedzie pracowac, pliz ktos wie?";
            _context.Controllers.Add(controller);
            //Створюємо UserHasController
            var userHasController = new UserHasController();

            userHasController.ControllerId = controller.Id;
            userHasController.UserId       = user.Id;
            userHasController.IsAdmin      = true;
            _context.UserHasControllers.Add(userHasController);
            //Зберігаємо зміни
            _context.SaveChanges();
            //Створюємо віртуальний пристрій
            var device = new Device
            {
                Name         = "Notification",
                Pin          = 0,
                MAC          = null,
                Status       = true,
                ControllerId = controller.Id,
                DeviceTypeId = _context.DeviceTypes.Where(p => p.TypeName == "Virtual").FirstOrDefault().Id,
            };

            _context.Devices.Add(device);
            _context.SaveChanges();
            //Ствоюємо UserasDevice
            var userHasDevice = new UserHasDevice
            {
                DeviceId = device.Id,
                UsersHaveControllerId = userHasController.Id
            };

            _context.UserHasDevices.Add(userHasDevice);
            _context.SaveChanges();
            //Повертаємо створений контролер як резльтат
            return(new JsonResult(controller.Adapt <ControllerViewModel>()));
        }