Exemplo n.º 1
0
        /// <summary>
        /// Gets the available bluetooth device information.
        /// </summary>
        /// <returns>List of Available bluetooth devices</returns>
        public async Task <AvailableBluetoothDevicesInfo> GetAvailableBluetoothDevicesInfoAsync()
        {
            AvailableBluetoothDevicesInfo bluetooth = null;
            ManualResetEvent bluetoothReceived      = new ManualResetEvent(false);
            WebSocketMessageReceivedEventHandler <AvailableBluetoothDevicesInfo> bluetoothReceivedHandler =
                delegate(DevicePortal sender, WebSocketMessageReceivedEventArgs <AvailableBluetoothDevicesInfo> bluetoothArgs)
            {
                if (bluetoothArgs.Message != null)
                {
                    bluetooth = bluetoothArgs.Message;
                    bluetoothReceived.Set();
                }
            };

            this.BluetoothDeviceListReceived += bluetoothReceivedHandler;

            await this.StartListeningForBluetoothAsync(AvailableBluetoothDevicesApi);

            bluetoothReceived.WaitOne();

            await this.StopListeningForBluetoothAsync();

            this.BluetoothDeviceListReceived -= bluetoothReceivedHandler;
            return(bluetooth);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the results for pairing a bluetooth device.
        /// </summary>
        /// <param name="deviceId">Device Id.</param>
        /// <returns>Results of pairing a bluetooth device</returns>
        public async Task <PairBluetoothDevicesInfo> GetPairBluetoothDevicesInfoAsync(string deviceId)
        {
            PairBluetoothDevicesInfo bluetooth             = null;
            ManualResetEvent         pairBluetoothReceived = new ManualResetEvent(false);
            WebSocketMessageReceivedEventHandler <PairBluetoothDevicesInfo> pairBluetoothReceivedHandler =
                delegate(DevicePortal sender, WebSocketMessageReceivedEventArgs <PairBluetoothDevicesInfo> bluetoothArgs)
            {
                if (bluetoothArgs.Message != null)
                {
                    bluetooth = bluetoothArgs.Message;
                    pairBluetoothReceived.Set();
                }
            };

            this.PairBluetoothDeviceListReceived += pairBluetoothReceivedHandler;

            await this.StartListeningForPairBluetoothAsync(PairBluetoothDevicesApi, string.Format("deviceId={0}", Utilities.Hex64Encode(deviceId)));

            pairBluetoothReceived.WaitOne();

            await this.StopListeningForPairBluetoothAsync();

            this.PairBluetoothDeviceListReceived -= pairBluetoothReceivedHandler;
            return(bluetooth);
        }
Exemplo n.º 3
0
        public void GetSystemPerfWebSocketTest()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.SystemPerfApi, HttpMethods.WebSocket);

            ManualResetEvent             systemPerfReceived = new ManualResetEvent(false);
            SystemPerformanceInformation systemPerfInfo     = null;

            WebSocketMessageReceivedEventHandler <SystemPerformanceInformation> systemPerfReceivedHandler = delegate(DevicePortal sender,
                                                                                                                     WebSocketMessageReceivedEventArgs <SystemPerformanceInformation> args)
            {
                if (args.Message != null)
                {
                    systemPerfInfo = args.Message;
                    systemPerfReceived.Set();
                }
            };

            TestHelpers.Portal.SystemPerfMessageReceived += systemPerfReceivedHandler;

            Task startListeningForSystemPerfTask = TestHelpers.Portal.StartListeningForSystemPerf();

            startListeningForSystemPerfTask.Wait();
            Assert.AreEqual(TaskStatus.RanToCompletion, startListeningForSystemPerfTask.Status);

            systemPerfReceived.WaitOne();

            Task stopListeningForSystemPerf = TestHelpers.Portal.StopListeningForSystemPerf();

            stopListeningForSystemPerf.Wait();
            Assert.AreEqual(TaskStatus.RanToCompletion, stopListeningForSystemPerf.Status);

            TestHelpers.Portal.SystemPerfMessageReceived -= systemPerfReceivedHandler;

            ValidateSystemPerm(systemPerfInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the paired bluetooth device information.
        /// </summary>
        /// <returns>List of paired bluetooth devices</returns>
        public PairedBluetoothDevicesInfo GetPairedBluetoothDevicesInfo()
        {
            PairedBluetoothDevicesInfo bluetooth = null;
            ManualResetEvent           PairedBluetoothReceived = new ManualResetEvent(false);
            WebSocketMessageReceivedEventHandler <PairedBluetoothDevicesInfo> pairedBluetoothReceivedHandler =
                delegate(DevicePortal sender, WebSocketMessageReceivedEventArgs <PairedBluetoothDevicesInfo> BluetoothArgs)
            {
                if (BluetoothArgs.Message != null)
                {
                    bluetooth = BluetoothArgs.Message;
                    PairedBluetoothReceived.Set();
                }
            };

            this.PairedBluetoothDeviceListReceived += pairedBluetoothReceivedHandler;

            Task startListeningForPairedBluetooth = this.StartListeningForPairedBluetoothAsync(PairedBluetoothDevicesApi);

            startListeningForPairedBluetooth.Wait();

            PairedBluetoothReceived.WaitOne();

            Task stopListeningForPairedBluetooth = this.StopListeningForPairedBluetoothAsync();

            stopListeningForPairedBluetooth.Wait();

            this.PairedBluetoothDeviceListReceived -= pairedBluetoothReceivedHandler;
            return(bluetooth);
        }
        /// <summary>
        /// Main entry point for handling a System Perf operation
        /// </summary>
        /// <param name="portal">DevicePortal reference for communicating with the device.</param>
        /// <param name="parameters">Parsed command line parameters.</param>
        public static void HandleOperation(DevicePortal portal, ParameterHelper parameters)
        {
            SystemPerformanceInformation systemPerformanceInformation = null;

            if (parameters.HasFlag(ParameterHelper.Listen))
            {
                ManualResetEvent systemPerfReceived = new ManualResetEvent(false);

                WebSocketMessageReceivedEventHandler <SystemPerformanceInformation> systemPerfReceivedHandler =
                    delegate(DevicePortal sender, WebSocketMessageReceivedEventArgs <SystemPerformanceInformation> sysPerfInfoArgs)
                {
                    if (sysPerfInfoArgs.Message != null)
                    {
                        systemPerformanceInformation = sysPerfInfoArgs.Message;
                        systemPerfReceived.Set();
                    }
                };

                portal.SystemPerfMessageReceived += systemPerfReceivedHandler;

                Task startListeningForSystemPerfTask = portal.StartListeningForSystemPerf();
                startListeningForSystemPerfTask.Wait();

                systemPerfReceived.WaitOne();

                Task stopListeningForSystemPerfTask = portal.StopListeningForRunningProcesses();
                stopListeningForSystemPerfTask.Wait();

                portal.SystemPerfMessageReceived -= systemPerfReceivedHandler;
            }
            else
            {
                Task <SystemPerformanceInformation> getRunningProcessesTask = portal.GetSystemPerf();
                systemPerformanceInformation = getRunningProcessesTask.Result;
            }

            Console.WriteLine("Available Pages: " + systemPerformanceInformation.AvailablePages);
            Console.WriteLine("Commit Limit: " + systemPerformanceInformation.CommitLimit);
            Console.WriteLine("Commited Pages: " + systemPerformanceInformation.CommittedPages);
            Console.WriteLine("CPU Load: " + systemPerformanceInformation.CpuLoad);
            Console.WriteLine("IoOther Speed: " + systemPerformanceInformation.IoOtherSpeed);
            Console.WriteLine("IoRead Speed: " + systemPerformanceInformation.IoReadSpeed);
            Console.WriteLine("IoWrite Speed: " + systemPerformanceInformation.IoWriteSpeed);
            Console.WriteLine("Non-paged Pool Pages: " + systemPerformanceInformation.NonPagedPoolPages);
            Console.WriteLine("Paged Pool Pages: " + systemPerformanceInformation.PagedPoolPages);
            Console.WriteLine("Page Size: " + systemPerformanceInformation.PageSize);
            Console.WriteLine("Total Installed Kb: " + systemPerformanceInformation.TotalInstalledKb);
            Console.WriteLine("Total Pages: " + systemPerformanceInformation.TotalPages);
        }
        /// <summary>
        /// Main entry point for handling listing processes
        /// </summary>
        /// <param name="portal">DevicePortal reference for communicating with the device.</param>
        /// <param name="parameters">Parsed command line parameters.</param>
        public static void HandleOperation(DevicePortal portal, ParameterHelper parameters)
        {
            RunningProcesses runningProcesses = null;

            if (parameters.HasFlag(ParameterHelper.Listen))
            {
                ManualResetEvent runningProcessesReceived = new ManualResetEvent(false);

                WebSocketMessageReceivedEventHandler <RunningProcesses> runningProcessesReceivedHandler =
                    delegate(DevicePortal sender, WebSocketMessageReceivedEventArgs <RunningProcesses> runningProccesesArgs)
                {
                    if (runningProccesesArgs.Message != null)
                    {
                        runningProcesses = runningProccesesArgs.Message;
                        runningProcessesReceived.Set();
                    }
                };

                portal.RunningProcessesMessageReceived += runningProcessesReceivedHandler;

                Task startListeningForProcessesTask = portal.StartListeningForRunningProcesses();
                startListeningForProcessesTask.Wait();

                runningProcessesReceived.WaitOne();

                Task stopListeningForProcessesTask = portal.StopListeningForRunningProcesses();
                stopListeningForProcessesTask.Wait();

                portal.RunningProcessesMessageReceived -= runningProcessesReceivedHandler;
            }
            else
            {
                Task <DevicePortal.RunningProcesses> getRunningProcessesTask = portal.GetRunningProcesses();
                runningProcesses = getRunningProcessesTask.Result;
            }

            foreach (DeviceProcessInfo process in runningProcesses.Processes)
            {
                if (!string.IsNullOrEmpty(process.Name))
                {
                    Console.WriteLine(process.Name);
                }
            }
        }