示例#1
0
 public static async Task <string> GetRequestAsync(SettingsModel settings, CitySettingsModel city)
 {
     try
     {
         return(await GetRequestAsync(settings, city.Id, city.City, city.Longitude, city.Latitude, city.ZMW));
     }
     catch (Exception)
     {
         return(null);
     }
 }
示例#2
0
 public CityViewModel(CitySettingsModel city, bool isLocate)
 {
     Id         = city.Id;
     City       = city.City;
     LastUpdate = city.LastUpdate;
     longitude  = city.Longitude;
     latitude   = city.Latitude;
     zmw        = city.ZMW;
     if (isLocate)
     {
         Locate = "";
     }
     Empty = false;
 }
示例#3
0
        private async void SendWeatherForecastIn(CitySettingsModel where)
        {
            // Take action and determine when the next trip to destination
            // Insert code here.

            // Replace the hardcoded strings used here with strings
            // appropriate for your application.

            // First, create the VoiceCommandUserMessage with the strings
            // that Cortana will show and speak.
            var userMessage = new VoiceCommandUserMessage();

            userMessage.DisplayMessage = where.City + "的天气状况:";
            userMessage.SpokenMessage  = "这是" + where.City + "的天气状况";

            // Optionally, present visual information about the answer.
            // For this example, create a VoiceCommandContentTile with an
            // icon and a string.
            var destinationsContentTiles = new List <VoiceCommandContentTile>();

            var destinationTile = new VoiceCommandContentTile();

            destinationTile.ContentTileType = VoiceCommandContentTileType.TitleWithText;
            // The user can tap on the visual content to launch the app.
            // Pass in a launch argument to enable the app to deep link to a
            // page relevant to the item displayed on the content tile.
            destinationTile.AppLaunchArgument = where.Id;
            destinationTile.Title             = where.City;
            destinationTile.TextLine1         = "August 3rd 2015";
            destinationsContentTiles.Add(destinationTile);

            // Create the VoiceCommandResponse from the userMessage and list
            // of content tiles.
            var response = VoiceCommandResponse.CreateResponse(userMessage, destinationsContentTiles);

            // Cortana will present a “Go to app_name” link that the user
            // can tap to launch the app.
            // Pass in a launch to enable the app to deep link to a page
            // relevant to the voice command.
            response.AppLaunchArgument = where.Id;

            // Ask Cortana to display the user message and content tile and
            // also speak the user message.
            await voiceServiceConnection.ReportSuccessAsync(response);
        }
