Пример #1
0
 public HomePage()
 {
     this.InitializeComponent();
     unsplashApiService = new WallpaperService();
     this.ViewModel     = new CollectionsViewModel();
     ViewModel.InitializeCollections();
 }
 public WallpaperServiceButton(WallpaperService service)
 {
     this.ws = service;
     Image logo = new Image( pluginManager.PluginManager.parsePath(this.ws.getLogo()) );
     this.Add(logo);
     //
     this.Clicked+=doClick;
     this.ShowAll();
 }
Пример #3
0
        /// <summary>
        /// Page Loading.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void RecommendPage_OnLoading(FrameworkElement sender, object args)
        {
            GridLoading.Visibility       = Visibility.Visible;
            ProgressRingLoading.IsActive = true;

            GenerateBgService generateBgService = new GenerateBgService();

            try
            {
                // 显示背景
                RecommendPageBg.ImageSource = await generateBgService.GetBitmapImageAsync();

                // 显示诗句
                DataContext = ViewModelLocator.Instance.RecommendPageViewModel;

                string text = ShowPoetryArea.Text;

                if (localSettings.Values["SetWallpaper"] != null &&
                    localSettings.Values["SetWallpaper"].Equals(true))
                {
                    // 用户允许将每日推荐图片设置为壁纸
                    await generateBgService.CreateBackgroundImageAsync(text);

                    WallpaperService wallpaperService = new WallpaperService();
                    if (!await wallpaperService.WallpaperChanger())
                    {
                        // Todo: 当设置壁纸失败时异常处理。
                    }
                }
                else if (localSettings.Values["SetLockScreen"] != null &&
                         localSettings.Values["SetLockScreen"].Equals(true))
                {
                    // 用户允许将每日推荐图片设置为锁屏
                    await generateBgService.CreateBackgroundImageAsync(text);

                    WallpaperService wallpaperService = new WallpaperService();
                    if (!await wallpaperService.LockScreenChanger())
                    {
                        // Todo: 当设置锁屏失败时异常处理。
                    }
                }
                ProgressRingLoading.IsActive = false;
                GridLoading.Visibility       = Visibility.Collapsed;
            }
            catch (Exception imgOrTxtException)
            {
                TextBlockLoading.FontSize = 20;

                TextBlockLoading.Text = "ExceptionInfo: " + imgOrTxtException.Message +
                                        "\n抱歉,这里发生了一些错误,请您确保网络连接正常 " +
                                        "\n如果仍存在加载失败的情况,请您及时给予我们反馈" +
                                        "\n我们将在新版本中解决该问题,以带给您更好的使用体验。谢谢!";
            }
        }
Пример #4
0
        public MainWindow(WallpaperService wallpaperService, VersionService versionService)
        {
            CreateHandle();
            logger.Info("App is starting.");
            logger.Info($"App directory: {DB.Instance.AppPath}");
            _wallpaperService = wallpaperService;
            _versionService   = versionService;
            this.Icon         = Icon.FromHandle(Resources.icon.GetHicon());

            InitializeComponent();
            interactiveComponents.Add(searchBox);
            interactiveComponents.Add(searchButton);
            interactiveComponents.Add(findNewButton);

            if (!string.IsNullOrEmpty(DB.Instance.GetConfig().searchTerms))
            {
                this.searchBox.Text = DB.Instance.GetConfig().searchTerms;
            }


            newVersionLabel.Visible = versionService.IsNewerVersionAvailable();

            LoadCurrentWallpaper();

            if (_wallpaperService.IsBusy())
            {
                logger.Info("Oops, servcie busy, waiting..");
                LoadingIndicatorStart();

                new Thread(() =>
                {
                    logger.Info("Wait thread start");
                    _wallpaperService.WaitFor();
                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        if (!(this.Disposing || this.IsDisposed))
                        {
                            logger.Info("Done waiting, stopping indicator");
                            LoadingIndicatorStop();
                        }
                        else
                        {
                            logger.Warn("Window is beeing disposed, won't change indicator state");
                        }
                    });
                }).Start();
            }
        }
