Beispiel #1
0
        public void ButtonSetPTZPresetAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Windows.Foundation.IAsyncOperation <Boolean> ret = null;
            Button send = sender as Button;

            if (send != null)
            {
                send.IsEnabled = false;
            }

            // int Idx = this.Presets.SelectedIndex;
            PTZPresetItem preset = this.Presets.getSelectecItem();

            /*if (preset.Token == "HomeToken")
             * {
             *  ret = this.SetHomePositionAsync();
             * }
             * else
             */
            {
                if (preset == null)
                {
                    return;
                }

                ret = this.setPTZPresetAsync(preset.Token);
            }
            if (send != null)
            {
                send.IsEnabled = true;
            }
            //       return ret;
        }
Beispiel #2
0
        public void ButtonDeletePTZPresetAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e)

        //     public Windows.Foundation.IAsyncOperation<Boolean> ButtonDeletePTZPresetAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Windows.Foundation.IAsyncOperation <Boolean> ret = null;
            Button send = sender as Button;

            if (send != null)
            {
                send.IsEnabled = false;
            }

            //   int Idx = this.Presets.SelectedIndex;

            PTZPresetItem preset = this.Presets.getSelectecItem();

            if (preset == null)
            {
                return;
            }

            ret = this.RemovePresetAsync(preset.Token);


            if (send != null)
            {
                send.IsEnabled = true;
            }
            return;
        }
Beispiel #3
0
        public Windows.Foundation.IAsyncOperation <IList <PTZPresetItem> > readPTZPresetsAsync()
        {
            Task <IList <PTZPresetItem> > ret = readPTZPresetsInternalAsync();

            Windows.Foundation.IAsyncOperation <IList <PTZPresetItem> > from = ret.AsAsyncOperation();
            return(from);
        }
Beispiel #4
0
        public async void ce()
        {
            StorageFolder storageFolder = KnownFolders.PicturesLibrary;

            reminder = storageFolder.Name;
            string file = "1.txt";

            Windows.Foundation.IAsyncOperation <StorageFile> wait_storageFile = storageFolder.CreateFileAsync(file, CreationCollisionOption.ReplaceExisting);
            StorageFile storageFile = await wait_storageFile;

            reminder = string.Format("名字{0} {1}", storageFile.Name, storageFile.Path);

            if (!string.IsNullOrEmpty(reminder) && storageFile != null)
            {
                await FileIO.WriteTextAsync(storageFile, reminder);

                reminder = "启动";
            }
            reminder = await FileIO.ReadTextAsync(storageFile);


            StorageFolder folder =
                Windows.Storage.ApplicationData.Current.LocalFolder;

            storageFile = await folder.CreateFileAsync(file);

            reminder = folder.Path;
            await FileIO.WriteTextAsync(storageFile, reminder);

            reminder = string.Format("名字:{0} {1},内容:{2}", storageFile.Name, storageFile.Path, await FileIO.ReadTextAsync(storageFile));
        }
Beispiel #5
0
 /// <summary>
 /// Event is fired by webview when the content is not a webpage, such as a file download
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     appendLog(String.Format("Content for \"{0}\" cannot be loaded into webview. Invoking the default launcher instead.\n", args.Uri.ToString()));
     // We turn around and hand the Uri to the system launcher to launch the default handler for it
     Windows.Foundation.IAsyncOperation <bool> b = Windows.System.Launcher.LaunchUriAsync(args.Uri);
     pageIsLoading = false;
 }
Beispiel #6
0
        public static T RunSynchronously <T>(Windows.Foundation.IAsyncOperation <T> iasync)
        {
            var task = iasync.AsTask();

            task.Wait();
            return(task.Result);
        }
