예제 #1
0
        private async void Upload()
        {
            if (this.SelectedFile == null)
            {
                return;
            }

            var successfulUpload = false;

            this.IsBusy = true;

            var scpCredentialsDialog = new ScpCredentialsDialog();
            var result = await scpCredentialsDialog.ShowAsync();

            if (result != ContentDialogResult.Primary)
            {
                this.IsBusy = false;
                return;
            }

            this.IsUploading = true;

            try
            {
                using (var scpClient = SecureConnectionsFactory.CreateScpClient(
                           scpCredentialsDialog.ViewModel.HostIP,
                           scpCredentialsDialog.ViewModel.Username,
                           scpCredentialsDialog.ViewModel.Password))
                {
                    scpClient.ErrorOccurred += OnClientErrorOccured;

                    var bytes = await ImageHelper.EncodeToSquareJpegImageAsync(this.SelectedFile, DefaultImageSize);

                    using (var memoryStream = new MemoryStream())
                    {
                        memoryStream.Write(bytes, 0, bytes.Length);
                        memoryStream.Seek(0, SeekOrigin.Begin);

                        scpClient.Upload(memoryStream, "/usr/share/asteroid-launcher/wallpapers/WinSteroid_" + this.SelectedFile.Name);
                    }

                    scpClient.ErrorOccurred -= OnClientErrorOccured;
                }

                successfulUpload = true;
            }
            catch (Exception exception)
            {
                await this.DialogService.ShowError(exception, ResourcesHelper.GetLocalizedString("SharedErrorTitle"));
            }

            this.IsUploading = false;

            if (successfulUpload)
            {
                ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsWallpapersWallpaperInstalledMessage"));
            }

            this.IsBusy = false;
        }
        private async void Upload()
        {
            if (this.SelectedFile == null)
            {
                return;
            }

            var successfulUpload = false;

            this.IsBusy = true;

            var scpCredentialsDialog = new ScpCredentialsDialog();
            var result = await scpCredentialsDialog.ShowAsync();

            if (result != ContentDialogResult.Primary)
            {
                this.IsBusy = false;
                return;
            }

            this.IsUploading = true;

            try
            {
                using (var scpClient = SecureConnectionsFactory.CreateScpClient(
                           scpCredentialsDialog.ViewModel.HostIP,
                           scpCredentialsDialog.ViewModel.Username,
                           scpCredentialsDialog.ViewModel.Password))
                {
                    scpClient.ErrorOccurred += OnClientErrorOccured;

                    using (var randomAccessStream = await this.SelectedFile.OpenReadAsync())
                    {
                        using (var stream = randomAccessStream.AsStream())
                        {
                            scpClient.Upload(stream, "/usr/share/asteroid-launcher/watchfaces/" + this.SelectedFile.Name);
                        }
                    }

                    scpClient.ErrorOccurred -= OnClientErrorOccured;
                }

                successfulUpload = true;
            }
            catch (Exception exception)
            {
                await this.DialogService.ShowError(exception, ResourcesHelper.GetLocalizedString("SharedErrorTitle"));
            }

            this.IsUploading = false;

            if (successfulUpload)
            {
                ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsWatchfaceWatchfaceInstalledMessage"));
            }

            //if (!successfulUpload)
            //{
            //    this.IsBusy = false;
            //    return;
            //}

            //var restartSystem = await this.DialogService.ShowMessage(
            //    message: "AsteroidOS may cache the current watchface. Do you want to restart device to refresh it?",
            //    title: "Watchface uploaded",
            //    buttonConfirmText: "Yes",
            //    buttonCancelText: "No",
            //    afterHideCallback: b => { });

            //if (!restartSystem)
            //{
            //    this.IsBusy = false;
            //    return;
            //}

            //try
            //{
            //    using (var sshClient = SecureConnectionsHelper.CreateSshClient(scpCredentialsDialog.HostIP, scpCredentialsDialog.Username, scpCredentialsDialog.Password))
            //    {
            //        sshClient.ErrorOccurred += OnClientErrorOccured;

            //        sshClient.RunCommand("systemctl restart user@1000");

            //        sshClient.ErrorOccurred -= OnClientErrorOccured;
            //    }
            //}
            //catch (Exception exception)
            //{
            //    await this.DialogService.ShowError(exception, "SSH Connection Error");
            //}

            this.IsBusy = false;
        }