Пример #5
0
        public async Task TestAsync(WallpaperService wallpaperService)
        {
            using (HttpClient _httpClient = new HttpClient())
            {
                // string url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=8&n=25";
                string url = string.Format("https://cn.bing.com/HPImageArchive.aspx?format=js&idx={0}&n={1}&mkt=zh-cn", 0, 6);
                Uri    uri = new Uri(url);
                //var httpClient = new HttpClient();
                string json = await _httpClient.GetStringAsync(uri);

                WallpapersData wallPapersData = JsonConvert.DeserializeObject <WallpapersData>(json);
            }

            //var data = await wallpaperService.GetWallparper(0, 6);
            // to do...
        }
Пример #6
0
 public dbBack(WallpaperService wall, Bitmap bmp, ISharedPreferences _settings) : base(wall)
 {
     BackBMP       = bmp;
     Settings      = _settings;
     DrawIMGAction = delegate {
         try
         {
             Functions.RunOnNewThread(delegate {
                 DrawFrame();
             });
         }
         catch
         {
             DrawFrame();
         }
     };
 }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();
            //
            // TODO: Insert code to start one or more asynchronous methods using the
            //       await keyword, for example:
            //
            // await ExampleMethodAsync();
            //
            using (wallpaperService = new WallpaperService())
            {
                var result = await wallpaperService.SetRandomWallpaperAsync(false);

                Debug.WriteLine($"TASK COMPLETED RESULT: {result}");
            }



            _deferral.Complete();
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WallpaperService wallpaperService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHangfireServer();
            app.UseHangfireDashboard();

            //RecurringJob.AddOrUpdate(()=>TestAsync(wallpaperService), Cron.Minutely());

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    RecurringJob.AddOrUpdate(() => TestAsync(wallpaperService), Cron.Minutely());
                    //var data = await wallpaperService.GetWallparper(0, 6);
                    await context.Response.WriteAsync("Hello World!");
                });
            });
        }
 private void newServiceBox(WallpaperService service)
 {
     WallpaperServiceButton but = new WallpaperServiceButton(service);
     but.Clicked+=this.serviceLogoClick;
     addBox(but);
 }
 private void registerService(WallpaperService service)
 {
     if(service==null)
         return;
     this.newServiceBox(service);
 }
Пример #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            try
            {
                Target.Register <DefaultLoggingTarget>("IrpyteDefault");
                var logger = LogManager.GetCurrentClassLogger();
                if (DuplicateInstanceUtil.HandleDuplicate())
                {
                    logger.Info("Oops, app already running. Closing");
                    Application.Exit();
                }
                else
                {
                    bool autostarted = false;
                    if (args.Length > 0 && args[0].ToLower().Equals("autostart"))
                    {
                        autostarted = true;
                        Application.Exit();
                    }

                    logger.Info($"App args: {String.Join(", ", args.ToList())}");



                    var downloader     = new IrpyteDownloader(DB.Instance.GetConfig().wallpaperUri);
                    var versionService = new VersionService(downloader);

                    versionService.AssureVersion();
                    versionService.CheckVersion();


                    var wallpaperService = new WallpaperService(downloader, versionService);

                    if (autostarted)
                    {
                        logger.Info("autostarted going to tick");
                        wallpaperService.Tick();
                        logger.Info("autostarted going to GetNewWallpaper");
                        wallpaperService.GetNewWallpaper().Wait();
                    }
                    else
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        var mainWindow = new MainWindow(wallpaperService, versionService);
                        logger.Info("setting  DuplicateInstanceUtil.OnShow ");

                        DuplicateInstanceUtil.OnShow = mainWindow.Show;
                        Application.Run(mainWindow);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetType());
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Application.Exit();
            }
        }