コード例 #1
0
ファイル: GCal.cs プロジェクト: hylcos/HUD-Mirror
        private async Task <CalendarItem[]> getItems(String agendaID)
        {
            using (HttpClient _httpClient = new HttpClient())
            {
                List <CalendarItem> calendarItems = new List <CalendarItem>();
                WebUrl         webUrl             = new WebUrl(protocol, host, port);
                string[]       paths  = { "calendar", "v3", "calendars", "primary", "events" };
                WebUrl.Query[] querys =
                {
                    new WebUrl.Query("key",        apiKey),
                    new WebUrl.Query("calendarId", agendaID),
                    new WebUrl.Query("timeMin",    DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ")),
                    new WebUrl.Query("maxResults", "100")
                };
                webUrl.addPath(paths);
                webUrl.addQuery(querys);
                Uri        url = webUrl.compose();
                JsonObject json;
                try
                {
                    json = JsonObject.Parse(await _httpClient.GetStringAsync(url));

                    Debug.WriteLine(json);
                    JsonArray jsonArray = json.GetNamedArray("items");
                    foreach (JsonValue item in jsonArray)
                    {
                        JsonObject it = item.GetObject();
                        JsonObject start = it.GetNamedObject("start");
                        JsonObject end = it.GetNamedObject("end");
                        IJsonValue nul = null;
                        DateTime   startDate, endDate;
                        if (start.TryGetValue("date", out nul))
                        {
                            startDate = Convert.ToDateTime(nul);
                            endDate   = Convert.ToDateTime(end.GetNamedString("date"));
                        }
                        else
                        {
                            startDate = Convert.ToDateTime(start.GetNamedString("dateTime"));
                            endDate   = Convert.ToDateTime(end.GetNamedString("dateTime"));
                        }
                        calendarItems.Add(new CalendarItem(it.GetNamedString("summary"), startDate, endDate, null));
                    }
                }
                catch (Exception e)
                {
                }
                return(calendarItems.ToArray());
            }
        }
コード例 #2
0
ファイル: GCal.cs プロジェクト: hylcos/HUD-Mirror
        private String getAccessToken(String refreshToken = "")
        {
            using (HttpClient _httpClient = new HttpClient())
            {
                WebUrl   webAuthUrl = new WebUrl(protocol, host, port);
                string[] paths      = { "oauth2", "v4", "token" };
                webAuthUrl.addPath(paths);
                FormUrlEncodedContent content;
                if (config.getSetting(name, "refresh_token") == "")
                {
                    content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("code", config.getSetting(name, "auth")),
                        new KeyValuePair <string, string>("redirect_uri", "http://hylcos.com"),
                        new KeyValuePair <string, string>("client_id", "855714885654-h2ojbbar2453n1g0n5j3f0kp9g4pmhll.apps.googleusercontent.com"),
                        new KeyValuePair <string, string>("client_secret", "nyBiwLPPCGTL6HoJhQgY4RLs"),
                        new KeyValuePair <string, string>("grant_type", "authorization_code")
                    });
                }
                else
                {
                    content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("refresh_token", config.getSetting(name, "refresh_token")),
                        new KeyValuePair <string, string>("redirect_uri", "http://hylcos.com"),
                        new KeyValuePair <string, string>("client_id", "855714885654-h2ojbbar2453n1g0n5j3f0kp9g4pmhll.apps.googleusercontent.com"),
                        new KeyValuePair <string, string>("client_secret", "nyBiwLPPCGTL6HoJhQgY4RLs"),
                        new KeyValuePair <string, string>("grant_type", "refresh_token")
                    });
                }
                JsonObject postJson;

                try
                {
                    var result = _httpClient.PostAsync(webAuthUrl.compose().ToString(), content).Result;
                    postJson = JsonObject.Parse(result.Content.ReadAsStringAsync().Result);
                    config.setSetting(name, "access_token", postJson.GetNamedString("access_token"));
                    Debug.WriteLine("Refresh token");
                    refreshToken = postJson.GetNamedString("refresh_token");
                    config.setSetting(name, "refresh_token", refreshToken);
                }
                catch
                {
                    Debug.WriteLine("GCAL: Something Happend !!!!");
                }

                return(access_token);
            }
        }