Beispiel #7
0
        /// <summary>
        /// Method that calls the funtion that checks the API health
        /// </summary>
        private async void GetApiStatus()
        {
            ProgressBarcontrol.IsIndeterminate = true;

            if (HttpHandling.GetAPIHealth())
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                Frame.Navigate(typeof(ListScreen));
            }
            else
            {
                MessageDialog message = new MessageDialog("Server health is not OK! Try again later.");

                UICommand taButton = new UICommand("Try again")
                {
                    Invoked = taButtonClick
                };
                message.Commands.Add(taButton);

                Windows.Foundation.IAsyncOperation <IUICommand> messageExploder = message.ShowAsync();
            }

            ProgressBarcontrol.IsIndeterminate = false;
        }
Beispiel #8
0
        public Windows.Foundation.IAsyncOperation <Boolean> InitAsync(int Adress)
        {
            Task <Boolean> from = InitInternalAsync(Adress);

            Windows.Foundation.IAsyncOperation <Boolean> to = from.AsAsyncOperation();

            return(to);
        }
Beispiel #9
0
        public Windows.Foundation.IAsyncOperation <Boolean> InitalizeAsync()
        {
            Task <Boolean> from = InitializeInternalAsync();

            Windows.Foundation.IAsyncOperation <Boolean> to = from.AsAsyncOperation();

            return(to);
        }
Beispiel #10
0
        public Windows.Foundation.IAsyncOperation <Boolean> GotoHomePositionAsync()
        {
            Task <Boolean> from = GotoHomePositionInternalAsync();

            Windows.Foundation.IAsyncOperation <Boolean> ret = from.AsAsyncOperation();

            return(ret);
        }
Beispiel #11
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Windows.ApplicationModel.DataTransfer.DataPackageView content          = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            Windows.Foundation.IAsyncOperation <string>           getTextOperation = content.GetTextAsync();
            string s = await getTextOperation;

            this.clipboardResultTextBox.Text = s;
        }
Beispiel #12
0
        public Windows.Foundation.IAsyncOperation <Boolean> SendMailAsync(string subject, string body)
        {
            Task <Boolean> from = sendInternalAsync(subject, body);

            Windows.Foundation.IAsyncOperation <Boolean> to = from.AsAsyncOperation();

            return(to);
        }
Beispiel #13
0
        public Windows.Foundation.IAsyncOperation <Boolean> GotoPresetAsync(string presettoken)
        {
            Task <Boolean> from = GotoPresetInternalAsync(presettoken);

            Windows.Foundation.IAsyncOperation <Boolean> ret = from.AsAsyncOperation();

            return(ret);
        }
Beispiel #14
0
        public Windows.Foundation.IAsyncOperation <int> GetAvailableWSEndpointsAsync()
        {
            //  m_SendPort = port;
            Task <int> from = GetAvailableWSEndpointsInternal();

            Windows.Foundation.IAsyncOperation <int> to = from.AsAsyncOperation();

            return(to);
        }
Beispiel #15
0
        public async Task <T> ExecuteAsync <T>(Windows.Foundation.IAsyncOperation <T> op)
        {
            var startTime = DateTime.Now;
            var result    = await op;
            var endTime   = DateTime.Now;

            ExecutionTime = endTime - startTime;

            return(result);
        }
Beispiel #16
0
 public SaveLoadIrpsViewModel()
 {
     //
     // make sure the file exists
     //
     Task.Run(() =>
     {
         Windows.Foundation.IAsyncOperation <StorageFile> asyncOperation = ApplicationData.Current.LocalFolder.CreateFileAsync(_filename, CreationCollisionOption.ReplaceExisting);
     });
 }
