Exemplo n.º 1
0
        public MainViewModel(IEventAggregator eventAggregator, ISignalRClient signalRClient, IAuthStore authStore,
            IProductsRepository productsRepository)
        {
            this.eventAggregator = eventAggregator;
            this.signalRClient = signalRClient;
            this.productsRepository = productsRepository;

            deleteRequest = new InteractionRequest<Confirmation>();
            CreateProductCommand = new DelegateCommand(CreateProduct);
            OpenProductCommand = new DelegateCommand<Product>(EditProduct);
            changePriceCommand = new DelegateCommand(ChangePrice, HasSelectedProducts);
            deleteCommand = new DelegateCommand(PromtDelete, HasSelectedProducts);

            cvs = new CollectionViewSource();
            items = new ObservableCollection<Product>();
            cvs.Source = items;
            cvs.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            cvs.SortDescriptions.Add(new SortDescription("Size", ListSortDirection.Ascending));

            var token = authStore.LoadToken();
            if (token != null)
            {
                IsEditor = token.IsEditor();
                IsAdmin = token.IsAdmin();
            }
        }
Exemplo n.º 2
0
 public void PostMessage(string msg, ISignalRClient client)
 {
     if (this.clientTransportMap.ContainsKey(client))
     {
         this.clientTransportMap[client].PostToSendQueue(msg);
     }
 }
Exemplo n.º 3
0
 public void PostMessage(string msg, ISignalRClient client)
 {
     if (this.clientTransportMap.ContainsKey(client))
     {
         this.clientTransportMap[client].PostToSendQueue(msg);
     }
 }
Exemplo n.º 4
0
        public SignalRLoggingClient(ScheduleLoggerProvider loggerProvider, SignalRClientFactory clientFactory)
        {
            _client = clientFactory.CreateClient(ILoggingClient.HubName);

            _callbacks = Connection.On(nameof(loggerProvider.StartLoggingAsync), loggerProvider.StartLoggingAsync);
            _callbacks = Connection.On(nameof(loggerProvider.StopLoggingAsync), loggerProvider.StopLoggingAsync);
        }
        /// <summary>
        /// Start discovering.
        /// </summary>
        public async Task StartAsync()
        {
            if (!IsStarted)
            {
                _discoveredServices = new List <ResonanceSignalRDiscoveredService <TReportedServiceInformation> >();

                _client = SignalRClientFactory.Default.Create(Mode, HubUrl);
                _client.EnableAutoReconnection = EnableAutoReconnection;
                _client.Error += OnDisconnected;
                await _client.StartAsync();

                await _client.InvokeAsync(ResonanceHubMethods.RegisterDiscoveryClient, Credentials);

                var services = await _client.InvokeAsync <List <TReportedServiceInformation> >(ResonanceHubMethods.GetAvailableServices, Credentials);

                foreach (var serviceInfo in services)
                {
                    OnServiceRegistered(serviceInfo);
                }

                _client.On <TReportedServiceInformation>(ResonanceHubMethods.ServiceRegistered, OnServiceRegistered);
                _client.On <TReportedServiceInformation>(ResonanceHubMethods.ServiceUnRegistered, OnServiceUnregistered);
                IsStarted = true;
            }
        }
Exemplo n.º 6
0
        public LoginViewModel(IAuthService authService, INavigationService navigationService, ISignalRClient signalRClient)
        {
            this.authService = authService;
            this.navigationService = navigationService;
            this.signalRClient = signalRClient;

            LoginCommand = new DelegateCommand(DoLogin);
        }
Exemplo n.º 7
0
 public SoundSystemBackgroundService(
     IConfiguration configuration,
     ISignalRClient signalRClient,
     ISoundControllerApi soundControllerApi
     )
 {
     _configuration      = configuration;
     _signalRClient      = signalRClient;
     _soundControllerApi = soundControllerApi;
 }
Exemplo n.º 8
0
        public ShellViewModel(IAuthStore authStore, IAuthService authService, ISignalRClient signalRClient,
            Func<LoginViewModel> loginFactory, Func<LoggedInViewModel> loggedInFactory)
        {
            this.authStore = authStore;
            this.authService = authService;
            this.signalRClient = signalRClient;
            this.loginFactory = loginFactory;
            this.loggedInFactory = loggedInFactory;

            Refresh();
        }
