Esempio n. 1
0
 public TileHub(StatesClient statesClient, ServiceClient serviceClient, CalendarClient calendarClient, IConfigStore configStore)
 {
     StatesClient   = statesClient;
     ServiceClient  = serviceClient;
     ConfigStore    = configStore;
     CalendarClient = calendarClient;
 }
Esempio n. 2
0
        private async Task ProcessOverrides(BaseTile tile)
        {
            switch (tile)
            {
            // Calendars use a special API that isn't (might not be?) exposed via the WebSocket API.
            case CalendarTile ct:
                // Required because for some reason, the calendar API is not available
                // via the "inside" supervisor API, only the "external" fully-qualified
                // API endpoint.
                var config = await ConfigStore.GetConfigAsync();

                var calClient = new CalendarClient(new Uri(!string.IsNullOrWhiteSpace(config.Settings?.OverrideAssetUri) ? config.Settings.OverrideAssetUri : config.Settings.BaseUri), config.Settings.AccessToken);

                var state = await StatesClient.GetState(ct.EntityId);

                var calItems = await calClient.GetEvents(ct.EntityId);

                await Clients.Caller.SendCalendarInfo(ct, state, calItems);

                break;

            // Date and time are rendered server-side to verify server connection, and to enforce timezone and date format selection.
            case DateTile dt:
                var date = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(dt.TimeZoneId));
                await Clients.Caller.SendDateTime(dt, date.ToString(dt.DateFormatString ?? "dddd MMMM d"), date.ToString(dt.TimeFormatString ?? "h:mm tt"));

                break;
            }
        }
Esempio n. 3
0
        public void GetOut(int queueId, StatesClient stateClient)
        {
            if (queueId == 0)
            {
                throw new ArgumentException("OperationQueueId is empty");
            }
            ;

            if ((int)stateClient == 0)
            {
                throw new ArgumentException("State client is not undefined");
            }
            ;

            string conString = Methods.GetStringConnection();

            SqlConnection connection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand("GetOutQueue", connection);

            command.CommandType = System.Data.CommandType.StoredProcedure;

            command.Parameters.Add("@queueId", System.Data.SqlDbType.Int).Value       = queueId;
            command.Parameters.Add("@stateClientId", System.Data.SqlDbType.Int).Value = (int)stateClient;

            connection.Open();

            using (connection)
            {
                command.ExecuteNonQuery();
            };
        }
Esempio n. 4
0
        private void TimerTask(object StateObj)
        {
            TimerObjClass State = (TimerObjClass)StateObj;

            Interlocked.Increment(ref State.NumberCall);

            StatesClient stateClient = _queueRepository.GetStateClient(State.Queue.Id);

            if (stateClient != StatesClient.Welcom)
            {
                State.TimerReference.Dispose();
            }
            else
            {
                if (State.NumberCall > State.Queue.MaxNumberCall)
                {
                    State.TimerReference.Dispose();

                    _queueRepository.GetOut(State.Queue.Id, StatesClient.GetOut);

                    string connectionIdEmployee = _hub.GetConnectionIdByLogin(State.Queue.Employee.Login);
                    if (!string.IsNullOrEmpty(connectionIdEmployee))
                    {
                        State.Context.Clients.Client(connectionIdEmployee).addMessageEmployee("Клиент не принял приглашение");
                    }
                    ;
                    string connectionIdClient = _hub.GetConnectionIdByLogin(State.Queue.Client.Login);
                    if (!string.IsNullOrEmpty(connectionIdClient))
                    {
                        State.Context.Clients.Client(connectionIdClient).addMessageClient("Вы исключены из очереди");
                        State.Context.Clients.Client(connectionIdClient).changeClass("#BtnAccept", "noVisible");
                    }
                    ;

                    State.Context.Clients.All.removeClientFromQueue(State.Queue.Id);
                }
                else
                {
                    string connectionIdEmployee = _hub.GetConnectionIdByLogin(State.Queue.Employee.Login);
                    if (!string.IsNullOrEmpty(connectionIdEmployee))
                    {
                        State.Context.Clients.Client(connectionIdEmployee).changeNumberCall(State.NumberCall, State.Queue.MaxNumberCall, State.Queue.TimeCall);
                    }
                    ;
                    string connectionIdClient = _hub.GetConnectionIdByLogin(State.Queue.Client.Login);
                    if (!string.IsNullOrEmpty(connectionIdClient))
                    {
                        State.Context.Clients.Client(connectionIdClient).changeNumberCall(State.NumberCall, State.Queue.MaxNumberCall, State.Queue.TimeCall);
                    }
                    ;
                }
            }
        }