Beispiel #17
0
        private void LoadCompleted(Windows.Foundation.IAsyncOperation <uint> asyncInfo, Windows.Foundation.AsyncStatus asyncStatus)
        {
            switch (asyncStatus)
            {
            case Windows.Foundation.AsyncStatus.Canceled:
                //logger.AddLog("Data load operation canceled");
                break;

            case Windows.Foundation.AsyncStatus.Completed:
                //logger.AddLog("Data load operation completed");
                if (TcpStreamReader.UnconsumedBufferLength.Equals(0))
                {
                    if (IsSocketConnected)
                    {
                        //logger.AddLog("Connection closed by remote host. Exiting");
                        IsSocketConnected = false;
                        IsConnectionClosedByRemoteHost = true;
                        CloseSocket();
                    }
                }
                else
                {
                    IBuffer buffer = TcpStreamReader.DetachBuffer();
                    RaiseDataReceivedEvent(buffer.ToArray());
                    DataReaderLoadOperation loadOperation = TcpStreamReader.LoadAsync(ReadBufferLength);
                    try
                    {
                        loadOperation.Completed = new Windows.Foundation.AsyncOperationCompletedHandler <UInt32>(LoadCompleted);
                    }
                    catch (Exception e)
                    {
                    }
                }
                break;

            case Windows.Foundation.AsyncStatus.Error:
                //logger.AddLog("Exception in data load operation");
                IsSocketConnected = false;
                if (asyncInfo.ErrorCode.HResult.Equals(-2147014842))
                {
                    IsConnectionClosedByRemoteHost = true;
                }
                else
                {
                    RaiseErrorOccuredEvent(asyncInfo.ErrorCode);
                }
                CloseSocket();
                break;

            case Windows.Foundation.AsyncStatus.Started:
                //logger.AddLog("Data load operation started");
                break;
            }
        }
Beispiel #18
0
 private void MapViewModel_OnError(object sender, string message)
 {
     var _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
     {
         if (currentDialogTask != null)
         {
             await currentDialogTask;
         }
         currentDialogTask = new Windows.UI.Popups.MessageDialog(message).ShowAsync();
         await currentDialogTask;
         currentDialogTask = null;
     });
 }
        private static StorageFile GetTestFile()
        {
            var folder = ApplicationData.Current.LocalFolder;
            var option = CreationCollisionOption.GenerateUniqueName;

            Windows.Foundation.IAsyncOperation <StorageFile> operation = folder.CreateFileAsync("test", option);
            Task <StorageFile> task = operation.AsTask <StorageFile>();

            task.Wait(1000);
            StorageFile file = task.Result;

            return(file);
        }
    private async void Start()
    {
        try
        {
            await _objectAnchorsService.InitializeAsync();
        }
        catch (System.ArgumentException ex)
        {
#if WINDOWS_UWP
            string message = ex.Message;
            Windows.Foundation.IAsyncOperation <Windows.UI.Popups.IUICommand> dialog = null;
            UnityEngine.WSA.Application.InvokeOnUIThread(() => dialog = new Windows.UI.Popups.MessageDialog(message, "Invalid account information").ShowAsync(), true);
            await dialog;
#elif UNITY_EDITOR
            UnityEditor.EditorUtility.DisplayDialog("Invaild account information", ex.Message, "OK");
#endif // WINDOWS_UWP
            throw ex;
        }

        TextLogger.Log($"Object search initialized.");

        foreach (var file in FileHelper.GetFilesInDirectory(Application.persistentDataPath, "*.ou"))
        {
            TextLogger.Log($"Loading model ({Path.GetFileNameWithoutExtension(file)})");

            await _objectAnchorsService.AddObjectModelAsync(file.Replace('/', '\\'));
        }

#if WINDOWS_UWP
        StorageFolder objects3d = KnownFolders.Objects3D;
        foreach (string filePath in FileHelper.GetFilesInDirectory(objects3d.Path, "*.ou"))
        {
            TextLogger.Log($"Loading model ({Path.GetFileNameWithoutExtension(filePath)})");

            byte[] buffer = await ReadFileBytesAsync(filePath);

            await _objectAnchorsService.AddObjectModelAsync(buffer);
        }
#endif

        _objectQueries = InitializeObjectQueries();

        if (IsDiagnosticsCaptureEnabled)
        {
            TextLogger.Log($"Start capture diagnostics.");

            _objectAnchorsService.StartDiagnosticsSession();
        }
    }
