Esempio n. 1
0
        private bool EventBusReceivedMessage(IMessageContainer arg)
        {
            // do things with the content


            return(true);
        }
Esempio n. 2
0
        private async void BaseMessageEvent(IMessageContainer arg)
        {
            SimpleStatusOverlays.ActivityOn();

            await Task.Run(() =>
            {
                if (this.CheckOptionAndLoadLandkreise(arg))
                {
                    return;
                }

                this._viewModel.ActualDataFromDate = StaticDataManager.ActualLoadedDataDate;

                this.Dispatcher.Invoke(() =>
                {
                    this._viewModel.Districts.Clear();
                });

                this._viewModel.CountyCount = 0;
                foreach (var item in StaticDataManager.ActualLoadedData)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        this._viewModel.Districts.Add(item);
                        this._viewModel.CountyCount++;
                    });
                }

                SimpleStatusOverlays.ActivityOff();
            });
        }
        public MainWindow(IMessageContainer groupChat, CacheSession cacheSession, IPluginUIIntegration uiIntegration, bool classicStyle)
        {
            this.InitializeComponent();

            this.GroupChat     = groupChat;
            this.CacheSession  = cacheSession;
            this.UIIntegration = uiIntegration;
            this.ClassicStyle  = classicStyle;

            this.MessagesWithAttachments =
                this.CacheSession.CacheForGroupOrChat
                .AsEnumerable()
                .Where(m => m.Attachments.Count > 0)
                .OrderByDescending(m => m.CreatedAtTime);

            this.HttpListener = new HttpListener();
            this.HttpListener.Prefixes.Add($"http://+:80/Temporary_Listen_Addresses/{this.ServerId}/");
            this.HttpListener.Start();

            this.CancellationTokenSource = new CancellationTokenSource();
            Task.Run(this.RunServer, this.CancellationTokenSource.Token);

            Debug.WriteLine($"http://+:80/Temporary_Listen_Addresses/{this.ServerId}/");

            this.ScriptingHelper = new ObjectForScriptingHelper(this);
            this.webBrowser.ObjectForScripting = this.ScriptingHelper;

            this.webBrowser.Navigate($"http://127.0.0.1:80/Temporary_Listen_Addresses/{this.ServerId}/gallery.html");

            this.Title = $"Image Gallery for {this.GroupChat.Name}";
        }
        private bool ReceiveUpdateCommand(IMessageContainer arg)
        {
            if (arg.Content is CommandMessage received && received.Equals(CommandMessage.Update))
            {
                var userItems = this._serviceConnector.GetAllUsers();

                foreach (var item in userItems)
                {
                    var user = this._viewModel.Users.FirstOrDefault(f => f.ID == item.ID);

                    if (user != null)
                    {
                        this._viewModel.Users.Remove(item);
                        this._viewModel.Users.Add(item);
                    }
                    else
                    {
                        this._viewModel.Users.Add(item);
                    }
                }

                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        private bool CheckOptionAndLoadLandkreise(IMessageContainer arg)
        {
            if (arg.Content is BaseMessageOptions option && option == BaseMessageOptions.LoadActualData)
            {
                var component = RkiCoronaLandkreiseComponent.GetInstance();
                component.RkiDataErrorEvent += this.Component_RkiDataErrorEvent;

                var landkreise = component.LoadData(out var safeData);

                if (safeData != null)
                {
                    SimpleStatusOverlays.ShowAsk("Question", "Overwrite local data with actual loaded data?", safeData);
                }

                if (landkreise == null)
                {
                    SimpleStatusOverlays.ActivityOff();
                    return(true);
                }

                // TODO aktuell wird nicht im jeden Datensatz das Datum hinterlegt.
                var districtItems = landkreise.Districts.Select(s => new DistrictItem
                {
                    Name          = s.Name,
                    Deaths        = s.Deaths,
                    WeekIncidence = s.WeekIncidence,
                    Date          = landkreise.Date
                });

                StaticDataManager.ActualLoadedDataDate = landkreise.Date;
                StaticDataManager.ActualLoadedData     = districtItems;
            }

            return(false);
        }
Esempio n. 6
0
 internal TransportPipe(int highWaterMark, HighWaterMarkBehavior highWaterMarkBehavior, IPEndPoint endPoint, SendingTransport transport, int sendingThreadNumber = 0)
 {
     _transport = transport;
     _highWaterMarkBehavior = highWaterMarkBehavior;
     EndPoint = endPoint;
     _highWaterMark = highWaterMark;
     MessageContainerConcurrentQueue = new MessageContainerConcurrentQueue(MaximumBatchCount, MaximumBatchSize);
     transport.AttachToIoThread(this, sendingThreadNumber);
 }
        private void BaseMessageEvent(IMessageContainer obj)
        {
            if (!(obj.Content is DataDialogContent dialogContent))
            {
                return;
            }

            this._viewModel.Header = dialogContent.Header;
        }
        public MainWindowViewModel(IMessageContainer messageContainer, CacheSession cacheSession)
        {
            this.MessageContainer = messageContainer;
            this.CacheSession     = cacheSession;

            var mostRecentGroupMessage  = this.CacheSession.GlobalCache.OrderByDescending(m => m.CreatedAtUnixTime).First();
            var mostRecentGlobalMessage = this.CacheSession.CacheForGroupOrChat.OrderByDescending(m => m.CreatedAtUnixTime).First();

            this.SomeGeneratedString = $"The most recent message in this group was {mostRecentGroupMessage.Text}. The most recent message in the cache from all groups is {mostRecentGlobalMessage.Text}";
        }
Esempio n. 9
0
 private void LogMessages(IMessageContainer messageContainer)
 {
     foreach (var message in messageContainer.Messages) {
     switch (message.Type) {
       case MessageType.Error: Log.LogError(message.ToString()); break; // TODO: other overload!
       case MessageType.Warning:Log.LogWarning(message.ToString()); break; // TODO: other overload!
       case MessageType.Info: Log.LogMessage(message.ToString()); break;
     }
       }
 }
Esempio n. 10
0
        private bool UpdateCommandMessageReceived(IMessageContainer arg)
        {
            if (arg.Content is ViewOpen command)
            {
                this._viewModel.ViewOpened = command;
                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        private bool UpdateCommandMessageReceived(IMessageContainer arg)
        {
            if (arg.Content is UserItem userItem)
            {
                this.Title = $"Mini Messenger - {userItem.Username}";
                return(true);
            }

            this.Title = $"Mini Messenger - ERROR";
            return(false);
        }
Esempio n. 12
0
 /// <summary>
 /// Subscribes to push notifications for a specific <see cref="IMessageContainer"/>.
 /// </summary>
 /// <param name="container">The container to receive notifications for.</param>
 /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
 public async Task SubscribeAsync(IMessageContainer container)
 {
     if (container is Group g)
     {
         await this.SubscribeGroupAsync(g);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine($"Subscribe not supported for name={container.Name}");
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Unsubscribes from push notifications for a specific <see cref="IMessageContainer"/>.
 /// </summary>
 /// <param name="container">The container to unsubscribe from receive notifications for.</param>
 public void Unsubscribe(IMessageContainer container)
 {
     if (container is Group g)
     {
         this.UnsubscribeGroup(g);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine($"Unsubscribe not supported for name={container.Name}");
     }
 }
Esempio n. 14
0
        public async Task ValidateAsync(IMessageContainer messageContainer)
        {
            if (messageContainer == null)
            {
                throw new ArgumentNullException(nameof(messageContainer));
            }

            var message = await this.GetBy(messageContainer);

            if (messageContainer.MessageId.HasValue && message == null)
            {
                throw new InvalidOperationException($"Message not found by id {messageContainer.MessageId}");
            }
        }
        /// <summary>
        /// Open new instance of a view. The view must setup the viewModel to the DataContext.
        /// </summary>
        /// <typeparam name="TView"></typeparam>
        public void OpenView <TView>(IMessageContainer message = null)
        {
            var t = typeof(TView);

            if (!this._messageContainers.ContainsKey(t))
            {
                this.OpenViewEvent?.Invoke((TView)Activator.CreateInstance(typeof(TView)));
            }

            if (message != null)
            {
                this.Send <TView, IMessageContainer>(message);
            }
        }
Esempio n. 16
0
        public Task Activated(IMessageContainer groupOrChat, CacheSession cacheSession, IPluginUIIntegration integration, Action <CacheSession> cleanup)
        {
            MainWindow mainWindow = new MainWindow(groupOrChat, cacheSession, integration, false);

            mainWindow.Closed += (s, e) =>
            {
                cleanup(cacheSession);
            };

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                mainWindow.Show();
            });

            return(Task.CompletedTask);
        }
        private bool EventBusReceivedMessage(IMessageContainer arg)
        {
            if (arg.Content is string path)
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(false);
                }

                this.ConvertImage(path);

                return(true);
            }

            return(false);
        }
        public MainWindowViewModel(IMessageContainer groupChat, CacheSession cacheSession, IPluginUIIntegration uIIntegration)
        {
            this.GroupChat     = groupChat;
            this.CacheSession  = cacheSession;
            this.UIIntegration = UIIntegration;

            var mostRecentGroupMessage  = this.CacheSession.CacheForGroupOrChat.OrderByDescending(m => m.CreatedAtUnixTime).First();
            var mostRecentGlobalMessage = this.CacheSession.GlobalCache.OrderByDescending(m => m.CreatedAtUnixTime).First();

            this.MaxNumWords           = 100;
            this.outputText            = "";
            this.phraseDictionary      = new Dictionary <GlobalUser, Dictionary <string, List <string> > >();
            this.phraseDictionaryLocal = new Dictionary <GlobalUser, Dictionary <string, List <string> > >();
            this.RegenerateOutput      = new RelayCommand(this.RegenerateChain);
            this.CopyOutput            = new RelayCommand(this.CopyOutputChain);
        }
        public Task Activated(IMessageContainer groupOrChat, CacheSession cacheSession, IPluginUIIntegration integration, Action <CacheSession> cleanup)
        {
            var mainWindow = new MainWindow(); // application entry point
            var vm         = new MainWindowViewModel(groupOrChat, cacheSession);

            mainWindow.DataContext = vm;

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                mainWindow.ShowDialog();
            });

            mainWindow.Closing += (s, e) =>
            {
                cleanup(cacheSession);
            };

            return(Task.CompletedTask);
        }
        public Task Activated(IMessageContainer groupOrChat, CacheSession cacheSession, IPluginUIIntegration integration, Action <CacheSession> cleanup)
        {
            var dataContext = new MainWindowViewModel(groupOrChat, cacheSession, integration);
            var window      = new MainWindow
            {
                DataContext = dataContext,
            };

            window.Closing += (s, e) =>
            {
                cleanup(cacheSession);
            };

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                window.Show();
            });

            return(Task.CompletedTask);
        }
