Example #1
0
        public MainWindowViewModel(DeviceSelectionViewModel deviceSelectionViewModel,
                                   FrameConfigurationViewModel frameConfigurationViewModel,
                                   DiagnosticsViewModel diagnosticsViewModel,
                                   FrameManagementViewModel frameManagementViewModel,
                                   EventManager eventManager,
                                   ICommandService commandService)
        {
            #region InjectingDependencies

            _deviceSelectionViewModel    = deviceSelectionViewModel;
            _frameConfigurationViewModel = frameConfigurationViewModel;
            _diagnosticsViewModel        = diagnosticsViewModel;
            _frameManagementViewModel    = frameManagementViewModel;
            _eventManager   = eventManager;
            _commandService = commandService;

            #endregion

            InitializeCommands();
            InitializeNavigationStack();
            AssignEvents();

            CurrentViewModel = _navigationStack.First();
            _commandService.OpenConnection();
        }
Example #2
0
        public async Task <bool> UpdateAvailableDevice()
        {
            DeviceSelectionViewModel.ClearCachedDevices();
            try
            {
                DeviceSelectionViewModel.ClearCachedDevices();
                var result = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate));

                if (result.Count > 0)
                {
                    foreach (var device in result)
                    {
                        var ble = await BluetoothLEDevice.FromIdAsync(device.Id) as BluetoothLEDevice;

                        DeviceSelectionViewModel.AddBLEDevice(ble);
                    }
                }
                else
                {
                    if (!await DeviceSelectionViewModel.IsBluetoothSettingOn())
                    {
                        ShowErrorMessage();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public DeviceSelectionPage()
        {
            InitializeComponent();
            NavigationPage.SetBackButtonTitle(this, "Back");

            viewModel      = App.ServiceLocator.DeviceSelectionViewModel;
            BindingContext = viewModel;
        }
        async void deviceFirmwareUpdateService_ServiceChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            IsServiceChanged = true;
            await Task.Delay(TimeSpan.FromMilliseconds(300));             //do we need this?

            await UpdateAvailableDevice();

            DeviceInformationItem newDevice = null;
            GattDeviceService     dfuService;
            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                newDevice = DeviceSelectionViewModel.GetBLEDevice(sender.Service.Device.DeviceId);
            });

            if (newDevice != null && newDevice.Services.TryGetValue(ToolboxIdentifications.GattServiceNames.DEVICE_FIRMWARE_UPDATE, out dfuService))
            {
                deviceFirmwareUpdateService.StarDfu(dfuService);
            }
        }