Beispiel #21
0
        public static async Task <GeoCoordinate> GetCurrentLocationAsync()
        {
            if (!Globals.IsLocationConsentEnabled)
            {
                return(null);
            }

            Globals.IsPhoneLocationServiceEnabled = true;
            Geoposition geoposition = null;

            try
            {
                Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracy = PositionAccuracy.High;
                Windows.Foundation.IAsyncOperation <Geoposition> locationTask = null;

                try
                {
                    locationTask = geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5));
                    geoposition  = await locationTask;
                }
                finally
                {
                    if (locationTask != null)
                    {
                        if (locationTask.Status == Windows.Foundation.AsyncStatus.Started)
                        {
                            locationTask.Cancel();
                        }

                        locationTask.Close();
                    }
                }
                geolocator = null;

                Globals.RecentLocation.Coordinate   = geoposition.Coordinate.ToGeoCoordinate();
                Globals.RecentLocation.CapturedTime = DateTime.Now;
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    Globals.IsPhoneLocationServiceEnabled = false;
                }
            }
            return(Globals.IsPhoneLocationServiceEnabled ? Globals.RecentLocation.Coordinate : null);
        }
Beispiel #22
0
        public string Scan(string DevicePID)
        {
            string selector = HidDevice.GetDeviceSelector(usagePage, usageID, vid, pid);

            Windows.Foundation.IAsyncOperation <DeviceInformationCollection> task = DeviceInformation.FindAllAsync(selector);
            while (task.Status == Windows.Foundation.AsyncStatus.Started)
            {
                Thread.Sleep(50);
            }
            DeviceInformationCollection devices = task.GetResults();

            if (devices.Count > 0)
            {
                return(devices[0].Id);
            }
            return("");
        }
Beispiel #23
0
        // Buttons Read Video-Encodings
        //public Windows.Foundation.IAsyncOperation<IList<PTZPresetItem>> ButtonreadPTZPresetsAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        public void ButtonreadPTZPresetsAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Button send = sender as Button;

            if (send != null)
            {
                send.IsEnabled = false;
            }

            Windows.Foundation.IAsyncOperation <IList <PTZPresetItem> > from = readPTZPresetsAsync();

            if (send != null)
            {
                send.IsEnabled = true;
            }
            //           return from;
        }
Beispiel #24
0
        private void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            Windows.Foundation.IAsyncOperation <BluetoothLEDevice> task = BluetoothLEDevice.FromIdAsync(args.Id);
            while (task.Status == Windows.Foundation.AsyncStatus.Started)
            {
                Thread.Sleep(50);
            }
            Device d = new Device(task.GetResults());

            discoveredDevices.Add(d);
            MainThread.BeginInvokeOnMainThread(() =>
            {
                DeviceDiscovered(this, new DeviceDiscoveredEventArgs()
                {
                    Device = d
                });
            });
        }