Esempio n. 21
0
        private bool ReceiveUpdateCommand(IMessageContainer arg)
        {
            if (arg.Content is CommandMessage received && received.Equals(CommandMessage.Update))
            {
                var deviceItems = this._serviceConnector.DeviceGetAll();

                foreach (var item in deviceItems)
                {
                    var deviceItem = this._viewModel.Devices.FirstOrDefault(f => f.ID == item.ID);

                    if (deviceItem == null)
                    {
                        this._viewModel.Devices.Add(item);
                    }
                    else
                    {
                        this._viewModel.Devices.Remove(deviceItem);
                        this._viewModel.Devices.Add(item);
                    }
                }
            }

            return false;
        }
Esempio n. 22
0
 public MessageProcessor(IMessageContainer messageContainer)
 {
     _messageContainer = messageContainer;
 }
Esempio n. 23
0
        private bool LoadCommandReceived(IMessageContainer arg)
        {
            this._viewModel.UserItem = arg.Content as UserItem;

            return(false);
        }
Esempio n. 24
0
 public User(IMessageContainer messageContainer, IFollowedUsersContainer followedUsersContainer)
 {
     _messageContainer       = messageContainer;
     _followedUsersContainer = followedUsersContainer;
 }
Esempio n. 25
0
 public User()
 {
     _messageContainer       = new MessageContainer();
     _followedUsersContainer = new FollowedUsersContainer();
 }
