/// <summary>
        /// Initializes a new instance of the <see cref="MixedRealityViewDialogViewModel" /> class.
        /// </summary>
        /// <param name="monitor">The DeviceMonitor responsible for communication with this device.</param>
        public MixedRealityViewDialogViewModel(
            DeviceMonitor monitor)
        {
            this.deviceMonitor = monitor;

            this.StartLiveView();
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceMonitorControl" /> class.
 /// </summary>
 /// <param name="monitor">The DeviceMonitor that is responsible for communication with the device.</param>
 public DeviceMonitorControl(
     DeviceMonitor monitor)
 {
     this.DataContext = new DeviceMonitorControlViewModel(
         this,
         monitor);
     this.InitializeComponent();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ManageAppsDialog" /> class.
 /// </summary>
 /// <param name="monitor">The DeviceMonitor that is responsible for communication with the device.</param>
 /// <param name="monitorControl">The DeviceMonitorControl that launched this dialog.</param>
 public ManageAppsDialog(
     DeviceMonitor monitor,
     DeviceMonitorControl monitorControl)
 {
     this.DataContext = new ManageAppsDialogViewModel(
         monitor,
         monitorControl);
     this.InitializeComponent();
 }
        /// <summary>
        /// Implementation of the connect to device command.
        /// </summary>
        /// <param name="connectOptions">Options used when connecting to the device.</param>
        /// <param name="name">Descriptive name to assign to the device.</param>
        /// <param name="suppressDialog">True causes the connection dialog to not be shown./param>
        /// <returns>Task object used for tracking method completion.</returns>
        private async Task ConnectToDeviceAsync(
            ConnectOptions connectOptions,
            string name,
            bool suppressDialog = false)
        {
            this.StatusMessage = string.Empty;

            if (!suppressDialog)
            {
                ContentDialog       dialog = new ConnectToDeviceDialog(connectOptions);
                ContentDialogResult result = await dialog.ShowAsync().AsTask <ContentDialogResult>();

                // Primary button == "Ok"
                if (result != ContentDialogResult.Primary)
                {
                    // The user decided not to connect.
                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(connectOptions.Address))
            {
                connectOptions.Address = DeviceMonitor.DefaultConnectionAddress;
            }

            DeviceMonitor monitor = new DeviceMonitor(this.dispatcher);

            try
            {
                this.StatusMessage = string.Format(
                    "Connecting to the device at {0}",
                    connectOptions.Address);

                await monitor.ConnectAsync(connectOptions);

                await this.RegisterDeviceAsync(
                    monitor,
                    name);

                await this.RefreshCommonAppsAsync();

                this.StatusMessage = "";
            }
            catch
            {
                string addr = connectOptions.Address;
                if (connectOptions.Address == DeviceMonitor.DefaultConnectionAddress)
                {
                    addr = "the attached device";
                }

                this.StatusMessage = string.Format(
                    "Failed to connect to {0}. Is it powered on? Paired with the Windows Device Portal?",
                    addr);
            }
        }
Пример #5
0
        /// <summary>
        /// Cleans up objects managed by the DeviceMonitorControlViewModel.
        /// </summary>
        /// <remarks>
        /// Failure to call this method will result in the object not being collected until
        /// finalization occurs.
        /// </remarks>
        public void Dispose()
        {
            this.deviceMonitor.HeartbeatLost     -= Device_HeartbeatLost;
            this.deviceMonitor.HeartbeatReceived -= Device_HeartbeatReceived;
            this.deviceMonitor.AppInstallStatus  -= DeviceMonitor_AppInstallStatus;
            this.deviceMonitor.Dispose();
            this.deviceMonitor = null;

            GC.SuppressFinalize(this);
        }
 /// <summary>
 /// Handles the ApplicationInstallStatus event.
 /// </summary>
 /// <param name="sender">The object which sent this event.</param>
 /// <param name="args">Event arguments.</param>
 private void DeviceMonitor_AppInstallStatus(
     DeviceMonitor sender,
     ApplicationInstallStatusEventArgs args)
 {
     if (args.Status == ApplicationInstallStatus.Completed)
     {
         // Assigning the return value of RefreshInstalledAppsAsync to a Task object to avoid
         // warning 4014 (call is not awaited).
         Task t = this.RefreshInstalledAppsAsync();
     }
 }
        /// <summary>
        /// Handles the HeartbeatReceived event.
        /// </summary>
        /// <param name="sender">The object which sent this event.</param>
        private void Device_HeartbeatReceived(DeviceMonitor sender)
        {
            this.IsConnected = true;

            // Did we recover from a heartbeat loss?
            if (this.StatusMessage == HeartbeatLostMessage)
            {
                this.ClearStatusMessage();
            }

            // Handle whether or not we were previously selected
            if (this.oldIsSelected &&
                !this.IsSelected)
            {
                this.IsSelected    = true;
                this.oldIsSelected = false;
            }

            // Was this the first time we received a heartbeat?
            if (!this.firstContact)
            {
                // Cause common apps to be refreshed.
                this.deviceMonitorControl.NotifySelectedChanged();
                this.firstContact = true;
            }

            if (this.Address != this.deviceMonitor.Address)
            {
                // Update the device address display.
                this.Address = this.deviceMonitor.Address;
                ((DeviceMonitorControlViewModel)(this.deviceMonitorControl.DataContext)).Address = this.Address;

                // Re-save the collection...
                this.deviceMonitorControl.NotifyTagChanged();
            }

            // Update the UI
            this.SetFilter();
            this.PowerIndicator = sender.BatteryState.IsOnAcPower ? OnAcPowerLabel : OnBatteryLabel;
            this.BatteryLevel   = string.Format("{0}%", sender.BatteryState.Level.ToString("#.00"));
            if (this.deviceMonitor.Platform == DevicePortalPlatforms.HoloLens)
            {
                this.ThermalStatus = (sender.ThermalStage == ThermalStages.Normal) ? Visibility.Collapsed : Visibility.Visible;
                this.Ipd           = sender.Ipd.ToString();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ManageAppsDialogViewModel" /> class.
        /// </summary>
        /// <param name="monitor">The DeviceMonitor responsible for communication with this device.</param>
        /// <param name="monitorControl">Instance of the control that launched this dialog.</param>
        public ManageAppsDialogViewModel(
            DeviceMonitor monitor,
            DeviceMonitorControl monitorControl)
        {
            this.deviceMonitor                   = monitor;
            this.deviceMonitorControl            = monitorControl;
            this.deviceMonitor.AppInstallStatus += DeviceMonitor_AppInstallStatus;

            this.InstalledApps = new ObservableCollection <string>();
            this.RunningApps   = new ObservableCollection <string>();

            this.RegisterCommands();

            // Assigning the return value of the following methods to a Task object to avoid
            // warning 4014 (call is not awaited).
            Task t = this.RefreshInstalledAppsAsync();

            t = this.RefreshRunningAppsAsync();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceMonitorControlViewModel" /> class.
        /// </summary>
        /// <param name="control">The DeviceMonitorControl to which this object is registered.</param>
        /// <param name="monitor">The DeviceMonitor responsible for communication with this device.</param>
        public DeviceMonitorControlViewModel(
            DeviceMonitorControl control,
            DeviceMonitor monitor)
        {
            this.deviceMonitorControl = control;

            this.RegisterCommands();

            this.deviceMonitor = monitor;
            this.deviceMonitor.HeartbeatLost     += Device_HeartbeatLost;
            this.deviceMonitor.HeartbeatReceived += Device_HeartbeatReceived;
            this.deviceMonitor.AppInstallStatus  += DeviceMonitor_AppInstallStatus;

            this.SetFilter();

            this.IsConnected = true;

            this.Address    = deviceMonitor.Address;
            this.IsSelected = true;
        }
Пример #10
0
        /// <summary>
        /// Handles the HeartbeatLost event.
        /// </summary>
        /// <param name="sender">The object which sent this event.</param>
        private void Device_HeartbeatLost(DeviceMonitor sender)
        {
            this.IsConnected = false;

            this.StatusMessage = HeartbeatLostMessage;

            // Handle whether or not we were previously selected
            if (!this.oldIsSelected &&
                this.IsSelected)
            {
                this.IsSelected    = false;
                this.oldIsSelected = true;
            }

            // Update the heartbeat based UI
            this.PowerIndicator = OnBatteryLabel;
            this.BatteryLevel   = "--";
            this.ThermalStatus  = Visibility.Collapsed;
            this.Ipd            = "--";
        }
Пример #11
0
        /// <summary>
        /// Implementation of the connect to device command.
        /// </summary>
        /// <param name="connectOptions">Options used when connecting to the device.</param>
        /// <param name="name">Descriptive name to assign to the device.</param>
        /// <param name="suppressDialog">True causes the connection dialog to not be shown./param>
        /// <returns>Task object used for tracking method completion.</returns>
        private async Task ConnectToDeviceAsync(
            ConnectOptions connectOptions,
            string name,
            bool suppressDialog = false)
        {
            this.StatusMessage = string.Empty;

            if (!suppressDialog)
            {
                ContentDialog       dialog = new ConnectToDeviceDialog(connectOptions);
                ContentDialogResult result = await dialog.ShowAsync().AsTask <ContentDialogResult>();

                // Primary button == "Ok"
                if (result != ContentDialogResult.Primary)
                {
                    // The user decided not to connect.
                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(connectOptions.Address))
            {
                connectOptions.Address = DeviceMonitor.DefaultConnectionAddress;
            }

            DeviceMonitor monitor = new DeviceMonitor(this.dispatcher);

            this.StatusMessage = string.Format(
                "Connecting to the device at {0}",
                connectOptions.Address);

            await monitor.ConnectAsync(connectOptions);

            this.StatusMessage = "";

            await this.RegisterDeviceAsync(
                monitor,
                name);
        }
        /// <summary>
        /// Registers the DeviceMonitor with the application.
        /// </summary>
        /// <param name="monitor">Device to register.</param>
        /// <param name="name">Descriptive name of the device.</param>
        /// <returns>Task object used for tracking method completion.</returns>
        private async Task RegisterDeviceAsync(
            DeviceMonitor monitor,
            string name)
        {
            DeviceMonitorControl deviceMonitorControl = new DeviceMonitorControl(monitor);

            deviceMonitorControl.AppInstalled       += DeviceMonitorControl_AppInstalled;
            deviceMonitorControl.AppUninstalled     += DeviceMonitorControl_AppUninstalled;
            deviceMonitorControl.DeviceDisconnected += DeviceMonitorControl_Disconnected;
            deviceMonitorControl.SelectedChanged    += DeviceMonitorControl_SelectedChanged;
            deviceMonitorControl.TagChanged         += DeviceMonitorControl_TagChanged;

            DeviceMonitorControlViewModel viewModel = deviceMonitorControl.DataContext as DeviceMonitorControlViewModel;

            viewModel.Name = name;

            // We want a sorted list of devices.
            List <DeviceMonitorControl> currentDevices = this.GetCopyOfRegisteredDevices();

            currentDevices.Add(deviceMonitorControl);
            currentDevices.Sort(new DeviceMonitorControlComparer());

            this.RegisteredDevices.Clear();
            foreach (DeviceMonitorControl monitorControl in currentDevices)
            {
                this.RegisteredDevices.Add(monitorControl);
            }
            if (this.RegisteredDevices.Count > 0)
            {
                this.HaveRegisteredDevices = true;
            }

            currentDevices.Clear();
            currentDevices = null;

            await this.SaveConnectionsAsync();
        }
        /// <summary>
        /// Handles the HeartbeatReceived event.
        /// </summary>
        /// <param name="sender">The object which sent this event.</param>
        private void Device_HeartbeatReceived(DeviceMonitor sender)
        {
            this.IsConnected = true;

            // Did we recover from a heartbeat loss?
            if (this.StatusMessage == HeartbeatLostMessage)
            {
                this.StatusMessage = "";
            }

            // Handle whether or not we were previously selected
            if (this.oldIsSelected &&
                !this.IsSelected)
            {
                this.IsSelected    = true;
                this.oldIsSelected = false;
            }

            // Update the heartbeat based UI
            this.PowerIndicator = sender.BatteryState.IsOnAcPower ? OnAcPowerLabel : OnBatteryLabel;
            this.BatteryLevel   = string.Format("{0}%", sender.BatteryState.Level.ToString("#.00"));
            this.ThermalStatus  = (sender.ThermalStage == ThermalStages.Normal) ? Visibility.Collapsed : Visibility.Visible;
            this.Ipd            = sender.Ipd.ToString();
        }
        /// <summary>
        /// Registers the DeviceMonitor with the application.
        /// </summary>
        /// <param name="monitor">Device to register.</param>
        /// <param name="name">Descriptive name of the device.</param>
        /// <returns>Task object used for tracking method completion.</returns>
        private async Task RegisterDeviceAsync(
            DeviceMonitor monitor,
            string name)
        {
            DeviceMonitorControl deviceMonitorControl = new DeviceMonitorControl(monitor);

            deviceMonitorControl.AppInstalled       += DeviceMonitorControl_AppInstalled;
            deviceMonitorControl.AppUninstalled     += DeviceMonitorControl_AppUninstalled;
            deviceMonitorControl.DeviceDisconnected += DeviceMonitorControl_Disconnected;
            deviceMonitorControl.SelectedChanged    += DeviceMonitorControl_SelectedChanged;
            deviceMonitorControl.TagChanged         += DeviceMonitorControl_TagChanged;

            DeviceMonitorControlViewModel viewModel = deviceMonitorControl.DataContext as DeviceMonitorControlViewModel;

            viewModel.Name = name;

            this.RegisteredDevices.Add(deviceMonitorControl);
            if (this.RegisteredDevices.Count > 0)
            {
                this.HaveRegisteredDevices = true;
            }

            await this.SaveConnectionsAsync();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceInformationDialogViewModel" /> class.
 /// </summary>
 /// <param name="monitor">The DeviceMonitor responsible for communication with this device.</param>
 public DeviceInformationDialogViewModel(
     DeviceMonitor monitor)
 {
     this.deviceMonitor = monitor;
 }
Пример #16
0
 /// <summary>
 /// Handles the ApplicationInstallStatus event.
 /// </summary>
 /// <param name="sender">The object which sent this event.</param>
 /// <param name="args">Event arguments.</param>
 private void DeviceMonitor_AppInstallStatus(
     DeviceMonitor sender,
     ApplicationInstallStatusEventArgs args)
 {
     this.StatusMessage = args.Message;
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MixedRealityViewDialog" /> class.
 /// </summary>
 /// <param name="monitor">The DeviceMonitor that is responsible for communication with the device.</param>
 public MixedRealityViewDialog(DeviceMonitor monitor)
 {
     this.DataContext = new MixedRealityViewDialogViewModel(
         monitor);
     this.InitializeComponent();
 }
Пример #18
0
 public DeviceInformationDialog(DeviceMonitor monitor)
 {
     this.DataContext = new DeviceInformationDialogViewModel(monitor);
     this.InitializeComponent();
 }