public static async void NotifySuccess(ulong bytesTransferred, string fileName) { try { // check to see if app has focus. If so, pop a dialog. If not, pop a toast if (GlobalNonPersistentState.IsCurrentlyActiveApp) { var dlg = new MessageDialog(string.Format("Transfer complete. Bytes transferred {0:N0}", bytesTransferred), "Transfer Complete"); await dlg.ShowAsync(); // App is in foreground, and the transfer was successful. Let's ask the user for a rating, // but only if they haven't previously rated the app, and we haven't already asked them during // this app usage session if (!Statistics.UserHasRatedApp && !_alreadyPromptedForRatingThisSession) { ShowRatingReviewDialog(); } } else { ToastContent toastContent = GenerateSuccessToastContent(bytesTransferred, fileName); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastContent.GetXml())); } } catch { // don't bomb out on a notification problem Analytics.LogEvent(AnalyticsEvent.NotificationSuccessError); } }
// code based on this: https://docs.microsoft.com/en-us/windows/uwp/monetize/request-ratings-and-reviews private async static void ShowRatingReviewDialog() { try { _alreadyPromptedForRatingThisSession = true; StoreSendRequestResult result = await StoreRequestHelper.SendRequestAsync( StoreContext.GetDefault(), 16, String.Empty); if (result.ExtendedError == null) { JObject jsonObject = JObject.Parse(result.Response); if (jsonObject.SelectToken("status").ToString() == "success") { // The customer rated or reviewed the app. Statistics.UserHasRatedApp = true; } else if (jsonObject.SelectToken("status").ToString() == "aborted") { // The customer chose not to rate the app Statistics.UserHasRatedApp = false; } } else { // There was an error rating the app } } catch { // don't crash app due to failure with rating / review Analytics.LogEvent(AnalyticsEvent.RatingReviewError); } }
protected static void WriteValue <T>(string key, T value) { try { ApplicationData.Current.RoamingSettings.Values[key] = value; } catch { Analytics.LogEvent(AnalyticsEvent.SettingsWriteError); } }
private void Cancel_Click(object sender, RoutedEventArgs e) { try { // Stop any in-process transfer _transferOperation.Cancel(); Cancel.IsEnabled = false; } catch { // don't bomb out on a cancel op Analytics.LogEvent(AnalyticsEvent.TransferCancelError); } }
public static async void NotifyError(ulong bytesTransferred, string fileName) { try { // check to see if app has focus. If so, pop a dialog. If not, pop a toast if (GlobalNonPersistentState.IsCurrentlyActiveApp) { var dlg = new MessageDialog(string.Format("Transfer Error. Bytes transferred {0:N0}", bytesTransferred), "Transfer Error"); await dlg.ShowAsync(); } else { ToastContent toastContent = GenerateSuccessToastContent(bytesTransferred, fileName); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastContent.GetXml())); } } catch { Analytics.LogEvent(AnalyticsEvent.NotificationErrorError); } }
protected static T GetValueOrDefault <T>(string key, T defaultValue) { try { if (ApplicationData.Current.RoamingSettings.Values.Keys.Contains(key)) { return((T)ApplicationData.Current.RoamingSettings.Values[key]); } else { WriteValue(key, defaultValue); return(defaultValue); } } catch { Analytics.LogEvent(AnalyticsEvent.SettingsReadError); return(defaultValue); } }
private async void SendSysExFile_Click(object sender, RoutedEventArgs e) { CloseAllTips(); // validate the user-entered parameters uint transferDelayBetweenBuffers = 0; if ((!uint.TryParse(EnteredTransferDelay.Text, out transferDelayBetweenBuffers)) || transferDelayBetweenBuffers < 0) { var dlg = new MessageDialog("For the send delay, please enter a positive whole number. This is the delay between buffers sent over MIDI."); await dlg.ShowAsync(); return; } // validate, open the port, and then send the file if (_inputFile != null) { if (_outputPortDeviceInformation != null) { // open the MIDI port var outputPort = await MidiOutPort.FromIdAsync(_outputPortDeviceInformation.Id); if (outputPort != null) { // open the file var stream = await _inputFile.OpenReadAsync(); if (stream != null && stream.CanRead) { // validate the file var validationStatus = await MidiSysExSender.MeasureAndValidateSysExFile(stream); if (validationStatus.Status != MidiSysExSender.MidiSysExFileValidationStatus.OK) { // TODO: log failure var dlg = new MessageDialog(validationStatus.GetStatusDescription()); dlg.Title = "Invalid SysEx file"; await dlg.ShowAsync(); return; } // Show statistics from the file FileInformationPanel.Visibility = Visibility.Visible; CalculatedBufferSize.Text = string.Format("{0:n0}", validationStatus.BufferSize); CalculatedSysExMessageCount.Text = string.Format("{0:n0}", validationStatus.MessageCount); CalculatedFileSize.Text = string.Format("{0:n0}", validationStatus.FileSize); // send the bytes _transferOperation = MidiSysExSender.SendSysExStreamAsyncWithProgress( stream, outputPort, validationStatus.BufferSize, transferDelayBetweenBuffers); // show progress of the operation. This is updated async ProgressPanel.Visibility = Visibility.Visible; Cancel.IsEnabled = true; //report progress _transferOperation.Progress = (result, progress) => { SysExSendProgressBar.Value = (double)progress.BytesRead; ProgressBytes.Text = string.Format("{0:n0}", progress.BytesRead); PercentComplete.Text = Math.Round(((double)progress.BytesRead / _fileSizeInBytes) * 100, 0) + "%"; TransferOperationInProgress.Text = MidiSysExSender.GetStageDescription(progress.Stage); }; // handle completion _transferOperation.Completed = async(result, progress) => { // no need for cancel anymore Cancel.IsEnabled = false; // nuke the stream stream.Dispose(); stream = null; // close the MIDI port outputPort = null; // show completion message, depending on what type of completion we have if (result.Status == AsyncStatus.Canceled) { TransferOperationInProgress.Text = "Canceled"; Statistics.TotalCancelCount += 1; Analytics.LogEvent(AnalyticsEvent.TransferCancel); var dlg = new MessageDialog("Transfer canceled."); await dlg.ShowAsync(); } else if (result.Status == AsyncStatus.Error) { TransferOperationInProgress.Text = "Error"; Statistics.TotalErrorCount += 1; Analytics.LogEvent(AnalyticsEvent.TransferError); var dlg = new MessageDialog("Transfer error. You may need to close and re-open this app, and likely also reboot your device."); await dlg.ShowAsync(); } else { SysExSendProgressBar.Value = (double)_fileSizeInBytes; ProgressBytes.Text = string.Format("{0:N0}", _fileSizeInBytes); PercentComplete.Text = "100%"; TransferOperationInProgress.Text = "Completed"; // save the user-entered settings, since they worked //Settings.TransferBufferSize = transferBufferSize; Settings.TransferDelayBetweenBuffers = transferDelayBetweenBuffers; //Settings.F0Delay = f0Delay; // update user stats (for local use and display) Statistics.TotalFilesTransferred += 1; Statistics.TotalBytesTransferred += _fileSizeInBytes; Analytics.LogEvent(AnalyticsEvent.TransferSuccess); NotificationManager.NotifySuccess(_fileSizeInBytes, _inputFile.Name); } }; } else { // TODO: log failure // stream is null or CanRead is false var dlg = new MessageDialog("Could not open file '" + _inputFile.Name + "' for reading."); await dlg.ShowAsync(); } } else { // TODO: log failure // outputPort is null var dlg = new MessageDialog("Could not open MIDI output port '" + _outputPortDeviceInformation.Name + "'"); await dlg.ShowAsync(); } } else { // TODO: log failure // _outputPortDeviceInformation is null var dlg = new MessageDialog("No MIDI output port selected'"); await dlg.ShowAsync(); } } else { // TODO: log failure // _inputFile is null var dlg = new MessageDialog("No SysEx input file selected'"); await dlg.ShowAsync(); } }