public void Add(int userId, IAsyncStreamReader <SubscriptionRequest> request, IServerStreamWriter <SubscriptionReply> reply)
        {
            var sub = SubscriptionLedger.FirstOrDefault(z => z.UserId == userId);

            if (sub != null)
            {
                sub = new SubscriptionContainer {
                    UserId = userId, StreamReader = request, StreamWriter = reply
                }
            }
            ;
            else
            {
                _subscriptionLegder.Add(new SubscriptionContainer {
                    UserId = userId, StreamReader = request, StreamWriter = reply
                });
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var cts       = new CancellationTokenSource();
            var container = new SubscriptionContainer();

            ObservableEventListener.FromTraceEvent("DocumentDBClient")
            .Buffer(TimeSpan.FromSeconds(1), 1000, cts.Token)
            .LogTo(xs =>
            {
                var d1 = xs.LogToFile("log.txt", x => $"[{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}][{x.Level}]{x.DumpPayload()}", Encoding.UTF8, autoFlush: true);
                var d2 = xs.LogToConsole();
                var d3 = xs.LogToFile("log.json", e => e.ToJson(), Encoding.UTF8, autoFlush: true);
                return(new[] { d1, d2, d3 });
            })
            .AddTo(container);

            Console.ReadLine();

            cts.Cancel();
            container.Dispose();
        }
Beispiel #3
0
        static void Main2(string[] args)
        {
            // in ApplicationStart, prepare two parts.
            var cts       = new CancellationTokenSource();
            var container = new SubscriptionContainer();

            // configure log
            ObservableEventListener.FromTraceEvent("DocumentDBClient")
            .Buffer(TimeSpan.FromSeconds(1), 1000, cts.Token)
            .LogTo(xs =>
            {
                var d1 = xs.LogToFile("log.txt", x => $"[{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}][{x.Level}]{x.DumpPayload()}", Encoding.UTF8, autoFlush: true);
                var d2 = xs.LogToConsole();
                return(new[] { d1, d2 });
            })
            .AddTo(container);

            // Application Running....
            Console.ReadLine();

            // End of Application(Form_Closed/Application_End/Main's last line/etc...)
            cts.Cancel();        // Cancel publish rest of buffered events.
            container.Dispose(); // Wait finish of subscriptions's buffer event.
        }