コード例 #3
0
ファイル: GCal.cs プロジェクト: hylcos/HUD-Mirror
        private async Task <CalendarItem[]> getCalendars()
        {
            using (HttpClient _httpClient = new HttpClient())
            {
                List <CalendarItem> calendarItems = new List <CalendarItem>();
                WebUrl         webUrl             = new WebUrl(protocol, host, port);
                string[]       paths  = { "calendar", "v3", "users", "me", "calendarList" };
                WebUrl.Query[] querys =
                {
                    new WebUrl.Query("key",          apiKey),
                    new WebUrl.Query("access_token", config.getSetting(name, "access_token"))
                };
                webUrl.addPath(paths);
                webUrl.addQuery(querys);
                Uri        url = webUrl.compose();
                JsonObject json;
                try
                {
                    json = JsonObject.Parse(await _httpClient.GetStringAsync(url));
                    JsonArray jsonArray = json.GetNamedArray("items");
                    foreach (JsonValue item in jsonArray)
                    {
                        JsonObject it = item.GetObject();
                        String     id = it.GetNamedString("id");
                        Debug.WriteLine(id);
                        CalendarItem[] tmpCalendarItems = await getItems(id);

                        calendarItems.AddRange(tmpCalendarItems);
                        Debug.WriteLine(id);
                    }
                }
                catch (Exception e)
                {
                    access_token = getAccessToken(refresh_token);
                }
                return(calendarItems.ToArray());
            }
        }
コード例 #4
0
        public async Task <Forecast> getForecast()
        {
            //List<int> forecasts = new List<int>();
            // Forecast[][] forecasts = new Forecast[6][];
            Forecast forecast = null;
            WebUrl   webUrl   = new WebUrl(protocol, host, port);

            string[] paths =
            {
                "data",
                "2.5",
                "weather"
            };
            WebUrl.Query[] querys =
            {
                new WebUrl.Query("lat",   config.getSetting(name,              "lat")),
                new WebUrl.Query("lon",   config.getSetting(name,              "long")),
                new WebUrl.Query("mode",  "xml"),
                new WebUrl.Query("appid", "11e536b32932b598cfb0b085d19fb203"),
                new WebUrl.Query("units", "metric")
            };
            webUrl.addPath(paths);
            webUrl.addQuery(querys);
            Uri url = webUrl.compose();

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(await httpClient.GetStringAsync(url));
                Debug.WriteLine(xmlDocument.ToString());
                XmlNode  element = xmlDocument["current"];
                DateTime sunset = new DateTime(), sunrise = new DateTime();
                String   mode = "", icon = "";
                String   temp = "", minTemp = "", maxTemp = "";
                String   speed = "", direction = "";
                String   location = "";
                foreach (XmlNode x in element)
                {
                    XmlAttributeCollection attributes = x.Attributes;
                    switch (x.Name)
                    {
                    case "city":
                        XmlNode city = x["sun"];
                        location = attributes[1].Value;
                        bool isDayLight = TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Now);

                        if (isDayLight)
                        {
                            sunrise = Convert.ToDateTime(city.Attributes[0].Value).AddHours(TimeZoneInfo.Local.BaseUtcOffset.TotalHours + 1);
                            sunset  = Convert.ToDateTime(city.Attributes[1].Value).AddHours(TimeZoneInfo.Local.BaseUtcOffset.TotalHours + 1);
                        }
                        else
                        {
                            sunrise = Convert.ToDateTime(city.Attributes[0].Value).AddHours(TimeZoneInfo.Local.BaseUtcOffset.TotalHours);
                            sunset  = Convert.ToDateTime(city.Attributes[1].Value).AddHours(TimeZoneInfo.Local.BaseUtcOffset.TotalHours);
                        }


                        break;

                    case "temperature":
                        temp    = attributes[0].Value;
                        minTemp = attributes[1].Value;
                        maxTemp = attributes[2].Value;
                        break;

                    case "weather":
                        mode = attributes[1].Value;
                        icon = attributes[2].Value;
                        break;

                    case "wind":
                        XmlNode speedNode     = x["speed"];
                        XmlNode directionNode = x["direction"];
                        speed     = speedNode.Attributes[1].Value;
                        direction = directionNode.Attributes[0].Value;
                        break;
                    }
                }
                forecast = new Forecast(sunrise, sunset, mode, icon, direction, speed, temp, minTemp, maxTemp, location);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
            return(forecast);
        }