示例#4
0
 internal void UpdateLocation(City cityInfo)
 {
     if (settings.Cities.LocatedCity != null && cityInfo.Id == settings.Cities.LocatedCity.Id)
     {
         return;
     }
     else
     {
         var c = new CitySettingsModel(cityInfo);
         if (settings.Cities.LocatedCity != null)
         {
             Cities.RemoveAt(0);
             Cities.Insert(0, new CityViewModel(c, true));
         }
         else
         {
             Cities.Insert(0, new CityViewModel(c, false));
         }
         settings.Cities.LocatedCity = c;
         UpdateLocated();
     }
 }
        private async Task Init(SettingsModel settings, CitySettingsModel currentCity)
        {
            string resstr = await Request.GetRequestAsync(settings, currentCity);

            if (!resstr.IsNullorEmpty())
            {
                var fetchresult = HeWeatherModel.Generate(resstr, settings.Preferences.DataSource);
                if (fetchresult == null || fetchresult.DailyForecast == null || fetchresult.HourlyForecast == null)
                {
                    return;
                }
                var utcOffset = fetchresult.Location.UpdateTime - fetchresult.Location.UtcTime;
                var current   = DateTimeHelper.ReviseLoc(utcOffset);
                try
                {
                    Sender.CreateMainTileQueue(await Generator.CreateAll(currentCity, fetchresult, current));
                }
                catch (Exception)
                {
                }

                try
                {
                    if (UserProfilePersonalizationSettings.IsSupported() && settings.Preferences.SetWallPaper)
                    {
                        var todayIndex = Array.FindIndex(fetchresult.DailyForecast, x =>
                        {
                            return(x.Date.Date == current.Date);
                        });
                        if (current.Hour <= 7)
                        {
                            todayIndex--;
                        }
                        if (todayIndex < 0)
                        {
                            todayIndex = 0;
                        }
                        TimeSpan sunRise, sunSet;
                        if (fetchresult.DailyForecast[todayIndex].SunRise == default(TimeSpan) || fetchresult.DailyForecast[todayIndex].SunSet == default(TimeSpan))
                        {
                            sunRise = Core.LunarCalendar.SunRiseSet.GetRise(new Models.Location(currentCity.Latitude, currentCity.Longitude), current);
                            sunSet  = Core.LunarCalendar.SunRiseSet.GetSet(new Models.Location(currentCity.Latitude, currentCity.Longitude), current);
                        }
                        else
                        {
                            sunRise = fetchresult.DailyForecast[todayIndex].SunRise;
                            sunSet  = fetchresult.DailyForecast[todayIndex].SunSet;
                        }
                        var file = await FileIOHelper.GetFilebyUriAsync(await settings.Immersive.GetCurrentBackgroundAsync(fetchresult.NowWeather.Now.Condition, WeatherModel.CalculateIsNight(current, sunRise, sunSet)));

                        var lFile = await FileIOHelper.CreateWallPaperFileAsync(Guid.NewGuid().ToString() + ".png");

                        var    d           = PointerDevice.GetPointerDevices();
                        var    m           = d.ToArray();
                        var    scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
                        var    size        = new Size(m[0].PhysicalDeviceRect.Width, m[0].PhysicalDeviceRect.Height);
                        var    ratio       = size.Height / size.Width;
                        var    cropSize    = new Size();
                        double scale;
                        var    startPoint = new Point();
                        using (var stream = await file.OpenReadAsync())
                        {
                            var bitmap = new BitmapImage();
                            await bitmap.SetSourceAsync(stream);

                            var width  = bitmap.PixelWidth;
                            var height = bitmap.PixelHeight;
                            var center = new Point(width / 2, height / 2);
                            if (width * ratio >= height)
                            {
                                cropSize.Width  = height / ratio;
                                cropSize.Height = height;
                                scale           = size.Height / height;
                            }
                            else
                            {
                                cropSize.Width  = width;
                                cropSize.Height = width * ratio;
                                scale           = size.Width / width;
                            }

                            startPoint.X = center.X - cropSize.Width / 2;
                            startPoint.Y = center.Y - cropSize.Height / 2;
                        }
                        await ImagingHelper.CropandScaleAsync(file, lFile, startPoint, cropSize, scale);

                        var uc = await ImagingHelper.SetWallpaperAsync(lFile);
                    }
                }
                catch (Exception)
                {
                }

                if (settings.Preferences.EnableMorning)
                {
                    var shu1 = settings.Preferences.MorningNoteTime.TotalHours;

                    var tomorrow8 = DateTime.Now.Hour > shu1 ? (DateTime.Today.AddDays(1)).AddHours(shu1) : (DateTime.Today.AddHours(shu1));

                    try
                    {
                        Sender.CreateScheduledToastNotification(await(Generator.CreateToast(fetchresult, currentCity, settings, DateTimeHelper.ReviseLoc(tomorrow8, utcOffset))), tomorrow8, "MorningToast");
                    }
                    catch (Exception)
                    {
                    }
                }
                if (settings.Preferences.EnableEvening)
                {
                    var shu2       = settings.Preferences.EveningNoteTime.TotalHours;
                    var tomorrow20 = DateTime.Now.Hour > shu2 ? (DateTime.Today.AddDays(1)).AddHours(shu2) : (DateTime.Today.AddHours(shu2));
                    try
                    {
                        Sender.CreateScheduledToastNotification(await(Generator.CreateToast(fetchresult, currentCity, settings, DateTimeHelper.ReviseLoc(tomorrow20, utcOffset))), tomorrow20, "EveningToast");
                    }
                    catch (Exception)
                    {
                    }
                }
                if (settings.Preferences.EnableAlarm)
                {
                    if (!fetchresult.Alarms.IsNullorEmpty() && (DateTime.Now - settings.Preferences.LastAlertTime).TotalDays > 1)
                    {
                        Sender.CreateBadge(Generator.GenerateAlertBadge());
                        Sender.CreateToast(Generator.CreateAlertToast(fetchresult, currentCity).GetXml());
                    }
                    else
                    {
                        Sender.ClearBadge();
                    }
                    var str = Generator.CalculateWeatherAlarm(fetchresult, currentCity, settings, DateTimeHelper.ReviseLoc(DateTime.Now, utcOffset));
                    if (!str.IsNullorEmpty() && str.Length > 1 && (DateTime.Now - settings.Preferences.LastAlarmTime).TotalDays > 1)
                    {
                        Sender.CreateToast(Generator.CreateAlarmToast(str, currentCity).GetXml());
                    }
                }
                await settings.Cities.SaveDataAsync(currentCity.Id.IsNullorEmpty()?currentCity.City : currentCity.Id, resstr, settings.Preferences.DataSource);

                currentCity.Update();
                if (settings.Cities.CurrentIndex != -1)
                {
                    settings.Cities.SavedCities[settings.Cities.CurrentIndex] = currentCity;
                }
                else
                {
                    settings.Cities.LocatedCity = currentCity;
                }
                settings.Cities.Save();
            }
        }
示例#6
0
 private void ReadSettings()
 {
     settings         = SettingsModel.Current;
     currentCityModel = settings.Cities.GetCurrentCity();
     InitialConverterParameter(settings);
 }
示例#7
0
 private void SendTemperatureIn(CitySettingsModel where)
 {
     throw new NotImplementedException();
 }