Example #1
0
        public static async Task<DisplayData> RefreshAsync(int displayId)
        {
            DisplayData data = new DisplayData()
            {
                DisplayId = 0,
                IdleInterval = 0,
                Hash = 0,
                RecycleTime = null
            };
            
            using (SqlCommand cmd = new SqlCommand("sp_GetDisplayData"))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@displayId", displayId);

                await cmd.ExecuteReaderExtAsync((reader) =>
                {
                    data.DisplayId = reader.IntOrZero("DisplayId");
                    data.IdleInterval = reader.IntOrZero("IdleInterval");
                    data.Hash = reader.IntOrZero("Hash");

                    if (reader["RecycleTime"] != DBNull.Value)
                    {
                        data.RecycleTime = (TimeSpan)reader["RecycleTime"];
                    }

                    return false;
                });
            }
            
            return data;
        }
Example #2
0
        public static async Task<Content> GetDataAsync(int contentId)
        {
            Content content = null;

            using (SqlCommand cmd = new SqlCommand() 
            {
                CommandType = CommandType.Text,
                CommandText = "SELECT TOP 1 * FROM Content WHERE [email protected]",
            })
            {
                cmd.Parameters.AddWithValue("@contentId", contentId);
                await cmd.ExecuteReaderExtAsync((reader) =>
                {
                    content = new Content()
                    {
                        ContentId = reader.IntOrZero("ContentId"),
                        Name = reader.StringOrBlank("Name"),
                        Type = reader.ValueOrDefault<ContentTypes>("Type", ContentTypes.ContentType_Picture),
                        Data = reader.BytesOrNull("Data"),
                    };
                    return false;
                });
            }

            return content;
        }
Example #3
0
        public static async Task<Frame> GetNextFrameAsync(int panelId, int displayId, int previousFrameId)
		{
            Frame nci = new Frame()
            {
                PanelId = panelId,
                DisplayId = displayId
            };

            using (SqlCommand cmd = new SqlCommand("sp_GetNextFrame"))
            {
				cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@panelId", SqlDbType.Int).Value = panelId;
                cmd.Parameters.Add("@displayId", SqlDbType.Int).Value = displayId;
                cmd.Parameters.Add("@lastFrameId", SqlDbType.Int).Value = previousFrameId;

                await cmd.ExecuteReaderExtAsync((dr) =>
                {
                    nci._initfromRow(dr);
                    return false;
                });
            }

            if (nci.FrameId > 0)
            {
                switch (nci.FrameType)
                {
                    case FrameTypes.Clock:
                        nci = new Clock(nci);
                        break;

                    case FrameTypes.Html:
                        nci = new Html(nci);
                        break;

                    case FrameTypes.Memo:
                        nci = new Memo(nci);
                        break;

                    //case FrameTypes.News:

                    case FrameTypes.Outlook:
                        nci = new Outlook(nci);
                        break;

                    case FrameTypes.Picture:
                        nci = new Picture(nci);
                        break;

                    case FrameTypes.Powerbi:
                        nci = new Powerbi(nci);
                        break;

                    case FrameTypes.Report:
                        nci = new Report(nci);
                        break;

                    case FrameTypes.Video:
                        nci = new Video(nci);
                        break;

                    case FrameTypes.Weather:
                        nci = new Weather(nci);
                        break;

                    case FrameTypes.YouTube:
                        nci = new YouTube(nci);
                        break;

                    default:
                        break;
                }
            }

            return nci;
		}
Example #4
0
        public static async Task<string> GetAccessTokenAsync(int accountId)
        {
            string accessToken = null;

            await DataAccess.ExecuteTransactionAsync(async (cnn, trn) => {
                using (SqlCommand cmd = new SqlCommand()
                {
                    CommandType = CommandType.Text,
                    CommandText = "select top 1 * from AzureAccount with(updlock,rowlock) where [email protected]",
                    Connection = cnn,
                    Transaction = trn,
                })
                {
                    cmd.Parameters.AddWithValue("@accountId", accountId);

                    DateTime? expiresOn = null;
                    string clientId = null, clientSecret = null, user = null, password = null, tenantId = null;
                    Models.AzureResources resource = Models.AzureResources.AzureResource_PowerBi;
                    await cmd.ExecuteReaderExtAsync((reader) =>
                    {
                        expiresOn = reader.AsNullable<DateTime>("ExpiresOn");
                        accessToken = reader.StringOrBlank("AccessToken").Trim();
                        resource = reader.ValueOrDefault<Models.AzureResources>("Resource", Models.AzureResources.AzureResource_PowerBi);
                        clientId = reader.StringOrBlank("ClientId");
                        clientSecret = reader.StringOrBlank("ClientSecret");
                        user = reader.StringOrBlank("User");
                        password = RsaUtil.Decrypt(reader.BytesOrNull("Password"));
                        tenantId = reader.StringOrDefault("TenantId", null);
                        return false;
                    });

                    if (string.IsNullOrWhiteSpace(accessToken) || !expiresOn.HasValue || expiresOn.Value < DateTime.UtcNow)
                    {
                        TokenInfo token = await Token.GetGrantTypePasswordAsync(
                            resource,
                            clientId,
                            clientSecret,
                            user,
                            password,
                            tenantId
                            );
                        using (SqlCommand cmdu = new SqlCommand()
                        {
                            CommandType = CommandType.Text,
                            CommandText = "update AzureAccount set [email protected], [email protected] where [email protected]",
                            Connection = cnn,
                            Transaction = trn,
                        })
                        {
                            cmdu.Parameters.AddWithValue("@accountId", accountId);
                            cmdu.Parameters.AddWithValue("@accessToken", token.AccessToken);
                            cmdu.Parameters.AddWithValue("@expiresOn", token.ExpiresOn.AddMinutes(-1)); // allow 1 minute to avoid issues
                            cmdu.ExecuteNonQuery();
                        }
                        accessToken = token.AccessToken;
                    }
                }
            });

            return accessToken;
        }