Example #5
0
        public ActionResult Execute(DeviceSelectionViewModel model)
        {
            string err = null;
            // get the ids of the items selected:
            List <long> selectedIds = model.getSelectedIds();

            // Use the ids to retrieve the records for the selected people
            // from the database:
            var selectedDevices = from x in db.Devices
                                  where selectedIds.Contains(x.ID)
                                  select x;

            switch (model.SelectedFunction)
            {
            case funcPrepareTaskerFile:
                err = CreateDeviceTemplate(selectedDevices);
                break;
            }

            return(RedirectToAction("Index", new { err = err }));
        }
        public async Task <bool> UpdateAvailableDevice()
        {
            try
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    DeviceSelectionViewModel.ClearCachedDevices();
                });

                var result = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(ToolboxIdentifications.GattServiceUuids.DeviceFirmwareUpdate));

                if (result.Count > 0)
                {
                    foreach (var device in result)
                    {
                        var ble = await BluetoothLEDevice.FromIdAsync(device.Id) as BluetoothLEDevice;

                        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            DeviceSelectionViewModel.AddBLEDevice(ble);
                        });
                    }
                }
                else
                {
                    if (!await DeviceSelectionViewModel.IsBluetoothSettingOn())
                    {
                        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            ShowBluetoothOffErrorMessage();
                        });
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #7
0
        public ActionResult Index(int?page)
        {
            ttTVMS.Models.MessageViewModel viewModel = new MessageViewModel();
            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            var messages = db.Messages.OrderByDescending(r => r.ID);

            List <SelectListItem> selectItems = new List <SelectListItem>();
            Array msgConstants = Enum.GetValues(typeof(MessageContants));

            Array.Sort(msgConstants);
            foreach (int msg in msgConstants)
            {
                selectItems.Add(new SelectListItem()
                {
                    Text = Enum.GetName(typeof(MessageContants), msg), Value = msg.ToString()
                });
            }

            ViewBag.Functions = new SelectList(selectItems.ToArray(), "Value", "Text");

            var model = new DeviceSelectionViewModel();
            var items =
                from d in db.Devices
                select d;

            //join r in db.Requests on d.ID equals r.DeviceID into dr
            //join l in db.DeviceLogs on d.ID equals l.DeviceID into dl
            //select new
            //{
            //    Device = d,
            //    LastRequest = dr.OrderByDescending(r => r.ID).Take(1).FirstOrDefault(),
            //    LastLog = dl.OrderByDescending(r => r.ID).Take(1).FirstOrDefault()
            //};

            foreach (var item in items) // (var device in db.Devices.Include(d => d.Requests.Where(dw => DateTime.Now.Subtract(dw.RequestDate).TotalDays ).Include(d => d.DeviceLogs))
            {
                var editorViewModel = new SelectDeviceEditorViewModel()
                {
                    ID              = item.ID,              // item.Device.ID,
                    AndriodVer      = item.AndriodVer,      // .Device.AndriodVer,
                    CreationDate    = item.CreationDate,    // .Device.CreationDate,
                    CustomerID      = item.CustomerID,      // .Device.CustomerID,
                    DeviceCode      = item.DeviceCode,      // .Device.DeviceCode,
                    DeviceType      = item.DeviceType,      // .Device.DeviceType,
                    ModelNo         = item.ModelNo,         // .Device.ModelNo,
                    LastRequestDate = item.LastRequestTime, // item.LastRequest == null ? (DateTime?)null : item.LastRequest.RequestDate,
                    LastRequestID   = item.LastRequestId,   // item.LastRequest == null ? (long?)null : item.LastRequest.ID,
                    LastLogDate     = item.LastLogTime,     // item.LastLog == null ? (DateTime?)null : item.LastLog.CreationDate,
                    LastLogID       = item.LastLogId,       // item.LastLog == null ? (long?)null : item.LastLog.ID,

                    Selected = item.DeviceType != 1
                };
                model.Devices.Add(editorViewModel);
            }
            viewModel.Devices  = model;
            viewModel.Messages = messages.ToPagedList(pageNumber, pageSize);

            return(View(viewModel));
        }