Exemplo n.º 9
0
        public List <ReceivedSignalRMsg> GetMesssges(ISignalRClient client)
        {
            List <ReceivedSignalRMsg> msg = null;

            if (this.clientTransportMap.ContainsKey(client))
            {
                msg = this.clientTransportMap[client].Read();
            }

            return(msg);
        }
Exemplo n.º 10
0
        public List<ReceivedSignalRMsg> GetMesssges(ISignalRClient client)
        {
            List<ReceivedSignalRMsg> msg = null;

            if (this.clientTransportMap.ContainsKey(client))
            {
                msg = this.clientTransportMap[client].Read();
            }

            return msg;
        }
Exemplo n.º 11
0
        public bool UnRegisterClient(ISignalRClient client)
        {
            var result = true;

            if (this.registeredClients.Contains(client))
            {
                this.hubConnCtrl.RemoveClientFromHub(client);
                this.registeredClients.Remove(client);
            }

            return result;
        }
Exemplo n.º 12
0
        public bool UnRegisterClient(ISignalRClient client)
        {
            var result = true;

            if (this.registeredClients.Contains(client))
            {
                this.hubConnCtrl.RemoveClientFromHub(client);
                this.registeredClients.Remove(client);
            }

            return(result);
        }
Exemplo n.º 13
0
        public TopMenuViewModel(IAuthStore authStore, INavigationService navigationService,
            IRegionManager regionManager, ISignalRClient signalRClient)
        {
            this.authStore = authStore;
            this.navigationService = navigationService;
            this.regionManager = regionManager;
            this.signalRClient = signalRClient;

            LogoutCommand = new DelegateCommand(Logout);

            NavigateToPageCommand = new DelegateCommand<string>(NavigateToPage);
        }
