An empty page that can be used on its own or navigated to within a Frame.
Inheritance: Windows.UI.Xaml.Controls.Page
Esempio n. 1
0
        private async Task <int> getImageFromURL()
        {
            string errorMessage = "";

            if (string.IsNullOrEmpty(URL.Text) || URL.Text.Equals("Please Enter a URL"))
            {
                URL.Text = "Please Enter a URL";
            }
            else
            {
                try
                {
                    String input      = URL.Text;
                    Uri    uri        = new Uri(input);
                    var    currentApp = (App)App.Current;
                    var    rass       = RandomAccessStreamReference.CreateFromUri(uri);
                    var    stream     = (await rass.OpenReadAsync()).AsStream();
                    int    len        = (int)stream.Length;
                    byte[] buff       = new byte[len];
                    int    pos        = 0;
                    int    r          = 0;
                    while ((r = stream.Read(buff, pos, len - pos)) > 0)
                    {
                        pos += r;
                    }

                    currentApp.CurrentImageRecog = new MemoryStream(buff);
                    try
                    {
                        currentApp.CurrentRecogResult = await App.VMHub.ProcessRequest(buff);

                        Frame.Navigate(typeof(WindowsApp.Views.RecogResultPage), "url");
                        return(0);
                    }

                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                    }

                    NetworkError.SetError(errorMessage);
                    Frame.Navigate(typeof(NetworkError));
                }
                catch
                {
                    URL.Text = "An image could not be found at this address";
                    errorImage.Visibility = Visibility.Visible;
                    errorText.Visibility  = Visibility.Visible;
                }
            }
            return(0);
        }
Esempio n. 2
0
        private async Task <int> UpdateProviderInfo()
        {
            string errorMessage = "";

            try
            {
                var currentApp = (App)App.Current;

                this.CurrentProvider.Text = "";
                App.VMHub.CurrentProvider = currentApp.CurrentProvider;
                if (!Object.ReferenceEquals(currentApp.CurrentProvider, null))
                {
                    this.CurrentProvider.Text = currentApp.CurrentProvider.RecogEngineName;
                    AddProvider(currentApp.CurrentProvider);
                    this.LastProvider = currentApp.CurrentProvider;
                }

                {
                    var lst = await App.VMHub.GetActiveProviders();

                    foreach (var item in lst)
                    {
                        if (lst == null)
                        {
                            return(0);
                        }
                        AddProvider(item);
                    }
                }
                var cnt = (double)(this.ProviderList.Count);
                if (String.IsNullOrEmpty(CurrentProvider.Text) && cnt > 0)
                {
                    LastProvider         = ProviderList[0];
                    CurrentProvider.Text = LastProvider.RecogEngineName;
                }
                this.ViewOfProvider.Height = cnt * 140.0;
                return(0);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            NetworkError.SetError(errorMessage);
            Frame.Navigate(typeof(NetworkError));
            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// resumes the application after choosing a photo from the photo library
        /// </summary>
        /// <param name="args"></param>
        public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
        {
            string errorMessage = "";

            if (args.Files.Count > 0)
            {
                MemoryStream stream;
                var          currentApp = (App)App.Current;

                IReadOnlyList <StorageFile> files = args.Files;

                var ms = await ReadFile(args.Files[0]);

                if (Object.ReferenceEquals(ms, null))
                {
                    currentApp.CurrentRecogResult = "no image selected. ";
                }
                else
                {
                    stream = new MemoryStream(ms);
                    currentApp.CurrentImageRecog = stream;
                    Byte[] buf = await ResizeImage(stream, 256);

                    try
                    {
                        await this.processRequestAfterRotate(buf);

                        return;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                    }

                    NetworkError.SetError(errorMessage);
                    Frame.Navigate(typeof(NetworkError));
                }
            }
            else
            {
                Frame.Navigate(typeof(OptionsPage));
            }
        }
Esempio n. 4
0
        private async Task <int> processRequestAfterRotate(byte[] buf)
        {
            string errorMessage = "";

            try
            {
                var currentApp = (App)App.Current;
                currentApp.CurrentRecogResult = await App.VMHub.ProcessRequest(buf);

                Frame.Navigate(typeof(WindowsApp.Views.RecogResultPage), "Upload Picture");
                return(0);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            NetworkError.SetError(errorMessage);
            Frame.Navigate(typeof(NetworkError));
            return(0);
        }