Exemplo n.º 1
0
 public UpdateTileTask()
 {
     userService = UserService.GetInstance();
     weatherService = WeatherService.GetInstance();
     userRespose = new GetUserRespose();
     userCityRespose = new GetUserCityRespose();
     weatherTypeRespose = new GetWeatherTypeRespose();
 }
Exemplo n.º 2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();
            //用户配置
            userRespose = await userService.GetUserAsync();
            bool IsAutoUpdateTime = false;
            //是否处于停止更新时间
            if (userRespose.UserConfig.IsAutoUpdateTimeSpan == 1)
            {
                IsAutoUpdateTime = IsAutoUpdateByTime();
            }
            if (!IsAutoUpdateTime)
            {
                //天气类型
                weatherTypeRespose = await weatherService.GetWeatherTypeAsync();

                //默认城市
                var defaultCity = await GetDefaultCity();

                if (defaultCity != null)
                {
                    if (userRespose.UserConfig.IsAutoUpdateForCity == 1)
                    {
                        //有网络
                        if (NetHelper.IsNetworkAvailable())
                        {
                            //无论使用移动数据还是WIFI都允许自动更新
                            if (userRespose.UserConfig.IsWifiAutoUpdate == 0)
                            {
                                await SetWeatherByNetTask(defaultCity);
                            }
                            else //使用WIFI更新
                            {
                                if (NetHelper.IsWifiConnection())
                                {
                                    await SetWeatherByNetTask(defaultCity);
                                }
                                else
                                {
                                    await GetWeatherByClientTask(defaultCity);
                                }
                            }
                        }
                        else
                        {
                            await GetWeatherByClientTask(defaultCity);
                        }
                    }
                }
            }
            //表示完成任务
            _deferral.Complete();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
        /// 逻辑上等同于 main() 或 WinMain()。
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += this.OnSuspending;

            userService = UserService.GetInstance();
            settingService = SettingService.GetInstance();

            userRespose = new GetUserRespose();
            settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();

        }
Exemplo n.º 4
0
 public SettingPage()
 {
     this.InitializeComponent();
     this.navigationHelper = new NavigationHelper(this);
     settingService = SettingService.GetInstance();
     userService = UserService.GetInstance();
     colorService = ColorService.GetInstance();
     switchesRespose = new GetSettingSwitchesRespose();
     autoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();
     userRespose = new GetUserRespose();
     colorResponse = new GetColorRespose();
 }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();

            userRespose = await userService.GetUserAsync();

            bool IsAutoUpdateTime = false;

            //是否处于停止更新时间
            if (userRespose.UserConfig.IsAutoUpdateTimeSpan == 1)
            {
                IsAutoUpdateTime = IsAutoUpdateByTime();
            }

            if (!IsAutoUpdateTime)
            {
                userCityRespose = await userService.GetUserCityAsync();

                if (userCityRespose != null && userRespose != null)
                {
                    //网络是否开启
                    if (NetHelper.IsNetworkAvailable())
                    {
                        //无论使用移动数据还是WIFI都允许自动更新
                        if (userRespose.UserConfig.IsWifiAutoUpdate == 0)
                        {
                            await UpdateWeather();
                        }
                        else
                        {
                            if (NetHelper.IsWifiConnection())
                            {
                                await UpdateWeather();
                            }
                            else
                            {
                                await UpdateWeatherByClientTask();
                            }
                        }
                    }
                    else
                    {
                        await UpdateWeatherByClientTask();
                    }
                }
            }
            //表示完成任务
            _deferral.Complete();
        }
Exemplo n.º 6
0
        public SettingPage()
        {
            this.InitializeComponent();

            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
            this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

            settingService = SettingService.GetInstance();
            userService = UserService.GetInstance();
            switchesRespose = new GetSettingSwitchesRespose();
            autoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();
            userRespose = new GetUserRespose();

        }
Exemplo n.º 7
0
        /// <summary>
        /// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
        /// 逻辑上等同于 main() 或 WinMain()。
        /// </summary>
        public App()
        {
            this.RequestedTheme = ApplicationTheme.Dark;
            this.InitializeComponent();
            this.Suspending += this.OnSuspending;

            userService = UserService.GetInstance();
            settingService = SettingService.GetInstance();
            colorService = ColorService.GetInstance();
            userRespose = new GetUserRespose();
            settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();

            HardwareButtons.BackPressed += HardwareButtons_BackPressed;

        }