Exemplo n.º 14
0
 public SignalRScheduleClient(
     ILoggerFactory loggerFactory,
     IServiceProvider services,
     IOptions <ScheduleOptions> scheduleOptions,
     SignalRClientFactory clientFactory)
 {
     _logger                 = loggerFactory.CreateLogger(GetType());
     _services               = services;
     _scheduleOptions        = scheduleOptions;
     _client                 = clientFactory.CreateClient(IScheduleClient.HubName);
     _defaultJobExecutorType = typeof(IJobExecutor <>);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the collection of available services for the provided credentials.
        /// </summary>
        /// <typeparam name="TCredentials">The type of the credentials.</typeparam>
        /// <typeparam name="TReportedServiceInformation">The type of the reported service information.</typeparam>
        /// <param name="credentials">The credentials.</param>
        /// <param name="url">The URL.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public async Task <List <TReportedServiceInformation> > GetAvailableServicesAsync <TCredentials, TReportedServiceInformation>(TCredentials credentials, String url, SignalRMode mode) where TReportedServiceInformation : IResonanceServiceInformation
        {
            ISignalRClient client = SignalRClientFactory.Default.Create(mode, url);

            await client.StartAsync();

            var services = await client.InvokeAsync <List <TReportedServiceInformation> >(ResonanceHubMethods.GetAvailableServices, credentials);

            await client.DisposeAsync();

            return(services);
        }
        public ChatConversationViewModel(IPlatformService platformService, IUserService userService, IChatService chatService, ISignalRClient signalRClient) : base(platformService)
        {
            _numberAlive++;
            Debug.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!CREATING!!!!!!!!!!!!!!!!!!!!! - ChatConversationViewModel - number alive : {0}", _numberAlive);

            _userService   = userService;
            _chatService   = chatService;
            _signalRClient = signalRClient;

            SendCommand           = new MvxCommand(async() => await SendMessage(), CanSendMessage);
            UserCommandEnableChat = false;
            _addMessageHandler    = async chatMessageModel => await AddMessage(chatMessageModel);
        }
Exemplo n.º 17
0
        public bool RemoveClientFromHub(ISignalRClient client)
        {
            var result = false;

            if (this.clientTransportMap.ContainsKey(client))
            {
                this.clientTransportMap[client].Close();
                this.clientTransportMap.Remove(client);

                result = true;
            }

            return(result);
        }
Exemplo n.º 18
0
        public bool RemoveClientFromHub(ISignalRClient client)
        {
            var result = false;

            if (this.clientTransportMap.ContainsKey(client))
            {
                this.clientTransportMap[client].Close();
                this.clientTransportMap.Remove(client);

                result = true;
            }

            return result;
        }
Exemplo n.º 19
0
        public bool RegisterClient(ISignalRClient client)
        {
            var result = true;

            if (!this.registeredClients.Contains(client))
            {
                var trans = this.transportFactory.CreateWebSocketTransport(client.HubName, client.HostServerUrl, client.UseSecureConnection);

                result = hubConnCtrl.ConnectToHub(client, trans);
                this.registeredClients.Add(client);
            }

            return result;
        }
Exemplo n.º 20
0
        public bool RegisterClient(ISignalRClient client)
        {
            var result = true;

            if (!this.registeredClients.Contains(client))
            {
                var trans = this.transportFactory.CreateWebSocketTransport(client.HubName, client.HostServerUrl, client.UseSecureConnection);

                result = hubConnCtrl.ConnectToHub(client, trans);
                this.registeredClients.Add(client);
            }

            return(result);
        }
Exemplo n.º 21
0
 public MainViewModel(IRepository repository, IDateTime dateTimeProvider,
                      ValidationMessageViewModel validationMessageViewModel, ISignalRClient signalRClient,
                      ISettingsUtility settingsUtility)
 {
     _repository = repository;
     _dateTime   = dateTimeProvider;
     _validationMessageViewModel = validationMessageViewModel;
     _selectedTimeSegment        = null;
     _client = signalRClient;
     _client.ConnectToServer();
     LoadActivities();
     _settings     = settingsUtility.Settings;
     _dailySummary = new DailySummary(settingsUtility, repository);
 }
Exemplo n.º 22
0
        public EventCategoriesViewModel(IPlatformService platformService, IEventService eventService, ISignalRClient signalRClient) : base(platformService)
        {
            _eventService  = eventService;
            _signalRClient = signalRClient;

            _eventClosedText     = Settings.GetResource(ResKeys.event_detail_btn_event_closed);
            _unattendButtonText  = Settings.GetResource(ResKeys.event_detail_btn_unattend);
            _attendButtonText    = Settings.GetResource(ResKeys.event_detail_btn_attend);
            _peopleAttendingText = Settings.GetResource(ResKeys.event_detail_people_attending);
            _eventInfoText       = Settings.GetResource(ResKeys.mobile_events_event_info);
            _eventDateText       = Settings.GetResource(ResKeys.mobile_events_event_date);
            _eventTimeLabel      = Settings.GetResource(ResKeys.mobile_events_event_time);
            _eventLocationLabel  = Settings.GetResource(ResKeys.mobile_events_location);
            _aboutHeaderLabel    = Settings.GetResource(ResKeys.mobile_events_about_event);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResonanceRegisteredService{TCredentials, TResonanceServiceInformation, TAdapterInformation}"/> class.
 /// </summary>
 /// <param name="credentials">The credentials.</param>
 /// <param name="serviceInformation">The service information.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="signalRClient">The signal r client.</param>
 internal ResonanceRegisteredService(TCredentials credentials, TResonanceServiceInformation serviceInformation, SignalRMode mode, ISignalRClient signalRClient)
 {
     IsRegistered          = true;
     Mode                  = mode;
     Credentials           = credentials;
     ServiceInformation    = serviceInformation;
     _client               = signalRClient;
     _client.Reconnecting -= OnReconnecting;
     _client.Reconnecting += OnReconnecting;
     _client.Reconnected  -= OnReconnected;
     _client.Reconnected  += OnReconnected;
     _client.Error        -= OnError;
     _client.Error        += OnError;
     _client.On <String, TAdapterInformation>(ResonanceHubMethods.ConnectionRequest, OnConnectionRequest);
 }
Exemplo n.º 24
0
 public MessageHandler(
     IRestClient restClient,
     IMediator mediator,
     ISignalRClient signalRClient,
     IConfiguration configuration,
     ITelegramLogger logger,
     ILokiLogger lokiLogger)
 {
     _restClient    = restClient;
     _mediator      = mediator;
     _signalRClient = signalRClient;
     _configuration = configuration;
     _homeAutomationLocalLightSystemId = _configuration.GetSection("HomeAutomationLocalLightingSystemId").Value;
     _logger     = logger;
     _lokiLogger = lokiLogger;
 }
Exemplo n.º 25
0
        public bool ConnectToHub(ISignalRClient client, ISignalRTransportCtrl transProtocol)
        {
            var connResult = false;

            if (!this.clientTransportMap.ContainsKey(client))
            {
                connResult = transProtocol.Connect();

                if (connResult)
                {
                    this.clientTransportMap.Add(client, transProtocol);
                }
            }

            return connResult;
        }
Exemplo n.º 26
0
        public bool ConnectToHub(ISignalRClient client, ISignalRTransportCtrl transProtocol)
        {
            var connResult = false;

            if (!this.clientTransportMap.ContainsKey(client))
            {
                connResult = transProtocol.Connect();

                if (connResult)
                {
                    this.clientTransportMap.Add(client, transProtocol);
                }
            }

            return(connResult);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Registers a new Resonance SignalR service.
        /// </summary>
        /// <typeparam name="TCredentials">The type of the credentials.</typeparam>
        /// <typeparam name="TResonanceServiceInformation">The type of the resonance service information.</typeparam>
        /// <typeparam name="TAdapterInformation">The type of the adapter information.</typeparam>
        /// <param name="credentials">The credentials used to authenticate the service.</param>
        /// <param name="serviceInformation">The service information.</param>
        /// <param name="url">The hub URL.</param>
        /// <param name="mode">The SignalR mode (legacy/core).</param>
        /// <returns></returns>
        public async Task <ResonanceRegisteredService <TCredentials, TResonanceServiceInformation, TAdapterInformation> > RegisterServiceAsync <TCredentials, TResonanceServiceInformation, TAdapterInformation>(TCredentials credentials, TResonanceServiceInformation serviceInformation, String url, SignalRMode mode) where TResonanceServiceInformation : IResonanceServiceInformation
        {
            Logger.LogDebug($"Registering service {{@ServiceInformation}}...", serviceInformation);

            ISignalRClient client = SignalRClientFactory.Default.Create(mode, url);

            client.EnableAutoReconnection = true;

            await client.StartAsync();

            await client.InvokeAsync(ResonanceHubMethods.Login, credentials);

            await client.InvokeAsync(ResonanceHubMethods.RegisterService, serviceInformation);

            return(new ResonanceRegisteredService <TCredentials, TResonanceServiceInformation, TAdapterInformation>(credentials, serviceInformation, mode, client));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Disposes component resources asynchronously.
        /// </summary>
        /// <returns></returns>
        public async Task DisposeAsync()
        {
            if (!IsDisposed)
            {
                try
                {
                    await UnregisterAsync();
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "Error occurred while disposing the registered service. Unregister service failed.");
                }

                IsDisposed = true;
                await _client?.StopAsync();

                await _client?.DisposeAsync();

                _client = null;
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ISignalRClient signalRClient,
            IRestClient restClient,
            IHomeAutomationMqttServer homeAutomationMqttServer,
            IMediator mediator,
            IOptions <Configuration> config,
            ITelegramLogger telegramLogger,
            ILokiLogger lokiLogger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            await app.RunSignalRClientAsync(_configuration, signalRClient);

            await app.RunMqttServerAsync(
                homeAutomationMqttServer,
                restClient,
                mediator,
                signalRClient,
                _configuration,
                telegramLogger,
                lokiLogger);
        }
 public ConnectionChangedArgs(ConnectionState oldState, ConnectionState newState, ISignalRClient client)
 {
     OldState = oldState;
     NewState = newState;
     Client   = client;
 }
Exemplo n.º 31
0
 public Program(ISignalRClient signalRClient, ILoggerProvider loggerProvider)
 {
     _signalRClient = new NotificationSignalRClient(new Uri("http://localhost:56479/signalr/notification"), loggerProvider);
 }
 public AndroidNotificationsViewModel(IPlatformService platformService, INotificationService notificationService, ISignalRClient signalRClient) : base(platformService, notificationService, signalRClient)
 {
 }
Exemplo n.º 33
0
        /// <summary>
        /// Called when the adapter is connecting.
        /// </summary>
        /// <returns></returns>
        protected override Task OnConnect()
        {
            bool completed = false;

            TaskCompletionSource <object> completionSource = new TaskCompletionSource <object>();

            Task.Factory.StartNew(() =>
            {
                try
                {
                    _client = SignalRClientFactory.Default.Create(Mode, Url);
                    _client.StartAsync().GetAwaiter().GetResult();

                    if (Role == SignalRAdapterRole.Connect)
                    {
                        _client.On(ResonanceHubMethods.Connected, () =>
                        {
                            try
                            {
                                if (!completed)
                                {
                                    completed = true;
                                    completionSource.SetResult(true);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (!completed)
                                {
                                    Logger.LogError(ex, "Error occurred after successful connection.");
                                    completed = true;
                                    completionSource.SetException(ex);
                                }
                            }
                        });

                        _client.On(ResonanceHubMethods.Declined, () =>
                        {
                            try
                            {
                                if (!completed)
                                {
                                    completed = true;

                                    var ex = new ConnectionDeclinedException();

                                    Logger.LogError(ex, "Error occurred after session created.");
                                    completionSource.SetException(ex);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (!completed)
                                {
                                    Logger.LogError(ex, "Error occurred after session created.");
                                    completed = true;
                                    completionSource.SetException(ex);
                                }
                            }
                        });
                    }

                    _client.On(ResonanceHubMethods.Disconnected, () =>
                    {
                        if (State == ResonanceComponentState.Connected)
                        {
                            //OnDisconnect(false); //Don't know what to do here.. We already have the resonance disconnection message.
                            //Maybe just raise an event..
                        }
                    });

                    _client.On(ResonanceHubMethods.ServiceDown, () =>
                    {
                        OnFailed(new ServiceDownException());
                    });

                    Logger.LogInformation("Authenticating with the remote hub {HubUrl}...", _client.Url);
                    _client.InvokeAsync(ResonanceHubMethods.Login, Credentials).GetAwaiter().GetResult();

                    if (Role == SignalRAdapterRole.Connect)
                    {
                        Logger.LogInformation("Connecting to service {ServiceId}...", ServiceId);
                        SessionId = _client.InvokeAsync <String>(ResonanceHubMethods.Connect, ServiceId).GetAwaiter().GetResult();
                    }
                    else
                    {
                        Logger.LogInformation("Accepting connection {SessionId}...", SessionId);
                        _client.InvokeAsync(ResonanceHubMethods.AcceptConnection, SessionId).GetAwaiter().GetResult();

                        if (!completed)
                        {
                            completed = true;
                            completionSource.SetResult(true);
                        }
                    }

                    _client.On <byte[]>(ResonanceHubMethods.DataAvailable, (data) => { OnDataAvailable(data); });

                    _client.Error        += OnError;
                    _client.Reconnecting += OnReconnecting;
                    _client.Reconnected  += OnReconnected;
                }
                catch (Exception ex)
                {
                    completed = true;
                    Logger.LogError(ex, "Error occurred while trying to connect.");
                    completionSource.SetException(ex);
                }
            });

            TimeoutTask.StartNew(() =>
            {
                if (!completed)
                {
                    completed = true;
                    completionSource.SetException(new TimeoutException("Could not connect after the given timeout."));
                }
            }, ConnectionTimeout);

            return(completionSource.Task);
        }
 public SignalRClientStarterService(ISignalRClient hubClient)
 {
     fHubClient = hubClient;
 }
Exemplo n.º 35
0
        public static MainViewModel GetMainViewModel(int selectedActivityIndex, IDateTime dateTimeProvider, ISignalRClient mockSignalRClientObject)
        {
            var mvm = new MainViewModel(GetMockRepositoryObject(), dateTimeProvider, new ValidationMessageViewModel(), mockSignalRClientObject, GetMockSettingsUtility())
            {
                SelectedActivityIndex = selectedActivityIndex
            };

            return(mvm);
        }
 public NotificationsViewModel(IPlatformService platformService, INotificationService notificationService, ISignalRClient signalRClient) : base(platformService)
 {
     _notificationService = notificationService;
     _signalRClient       = signalRClient;
 }