Esempio n. 5
0
        public async Task RequestTileState(string tileName)
        {
            var config = await ConfigStore.GetConfigAsync();

            var tile = config.Tiles.FirstOrDefault(t => t.Name == tileName);

            // TOOD: Refactor this into something more elegant.
            switch (tile)
            {
            case WeatherTile wt:
                var states = new Dictionary <string, StateObject> {
                    [nameof(wt.EntityId)]            = wt.StateManipulator(await StatesClient.GetState(wt.EntityId)),
                    [nameof(wt.IconEntity)]          = string.IsNullOrWhiteSpace(wt.IconEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.IconEntity)),
                    [nameof(wt.SummaryEntity)]       = string.IsNullOrWhiteSpace(wt.SummaryEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.SummaryEntity)),
                    [nameof(wt.PrecipChanceEntity)]  = string.IsNullOrWhiteSpace(wt.PrecipChanceEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.PrecipChanceEntity)),
                    [nameof(wt.HighTempEntity)]      = string.IsNullOrWhiteSpace(wt.HighTempEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.HighTempEntity)),
                    [nameof(wt.LowTempEntity)]       = string.IsNullOrWhiteSpace(wt.LowTempEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.LowTempEntity)),
                    [nameof(wt.WindSpeedEntity)]     = string.IsNullOrWhiteSpace(wt.WindSpeedEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.WindSpeedEntity)),
                    [nameof(wt.WindDirectionEntity)] = string.IsNullOrWhiteSpace(wt.WindDirectionEntity) ? null : wt.StateManipulator(await StatesClient.GetState(wt.WindDirectionEntity))
                };
                await Clients.All.SendTileStates(wt, states);

                break;

            case BaseEntityTile et:
                var state = await StatesClient.GetState(et.EntityId);

                state = et.StateManipulator(state);
                await Clients.All.SendTileState(et, state);

                break;

            case DateTile dt:
                var date = !string.IsNullOrWhiteSpace(dt.TimeZoneId)
                        ? TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(dt.TimeZoneId))
                        : DateTime.Now;
                await Clients.All.SendDateTime(dt, date.ToString(dt.DateFormatString ?? "dddd MMMM d"), date.ToString(dt.TimeFormatString ?? "h:mm tt"));

                break;

            case BlankTile _:
            case LabelTile _:
            case null:
                break;

            default:
                await Clients.All.SendWarning($"Tile of type {tile.GetType().FullName} does not have a send method.");

                break;
            }
        }
 private void Initialize()
 {
     if (!initialized)
     {
         lock (initLock)
         {
             if (!initialized)
             {
                 ClientFactory.Initialize(url, apiKey);
                 statesClient  = ClientFactory.GetClient <StatesClient>();
                 serviceClient = ClientFactory.GetClient <ServiceClient>();
                 initialized   = true;
             }
         }
     }
 }
Esempio n. 7
0
        private async Task ProcessOverrides(BaseTile tile)
        {
            switch (tile)
            {
            // Calendars use a special API that isn't (might not be?) exposed via the WebSocket API.
            case CalendarTile ct:
                await Clients.Caller.SendCalendarInfo(ct, await StatesClient.GetState(ct.EntityId), await CalendarClient.GetEvents(ct.EntityId));

                break;

            // Date and time are rendered server-side to verify server connection, and to enforce timezone and date format selection.
            case DateTile dt:
                var date = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(dt.TimeZoneId));
                await Clients.Caller.SendDateTime(dt, date.ToString(dt.DateFormatString ?? "dddd MMMM d"), date.ToString(dt.TimeFormatString ?? "h:mm tt"));

                break;
            }
        }
        private async Task ProcessOverrides(BaseTile tile)
        {
            switch (tile)
            {
            // Calendars use a special API that isn't (might not be?) exposed via the WebSocket API.
            case CalendarTile ct:
                await Clients.All.SendCalendarInfo(ct, await StatesClient.GetState(ct.EntityId), await CalendarClient.GetEvents(ct.EntityId));

                break;

            // Date and time are rendered server-side to verify server connection, and to enforce timezone and date format selection.
            case DateTile dt:
                var date = !string.IsNullOrWhiteSpace(dt.TimeZoneId)
                        ? TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(dt.TimeZoneId))
                        : DateTime.Now;
                await Clients.All.SendDateTime(dt, date.ToString(dt.DateFormatString ?? "dddd MMMM d"), date.ToString(dt.TimeFormatString ?? "h:mm tt"));

                break;
            }
        }
Esempio n. 9
0
        public Queue GetIn(string clientLogin, int operationId, StatesClient stateClient)
        {
            if (string.IsNullOrEmpty(clientLogin))
            {
                throw new ArgumentException("Client's login is null or empty");
            }
            ;

            if (operationId == 0)
            {
                throw new ArgumentException("OperationId is empty");
            }
            ;

            if ((int)stateClient == 0)
            {
                throw new ArgumentException("State client is not undefined");
            }
            ;

            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@login", System.Data.SqlDbType.VarChar)
            {
                Value = clientLogin
            });
            parameters.Add(new SqlParameter("@operationId", System.Data.SqlDbType.Int)
            {
                Value = operationId
            });
            parameters.Add(new SqlParameter("@stateClientId", System.Data.SqlDbType.Int)
            {
                Value = (int)stateClient
            });

            return(ParseQueue("GetInQueue", parameters));
        }
Esempio n. 10
0
        public StatesClient GetStateClient(int queueId)
        {
            if (queueId == 0)
            {
                throw new ArgumentException("Queue.ID is empty");
            }
            ;

            string conString = Methods.GetStringConnection();

            SqlConnection connection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand("GetStateClient", connection);

            command.Parameters.Add("@queueId", System.Data.SqlDbType.Int).Value = queueId;

            command.CommandType = System.Data.CommandType.StoredProcedure;

            connection.Open();

            StatesClient result = 0;

            using (connection)
            {
                SqlDataReader reader = command.ExecuteReader();

                using (reader)
                {
                    if (reader.Read())
                    {
                        result = (StatesClient)Convert.ToInt32(reader["StateClientId"]);
                    }
                }
            };
            return(result);
        }
Esempio n. 11
0
 public TileHub(StatesClient statesClient, ServiceClient serviceClient, IConfigStore configStore)
 {
     StatesClient  = statesClient;
     ServiceClient = serviceClient;
     ConfigStore   = configStore;
 }