public AccountSessionHandler(SessionData sessionData, ILogger <AccountSessionHandler> logger, IChatsRepository chatsRepository, SubscriptionFactory subscriptionFactory)
        {
            _sessionData     = sessionData;
            _logger          = logger;
            _chatsRepository = chatsRepository;
            _subscription    = subscriptionFactory.Create();
            _sessionSubject  = new BehaviorSubject <SessionData>(sessionData);
            _subscription.Add(_sessionSubject);
            SessionChanges = _sessionSubject;
            _cancelSubject = new Subject <Unit>();
            _subscription.Add(_cancelSubject);

            _supportedMessages = new Dictionary <string, Func <IObservable <Unit> > >(StringComparer.OrdinalIgnoreCase)
            {
                { "/start", () => Observable.Empty <Unit>() },
                { "/stop", () => Observable.Empty <Unit>() },
                { "/help", () => ShowHelp() },
                { "/login", () => Login() },
                { "/username", () => RequestUsername() },
                { "/session", () => RequestSession() },
                { "/token", () => RequestAuthToken() },
                { "/cancel", () => Cancel() },
                { "/pause", () => StartPauseDialog() },
                { "/resume", () => Resume() },
                { "/mute", () => StartMuteDialog() },
                { "/unmute", () => Unmute() },
                { "/timezone", () => RequestTimezone() },
            };
        }
        public MaintananceHostedService(ILogger <MaintananceHostedService> logger, SubscriptionFactory subscriptionFactory)
        {
            _subscription = subscriptionFactory.Create();
            _logger       = logger;
            _httpClient   = new HttpClient();

            _subscription.Add(_httpClient);
        }
        public TelegramAccountsHandler(SubscriptionFactory subscriptionFactory, IChatsRepository chatsRepository, BotClientFactory botClientFactory, MessageFactory messageFactory, MessageSender messageSender)
        {
            _subscriptions  = subscriptionFactory.Create();
            _sessionChanges = new Subject <SessionData>();
            _subscriptions.Add(_sessionChanges);

            _chatsRepository    = chatsRepository;
            _botClientFactory   = botClientFactory;
            _messageFactory     = messageFactory;
            this._messageSender = messageSender;
        }
Пример #4
0
        static void Main(string[] args)
        {
            //similar Decorator
            ASubscription subcription = new Occasional(new Electric(20, 3));

            Console.WriteLine($"Subscription Rental Eur {subcription.Calculate()}");
            //Factory from Model base for MVC
            ASubscription subscriptionFromFactory = SubscriptionFactory.Create(new Library.Core.Models.Data()
            {
                Car          = "Large",
                Subscription = "Frequent",
                Kilometers   = 100,
                Hours        = 5
            });

            Console.WriteLine($"Subscription Rental from Factory Eur {subscriptionFromFactory.Calculate()}");
            Console.ReadLine();
        }
        public void Execute()
        {
            var url = Properties.Settings.Default.RabbitMqUrl;

            using (var connectionFactory = new DisposableConnectionFactory())
            using (var connection = connectionFactory.Create(url))
            using (var channel = connection.CreateModel())
            using (var subscriptionFactory = new SubscriptionFactory())
            using (var subscription = subscriptionFactory.Create(channel:channel,queueName:"TheUsableMessageQueue"))
            {
                
                foreach (var message in subscription.Messages)
                {
                    var messageBody = message.BodyAsJson<UsableMessage>();
                    ProcessMessage(messageBody);
                    
                    subscription.Ack(message);
                }
            }
        }
        public void Initialize()
        {
            _sessionsObservable = Observable.Create <SessionData>(observer =>
            {
                var subscription = _subscriptionFactory.Create();

                var sessionsSubscription = _accountsService.GetSessions().Subscribe(session =>
                {
                    if (_accounts.TryGetValue(session.SessionId, out var sessionHandler))
                    {
                        if (session.IsDeleted)
                        {
                            _accounts.TryRemove(session.SessionId, out sessionHandler);
                            sessionHandler.Dispose();
                            subscription.Remove(sessionHandler);

                            observer.OnNext(session);
                        }
                    }
                    else
                    {
                        sessionHandler = new AccountSessionHandler(session, _accountsLogger, _chatsRepository, _subscriptionFactory);
                        sessionHandler.Initialize();
                        subscription.Add(sessionHandler);
                        _accounts.TryAdd(session.SessionId, sessionHandler);

                        subscription.Add(
                            sessionHandler.SessionChanges.Subscribe(sessionChanges => observer.OnNext(sessionChanges))
                            );
                    }
                },
                                                                                    error => observer.OnError(error),
                                                                                    () => observer.OnCompleted()
                                                                                    );
                subscription.Add(sessionsSubscription);

                return(() => subscription.Dispose());
            }).LogException(_accountsHandlerLogger);
        }