Exemplo n.º 1
0
 private async void INSTANCE_ChatChanged(ChatDBManager handler, ChatChangedEventArgs args)
 {
     if (!(args.CHAT is null) && string.Equals(args.CHAT.id, chatId))
     {
         await SharedUtils.CallDispatcherAsync(() => Chat = args.CHAT).ConfAwaitFalse();
     }
 }
 private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     lock (SyncRoot)
     {
         SharedUtils.CallDispatcherAsync(() => CollectionChanged?.Invoke(sender, e)).Wait();
     }
 }
Exemplo n.º 3
0
 private async void Client_NewChatMessage(XMPPClient client, NewChatMessageEventArgs args)
 {
     if (await VIEW_MODEL.OnNewChatMessage(args.getMessage(), btDeviceInfo_btdic.VIEW_MODEL.MODEL.Jid, client))
     {
         await SharedUtils.CallDispatcherAsync(() => UpdateViewState(State_6.Name));
     }
 }
 //--------------------------------------------------------Events:---------------------------------------------------------------------\\
 #region --Events--
 private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     lock (SyncRoot)
     {
         SharedUtils.CallDispatcherAsync(() => PropertyChanged?.Invoke(sender, e)).Wait();
     }
 }
 private async void Client_NewChatMessage(XMPPClient client, NewChatMessageEventArgs args)
 {
     if (await VIEW_MODEL.OnNewChatMessage(args.getMessage(), btDeviceInfo_btdic.VIEW_MODEL.MODEL.Jid, ConnectionHandler.INSTANCE.GetClient(client.getXMPPAccount().getBareJid()).client))
     {
         await SharedUtils.CallDispatcherAsync(() => UpdateViewState(State_6.Name));
     }
 }
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--


        #endregion

        #region --Misc Methods (Private)--


        #endregion

        #region --Misc Methods (Protected)--


        #endregion
        //--------------------------------------------------------Events:---------------------------------------------------------------------\\
        #region --Events--
        private async void QrCodeScannerControl_NewInvalidQrCode(QrCodeScannerControl sender, NewQrCodeEventArgs args)
        {
            await SharedUtils.CallDispatcherAsync(async() =>
            {
                invalidQrCode_grid.Visibility = Visibility.Visible;
                validQrCode_grid.Visibility   = Visibility.Collapsed;
                await Task.Delay(5000);
                invalidQrCode_grid.Visibility = Visibility.Collapsed;
            });
        }
Exemplo n.º 7
0
 protected async override void OnPropertyChanged(PropertyChangedEventArgs e)
 {
     if (INVOKE_IN_UI_THREAD)
     {
         await SharedUtils.CallDispatcherAsync(() => base.OnPropertyChanged(e));
     }
     else
     {
         base.OnPropertyChanged(e);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Converts the path to an BitmapImage.
        /// This is a workaround to open also images that are stored on a separate drive.
        /// </summary>
        /// <param name="imgModel">The actual image the <paramref name="path"/> corresponds to.</param>
        /// <param name="path">The absolute path to the image.</param>
        /// <returns>The BitmapImage representation of the current path object.</returns>
        private async Task <BitmapImage> GetBitmapImageAsync(ChatMessageImageModel imgModel, string path)
        {
            if (path is null)
            {
                return(null);
            }

            try
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);

                if (file is null)
                {
                    return(null);
                }

                BitmapImage img = null;
                // Bitmap stuff has to be done in the UI thread,
                // so make sure we execute it there:
                Exception ex = null;
                await SharedUtils.CallDispatcherAsync(async() =>
                {
                    try
                    {
                        img = new BitmapImage();
                        img.SetSource(await file.OpenReadAsync());
                    }
                    catch (Exception e)
                    {
                        ex = e;
                    }
                });

                // If loading the image failed log the exception:
                if (!(ex is null))
                {
                    Logger.Error("Failed to load image: " + path, ex);
                    MODEL.ErrorText = "Failed to load image. Try downloading it again.";
                    imgModel.state  = DownloadState.ERROR;
                    imgModel.Update();
                    return(null);
                }

                return(img);
            }
            catch (Exception e)
            {
                Logger.Error("Failed to load image: " + path, e);
                MODEL.ErrorText = "Failed to load image. Try downloading it again.";
                imgModel.state  = DownloadState.ERROR;
                imgModel.Update();
                return(null);
            }
        }