Exemplo n.º 8
0
        public MyCityPage()
        {
            this.InitializeComponent();

            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
            this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

            userService = UserService.GetInstance();
            weatherService = WeatherService.GetInstance();
            userRespose = new GetUserRespose();
            userCityRespose = new GetUserCityRespose();
            weatherTypeRespose = new GetWeatherTypeRespose();
            weatherRespose = new GetWeatherRespose();
            myCityPage = new ViewModel.MyCityPage();
            myCityPageModelList = new List<ViewModel.MyCityPageModel>();

        }
Exemplo n.º 9
0
        public PivotPage()
        {
            this.InitializeComponent();

            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
            this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
            this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;

            userService = UserService.GetInstance();
            weatherService = WeatherService.GetInstance();
            settingService = SettingService.GetInstance();
            userRespose = new GetUserRespose();
            userCityRespose = new GetUserCityRespose();
            weatherRespose = new GetWeatherRespose();
            weatherTypeRespose = new GetWeatherTypeRespose();
            settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();
        }
Exemplo n.º 10
0
        public MainPage()
        {
            this.navigationHelper = new NavigationHelper(this);
            this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;

            userService = UserService.GetInstance();
            weatherService = WeatherService.GetInstance();
            settingService = SettingService.GetInstance();
            colorService = ColorService.GetInstance();

            userRespose = new GetUserRespose();
            userCityRespose = new GetUserCityRespose();
            weatherRespose = new GetWeatherRespose();
            weatherTypeRespose = new GetWeatherTypeRespose();
            settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();
            colorResponse = new GetColorRespose();
            homePageModel = new HomePageModel();


            this.InitializeComponent();
            Loaded += MainPage_Loaded;
        }
Exemplo n.º 11
0
        /// <summary>
        /// 此部分中提供的方法只是用于使
        /// NavigationHelper 可响应页面的导航方法。
        /// <para>
        /// 应将页面特有的逻辑放入用于
        /// <see cref="NavigationHelper.LoadState"/>
        /// 和 <see cref="NavigationHelper.SaveState"/> 的事件处理程序中。
        /// 除了在会话期间保留的页面状态之外
        /// LoadState 方法中还提供导航参数。
        /// </para>
        /// </summary>
        /// <param name="e">提供导航方法数据和
        /// 无法取消导航请求的事件处理程序。</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            try
            {
                userCityRespose = await userService.GetUserCityAsync();

                userRespose = await userService.GetUserAsync();

                weatherTypeRespose = await weatherService.GetWeatherTypeAsync();

                if (userCityRespose != null && userRespose != null && weatherTypeRespose != null)
                {
                    await GetWeather(0);
                }

            }
            catch (Exception)
            {

                throw;
            }


        }
Exemplo n.º 12
0
        /// <summary>
        /// 此部分中提供的方法只是用于使
        /// NavigationHelper 可响应页面的导航方法。
        /// <para>
        /// 应将页面特有的逻辑放入用于
        /// <see cref="NavigationHelper.LoadState"/>
        /// 和 <see cref="NavigationHelper.SaveState"/> 的事件处理程序中。
        /// 除了在会话期间保留的页面状态之外
        /// LoadState 方法中还提供导航参数。
        /// </para>
        /// </summary>
        /// <param name="e">提供导航方法数据和
        /// 无法取消导航请求的事件处理程序。</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            colorResponse = new GetColorRespose();

            StatusBar sb = StatusBar.GetForCurrentView();
            await sb.HideAsync();

            VisualStateManager.GoToState(this, "MoreHide", false);
            cityId = e.Parameter == null ? "" : e.Parameter.ToString();
            this.navigationHelper.OnNavigatedTo(e);

            userCityRespose = await userService.GetUserCityAsync();

            if (userCityRespose == null)
            {
                Frame.Navigate(typeof(AddCityPage), 1);
                return;
            }
            else
            {
                if (cityId == "")
                {
                    cityId = userCityRespose.UserCities.FirstOrDefault().CityId;
                }
                try
                {
                    userRespose = await userService.GetUserAsync();
                    weatherTypeRespose = await weatherService.GetWeatherTypeAsync();
                    await GetWeather(cityId, 0);

                    colorResponse = await colorService.GetColorAsync();
                    int timeSection = TimeHelper.GetNowSectionByWeight();
                    ChangeBgColor(timeSection);


                }
                catch (Exception)
                {


                }
                _timer = new DispatcherTimer();
                _timer.Interval = TimeSpan.FromMinutes(1);
                _timer.Tick += _timer_Tick;
                _timer.Start();
            }

        }