Example #8
0
        // GET: /Device/

        public ActionResult Index(string err = null)
        {
            ViewBag.Error     = err;
            ViewBag.Functions = new SelectList(new SelectListItem[] {
                new SelectListItem()
                {
                    Text = "Prepare Tasker File", Value = funcPrepareTaskerFile.ToString()
                },
                new SelectListItem()
                {
                    Text = "Coming soon", Value = "2"
                }
            }, "Value", "Text");

            var model = new DeviceSelectionViewModel();
            var items =
                from d in db.Devices
                //join r in db.Requests on d.ID equals r.DeviceID into dr
                //join l in db.DeviceLogs on d.ID equals l.DeviceID into dl
                select new SelectDeviceEditorViewModel
            {
                ID                            = d.ID,
                AndriodVer                    = d.AndriodVer,
                CreationDate                  = d.CreationDate,
                CustomerID                    = d.CustomerID,
                ModelNo                       = d.ModelNo,
                DeviceCode                    = d.DeviceCode,
                DeviceType                    = d.DeviceType,
                TaskerVersion                 = d.TaskerVersion,
                TodayNetworkConnectivity      = d.TodayNetworkConnectivity,
                Last30DaysNetworkConnectivity = d.Last30DaysNetworkConnectivity,
                LastRequestID                 = d.LastRequestId,
                LastRequestDate               = d.LastRequestTime,
                LastLogID                     = d.LastLogId,
                LastLogDate                   = d.LastLogTime,
                LastRunMinute                 = d.LastRunMinute,
                TodayShowRate                 = d.TodayShowRate,
                LastRunIndex                  = d.LastRunIndex,
                LastCommandIssued             = d.LastCommandIssued,
                LastCommandIssueTime          = d.LastCommandIssueTime,
                LastCommandExecuted           = d.LastCommandExecuted,
                LastCommandExecuteTime        = d.LastCommandExecuteTime,
                //Status = (Device.DeviceStatus)d.Status, // d.GetStatus(), //.HasValue? (Device.DeviceStatus)d.Status.Value: Device.DeviceStatus.Unknown,

                Selected = true
                           //LastRequest = dr.OrderByDescending(r => r.ID).Take(1).FirstOrDefault(),
                           //LastLog = dl.OrderByDescending(r => r.ID).Take(1).FirstOrDefault()
            };

            foreach (var item in items)
            {
                model.Devices.Add(item);
            }

            ////var items = db.Devices
            ////    .Join(db.DeviceLogs, d => d.ID, l => l.DeviceID, (d, l) => new {device = d, log = l}) //.OrderBy(d => d.device.ID).ThenByDescending(d => d.log.ID)
            ////    .Join(db.Requests, d => d.device.ID, r => r.DeviceID, (d, r) => new {device = d.device, log = d.log, req = r})
            ////    .OrderBy(d => d.device.ID)
            ////    .ThenByDescending(d => d.req.ID)
            ////    .ThenByDescending(d => d.log.ID);
            ////var devices =
            ////    from d in db.Devices
            ////    join r in db.Requests on d.ID equals r.DeviceID into dr
            ////    join l in db.DeviceLogs on d.ID equals l.DeviceID into dl
            ////    orderby d.ID
            ////    orderby r. descending
            ////    select new { Devices = d, Requests = dr, Logs = dl};
            ////foreach (var device in db.Devices.Include(d => d.Requests.OrderByDescending(o => o.ID).Take(10)).Include(d => d.DeviceLogs.OrderByDescending(l => l.ID).Take(10)))
            //foreach (var item in items) // (var device in db.Devices.Include(d => d.Requests.Where(dw => DateTime.Now.Subtract(dw.RequestDate).TotalDays ).Include(d => d.DeviceLogs))
            //{
            //    var editorViewModel = new SelectDeviceEditorViewModel()
            //    {
            //        ID = item.Device.ID,
            //        AndriodVer = item.Device.AndriodVer,
            //        CreationDate = item.Device.CreationDate,
            //        CustomerID = item.Device.CustomerID,
            //        DeviceID = item.Device.DeviceID,
            //        DeviceType = item.Device.DeviceType,
            //        ModelNo = item.Device.ModelNo,
            //        LastRequestDate = item.LastRequest == null? (DateTime?)null: item.LastRequest.RequestDate,
            //        LastRequestID = item.LastRequest == null ? (long?)null : item.LastRequest.ID,
            //        LastLogDate = item.LastLog == null ? (DateTime?)null : item.LastLog.CreationDate,
            //        LastLogID = item.LastLog == null ? (long?)null : item.LastLog.ID,

            //        //ID = device.ID,
            //        //AndriodVer = device.AndriodVer,
            //        //CreationDate = device.CreationDate,
            //        //CustomerID = device.CustomerID,
            //        //DeviceID = device.DeviceID,
            //        //DeviceType = device.DeviceType,
            //        //ModelNo = device.ModelNo,
            //        Selected = true
            //    };
            //    //if (device.Requests != null && device.Requests.Count > 0)
            //    //{
            //    //    var lastReq = device.Requests.OrderByDescending(o => o.ID).First();
            //    //    editorViewModel.LastRequestDate = lastReq.RequestDate;
            //    //    editorViewModel.LastRequestID = lastReq.ID;
            //    //}
            //    //if (device.DeviceLogs != null && device.DeviceLogs.Count > 0)
            //    //{
            //    //    var lastRLog = device.DeviceLogs.OrderByDescending(o => o.ID).First();
            //    //    editorViewModel.LastLogDate = lastRLog.CreationDate;
            //    //    editorViewModel.LastLogID = lastRLog.ID;
            //    //}
            //    model.Devices.Add(editorViewModel);
            //}
            //return View(model);
            return(View(model));
        }