public override async Task ProcessRequestAsync(HttpContext context)
		{
			HttpRequest Request = context.Request;
			HttpResponse Response = context.Response;

            int frameId = Request.IntOrZero("frame");
            int woeid = Request.IntOrZero("woeid");
            string tempUnit = Request.StringOrBlank("tempU");
            string json = "";

            try
            {
                Weather weather = new Weather(frameId);

                if (weather.FrameId != 0)
                {
                    // get RSS feed
                    Dictionary<string, object> map = await HttpRuntime.Cache.GetOrAddAbsoluteAsync(
                        string.Format("weather_{0}_{1}_{2}_{3}", weather.FrameId, weather.Version, tempUnit, woeid),
                        async (expire) => 
                        {
                            expire.When = DateTime.Now.AddMinutes(weather.CacheInterval);
                            return await GetYahooWeatherAsync(tempUnit, woeid); 
                        });

                    JavaScriptSerializer oSerializer = new JavaScriptSerializer();
                    json = oSerializer.Serialize(map);
                }

                else
                    throw new Exception("Incorrect frame data");
            }

            catch (Exception ex)
            {
                JavaScriptSerializer s = new JavaScriptSerializer();
                json = s.Serialize(new
                {
                    Error = ex.Message,
                    //Stack = ex.StackTrace,
                    Data = new
                    {
                        WoeId = woeid,
                        TemperatureUnit = tempUnit,
                    },
                });
            }

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