private static void UploadWorker()
        {
            Debug.WriteLine("Upload master worker is online.");
            Conf.Log("upload worker activated.", LogLevel.Complete);
            while (Conf.CurrentConf.EnableForwarding)
            {
                if (UnsentNotificationPool.Count == 0)
                {
                    goto Skip;
                }
                Debug.WriteLine("Starting data upload...");
                var sessionId          = Conf.GetRandomString(10);
                var pending            = new ClientData();
                int processedEndPoints = 0;
                lock (UnsentNotificationPool)
                {
                    Conf.Log($"[{sessionId}] starting forwarding {UnsentNotificationPool.Count} notification(s)...");
                    pending.Notifications.AddRange(UnsentNotificationPool);
                    UnsentNotificationPool.Clear();
                }
                foreach (var endPoint in Conf.CurrentConf.ApiEndPoints2)
                {
                    Debug.WriteLine($"Sending data to {endPoint}");
                    Conf.Log($"[{sessionId}] preparing to send data to {endPoint}...");
                    ClientData.Send(endPoint, pending, sessionId);
                    processedEndPoints++;
                }
                Conf.Log($"[{sessionId}] all uploads started, {processedEndPoints} endpoint(s) to go.", LogLevel.Complete);
Skip:
                Thread.Sleep(1000);
            }
            Debug.WriteLine("Upload master worker is offline.");
            Conf.Log("upload worker exited.");
        }
Exemple #2
0
        private async void NotificationHandler(object sender, UserNotificationChangedEventArgs e)
        {
            if (!IsListenerActive)
            {
                return;
            }
            if (e.ChangeKind != UserNotificationChangedKind.Added)
            {
                return;
            }
            try
            {
                var notifs = await Listener.GetNotificationsAsync(NotificationKinds.Toast);

                var newlyAdded = notifs.Except(Notifications, new NotificationComparer()).ToList();
                Conf.Log($"received {newlyAdded.Count} notification(s) from listener");
                NewNotificationPool.AddRange(newlyAdded);
                Notifications.AddRange(newlyAdded);
                foreach (var item in newlyAdded)
                {
                    Conf.CurrentConf.AddApp(new AppInfo(item.AppInfo)
                    {
                        ForwardingEnabled = !Conf.CurrentConf.MuteNewApps
                    });
                    var appIndex = Conf.CurrentConf.FindAppIndex(new AppInfo(item.AppInfo));
                    if (appIndex == -1 && !Conf.CurrentConf.MuteNewApps)
                    {
                        continue;
                    }
                    if (!Conf.CurrentConf.AppsToForward[appIndex].ForwardingEnabled)
                    {
                        continue;
                    }
                    Conf.Log($"marked notification #{item.Id} as pending, app: {item.AppInfo.AppUserModelId}");
                    UnsentNotificationPool.Add(new Protocol.Notification(item));
                }
                Conf.CurrentConf.NotificationsReceived += newlyAdded.Count;
            }
            catch (Exception ex)
            {
                Conf.Log($"notification listener failed: {ex.Message}, HRESULT {ex.HResult:x}", LogLevel.Error);
                if (ex.HResult == -2147024891)
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await NoPermissionDialog(); });
                }
            }
        }