Exemplo n.º 9
0
 private async void INSTANCE_MUCInfoChanged(MUCDBManager handler, MUCInfoChangedEventArgs args)
 {
     if (!(args.MUC_INFO is null) && string.Equals(args.MUC_INFO.chatId, chatId))
     {
         await SharedUtils.CallDispatcherAsync(() =>
         {
             // Force update property:
             MucInfo = null;
             MucInfo = args.MUC_INFO;
         }).ConfAwaitFalse();
     }
 }
 private async void QrCodeScannerControl_NewValidQrCode(QrCodeScannerControl sender, NewQrCodeEventArgs args)
 {
     VIEW_MODEL.OnValidQrCode(args.QR_CODE);
     await SharedUtils.CallDispatcherAsync(async() =>
     {
         IsSecondaryButtonEnabled      = false;
         invalidQrCode_grid.Visibility = Visibility.Collapsed;
         validQrCode_grid.Visibility   = Visibility.Visible;
         await Task.Delay(1500);
         Hide();
     });
 }
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public void UpdateView(string obfuscatedId)
        {
            Task.Run(async() =>
            {
                // Ensure no updates are run in parallel:
                await LOADING_SEMA.WaitAsync();
                if (MODEL.IsLoading)
                {
                    LOADING_SEMA.Release();
                    return;
                }
                MODEL.IsLoading = true;
                LOADING_SEMA.Release();

                if (string.IsNullOrEmpty(obfuscatedId))
                {
                    MODEL.Image = null;
                }
                else
                {
                    User user = await UserManager.INSTANCE.UpdateUserAsync(Vault.LoadCredentials(Storage.Classes.Settings.GetSettingString(SettingsConsts.TUM_ID)), obfuscatedId, false).ConfAwaitFalse();
                    try
                    {
                        SoftwareBitmap img = null;
                        if (!(user.Image is null) && user.Image.Length > 0)
                        {
                            img = await ImageUtils.ToSoftwareBitmapImageAsync(user.Image);
                        }
                        if (!(img is null))
                        {
                            await SharedUtils.CallDispatcherAsync(async() =>
                            {
                                try
                                {
                                    MODEL.Image = new SoftwareBitmapSource();
                                    await MODEL.Image.SetBitmapAsync(img);
                                }
                                catch (Exception e)
                                {
                                    Logger.Error("Failed to set TUMonlie user image as SoftwareBitmapSource.", e);
                                }
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Failed to load TUMonline user image from bytes.", e);
                    }
                }
                MODEL.IsLoading = false;
            });
        }
        private async void QrCodeScannerControl_NewValidQrCode(QrCodeScannerControl sender, NewQrCodeEventArgs args)
        {
            IUriAction action = UriUtils.parse(new Uri(args.QR_CODE));

            if (action is RegisterIoTUriAction registerIoTUriAction)
            {
                await SharedUtils.CallDispatcherAsync(async() =>
                {
                    await qrCodeScanner.StopAsync();

                    UpdateViewState(State_2.Name);
                    VIEW_MODEL.MODEL.RegisterIoTUriAction = registerIoTUriAction;
                });
            }
        }
Exemplo n.º 13
0
 private void LoadMembers(ChatDataTemplate chat)
 {
     Task.Run(async() =>
     {
         MODEL.IsLoading = true;
         MODEL.MEMBERS.Clear();
         MODEL.MEMBERS.AddRange(chat.Chat.muc.occupants.Select((x) => new MucMemberDataTemplate()
         {
             Member = x, Chat = chat
         }));
         MODEL.MembersFound = chat.Chat.muc.occupants.Count > 0;
         await SharedUtils.CallDispatcherAsync(() => MODEL.MEMBERS_SORTED.Source = MODEL.MEMBERS);
         MODEL.HeaderText = "Members (" + chat.Chat.muc.occupants.Count + ')';
         MODEL.IsLoading  = false;
     });
 }
Exemplo n.º 14
0
 private void LoadMembers(ChatDataTemplate chat)
 {
     Task.Run(async() =>
     {
         MODEL.IsLoading = true;
         List <MUCOccupantTable> members = MUCDBManager.INSTANCE.getAllMUCMembers(chat.Chat.id);
         MODEL.MEMBERS.Clear();
         MODEL.MEMBERS.AddRange(members.Select((x) => new MucMemberDataTemplate()
         {
             Member = x, Chat = chat
         }));
         MODEL.MembersFound = members.Count > 0;
         await SharedUtils.CallDispatcherAsync(() => MODEL.MEMBERS_SORTED.Source = MODEL.MEMBERS);
         MODEL.HeaderText = "Members (" + members.Count + ')';
         MODEL.IsLoading  = false;
     });
 }
Exemplo n.º 15
0
 public async void UpdateViewClient(XMPPClient client)
 {
     if (!(client is null))
     {
         // Account color:
         await SharedUtils.CallDispatcherAsync(() =>
         {
             if (UiUtils.IsHexColor(client.getXMPPAccount().color))
             {
                 AccountColorBrush         = UiUtils.HexStringToBrush(client.getXMPPAccount().color);
                 AccountColorBrush.Opacity = 0.9;
             }
             else
             {
                 AccountColorBrush = new SolidColorBrush(Colors.Transparent);
             }
         });
     }
 }
Exemplo n.º 16
0
        private async Task TrackErrorInTaskAsync(Exception ex, string descriptionMd, Dictionary <string, string> payload)
        {
            TrackErrorEventArgs args = new TrackErrorEventArgs(ex, descriptionMd, payload);
            Func <AppCenterCrashHelper, TrackErrorEventArgs, Task> handler = OnTrackError;

            if (!(handler is null))
            {
                Delegate[]    invocationList = handler.GetInvocationList();
                Task[]        handlerTasks   = new Task[invocationList.Length];
                SemaphoreSlim sema           = new SemaphoreSlim(0);

                // Call them in the UI thread to ensure we await everything:
                await SharedUtils.CallDispatcherAsync(() =>
                {
                    for (int i = 0; i < invocationList.Length; i++)
                    {
                        handlerTasks[i] = ((Func <AppCenterCrashHelper, TrackErrorEventArgs, Task>)invocationList[i])(this, args);
                    }
                    sema.Release();
                });

                await sema.WaitAsync();

                await Task.WhenAll(handlerTasks);
            }

            if (!args.Cancel)
            {
                if (Crashes.Instance.InstanceEnabled)
                {
                    Crashes.TrackError(ex);
                    Logger.Info("Crash has been reported.");
                }
                else
                {
                    Logger.Warn("Crash has not been reported. Crash reporting disabled!");
                }
            }
            else
            {
                Logger.Warn("Crash has not been reported. User declined!");
            }
        }
Exemplo n.º 17
0
 private void LoadEmoji(AdvancedCollectionView target, SortedSet <SingleEmoji>[] sources)
 {
     Task.Run(async() =>
     {
         IsLoading = true;
         if (target.Source.Count <= 0)
         {
             SortedSet <SingleEmoji> result = sources[0];
             for (int i = 1; i < sources.Length; i++)
             {
                 result.Union(sources[i]);
             }
             List <SingleEmoji> emoji = result.Where((x) => x.HasGlyph).ToList();
             await SharedUtils.CallDispatcherAsync(() => target.Source = emoji);
         }
         target.RefreshFilter();
         SelectedList = target;
         IsLoading    = false;
     });
 }
Exemplo n.º 18
0
        private void GenQrCode()
        {
            if (curQrCodeText is null)
            {
                QrCodeImage = null;
            }
            else
            {
                IsLoading = true;
                Color c = GetQrCodeBackgroundColor();
                Task.Run(async() =>
                {
                    QRCodeData qRCodeData = QR_CODE_GENERATOR.CreateQrCode(curQrCodeText, QRCodeGenerator.ECCLevel.Q);
                    PngByteQRCode qRCode  = new PngByteQRCode(qRCodeData);
                    byte[] qRCodeGraphic;
                    if (DefaultQrCode)
                    {
                        qRCodeGraphic = qRCode.GetGraphic(10);
                    }
                    else
                    {
                        qRCodeGraphic = qRCode.GetGraphic(10, new byte[] { (byte)~c.R, (byte)~c.G, (byte)~c.B }, new byte[] { c.R, c.G, c.B });
                    }

                    await SharedUtils.CallDispatcherAsync(async() =>
                    {
                        using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                        {
                            using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0)))
                            {
                                writer.WriteBytes(qRCodeGraphic);
                                await writer.StoreAsync();
                            }
                            QrCodeImage = new BitmapImage();
                            await QrCodeImage.SetSourceAsync(stream);
                        }
                        IsLoading = false;
                    });
                });
            }
        }
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--


        #endregion

        #region --Misc Methods (Private)--
        private async Task ShowRestartDialogAsync()
        {
            await SharedUtils.CallDispatcherAsync(() =>
            {
            });
        }
 //--------------------------------------------------------Events:---------------------------------------------------------------------\\
 #region --Events--
 private async void SPLASH_SCREEN_Dismissed(SplashScreen sender, object args)
 {
     await SharedUtils.CallDispatcherAsync(async() => await LoadAppAsync());
 }
Exemplo n.º 21
0
 private async Task ShowCellVoltagesAsync()
 {
     byte[] data = OnewheelConnectionHelper.INSTANCE.CACHE.GetBytes(OnewheelCharacteristicsCache.CHARACTERISTIC_BATTERY_CELL_VOLTAGES);
     await SharedUtils.CallDispatcherAsync(() => batteryCellVoltages_bcvc.SetVoltages(data));
 }
Exemplo n.º 22
0
 private async Task ShowFirmwareRevisionAsync()
 {
     uint fw = OnewheelConnectionHelper.INSTANCE.CACHE.GetUint(OnewheelCharacteristicsCache.CHARACTERISTIC_FIRMWARE_REVISION);
     await SharedUtils.CallDispatcherAsync(() => firmware_tbx.Text = fw.ToString());
 }