Esempio n. 26
0
 /// <summary>
 /// Adds all the messages of a message container into another one.
 /// </summary>
 /// <param name="self">Extended instance. Will receive all messages from <paramref name="source"/>.</param>
 /// <param name="source">The message container to draw messages from.</param>
 public static void Slurp(this IMessageContainer self, IMessageContainer source)
 {
     if (self == null) throw new InstanceArgumentNullException();
       if (source == null) return;
       source.Messages.ForEach(message => self.AddMessage(message));
 }
Esempio n. 27
0
 private bool MessageEventHost_SendEvent(IMessageContainer message) => throw new NotImplementedException();
Esempio n. 28
0
 public void Send(IMessageContainer message) => this.SendEvent?.Invoke(message);
Esempio n. 29
0
        /// <summary>
        /// Uploads an image to GroupMe and returns the created <see cref="ImageAttachment"/>.
        /// </summary>
        /// <param name="image">The image to upload.</param>
        /// <param name="messageContainer">The <see cref="IMessageContainer"/> that the message is being sent to.</param>
        /// <param name="uploadProgress">A monitor that will receive progress updates for the image upload operation.</param>
        /// <returns>An <see cref="ImageAttachment"/> if uploaded successfully, null otherwise.</returns>
        public static async Task <ImageAttachment> CreateImageAttachment(byte[] image, IMessageContainer messageContainer, UploadProgress uploadProgress = null)
        {
            uploadProgress = uploadProgress ?? new UploadProgress();

            var cancellationTokenSource = new CancellationTokenSource();
            var restResponse            = await messageContainer.Client.ExecuteRestRequestAsync(
                GroupMeImageApiUrl,
                image,
                "image/jpeg",
                cancellationTokenSource.Token,
                uploadProgress);

            if (restResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var result = JsonConvert.DeserializeObject <ImageUploadResponse>(await restResponse.Content.ReadAsStringAsync());

                return(new ImageAttachment()
                {
                    Url = result.Payload.Url,
                });
            }
            else
            {
                return(null);
            }
        }
Esempio n. 30
0
 /// <summary>
 /// Toast notification constructor
 /// </summary>
 /// <param name="messageContainerFactory"></param>
 /// <param name="nToastNotifyOptions">Default toast notify options</param>
 public ToastNotification(IMessageContainerFactory messageContainerFactory, NToastNotifyOption nToastNotifyOptions)
 {
     _messageContainer           = messageContainerFactory.Create();
     _defaultNtoastNotifyOptions = nToastNotifyOptions.MergeWith(NToastNotifyOption.Defaults);
 }
 private void BaseMessageEvent(IMessageContainer arg)
 {
 }
Esempio n. 32
0
 protected ToastNotification(IMessageContainerFactory messageContainerFactory)
 {
     MessageContainer = messageContainerFactory.Create <TMessage>();
 }
Esempio n. 33
0
        private void PrepareMessage(InvocationTransaction transaction, IMessageContainer messageContainer)
        {
            var message = _binarySerializer.Serialize(transaction);

            messageContainer.RegisterMessage(message);
        }