public static Message AlreadyExist(string opr, params object[] args)
    {
        var msg = new Message(ALDY_EXST, DateTime.Now.ToString("hh:mm:ss yy/MM/dd") + " - " + " عملیات " + opr + " به علت تکراری بودن مقادیر " + ParamsToString(args) + "لغو شد ", ALDY_EXST_COL);

        MessageObserver.Notify(msg);
        return(msg);
    }
Exemplo n.º 2
0
        public async Task <List <string> > LoadDurableSubscriptionsAsync(string identity)
        {
            List <string> list = new List <string>();

            IEnumerable <string> subscriptionUriStrings = await graphManager.GetSubscriberSubscriptionsListAsync(identity);

            if (subscriptionUriStrings == null || subscriptionUriStrings.Count() == 0)
            {
                return(null);
            }

            foreach (var item in subscriptionUriStrings)
            {
                if (!durableObservers.ContainsKey(item))
                {
                    MessageObserver observer = new MessageObserver();
                    observer.OnNotify += Observer_OnNotify;

                    //set the observer in the subscription with the lease lifetime
                    TimeSpan leaseTime = TimeSpan.FromSeconds(20.0);

                    string leaseKey = await graphManager.AddSubscriptionObserverAsync(item, leaseTime, observer);

                    //add the lease key to the list of ephemeral observers
                    durableObservers.Add(item, observer);
                    Console.WriteLine($"Durable observer added - '{item}' - {DateTime.UtcNow.ToString("yyyy-MM-ddTHH-MM-ss.fffff")}");

                    //get the resource from the subscription
                    Uri    uri = new Uri(item);
                    string resourceUriString = item.Replace(uri.Segments[^ 1], "");
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var messageSerializer = new MessageSerializer();
              var messageBodySerializer = new MessageBodySerializer();
              var messageFactory = new MessageFactory();
              var pathFactory = new PathFactory();
              var broker = new Broker(1337,
                              messageSerializer,
                              messageBodySerializer,
                              messageFactory,
                              pathFactory);
              var messageObserver = new MessageObserver<Foo>(broker.ID,
                                                     messageBodySerializer)
                            {
                              InterceptRemoteMessagesOnly = false,
                              InterceptOnNext = foo =>
                                                {
                                                  // TODO what to do next ...
                                                }
                            };
              broker.Subscribe(messageObserver);
              broker.Start();

              broker.Publish(new Foo
                     {
                       Bar = "hello" // Not L10N
                     });

              Console.ReadLine();
        }
    public static Message Fail(string opr, params object[] args)
    {
        var msg = new Message(FAIL, DateTime.Now.ToString("hh:mm:ss yy/MM/dd") + " - " + " شکست " + opr + "؛ " + ParamsToString(args), FAIL_COL);

        MessageObserver.Notify(msg);
        return(msg);
    }
Exemplo n.º 5
0
 /// <summary>
 /// Creates new sticky connector for HMQ protocol clients
 /// </summary>
 public HmqStickyConnector(TimeSpan reconnectInterval, Func <HorseClient> createInstance = null)
     : base(reconnectInterval, createInstance)
 {
     _observer = new MessageObserver(ReadMessage);
     Events    = new EventManager();
     Bus       = new HorseBus(this);
 }
    public static Message NotExist(string opr, params object[] args)
    {
        var msg = new Message(NOT_EXST, DateTime.Now.ToString("hh:mm:ss yy/MM/dd") + " - " + " عملیات " + opr + " به علت عدم وجود مقادیر " + ParamsToString(args) + "لغو شد ", NOT_EXST_COL);

        MessageObserver.Notify(msg);
        return(msg);
    }
Exemplo n.º 7
0
        public async Task <string> SubscribeAsync(string resourceUriString, SubscriptionMetadata metadata)
        {
            metadata.IsEphemeral = true;
            string subscriptionUriString = await GraphManager.SubscribeAsync(resourceUriString, metadata);

            //create and observer and wire up event to receive notifications
            MessageObserver observer = new MessageObserver();

            observer.OnNotify += Observer_OnNotify;

            //set the observer in the subscription with the lease lifetime
            TimeSpan leaseTime = TimeSpan.FromSeconds(20.0);

            string leaseKey = await GraphManager.AddSubscriptionObserverAsync(subscriptionUriString, leaseTime, observer);

            //add the lease key to the list of ephemeral observers
            ephemeralObservers.Add(subscriptionUriString, observer);

            //add the resource, subscription, and lease key the container
            if (!container.ContainsKey(resourceUriString))
            {
                container.Add(resourceUriString, new Tuple <string, string>(subscriptionUriString, leaseKey));
            }

            //ensure the lease timer is running
            EnsureLeaseTimer();

            return(subscriptionUriString);
        }
    internal static Message Conflict(string opr, params object[] args)
    {
        var msg = new Message(CONFLICT, DateTime.Now.ToString("hh:mm:ss yy/MM/dd") + " - " + " عملیات " + opr + " به علت مغایرت و همپوشانی مقادیر " + ParamsToString(args) + "لغو شد ", CONFLICT_COL);

        MessageObserver.Notify(msg);
        return(msg);
    }
Exemplo n.º 9
0
 public Game(string name, string gameText)
 {
     this.Name               = name ?? throw new ArgumentNullException(nameof(name));
     this.GameText           = gameText ?? throw new ArgumentNullException(nameof(gameText));
     this.State              = GameState.Lobby;
     this.players            = new ConcurrentDictionary <string, Player>();
     this.gameStreamObserver = new MessageObserver <GameStreamEvent>();
 }
Exemplo n.º 10
0
    public static Message Succ(string opr, params object[] args)
    {
        var msg = new Message(SUCC, DateTime.Now.ToString("hh:mm:ss yy/MM/dd") + " - " + " عملیات موفق " + opr + "؛ " + ParamsToString(args), SUCC_COL);

        MessageObserver.Notify(msg);
        // ثبت عملیات موفق در کارکرد روزانه
        return(msg);
    }
Exemplo n.º 11
0
        public static void InitSystemInfra()
        {
            RouteConfig.RegisterRoutes();
            HebrewCalendarManager.init();
            MessageObserver message = new MessageObserver();

            message.Run();
        }
Exemplo n.º 12
0
        public Task <ConnectionResult> Connect(MessageObserver observer, CancellationToken canceltoken = default)
        {
            var tcs = new TaskCompletionSource <ConnectionResult>();

            _mqttclient.Connect(_hostname, _token, canceltoken).ContinueWith(t =>
            {
                try
                {
                    if (t.IsFaulted)
                    {
                        tcs.TrySetException(t.Exception.InnerException);
                    }
                    else if (t.IsCanceled)
                    {
                        tcs.TrySetCanceled(canceltoken);
                    }
                    else
                    {
                        if (t.Result.IsSuccess)
                        {
                            Subscribe(observer).ContinueWith(t2 =>
                            {
                                if (t2.IsFaulted)
                                {
                                    tcs.SetException(t2.Exception.InnerException);
                                }
                                else
                                {
                                    if (t2.Result.IsSuccess)
                                    {
                                        _unsubscriber =
                                            _mqttclient.ResponseObservable.Subscribe(
                                                new NikoresponseObserver(ParseMessage));
                                        tcs.TrySetResult(new ConnectionResult(t.Result.ResultCode));
                                    }
                                    else
                                    {
                                        Disconnect();
                                        tcs.TrySetResult(new ConnectionResult(ConnectResultCode.SubscriptionError,
                                                                              t2.Result.ResultCode.ToString()));
                                    }
                                }
                            });
                        }
                        else
                        {
                            tcs.TrySetResult(new ConnectionResult(t.Result.ResultCode));
                        }
                    }
                }
                catch (Exception e)
                {
                    tcs.TrySetException(e);
                }
            }, canceltoken);

            return(tcs.Task);
        }
Exemplo n.º 13
0
        public void ObserverPatternTest()
        {
            MessageProvider messageProvider = new MessageProvider();
            MessageObserver messageObserver = new MessageObserver();

            messageObserver.Subscribe(messageProvider);

            messageProvider.PublishMessage("Hello");
        }
Exemplo n.º 14
0
        public MainPage()
        {
            InitializeComponent();

            this.client = new IrcClient();
            this.client.CreateConnectionCompleted += OnCreateConnectionCompleted;

            this.observer = new MessageObserver(client);
        }
Exemplo n.º 15
0
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     hype            = HYP.Instance();
     networkObserver = new NetworkObserver(this);
     stateObserver   = new StateObserver(this);
     messageObserver = new MessageObserver(this);
     FoundInstances  = new Dictionary <string, HYPInstance>();
     FoundLounges    = new Dictionary <string, Lounge>();
     RequestHypeToStart();
 }
Exemplo n.º 16
0
        public Client(Guid userId, int clientPort, IPEndPoint stanServerIP, int refreshInterval, SynchronizationContext ctx)
        {
            _selfId         = userId;
            _stanIP         = stanServerIP;
            _refreshMs      = refreshInterval;
            _clientPort     = clientPort;
            userObserver    = new UserObserver();
            messageObserver = new MessageObserver(_selfId);
            var blackHole = new UndefinedResolver();
            var routes    = userObserver.Compose(messageObserver, blackHole);

            observer = new UDPObserver(_clientPort, ctx, routes);
        }
Exemplo n.º 17
0
        public async Task <List <string> > LoadDurableSubscriptionsAsync(string identity)
        {
            List <string> list = new List <string>();

            IEnumerable <string> subscriptionUriStrings = await GraphManager.GetSubscriberSubscriptionsListAsync(identity);

            if (subscriptionUriStrings == null || subscriptionUriStrings.Count() == 0)
            {
                return(null);
            }

            foreach (var item in subscriptionUriStrings)
            {
                if (!durableObservers.ContainsKey(item))
                {
                    MessageObserver observer = new MessageObserver();
                    observer.OnNotify += Observer_OnNotify;

                    //set the observer in the subscription with the lease lifetime
                    TimeSpan leaseTime = TimeSpan.FromSeconds(20.0);

                    string leaseKey = await GraphManager.AddSubscriptionObserverAsync(item, leaseTime, observer);

                    //add the lease key to the list of ephemeral observers
                    durableObservers.Add(item, observer);


                    //get the resource from the subscription
                    Uri    uri = new Uri(item);
                    string resourceUriString = item.Replace(uri.Segments[uri.Segments.Length - 1], "");

                    list.Add(resourceUriString); //add to list to return

                    //add the resource, subscription, and lease key the container

                    if (!container.ContainsKey(resourceUriString))
                    {
                        container.Add(resourceUriString, new Tuple <string, string>(item, leaseKey));
                    }
                }
            }

            if (subscriptionUriStrings.Count() > 0)
            {
                EnsureLeaseTimer();
            }

            return(list.Count == 0 ? null : list);
        }
        public static void RunScrumBoardClient()
        {
            Console.WriteLine("Example of the State Pattern");
            Console.WriteLine("Welcome to the Scrum Board!");

            Task task = new Task();

            task.Name = "Build DB";
            task.SetInProgress();

            MessageObserver messageObserver = new MessageObserver();

            task.messageProvider.Subscribe(messageObserver);

            bool runLoop = true;

            while (runLoop)
            {
                var input = Console.ReadKey();

                switch (input.KeyChar.ToString())
                {
                case "T":
                    task.SetToDo();
                    break;

                case "I":
                    task.SetInProgress();
                    break;

                case "D":
                    task.SetDone();
                    break;

                case "Q":
                    runLoop = false;
                    Console.WriteLine("Goodbye");
                    break;

                default:
                    Console.WriteLine("Enter T for To Do. I for Inprogress, D for Done. Q to quit");
                    break;
                }
            }
        }
Exemplo n.º 19
0
        private Task <SubscribeResult> Subscribe(MessageObserver observer)
        {
            var tcs = new TaskCompletionSource <SubscribeResult>();

            _mqttclient.Subscribe().ContinueWith(t =>
            {
                try
                {
                    _messageObservable.Subscribe(observer);
                    tcs.TrySetResult(t.Result);
                }
                catch (Exception e)
                {
                    tcs.TrySetException(e);
                }
            });

            return(tcs.Task);
        }
Exemplo n.º 20
0
        public void TestDrive()
        {
            Console.WriteLine("Example of the Adapter Pattern.");
            Console.WriteLine("Lets Test Drive some cars!");

            MessageProvider messageProvider = new MessageProvider();
            MessageObserver messageObserver = new MessageObserver();

            messageObserver.Subscribe(messageProvider);

            ICar holden = new Holden(messageProvider);

            driver.Drive(holden);

            IElectricCar      tesla             = new Tesla(messageProvider);
            ElecticCarAdpater electicCarAdapter = new ElecticCarAdpater(tesla);

            driver.Drive(electicCarAdapter);
        }
        public static void AddAndConfigureMassTransit(this IServiceCollection services, IConfiguration config, Action <IServiceCollectionBusConfigurator>?configure = null)
        {
            var rabbitMqConfig = config.GetSection(RabbitMqConfiguration.Section).Get <RabbitMqConfiguration>();

            if (rabbitMqConfig == null || rabbitMqConfig.SchedulerEndpoint == null)
            {
                return;
            }

            services.AddMassTransit(cfg =>
            {
                var schedulerEndpoint = new Uri(rabbitMqConfig.SchedulerEndpoint);

                cfg.SetKebabCaseEndpointNameFormatter();
                cfg.AddMessageScheduler(schedulerEndpoint);

                cfg.UsingRabbitMq((context, cfg) =>
                {
                    cfg.Host(rabbitMqConfig.Host);

                    cfg.UseMessageScheduler(schedulerEndpoint);

                    var auditStore      = new MessageAuditStore();
                    var receiveObserver = new MessageObserver();

                    //cfg.ConnectSendAuditObservers(auditStore);
                    //cfg.ConnectConsumeAuditObserver(auditStore);
                    //cfg.ConnectReceiveObserver(receiveObserver);

                    // Automatically configure endpoints for all consumers
                    cfg.ConfigureEndpoints(context);
                });

                // Allows the caller to set publishers and consumers
                if (configure != null)
                {
                    configure(cfg);
                }
            });
        }
Exemplo n.º 22
0
        public MainPage()
        {
            InitializeComponent();

            _messageObserver = new MessageObserver(ParseMessage);
        }
Exemplo n.º 23
0
        public frmMain()
        {
            InitializeComponent();

            MessageObserver.Attach(this);
        }
 /// <summary>
 /// Creates new single message connector for HMQ protocol clients
 /// </summary>
 public HmqSingleMessageConnector(Func <HorseClient> createInstance = null) : base(createInstance)
 {
     _observer = new MessageObserver(ReadMessage);
 }
Exemplo n.º 25
0
 public void Unregister(MessageObserver observer)
 {
     Observers.Remove(observer);
 }
Exemplo n.º 26
0
 public void Register(MessageObserver observer)
 {
     Observers.Add(observer);
 }