Exemple #1
0
        async void ShowNotification(DisplayMessageData obj, DisplayMessageNotificationViewModel content)
        {
            if (_core.TryGetUiManager(out IUiManager ui))
            {
                ui.Notify(content);
                if (obj.AllowCloseAfter > 0)
                {
                    content.Closable = false;
                    var t = new Timer {
                        Interval = obj.AllowCloseAfter * 1000
                    };
                    t.Elapsed += (ooo, eee) =>
                    {
                        t.Stop();
                        t.Enabled = false;
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            content.Closable = true;
                        }));
                    };
                    t.Start();
                }
                if (obj.MaxDisplayTime != 0)
                {
                    var t = new Timer();
                    t.Interval = obj.MaxDisplayTime * 1000;
                    t.Elapsed += (ooo, eee) =>
                    {
                        t.Stop();
                        t.Enabled = false;
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            content.Close();
                        }));
                    };
                    t.Start();
                }
                await content.GetTask();

                ui.Refrain(content);
            }
        }
Exemple #2
0
        public Task EndInit()
        {
            Action <DisplayMessageModel> action = (obj) =>
            {
                if (_core.TryGetUiManager(out IUiManager ui))
                {
                    //ui.Unlock();
                }

                try
                {
                    if (_core.TryGetBilling(out IBillingManager billing))
                    {
                        var userServices = billing.GetActiveUserServices()
                                           .Select(p => p.Plugin)
                                           .Distinct()
                                           .ToList();
                        var serv = obj.Data.Services;
                        if (serv.Count > 0 && serv.All(billing.IsPluginFree))
                        {
                            return;
                        }

                        if (serv.Count >= 0 && _core.UserService.User.Id != null && serv.Any(s => userServices?.Contains(s) == true))
                        {
                            return;
                        }
                    }
                }
                catch
                {
                }

                Application.Current.Dispatcher.Invoke(async() =>
                {
                    switch (obj.Type)
                    {
                    case "notify":
                        var content = new DisplayMessageNotificationViewModel()
                        {
                            Data     = obj.Data,
                            Closable = true
                        };

                        ShowNotification(obj.Data, content);
                        break;

                    case "rtf":
                        var data = await _core.HttpClient.DownloadDataAsync(obj.Data.FileUrl);
                        try
                        {
                            var viewer = new RtfViewerViewModel()
                            {
                                Document = new System.Windows.Documents.FlowDocument()
                            };
                            using (var fStream = new MemoryStream(data))
                            {
                                var range =
                                    new TextRange(viewer.Document.ContentStart,
                                                  viewer.Document.ContentEnd);
                                range.Load(fStream, DataFormats.Rtf);
                                fStream.Close();
                            }
                            ShowMessage(obj.Data, viewer);
                        }
                        catch
                        {
                        }
                        break;

                    case "image":
                        var image = new ImageViewerViewModel()
                        {
                            ImageUrl = obj.Data.FileUrl
                        };
                        ShowMessage(obj.Data, image);
                        break;
                    }
                });
            };

            _core.WebSocket.On <DisplayMessageModel>("alert", (dyn) => action(dyn));
            return(Task.CompletedTask);
        }