예제 #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;
        }
예제 #2
0
        private async void Export()
        {
            var result = await this.ApplicationsService.ExportDataAsync();

            if (result)
            {
                ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsApplicationsDataExportedMessage"));
            }
        }
예제 #3
0
        private static async void OnScreenshotContentCharacteristicValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            var bytes = new byte[args.CharacteristicValue.Length];

            DataReader.FromBuffer(args.CharacteristicValue).ReadBytes(bytes);

            if (!TotalSize.HasValue)
            {
                var size = BitConverter.ToInt32(bytes, 0);
                TotalData = new byte[size];
                TotalSize = size;
                Progress  = 0;
                return;
            }

            if (Progress.Value + bytes.Length <= TotalData.Length)
            {
                Array.Copy(bytes, 0, TotalData, Progress.Value, bytes.Length);
            }

            Progress += bytes.Length;

            if (Progress.Value < TotalSize.Value)
            {
                var percentage = (int)Math.Ceiling((Progress.Value * 100d) / TotalSize.Value);
                Messenger.Default.Send(new Messages.ScreenshotProgressMessage(percentage));
                return;
            }

            var screenshotsFolder = await FilesHelper.GetScreenshotsFolderAsync();

            var fileName = $"{Package.Current.DisplayName}_Screenshot_{DateTime.Now.ToString("yyyyMMdd")}_{DateTime.Now.ToString("HHmmss")}.jpg";

            var screenshotFile = await screenshotsFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteBytesAsync(screenshotFile, TotalData);

            ToastsHelper.Show(string.Format(ResourcesHelper.GetLocalizedString("ScreenshotAcquiredMessageFormat"), fileName));

            sender.ValueChanged -= OnScreenshotContentCharacteristicValueChanged;

            TotalSize = null;
            TotalData = null;
            Progress  = null;

            Messenger.Default.Send(new Messages.ScreenshotAcquiredMessage(fileName));
        }
예제 #4
0
        private async void Import()
        {
            try
            {
                var importedIconPreferences = await this.ApplicationsService.ImportDataAsync();

                if (importedIconPreferences.IsNullOrEmpty())
                {
                    return;
                }

                var overWriteExistingApplicationPreferences = false;
                if (importedIconPreferences.Any(ap => this.IconPreferences.Any(i => i.Id == ap.AppId)))
                {
                    overWriteExistingApplicationPreferences = await this.DialogService.ShowConfirmMessage(
                        ResourcesHelper.GetLocalizedString("SettingsApplicationsImportFoundConflictMessage"),
                        ResourcesHelper.GetLocalizedString("SettingsApplicationsImportFoundConflictTitle"));
                }

                foreach (var importedIconPreference in importedIconPreferences)
                {
                    var iconPreferenceExists = this.IconPreferences.Any(i => i.Id == importedIconPreference.AppId);
                    if (iconPreferenceExists && !overWriteExistingApplicationPreferences)
                    {
                        continue;
                    }

                    this.ApplicationsService.UpsertUserIcon(importedIconPreference);
                }

                ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsApplicationsDataImportedMessage"));

                this.RefreshIconsPreferences();
            }
            catch (Exception exception)
            {
                Microsoft.HockeyApp.HockeyClient.Current.TrackException(exception);

                await this.DialogService.ShowError(exception.Message, ResourcesHelper.GetLocalizedString("SharedErrorTitle"));
            }
        }
        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;
        }