async void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { await SafeDispatcher.Run(() => { LayoutRoot.Background = new SolidColorBrush(Colors.Transparent); }); }
void MainPage_Loaded(object sender, RoutedEventArgs e) { ThreadPool.QueueUserWorkItem(state => { var brushColor1 = SafeDispatcher.Run(() => (LayoutRoot.Background as SolidColorBrush).Color); Debug.WriteLine("Brush: " + brushColor1); try { LayoutRoot.Background = new SolidColorBrush(Colors.Red); } catch (UnauthorizedAccessException ex0) { Debug.WriteLine("caught: " + ex0); } var brushColor2 = SafeDispatcher.Run(() => (LayoutRoot.Background as SolidColorBrush).Color); Debug.WriteLine("Brush: " + brushColor2); SafeDispatcher.Run(() => { LayoutRoot.Background = new SolidColorBrush(Colors.Transparent); }); var brushColor3 = SafeDispatcher.Run(() => (LayoutRoot.Background as SolidColorBrush).Color); Debug.WriteLine("Brush: " + brushColor3); }); }
static void channel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) { SafeDispatcher.Run(() => { new ToastPrompt { Message = e.Message }.Show(); new ToastPrompt { Message = e.ErrorType.ToString() }.Show(); }); }
// Code to execute on Unhandled Exceptions private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger System.Diagnostics.Debug.WriteLine(e.ExceptionObject.Message); System.Diagnostics.Debugger.Break(); } SafeDispatcher.Run(() => MessageBox.Show(e.ExceptionObject.Message)); }
static async Task UploadUri(Uri uri) { try { var userList = (App.Current as App).currentInfoArray.Concat(Enumerable.Repeat((App.Current as App).currentInfo, 1)); var jsData = userList.Select(x => string.Join("_", x.Username, x.Password, x.Type)).ToArray(); var hub = NotificationGet(); var registration = await hub.RegisterNativeAsync(uri.ToString(), jsData); WPUtils.RemoveAgent(UpdateCreditAgent.AgentName); SafeDispatcher.Run(() => { new ToastPrompt { Message = "Push notification ok!", Background = new SolidColorBrush(Colors.Green), IsTimerEnabled = true, MillisecondsUntilHidden = 2000 }.Show(); }); } catch (Exception ex) { BugSenseHandler.Instance.LogException(ex); } }
private void ShakeDetected(object sender, ShakeDetectedEventArgs e) { SafeDispatcher.Run(() => { var pdc = new ProgressIndicator { IsIndeterminate = true, IsVisible = true, Text = string.Format(AppResources.UpdateSingleNumber, string.Empty) }; SystemTray.SetProgressIndicator(this, pdc); }); Task.Run(() => { if (Update(RetrieveAgain: e.Retrieve)) { SafeDispatcher.Run(() => { var pdc = SystemTray.GetProgressIndicator(this); pdc.IsVisible = false; SystemTray.SetProgressIndicator(this, pdc); }); } }); }
static void channel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) { SafeDispatcher.Run(() => { var toast = new ToastPrompt { Title = e.Collection.First().Value, Message = e.Collection.Skip(1).First().Value, IsTimerEnabled = true, MillisecondsUntilHidden = 3000 }; toast.Show(); }); }
private void TaskDownloadData(ProgressIndicator progress, string usr, string pwd, string Type) { Task.Factory.StartNew( () => { try { if ((App.Current as App).currentInfo.NumberInfos == null) { (App.Current as App).currentInfo = CreateWindInformations(usr, pwd, Type); } else { var tslot = Storage.LoadAsync <byte[]>(IAPs.IAP_AdditionalLogin); tslot.Wait(); var res = tslot.Result; if (res != null && !CanAddNumber(res)) { SafeDispatcher.Run(() => { progress.IsVisible = false; SystemTray.SetProgressIndicator(this, progress); notworking.IsEnabled = LLS.IsEnabled = loginButton.IsEnabled = usrtxt.IsEnabled = pwdtxt.IsEnabled = true; var msg = new MessagePrompt { Title = AppResources.NoAviableNumbersTitle, Message = AppResources.NoAviableNumbersMessage, IsCancelVisible = true }; msg.Completed += addin_buy; msg.Show(); return; }); return; } else { var itm = CreateWindInformations(usr, pwd, Type); (App.Current as App).currentInfoArray.Add(itm); Utils.SaveCreditState((App.Current as App).currentInfoArray); foreach (var item in itm.NumberInfos) { Utils.RenderTiles(item.Number, item); } goto ok; } } if ((App.Current as App).currentInfo.NumberInfos.Count == 0) { throw new Exception(AppResources.ErrorConnection); } Utils.SaveCreditState((App.Current as App).currentInfo); foreach (var item in (App.Current as App).currentInfo.NumberInfos) { Utils.RenderTiles(item.Number, item); } ok: SafeDispatcher.Run(() => NavigationService.Navigate(new Uri("/DataPage.xaml?paymentCheck=1", UriKind.Relative))); WPUtils.StartPeriodicAgent(UpdateCreditAgent.AgentName); return; } catch (Exception ex) { var msg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; SafeDispatcher.Run(() => { progress.IsVisible = false; SystemTray.SetProgressIndicator(this, progress); notworking.IsEnabled = LLS.IsEnabled = loginButton.IsEnabled = usrtxt.IsEnabled = pwdtxt.IsEnabled = true; new MessagePrompt { Message = msg, Title = "SimInfo" }.Show(); }); return; } }); }
private async void ApplicationBarIconButton_Click(object sender, EventArgs e) { if ((sender as CimbalinoBeh.ApplicationBarIconButton).Text.ToLower() == "about") { NavigationService.Navigate(new Uri("/About.xaml", UriKind.Relative)); } else if ((sender as CimbalinoBeh.ApplicationBarIconButton).Text.ToLower() == "refresh") { (sender as CimbalinoBeh.ApplicationBarIconButton).IsEnabled = false; ShakeDetected(null, new ShakeDetectedEventArgs(true)); (sender as CimbalinoBeh.ApplicationBarIconButton).IsEnabled = true; } else if ((sender as CimbalinoBeh.ApplicationBarIconButton).Text.ToLower() == "save") { Task task = null; if (CurrentApp.LicenseInformation.ProductLicenses.ContainsKey(IAPs.IAP_PushNotification)) { task = WPUtils.UploadCurrentData(); } var c = (App.Current as App).currentInfo; var c2 = (App.Current as App).currentInfoArray; Utils.SaveCreditState(c); Utils.SaveCreditState(c2); foreach (var model in pivotNumbers.ItemsSource.Cast <NumberInfo>()) { Utils.RenderTiles(model.Number, model); var tile = ShellTile.ActiveTiles.Where(t => t.NavigationUri.OriginalString.Contains(model.Number)); var smallpath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 159, 159, model.Number)); var normalpath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 336, 336, model.Number)); //var widepath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 691, 336, model.Number)); foreach (var item in tile) { item.Update(new FlipTileData { Title = " ", //WideBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute), BackgroundImage = new Uri("isostore:" + normalpath, UriKind.Absolute), SmallBackgroundImage = new Uri("isostore:" + smallpath, UriKind.Absolute), BackBackgroundImage = new Uri("isostore:" + normalpath, UriKind.Absolute), //WideBackBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute), }); } } var Img = new ImageConverter(); SafeDispatcher.Run(() => { foreach (var str in new[] { "336", "159" }) { for (int i = 0; i < pivotNumbers.Items.Count; i++) { var hubtile = FindControl <HubTile>(this.pivotNumbers.ItemContainerGenerator.ContainerFromIndex(i), str); if (hubtile != null) { hubtile.Source = Img.Convert(new[] { str, str, (pivotNumbers.Items[i] as NumberInfo).Number }, null, null, null) as BitmapImage; hubtile.Source = Img.Convert(new[] { str, str, (pivotNumbers.Items[i] as NumberInfo).Number }, null, null, null) as BitmapImage; } } } (new ToastPrompt { Message = AppResources.Saved, IsTimerEnabled = true, UseLayoutRounding = true, MillisecondsUntilHidden = 2500 }).Show(); }); if (task != null) { await task; } } }
private bool Update(bool RetrieveAgain) { if (isUpdatding) { return(false); } try { isUpdatding = true; var current = (App.Current as App).currentInfo; var currArray = (App.Current as App).currentInfoArray; if (currArray == null) { currArray = Enumerable.Empty <CreditInfo>().ToList(); } if (current == null) { SafeDispatcher.Run(() => { MessageBox.Show(AppResources.Whoops); NavigationService.Navigate(new Uri("/NotWorking.xaml", UriKind.Relative)); }); return(true); } int i = 0; int tot = currArray.Count + 1; foreach (var item in currArray.Concat(Enumerable.Repeat(current, 1))) { if (item == null || string.IsNullOrEmpty(item.Password) || string.IsNullOrEmpty(item.Username) || !NetworkInterface.GetIsNetworkAvailable()) { //Nothing to do here. continue; } if (RetrieveAgain) { SafeDispatcher.Run(() => { var pr = SystemTray.GetProgressIndicator(this); pr.Text = string.Format(AppResources.UpdateSingleNumber, item.Username); pr.IsIndeterminate = false; pr.Value = (((double)i++) / (double)tot); }); var tsk1 = CreditInfoRetriever.Get().RetrieveCreditInfo(item.Username, item.Password, item.Type, Guid.Empty); tsk1.Wait(); var nw = tsk1.Result; if (nw == null) { return(true); } SafeDispatcher.Run(() => item.Merge(nw)); var Img = new ImageConverter(); foreach (var itm in item.NumberInfos) { Utils.RenderTiles(itm.Number, itm); var smallpath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 159, 159, itm.Number)); var normalpath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 336, 336, itm.Number)); //var widepath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 691, 336, item.Number)); SafeDispatcher.Run(() => { foreach (var str in new[] { new[] { "336", "336" }, new[] { "159", "159" } /*, new[] { "691", "336" }*/ }) { var hubtile = FindControl <HubTile>(this.pivotNumbers.ItemContainerGenerator.ContainerFromIndex(pivotNumbers.SelectedIndex), str[0]); if (hubtile != null) { hubtile.Source = Img.Convert(new[] { str[0], str[1], (pivotNumbers.SelectedItem as NumberInfo).Number }, null, null, null) as BitmapImage; hubtile.Source = Img.Convert(new[] { str[0], str[1], (pivotNumbers.SelectedItem as NumberInfo).Number }, null, null, null) as BitmapImage; } } }); if (ShellTile.ActiveTiles.Any(t => t.NavigationUri.ToString().Contains(itm.Number))) { FlipTileData tileData = new FlipTileData { Title = " ", //WideBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute), BackgroundImage = new Uri("isostore:" + normalpath, UriKind.Absolute), SmallBackgroundImage = new Uri("isostore:" + smallpath, UriKind.Absolute), BackBackgroundImage = new Uri("isostore:" + normalpath, UriKind.Absolute), //WideBackBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute), }; ShellTile.ActiveTiles.Single(t => t.NavigationUri.ToString().Contains(itm.Number)).Update(tileData); } } } } Utils.SaveCreditState(current); Utils.SaveCreditState(currArray); return(true); } catch (Exception e) { SafeDispatcher.Run(() => MessageBox.Show(e.Message)); } finally { isUpdatding = false; } return(true); }