Ejemplo n.º 1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SurfaceWindow1()
        {
            InitializeComponent();

            // Add handlers for window availability events
            AddWindowAvailabilityHandlers();

            canvasController = new CanvasController(MainCanvas, (int)MainWindow.Width, (int)MainWindow.Height, DebugText);

            IdeaInput.Visibility = System.Windows.Visibility.Hidden;
            IdeaInput.KeyUp     += new KeyEventHandler(IdeaInput_KeyUp);

            messageHub.Subscribe <NewIdeaEvent>((m) =>
            {
                Debug.WriteLine("Received");
                toggleTextBoxHide();
            }
                                                );

            messageHub.Subscribe <DismissTextboxEvent>((m) =>
            {
                Debug.WriteLine("Dismiss textbox");
                IdeaInput.Visibility = Visibility.Hidden;
            }
                                                       );
        }
Ejemplo n.º 2
0
        private void subscribe()
        {
            _msgr.Subscribe <IDoSomethingOuter>(onDoSomethingOuter);                 //request comes in from outer
            //_msgr.Subscribe<IDoSomethingInner>(onDoSomethingInner); //processes
            _msgr.Subscribe <IDoSomethingInnerResponse>(onDoSomethingInnerResponse); //returns

            //_msgr.Subscribe<IDoSomethingOuterResponse>(onDoSomethingOuterResponse);//passed to outer
            _msgr.Subscribe <IDoSomethingOuterResponseReceived>(onDoSomethingOuterResponseReceived);//verify response
        }
Ejemplo n.º 3
0
        public void init(ColorModel colorModel, HardwareModel hardwareModel, TinyMessengerHub messageHub)
        {
            this.colorModel    = colorModel;
            this.hardwareModel = hardwareModel;
            this.messageHub    = messageHub;

            messageHub.Subscribe <ColorModelMessage>((m) => colorModelUpdated(m.Content));
            messageHub.Subscribe <HardwareModelMessage>((m) => { this.Invoke(new MethodInvoker(hardwareModelUpdated)); });
            messageHub.Subscribe <SettingsModelMessage>((m) => { this.Invoke(new MethodInvoker(settingsModelUpdated)); });
        }