Exemplo n.º 13
0
        /// <summary>
        /// 此部分中提供的方法只是用于使
        /// NavigationHelper 可响应页面的导航方法。
        /// <para>
        /// 应将页面特有的逻辑放入用于
        /// <see cref="NavigationHelper.LoadState"/>
        /// 和 <see cref="NavigationHelper.SaveState"/> 的事件处理程序中。
        /// 除了在会话期间保留的页面状态之外
        /// LoadState 方法中还提供导航参数。
        /// </para>
        /// </summary>
        /// <param name="e">提供导航方法数据和
        /// 无法取消导航请求的事件处理程序。</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            cityId = e.Parameter == null ? "" : e.Parameter.ToString();
            this.navigationHelper.OnNavigatedTo(e);

            userCityRespose = await userService.GetUserCityAsync();

            if (userCityRespose == null)
            {
                Frame.Navigate(typeof(AddCityPage), 1);
                return;
            }
            else
            {
                userRespose = await userService.GetUserAsync();
                weatherTypeRespose = await weatherService.GetWeatherTypeAsync();
                await GetWeather(cityId, 0);
            }

            HardwareButtons.BackPressed += HardwareButtons_BackPressed;

        }
Exemplo n.º 14
0
        private async Task LoadData()
        {
            switchesRespose = settingService.GetSettingSwitches();
            autoUpdateTimeRepose = settingService.GetSettingAutoUpdateTime();
            userRespose = await userService.GetUserAsync();

            ViewModel.AutoUpdateSettingPage autoUpdateSettingPage = new ViewModel.AutoUpdateSettingPage()
            {
                Switches = switchesRespose.Switches,
                AutoUpdateTimes = autoUpdateTimeRepose.AutoUpdateTimes
            };
            ViewModel.GeneralSettingPage generalSettingPage = new ViewModel.GeneralSettingPage()
            {
                Switches = switchesRespose.Switches
            };
            ViewModel.SettingPage settingPage = new ViewModel.SettingPage()
            {
                AutoUpdateSettingPage = autoUpdateSettingPage,
                GeneralSettingPage = generalSettingPage,
                UserConfig = userRespose.UserConfig

            };
            colorResponse = await colorService.GetColorAsync();
            this.LVMood.DataContext = colorResponse.UserColors;
            this.LayoutRoot.DataContext = null;
            this.LayoutRoot.DataContext = settingPage;
        }
Exemplo n.º 15
0
        private async void LoadData()
        {
            switchesRespose = settingService.GetSettingSwitches();
            autoUpdateTimeRepose = settingService.GetSettingAutoUpdateTime();
            userRespose = await userService.GetUserAsync();

            ViewModel.AutoUpdateSettingPage autoUpdateSettingPage = new ViewModel.AutoUpdateSettingPage()
            {
                Switches = switchesRespose.Switches,
                AutoUpdateTimes = autoUpdateTimeRepose.AutoUpdateTimes
            };
            ViewModel.GeneralSettingPage generalSettingPage = new ViewModel.GeneralSettingPage()
            {
                Switches = switchesRespose.Switches
            };
            ViewModel.SettingPage settingPage = new ViewModel.SettingPage()
            {
                AutoUpdateSettingPage = autoUpdateSettingPage,
                GeneralSettingPage = generalSettingPage,
                UserConfig = userRespose.UserConfig

            };
            LayoutRoot.DataContext = settingPage;
        }
Exemplo n.º 16
0
        /// <summary>
        /// 创建后台任务
        /// </summary>
        /// <param name="taskName"></param>
        /// <param name="taskEntryPoint"></param>
        private async void CreateTask(string taskName, string taskEntryPoint)
        {
            userRespose = await userService.GetUserAsync();

            BackgroundTaskExecute backgroundTaskExecute = new BackgroundTaskExecute();
            if (BackgroundTaskHelper.IsExist(taskName))
            {
                backgroundTaskExecute.Execute(taskName);
            }
            else
            {
                settingAutoUpdateTimeRepose = settingService.GetSettingAutoUpdateTime();
                int time = settingAutoUpdateTimeRepose.AutoUpdateTimes.FirstOrDefault(x => x.Id == userRespose.UserConfig.AutoUpdateTime).Time;
                backgroundTaskExecute.Create(taskName, taskEntryPoint, time, null);
            }
        }