Beispiel #25
0
        public void Load(string devicePath)
        {
            string selector = HidDevice.GetDeviceSelector(usagePage, usageID, vid, pid);

            Windows.Foundation.IAsyncOperation <DeviceInformationCollection> task = DeviceInformation.FindAllAsync(selector);
            while (task.Status == Windows.Foundation.AsyncStatus.Started)
            {
                Thread.Sleep(50);
            }
            DeviceInformationCollection devices = task.GetResults();

            foreach (DeviceInformation device in devices)
            {
                if (device.Id == devicePath)
                {
                    FoundDevice(device);
                    return;
                }
            }
        }
        /// <summary>
        /// Gets the results from querying the Cloud Error Message (CEM) service and prints it to the screen
        /// </summary>
        public async void GetHRESULT(Windows.Foundation.IAsyncOperation <Windows.Foundation.Diagnostics.ErrorDetails> info, AsyncStatus status)
        {
            retrievalTick.Change(System.Threading.Timeout.Infinite, 1000);
            try
            {
                // Write verbose information to the debug stream if there's a debugger attached
                var result = info.GetResults();
                System.Diagnostics.Debug.WriteLine("Got the HRESULT");
                System.Diagnostics.Debug.WriteLine("URI: " + result.HelpUri);
                System.Diagnostics.Debug.WriteLine("Description: " + result.Description);
                System.Diagnostics.Debug.WriteLine("Long Description: " + result.LongDescription);

                // Update the output box on the main thread
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (string.IsNullOrEmpty(result.Description))
                    {
                        boundText.Text = "Sorry, no result found\n" + boundText.Text;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Pushing error code");
                        string textToReport = "Retrieved error code in " + retrievalWatch.ElapsedMilliseconds + "ms" +
                                              "\nError Code: " + errorCodeBeingLookedUp +
                                              "\nError Code: 0x" + errorCodeBeingLookedUp.ToString("X8") +
                                              "\nError Message: " + result.Description;
                        System.Diagnostics.Debug.WriteLine(textToReport);
                        boundText.Text = textToReport + boundText.Text;
                    }
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("There was a problem getting the HRESULT");
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            // Done looking up an error code so allow the next lookup to occur
            currentlyLookingUpCode = false;
        }
Beispiel #27
0
 private void CompletedBackgroundRequest(Windows.Foundation.IAsyncOperation <BackgroundAccessStatus> asyncInfo, Windows.Foundation.AsyncStatus asyncStatus)
 {
     OnBackgroundStatusChanged();
 }
Beispiel #28
0
        /// <summary>
        /// Displays a <see cref="Windows.UI.Xaml.Controls.ContentDialog"/>.
        /// </summary>
        /// <param name="title">The dialog's title.</param>
        /// <param name="textContent">The dialog's text contents.</param>
        /// <param name="primaryButton">The primary button text.</param>
        /// <param name="secondaryButton">The secondary button text.</param>
        /// <param name="defaultBtn">Which <see cref="Windows.UI.Xaml.Controls.ContentDialogButton"/> will be primary?</param>
        /// <returns>bool? result of displaying.</returns>
        public static bool?ShowDialog
            (string title, string primaryButton, string secondaryButton, string textContent = "",
            Windows.UI.Xaml.Controls.ContentDialogButton?defaultBtn = Windows.UI.Xaml.Controls.ContentDialogButton.Primary)
        {
            Windows.UI.Xaml.Controls.ContentDialog dialog = new Windows.UI.Xaml.Controls.ContentDialog
            {
                Title               = title,
                Content             = textContent,
                PrimaryButtonText   = primaryButton,
                SecondaryButtonText = secondaryButton,
                CloseButtonText     = "Cancel",
                DefaultButton       = (Windows.UI.Xaml.Controls.ContentDialogButton)defaultBtn
            };

            Windows.Foundation.IAsyncOperation <Windows.UI.Xaml.Controls.ContentDialogResult> operation = dialog.ShowAsync(); //run the dialog asynchronously
            if (operation.Status == Windows.Foundation.AsyncStatus.Started)                                                   //check the status
            {
                return(true);
            }
            return(null);
        }
Beispiel #29
0
 public override void DiscoverServices()
 {
     Windows.Foundation.IAsyncOperation <Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceServicesResult> task = nativeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
     while (task.Status == Windows.Foundation.AsyncStatus.Started)
     {
         Thread.Sleep(50);
     }
     Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceServicesResult result = task.GetResults();
     this._services.Clear();
     if (result.Status == Windows.Devices.Bluetooth.GenericAttributeProfile.GattCommunicationStatus.Success)
     {
         foreach (var item in result.Services)
         {
             Debug.WriteLine("Device.Discovered Service: " + item.DeviceId);
             this._services.Add(new Service(item));
         }
         ServicesDiscovered?.Invoke(this, new EventArgs());
     }
     else
     {
     }
 }
        //LISTEN FOR NEXT RECEIVE
        private async Task <int> Listen()
        {
            const int NUMBER_OF_BYTES_TO_RECEIVE = 1;           //<<<<<SET THE NUMBER OF BYTES YOU WANT TO WAIT FOR

            byte[]      ReceiveData;
            UInt32      bytesRead;
            MidiMessage ChannelMessage = new MidiMessage();

            //MidiMessage GlobalMessage = new MidiMessage();

            try
            {
                if (UartPort != null)
                {
                    while (true)
                    {
                        //###### WINDOWS IoT MEMORY LEAK BUG 2017-03 - USING CancellationToken WITH LoadAsync() CAUSES A BAD MEMORY LEAK.  WORKAROUND IS
                        //TO BUILD RELEASE WITHOUT USING THE .NET NATIVE TOOLCHAIN OR TO NOT USE A CancellationToken IN THE CALL #####
                        //bytesRead = await DataReaderObject.LoadAsync(NUMBER_OF_BYTES_TO_RECEIVE).AsTask(ReadCancellationTokenSource.Token);	//Wait until buffer is full

                        Windows.Foundation.IAsyncOperation <uint> taskLoad = DataReaderObject.LoadAsync(NUMBER_OF_BYTES_TO_RECEIVE);
                        taskLoad.AsTask().Wait();
                        bytesRead = taskLoad.GetResults();

                        //bytesRead = await DataReaderObject.LoadAsync(NUMBER_OF_BYTES_TO_RECEIVE).AsTask();  //Wait until buffer is full


                        if ((ReadCancellationTokenSource.Token.IsCancellationRequested) || (UartPort == null))
                        {
                            break;
                        }

                        if (bytesRead > 0)
                        {
                            ReceiveData = new byte[NUMBER_OF_BYTES_TO_RECEIVE];

                            DataReaderObject.ReadBytes(ReceiveData);

                            foreach (byte Data in ReceiveData)
                            {
                                //-------------------------------
                                //-------------------------------
                                //----- RECEIVED NEXT BYTE ------
                                //-------------------------------
                                //-------------------------------

                                if (Data >= 0x80 && Data <= 0xEF) //new Channel Message
                                {
                                    if (ChannelMessage.IsSet1)    //We already have data in this object
                                    {
                                        //there is data in the current message
                                        RouteMessage(ChannelMessage);
                                        ChannelMessage = new MidiMessage(Data);
                                    }
                                    else     //No data in the message
                                    {
                                        ChannelMessage.Status = Data;
                                        if (MidiMessage.ByteCount(ChannelMessage.MessageClass) == 0)
                                        {
                                            RouteMessage(ChannelMessage);
                                            ChannelMessage = new MidiMessage();
                                        }
                                    }
                                }
                                else //not a status byte
                                {
                                    if (ChannelMessage.Status != 0 && !ChannelMessage.IsSet1)
                                    {
                                        ChannelMessage.Data1 = Data;
                                        if (MidiMessage.ByteCount(ChannelMessage.MessageClass) == 1)
                                        {
                                            RouteMessage(ChannelMessage);
                                            ChannelMessage = new MidiMessage();
                                        }
                                    }
                                    else //Data1 is full
                                    {
                                        if (ChannelMessage.Status != 0 && !ChannelMessage.IsSet2)
                                        {
                                            ChannelMessage.Data2 = Data;
                                            RouteMessage(ChannelMessage);
                                            ChannelMessage = new MidiMessage();
                                        }
                                    }
                                }
                            }


                            /*if (Data > 0xF0 ) //SysEx message (Global)
                             * {
                             *  //Throw away data until we get to F7
                             * }*/
                        }
                    } //while
                }     //check the port
            } catch (Exception e)
            {
                //We will get here often if the USB serial cable is removed so reset ready for a new connection (otherwise a never ending error occurs)
                if (ReadCancellationTokenSource != null)
                {
                    ReadCancellationTokenSource.Cancel();
                }
                System.Diagnostics.Debug.WriteLine("UART ReadAsync Exception: {0}", e.Message);
            }
            return(await Task.FromResult(0));
        }