Ejemplo n.º 4
0
        public FavoritesViewModel()
        {
            _hub = DependencyService.Resolve <TinyMessengerHub>();
            _hub.Subscribe <LoggedInMessage>(OnLoggedIn);
            _hub.Subscribe <LoggedOutMessage>(OnLoggedOut);

            _client = DependencyService.Resolve <IJSONWebClient>();
            FetchPapers();

            PaperSelectedCommand = new Command <Paper>(PaperSelected);
            RefreshCommand       = new Command(FetchPapers);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new Scenegraph View Model
        /// </summary>
        public ScenegraphViewModel(TinyMessengerHub messenger)
        {
            SelectItemViewModelChangedCommand = new RelayCommand <EntityViewModel>(c => SelectedItem = c);
            RemoveItemCommand             = new RelayCommand <EntityViewModel>(RemoveItem);
            MoveItemCommand               = new RelayCommand <EntityViewModel>(MoveTo);
            SelectRawEntityChangedCommand = new RelayCommand <Entity>(SetRawEntityAsSelectedItem);
            Messenger = messenger;
            Messenger.Subscribe <ScenegraphChanged>(OnScenegraphChanged);
            Messenger.Subscribe <InvalidateEntity>(OnInvalidateEntitiesMessage);
            //MessengerInstance.Register<ProjectActivated>(this, ProjectChanged);
            //MessengerInstance.Register<InvalidateEntities>(this, OnInvalidateEntitiesMessage);
            //MessengerInstance.Register<ProjectActivated>(this, OnProjectActivated);

            Items = new ObservableCollection <ISceneNode>();
            lastNotifyProxyProperty = DateTime.Now;
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var messageBus        = new TinyMessengerHub();
            var repositoryFactory = new RepositoryFactory(messageBus);

            Settings.GitPath = @"C:\Program Files\git\bin\git.exe";

            messageBus.Subscribe <GenericTinyMessage <Exception> >(m => Console.WriteLine("Wyjatek: {0}", m.Content.Message));
            messageBus.Subscribe <GenericTinyMessage <string> >(m => Console.WriteLine("Sukcess: {0}", m.Content));

            RepositoryBase repository = repositoryFactory.Create(RepositoryType.Git, @"D:\programowanie\project\code_kats\LCD_Kat");

            repository.Update();

            Console.ReadLine();
        }
Ejemplo n.º 7
0
 private void subscribe()
 {
     _msgr.Subscribe <IDoSomethingOuterResponse>(msg =>
     {
         Console.WriteLine("Outer:DoSomethingOuterResponse");
         Action <object> callback = _callbacks[msg.SessionUid];
         callback(msg);
     });
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            messenger.Subscribe <MyMessage>(m => { Console.WriteLine("recieved"); });
            messenger.Publish(new MyMessage());
            Console.WriteLine("Hello World!");
            Timer t = new Timer(TimerCallback, null, 0, 2000);

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        private Global()
        {
            MessageHub = new TinyMessengerHub();

            Texts = new ResXResourceSet(@".\Resources\Texts.resx");

            MessageHub.Subscribe<UserBoatsRetrieved>((m) => {
                UserBoats = m.Content;
#if DEBUG                
                MessageHub.PublishAsync(new LogMessage(this, new LogText(Texts.GetString("UserBoatsRetrieved"))));
#endif
            });

            MessageHub.Subscribe<SelectedBoatRefreshed>((m) => {
                Boat = m.Content;
                Boat.FixTime = DateTime.Now;
                if(Boat.FixQuality == InstrumentsData.FixQualityType.ESTIMATED_DEAD_RECKONING)
                {
                    MessageHub.PublishAsync(new LogMessage(this, new LogText($"{Texts.GetString("BoatDataRefreshedDeadReckoning")} - {Boat.UserName}'s {Boat.BoatName} - {DateTime.Now.ToString("hh:mm:ss")}", Color.Goldenrod)));
                } else
                {
                    MessageHub.PublishAsync(new LogMessage(this, new LogText($"{Texts.GetString("BoatDataRefreshed")} - {Boat.UserName}'s {Boat.BoatName} - {DateTime.Now.ToString("hh:mm:ss")}", Color.DarkGreen)));
                }
                Boat.toInstrumentsData(ref boatData);
                NmeaServer.SendData();
            });

            NmeaServer = new NMEAServer(ref boatData, NmeaTcpPort);
            NmeaServer.OnServerStarted += delegate
            {
                MessageHub.PublishAsync(new LogMessage(this, new LogText($"{Texts.GetString("NMEAServerStarted")} {NmeaTcpPort}")));
            };
            NmeaServer.OnServerStop += delegate
            {
                MessageHub.PublishAsync(new LogMessage(this, new LogText(Texts.GetString("NMEAServerStopped"))));
            };
            NmeaServer.OnNMEASent += NmeaServer_OnNMEASent;
            NmeaServer.OnServerError += NmeaServer_OnServerError;
            NmeaServer.OnClientConnected += NmeaServer_OnClientConnected;

            DeadReckoning.Active = true;
            DeadReckoning.Rate = 1;
            DeadReckoning.StartDeadReckoningTask();
        }
Ejemplo n.º 10
0
        public Form1()
        {
            InitializeComponent();
            W = new World();
            C = new Clock(100);
            C.Worker.ProgressChanged    += ClockProgressChanged;
            C.Worker.RunWorkerCompleted += ClockCompleted;

            g          = pictureBox1.CreateGraphics();
            MessageHub = new TinyMessengerHub();
            this.Rand  = new Random();

            W.Trails.Add(new ChemTrail(200, 10, 800));

            this.Ants = new List <Ant>();
            Ants.Add(new Ant(200, 200, 4, 1, W, ref label2, 19));
            Ants.Add(new Ant(200, 200, 4, 2, W, ref label3, 18));
            Ants.Add(new Ant(200, 200, 4, 3, W, ref label4, 17));
            Ants.Add(new Ant(200, 200, 2, 4, W, ref label5));
            Ants.Add(new Ant(200, 200, 2, 5, W, ref label6));
            Ants.Add(new Ant(200, 200, 2, 6, W, ref label7));
            Ants.Add(new Ant(200, 200, 2, 7, W, ref label8));
            Ants.Add(new Ant(200, 200, 2, 8, W, ref label9));
            Ants.Add(new Ant(200, 200, 2, 9, W, ref label10));
            Ants.Add(new Ant(200, 200, 2, 10, W, ref label11));
            Ants.Add(new Ant(200, 200, 2, 11, W, ref label12));
            Ants.Add(new Ant(200, 200, 2, 12, W, ref label13));
            Ants.Add(new Ant(200, 200, 2, 13, W, ref label14));
            Ants.Add(new Ant(200, 200, 2, 14, W, ref label15));

            //MessageHub.Subscribe<MoveMsg>((m) =>
            //{
            //    //label1.Text = string.Format("Tick {0} - Playing", C.Count);
            //    pictureBox1.Refresh();
            //    //g.DrawLine(pen1, 190, 210, 210, 190);
            //    //g.DrawLine(pen1, 190, 190, 210, 210);

            //    //g.DrawLine(pen2, 190, 20, 210, 0);
            //    //g.DrawLine(pen2, 190, 0, 210, 20);
            //});

            foreach (Ant A in Ants)
            {
                MessageHub.Subscribe <MoveMsg>((m) =>
                {
                    A.Move();
                    g.FillRectangle(new System.Drawing.SolidBrush((A.Color)), A.X - 2, A.Y - 2, 5, 5);
                    ChemTrail t = W.AddTrail(new ChemTrail(A.X, A.Y, 50));
                });
            }
        }
Ejemplo n.º 11
0
 public TinyMessageSubscriptionToken Subscribe <TMessage>(Action <TMessage> handler)
     where TMessage : class, ITinyMessage
 {
     return(hub.Subscribe(handler));
 }
Ejemplo n.º 12
0
 public AppViewModel()
 {
     _hub = DependencyService.Resolve <TinyMessengerHub>();
     _hub.Subscribe <LoggedInMessage>(OnLoggedIn);
     _hub.Subscribe <LoggedOutMessage>(OnLoggedOut);
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            ConfigureServices(serviceCollection);

            serviceProvider = serviceCollection.BuildServiceProvider();

            logger = serviceProvider.GetService <ILogger <Program> >();

            logger.LogInformation($"Shortel Token {appConfig.ShoreTelToken}");
            logger.LogInformation($"Shoretel Host {appConfig.Host}");
            logger.LogInformation($"Shortel Domain {appConfig.Domain}");
            logger.LogInformation($"Shortel Username {appConfig.UserName}");
            logger.LogInformation($"Smtp Host {appConfig.SmtpHost}");
            logger.LogInformation($"Smtp port {appConfig.SmtpPort}");
            logger.LogInformation($"Smtp port {appConfig.SendEmailDelay}");
            foreach (string user in appConfig.UsersToRespondTo)
            {
                logger.LogInformation($"Users to respond to {user}");
            }

            msgHub = new TinyMessengerHub(new ErrorHandler(logger));

            msgHub.Subscribe <ActiveMessage>(m =>
            {
                logger.LogDebug("Enter ActiveMessage");
                try
                {
                    var email = emailCollection.GetOrAdd(m.message.Thread, e => new Email(m.message.From.Bare, m.message.Thread));
                    Monitor.Enter(email);
                    try
                    {
                        if (email.mailBody.Length < 1)
                        {
                            if (appConfig.UsersToRespondTo.FindIndex(x => x.Equals(email.EmailFrom, StringComparison.OrdinalIgnoreCase)) >= 0)
                            {
                                var txtMsg = "I am unable to respond to ShoreTel IMs right now.  Leave a message, exit the conversation and I will get back with you,";
                                var sndMsg = new Matrix.Xmpp.Client.Message(m.message.From, MessageType.Chat, txtMsg, "");
                                xmppClient.SendAsync(sndMsg).GetAwaiter().GetResult();
                            }
                        }
                        email.AddString(m.message.Body);
                    }
                    finally
                    {
                        Monitor.Exit(email);
                    }
                }
                catch (Exception e)
                {
                    logger.LogError($"Active message error {e.Message}");
                }
                logger.LogDebug("Exit ActiveMessage");
            });

            msgHub.Subscribe <GoneMessage>(m =>
            {
                logger.LogDebug("Enter GoneMessage");
                try
                {
                    Email email;
                    if (emailCollection.TryRemove(m.Thread, out email))
                    {
                        Monitor.Enter(email);
                        try
                        {
                            using (var client = new SmtpClient(new MailKit.ProtocolLogger("smtp.log", false)))
                            {
                                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                                client.CheckCertificateRevocation          = false;

                                client.ConnectAsync(appConfig.SmtpHost, appConfig.SmtpPort, SecureSocketOptions.StartTlsWhenAvailable).GetAwaiter().GetResult();

                                var mailMsg = new MimeMessage();

                                mailMsg.From.Add(new MailboxAddress(email.EmailFrom));
                                mailMsg.To.Add(new MailboxAddress(appConfig.UserName));

                                mailMsg.Subject = $"ShoreTel message from {email.EmailFrom}";

                                var builder = new BodyBuilder
                                {
                                    TextBody = email.mailBody.ToString()
                                };

                                mailMsg.Body = builder.ToMessageBody();

                                client.SendAsync(mailMsg).GetAwaiter().GetResult();

                                client.DisconnectAsync(true).GetAwaiter().GetResult();
                            }
                        }
                        finally
                        {
                            Monitor.Exit(email);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.LogError($"Gone message error {e.Message}");
                }
                logger.LogDebug("Exit GoneMessage");
            });


            var pipelineInitializerAction = new Action <IChannelPipeline, ISession>((pipeline, session) =>
            {
                pipeline.AddFirst(new MyLoggingHandler(logger));
            });

            xmppClient = new XmppClient()
            {
                Username    = appConfig.UserName,
                XmppDomain  = appConfig.Domain,
                SaslHandler = new ShoretelSSOProcessor(appConfig.ShoreTelToken),
                // use a local server for dev purposes running
                // on a non standard XMPP port 5333
                HostnameResolver = new StaticNameResolver(IPAddress.Parse(appConfig.Host), appConfig.Port)
            };

            xmppClient.XmppSessionStateObserver.Subscribe(v =>
            {
                Console.WriteLine($"State changed: {v}");
                logger.LogInformation(v.ToString());
            });

            xmppClient
            .XmppXElementStreamObserver
            .Where(el => el is Presence)
            .Subscribe(el =>
            {
                logger.LogDebug("Enter Presence observer");
                //Console.WriteLine(el.ToString());
                //logger.LogInformation(el.ToString());
                logger.LogDebug("Exit Presence observer");
            });

            xmppClient
            .XmppXElementStreamObserver
            .Where(el => el is Message)
            .Subscribe(el =>
            {
                logger.LogDebug("Enter Message observer");
                var msg = el as Message;

                switch (msg.Chatstate)
                {
                case Matrix.Xmpp.Chatstates.Chatstate.Active:
                    msgHub.PublishAsync(new ActiveMessage(msg), x => { });
                    break;

                case Matrix.Xmpp.Chatstates.Chatstate.Composing:
                    break;

                case Matrix.Xmpp.Chatstates.Chatstate.Gone:
                    msgHub.PublishAsync(new GoneMessage(msg.Thread), x => { });
                    break;
                }

                logger.LogDebug("Exit Message observer");
            });

            xmppClient
            .XmppXElementStreamObserver
            .Where(el => el is Iq)
            .Subscribe(el =>
            {
                Console.WriteLine(el.ToString());
                logger.LogInformation(el.ToString());
            });

            xmppClient.ConnectAsync().GetAwaiter().GetResult();

            // Send our presence to the server
            xmppClient.SendPresenceAsync(Show.Chat, "free for chat").GetAwaiter().GetResult();

            using (Timer t = new Timer(TimerCallback, null, 0, 1000))
            {
                Console.ReadLine();
            }

            // Disconnect the XMPP connection
            xmppClient.DisconnectAsync().GetAwaiter().GetResult();
        }
Ejemplo n.º 14
0
 public AppViewModel()
 {
     _hub = DependencyService.Resolve <TinyMessengerHub>();
     _hub.Subscribe <AppThemeChangedMessage>(OnThemeChanged);
 }
Ejemplo n.º 15
0
 private static void TinyInit()
 {
     MessageHub.Subscribe <SoldierCreatedEvent>(OnSoldierCreateEvent);
 }