Beispiel #1
0
        async void LoadPdf()
        {
            ViewPrint.IsEnabled = false;
            ViewHare.IsEnabled  = false;
            new Task(async() =>
            {
                byte[] stream;
                stream = await server.DownloadFileAsync(_billInfo.ID.ToString(), 1);
                if (stream != null)
                {
                    Stream streamM = new MemoryStream(stream);
                    Device.BeginInvokeOnMainThread(async() =>
                                                   Image.Source = ImageSource.FromStream(() => { return(streamM); }));
                    _file = await server.DownloadFileAsync(_billInfo.ID.ToString());
                }
                else
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await DisplayAlert(AppResources.ErrorTitle, "Не удалось скачать файл", "OK");
                    });
                }

                Device.BeginInvokeOnMainThread(async() =>
                {
                    ViewPrint.IsEnabled = true;
                    ViewHare.IsEnabled  = true;
                    progress.IsVisible  = false;
                });
            }).Start();
        }
        public async void GetFile(string id, string fileName, BillInfo period)
        {
            // Loading settings
            Configurations.LoadingConfig = new LoadingConfig
            {
                IndicatorColor = (Color)Application.Current.Resources["MainColor"],
                OverlayColor   = Color.Black,
                Opacity        = 0.8,
                DefaultMessage = AppResources.Loading,
            };
            byte[] stream = null;

            bool result = false;

            if (Device.RuntimePlatform == "iOS")
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Loading.Instance.StartAsync(async progress =>
                    {
                        try
                        {
                            byte[] stream;
                            stream = await server.DownloadFileAsync(id, 1);
                            if (stream != null)
                            {
                                Device.BeginInvokeOnMainThread(async() =>
                                {
                                });
                                //
                                // await DependencyService.Get<IFileWorker>().SaveTextAsync(fileName, stream);
                                // result = true;
                                // await Launcher.OpenAsync(new OpenFileRequest
                                // {
                                //     File = new ReadOnlyFile(DependencyService.Get<IFileWorker>().GetFilePath(fileName))
                                // });
                            }
                            else
                            {
                                await DisplayAlert(AppResources.ErrorTitle, "Не удалось скачать файл", "OK");
                                result = false;
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            await DisplayAlert(AppResources.ErrorTitle, "Не удалось скачать файл", "OK");
                            result = false;
                        }
                    });
                });
            }
            else
            {
                await Loading.Instance.StartAsync(async progress =>
                {
                    try
                    {
                        period.stream = await server.DownloadFileAsync(id, 1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        await DisplayAlert(AppResources.ErrorTitle, "Не удалось скачать файл", "OK");
                        result = false;
                    }
                });
            }
        }