コード例 #5
0
        public Nos(Grid UiRoot, Config config) : base(UiRoot, "News", config, 800, 300, new Thickness(10, 110, 10, 10), HorizontalAlignment.Right, VerticalAlignment.Top, TimeSpan.FromMinutes(5))
        {
            state = config.getEnabled(name);

            maxScrollSlots = ((int)widgetBox.Height / (fontsize + margin)) + 1;
            webUrl         = new WebUrl(protocol, host, port);
            string[] paths =
            {
                "nosjournaal"
            };
            WebUrl.Query[] querys =
            {
                new WebUrl.Query("format", "xml")
            };
            webUrl.addPath(paths);
            webUrl.addQuery(querys);
            rssUri     = webUrl.compose();
            httpClient = new HttpClient();

            clearWidget(); //just to be sure

            headlineBox = new Grid();

            Color transBlack = new Color();

            transBlack.A = 0;
            transBlack.R = 0;
            transBlack.G = 0;
            transBlack.B = 0;

            LinearGradientBrush linearTop = new LinearGradientBrush();

            linearTop.StartPoint = new Point(0.5, 0);
            linearTop.EndPoint   = new Point(0.5, 1);
            linearTop.GradientStops.Add(new GradientStop()
            {
                Color = Colors.Black, Offset = 0.0
            });
            linearTop.GradientStops.Add(new GradientStop()
            {
                Color = transBlack, Offset = 1.0
            });

            Rectangle topFade = new Rectangle();

            topFade.Height            = 30;
            topFade.VerticalAlignment = VerticalAlignment.Top;
            topFade.Fill = linearTop;


            LinearGradientBrush linearBottom = new LinearGradientBrush();

            linearBottom.StartPoint = new Point(0.5, 0);
            linearBottom.EndPoint   = new Point(0.5, 1);
            linearBottom.GradientStops.Add(new GradientStop()
            {
                Color = Colors.Black, Offset = 1.0
            });
            linearBottom.GradientStops.Add(new GradientStop()
            {
                Color = transBlack, Offset = 0.0
            });

            Rectangle bottomFade = new Rectangle();

            bottomFade.Height            = 30;
            bottomFade.VerticalAlignment = VerticalAlignment.Bottom;
            bottomFade.Fill = linearBottom;

            Rectangle topHide = new Rectangle();

            topHide.Height            = margin + fontsize;
            topHide.VerticalAlignment = VerticalAlignment.Top;
            topHide.Margin            = new Thickness(0, -(margin + fontsize), 0, 0);
            topHide.Fill = new SolidColorBrush(Colors.Black);

            TextBlock topText = new TextBlock();

            topText.Height            = margin + fontsize;
            topText.VerticalAlignment = VerticalAlignment.Top;
            topText.Margin            = new Thickness(0, -(margin + fontsize), 0, 0);
            topText.Text                = "NIEUWS";
            topText.FontSize            = 20;
            topText.HorizontalAlignment = HorizontalAlignment.Right;
            topText.Foreground          = new SolidColorBrush(Colors.White);
            topText.FontWeight          = FontWeights.Bold;

            addToWidget(headlineBox);

            addToWidget(topHide);
            addToWidget(topFade);
            addToWidget(bottomFade);
            addToWidget(topText);
            ScrollThread();
        }