Esempio n. 1
0
        public override async Task ProcessRequestAsync(HttpContext context)
		{
			HttpRequest request = context.Request;
			HttpResponse response = context.Response;

            int frameId = request.IntOrZero("frame");
            int panelId = request.IntOrZero("panel");
            int displayId = request.IntOrZero("display");
            string culture = request.StringOrBlank("culture");

			string json = "";
				
			try
			{
                // set culture
                Powerbi powerbi = new Powerbi(frameId);
                Location location = new Location(displayId);

                if (string.IsNullOrWhiteSpace(culture))
                    culture = location.Culture;
                
                if (!string.IsNullOrWhiteSpace(culture))
                {
                    System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(culture);
                    System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
                    System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
                }

                JavaScriptSerializer jss = new JavaScriptSerializer();
                json = jss.Serialize(new
                {
                    accessToken = await powerbi.GetAccessTokenAsync(),
                });
			}

            catch (Exception ex)
			{
                JavaScriptSerializer s = new JavaScriptSerializer();
                json = s.Serialize(new
                {
                    Error = ex.Message,
                    //Stack = ex.StackTrace,
                    Data = new
                    {
                        FrameId = frameId,
                        PanelId = panelId,
                        DisplayId = displayId,
                        Culture = culture,
                        Details = ex.GetType() == typeof(AzureTokenException) ? (ex as AzureTokenException).Details : null,
                    },
                });
			}

            response.Clear();
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.Cache.SetSlidingExpiration(true);
            response.Cache.SetNoStore();
            response.ContentType = "application/json";
			response.Write(json);
            response.Flush();
        }
Esempio n. 2
0
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            int    frameId   = request.IntOrZero("frame");
            int    panelId   = request.IntOrZero("panel");
            int    displayId = request.IntOrZero("display");
            string culture   = request.StringOrBlank("culture");
            int    trace     = request.IntOrZero("trace");

            string json = "";

            try
            {
                // set culture
                Powerbi  powerbi  = new Powerbi(frameId);
                Location location = new Location(displayId);

                if (string.IsNullOrWhiteSpace(culture))
                {
                    culture = location.Culture;
                }

                if (!string.IsNullOrWhiteSpace(culture))
                {
                    System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(culture);
                    System.Threading.Thread.CurrentThread.CurrentCulture   = cultureInfo;
                    System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
                }

                JavaScriptSerializer jss = new JavaScriptSerializer();
                json = jss.Serialize(new
                {
                    accessToken = await powerbi.GetAccessTokenAsync(),
                });
            }

            catch (Exception ex)
            {
                JavaScriptSerializer s = new JavaScriptSerializer();
                if (trace == 0)
                {
                    json = s.Serialize(new
                    {
                        Error = ex.Message,
                        Data  = new
                        {
                            FrameId   = frameId,
                            PanelId   = panelId,
                            DisplayId = displayId,
                            Culture   = culture,
                            Details   = ex.GetType() == typeof(AzureTokenException) ? (ex as AzureTokenException).Details : null,
                        },
                    });
                }
                else
                {
                    json = s.Serialize(new
                    {
                        Error = ex.Message,
                        Stack = ex.StackTrace,
                        Data  = new
                        {
                            FrameId   = frameId,
                            PanelId   = panelId,
                            DisplayId = displayId,
                            Culture   = culture,
                            Details   = ex.GetType() == typeof(AzureTokenException) ? (ex as AzureTokenException).Details : null,
                        },
                    });
                }
            }

            response.Clear();
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.Cache.SetSlidingExpiration(true);
            response.Cache.SetNoStore();
            response.ContentType = "application/json";
            response.Write(json);
            response.Flush();
        }
Esempio n. 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);
        }