Esempio n. 1
0
        //All logic pertaining to starting the service
        private void StartLogic()
        {
            if (!_serviceRunning)
            {
                //notifyIcon1.ShowBalloonTip(200, "", "EarthLive# Service Started", ToolTipIcon.Warning);
                Cfg.Load();
                var testUrl = Cfg.GetImageHostUrl();
                Scraper.ImageHost = testUrl;

                Scraper.MaxNumber = Cfg.MaxNumber;
                Scraper.UpdateImage();

                BtnStart.Enabled   = false;
                BtnStop.Enabled    = true;
                BtnSetting.Enabled = false;

                MyTimer.Interval = Cfg.Interval * 1000 * 60;
                MyTimer.Start();

                SetWallpaper();

                _serviceRunning     = true;
                LblStatus.Text      = Resources.MainForm_Running;
                LblStatus.ForeColor = Color.DarkGreen;
            }
            else if (_serviceRunning)
            {
                MessageBox.Show(Resources.MainForm_Service_already_running);
            }
            ContextMenuSetter();
        }
Esempio n. 2
0
 public static void CleanCDN()
 {
     Cfg.Load();
     if (Cfg.api_key.Length == 0)
     {
         return;
     }
     if (Cfg.api_secret.Length == 0)
     {
         return;
     }
     try
     {
         HttpWebRequest request = WebRequest.Create("https://api.cloudinary.com/v1_1/" + Cfg.cloud_name + "/resources/image/fetch?prefix=http://himawari8-dl") as HttpWebRequest;
         request.Method      = "DELETE";
         request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
         string svcCredentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(Cfg.api_key + ":" + Cfg.api_secret));
         request.Headers.Add("Authorization", "Basic " + svcCredentials);
         HttpWebResponse response = null;
         StreamReader    reader   = null;
         string          result   = null;
         for (int i = 0; i < 3; i++) // max 3 request each hour.
         {
             response = request.GetResponse() as HttpWebResponse;
             if (response.StatusCode != HttpStatusCode.OK)
             {
                 throw new Exception("[clean CND cache connection error]");
             }
             if (!response.ContentType.Contains("application/json"))
             {
                 throw new Exception("[clean CND cache no json recieved. your Internet connection is hijacked]");
             }
             reader = new StreamReader(response.GetResponseStream());
             result = reader.ReadToEnd();
             if (result.Contains("\"error\""))
             {
                 throw new Exception("[clean CND cache request error]\n" + result);
             }
             if (result.Contains("\"partial\":false"))
             {
                 Trace.WriteLine("[clean CDN cache done]");
                 break; // end of Clean CDN
             }
             else
             {
                 Trace.WriteLine("[more images to delete]");
             }
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine("[error when delete CDN cache]");
         Trace.WriteLine(e.Message);
         return;
     }
 }
Esempio n. 3
0
 private void button3_Click(object sender, EventArgs e)
 {
     Cfg.source_select = comboBox1.Text;
     Cfg.interval      = (int)(numericUpDown1.Value);
     Cfg.max_number    = (int)(numericUpDown2.Value);
     Cfg.autostart     = checkBox1.Checked;
     Cfg.display_mode  = comboBox_DisplayMode.SelectedIndex;
     Cfg.Save();
     Autostart.Set(Cfg.autostart);
 }
Esempio n. 4
0
        private void Save()
        {
            Cfg.SourceSelect = CbImageSource.Text;
            Cfg.Interval     = (int)(TxtUpdateMinutes.Value);
            Cfg.MaxNumber    = (int)(TxtMaxImageNumber.Value);
            Cfg.Autostart    = CbAutoStart.Checked;
            Cfg.DisplayMode  = CbDisplayMode.SelectedIndex;
            Cfg.Save();

            Autostart.Set(Cfg.Autostart);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            if (File.Exists(Application.StartupPath + @"\trace.log"))
            {
                File.Delete(Application.StartupPath + @"\trace.log");
            }
            if (!File.Exists(Application.ExecutablePath + ".config"))
            {
                // 生成配置文件

                //File.WriteAllText(Application.ExecutablePath + ".config"),Properties.Resources.config,System.Text.Encoding.Default);
                FileStream   fs = new FileStream(Application.ExecutablePath + ".config", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(Properties.Resources.config);
                sw.Close();
                fs.Close();
                //File.Delete(Application.StartupPath + @"\trace.log");
            }

            Trace.Listeners.Add(new TextWriterTraceListener(Application.StartupPath + @"\trace.log"));
            Trace.AutoFlush = true;

            try
            {
                Cfg.Load();
            }
            catch
            {
                return;
            }
            if (Cfg.source_selection == 0 & Cfg.cloud_name.Equals("demo"))
            {
                //#if DEBUG

                //#else
                //DialogResult dr = MessageBox.Show("WARNING: it's recommended to get images from CDN. \n 注意:推荐使用CDN方式来抓取图片,以提高稳定性。", "EarthLiveSharp");
                //if (dr == DialogResult.OK)
                //{
                //    Process.Start("https://github.com/bitdust/EarthLiveSharp/issues/32");
                //}
                //#endif
            }
            Cfg.image_folder = Application.StartupPath + @"\images";
            Cfg.Save();
            // scraper.image_source = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
        }
        private void settingsForm_Load(object sender, EventArgs e)
        {
            Cfg.Load();
            version_number.Text = Cfg.version;
            cloud_name.Text     = Cfg.cloud_name;
            autostart.Checked   = Cfg.autostart;
            interval.Value      = Cfg.interval;
            image_zoom.Value    = Cfg.zoom;
            api_key.Text        = Cfg.api_key;
            api_secret.Text     = Cfg.api_secret;
            if (Cfg.source_selection == 1)
            {
                radioButton_CDN.Checked = true;
                panel2.Enabled          = true;
            }
            else
            {
                radioButton_Orgin.Checked = true;
                panel2.Enabled            = false;
            }

            switch (Cfg.satellite)
            {
            case "Himawari8": satellite.SelectedIndex = 0; image_size.Enabled = true; break;

            case "FengYun4": satellite.SelectedIndex = 1; image_size.Enabled = false; break;

            default: satellite.SelectedIndex = 0; image_size.Enabled = true; break;
            }

            switch (Cfg.size)
            {
            case 1: image_size.SelectedIndex = 0; break;

            case 2: image_size.SelectedIndex = 1; break;

            case 4: image_size.SelectedIndex = 2; break;

            case 8: image_size.SelectedIndex = 3; break;

            case 16: image_size.SelectedIndex = 4; break;

            default: image_size.SelectedIndex = 0; break;
            }
        }
Esempio n. 7
0
 public settingsForm()
 {
     InitializeComponent();
     Cfg.Load();
     if (Cfg.source_select == "origin")
     {
         comboBox1.SelectedIndex = 0;
     }
     else
     {
         comboBox1.SelectedIndex = 1;
     }
     numericUpDown1.Value = Cfg.interval;
     numericUpDown2.Value = Cfg.max_number;
     checkBox1.Checked    = Cfg.autostart;
     label5.Text          = Cfg.version;
     comboBox_DisplayMode.SelectedIndex = Cfg.display_mode;
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                SetProcessDPIAware();
            }
            if (File.Exists(Application.StartupPath + @"\trace.log"))
            {
                File.Delete(Application.StartupPath + @"\trace.log");
            }
            Trace.Listeners.Add(new TextWriterTraceListener(Application.StartupPath + @"\trace.log"));
            Trace.AutoFlush = true;

            try
            {
                Cfg.Load();
            }
            catch
            {
                return;
            }
            if (Cfg.source_selection == 0 & Cfg.cloud_name.Equals("demo"))
            {
                #if DEBUG
                #else
                DialogResult dr = MessageBox.Show("WARNING: it's recommended to get images from CDN. \n 注意:推荐使用CDN方式来抓取图片,以提高稳定性。", "EarthLiveSharp");
                if (dr == DialogResult.OK)
                {
                    Process.Start("https://github.com/bitdust/EarthLiveSharp/issues/32");
                }
                #endif
            }
            //if (Cfg.language.Equals("en")| Cfg.language.Equals("zh-Hans")| Cfg.language.Equals("zh-Hant"))
            //{
            //    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Cfg.language);
            //}
            Cfg.image_folder = Application.StartupPath + @"\images";
            Cfg.Save();
            Scrap_wrapper.set_scraper();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                SetProcessDPIAware();
            }
            if (File.Exists(Application.StartupPath + @"\trace.log"))
            {
                File.Delete(Application.StartupPath + @"\trace.log");
            }
            Trace.Listeners.Add(new TextWriterTraceListener(Application.StartupPath + @"\trace.log"));
            Trace.AutoFlush = true;

            try
            {
                Cfg.Load();
            }
            catch
            {
                return;
            }
            if (Cfg.source_selection == 0 & Cfg.cloud_name.Equals("demo"))
            {
#if DEBUG
#else
                DialogResult dr = MessageBox.Show("WARNING: it's recommended to get images from CDN. \n 注意:推荐使用CDN方式来抓取图片,以提高稳定性。", "EarthLiveSharp");
                if (dr == DialogResult.OK)
                {
                    Process.Start("https://github.com/bitdust/EarthLiveSharp/issues/32");
                }
#endif
            }
            var now = DateTime.Now;
            Cfg.image_folder = Application.StartupPath + @"\images\";
            Cfg.Save();
            // scraper.image_source = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
        }
Esempio n. 10
0
        private void save_config()
        {
            Cfg.satellite     = satellite.Text;
            Cfg.interval      = (int)(interval.Value);
            Cfg.zoom          = (int)(image_zoom.Value);
            Cfg.autostart     = autostart.Checked;
            Cfg.setwallpaper  = setwallpaper.Checked;
            Cfg.saveTexture   = Save_Texture.Checked;
            Cfg.saveMaxCount  = (int)Save_Max_Count.Value;
            Cfg.saveDirectory = Directory_Display.Text;

            if (radioButton_CDN.Checked)
            {
                Cfg.source_selection = 1;
                Cfg.cloud_name       = cloud_name.Text;
                Cfg.api_key          = api_key.Text;
                Cfg.api_secret       = api_secret.Text;
            }
            else
            {
                Cfg.source_selection = 0;
            }
            switch (image_size.SelectedIndex)
            {
            case 0: Cfg.size = 1; break;

            case 1: Cfg.size = 2; break;

            case 2: Cfg.size = 4; break;

            case 3: Cfg.size = 8; break;

            case 4: Cfg.size = 16; break;

            default: Cfg.size = 1; break;
            }
            Cfg.Save();
            Autostart.Set(Cfg.autostart);
        }
Esempio n. 11
0
 //All logic pertaining to stopping the service
 private void stopLogic()
 {
     if (serviceRunning)
     {
         timer1.Stop();
         timer2.Stop();
         timer3.Stop();
         button_start.Enabled    = true;
         button_stop.Enabled     = false;
         button_settings.Enabled = true;
         runningLabel.Text       = "Not Running";
         runningLabel.ForeColor  = Color.DarkRed;
         serviceRunning          = false;
     }
     else if (!serviceRunning)
     {
         MessageBox.Show("Service is not currently running");
     }
     Cfg.showcoastline = radioButton1.Checked;
     Cfg.Save();
     contextMenuSetter();
 }
Esempio n. 12
0
        private void button1_Click(object sender, EventArgs e)
        {
            Cfg.interval       = (int)(interval.Value);
            Cfg.retry_interval = (int)(retry_interval.Value);
            Cfg.delete_timeout = (int)(delete_timeout.Value);
            Cfg.zoom           = (int)(image_zoom.Value);
            Cfg.autostart      = autostart.Checked;
            if (radioButton_CDN.Checked)
            {
                Cfg.source_selection = 1;
                Cfg.cloud_name       = cloud_name.Text;
                Cfg.api_key          = api_key.Text;
                Cfg.api_secret       = api_secret.Text;
                Cfg.image_source     = Cfg.cloud_url_base + Cfg.cloud_name + "/image/fetch/http://himawari8-dl.nict.go.jp/himawari8/img/D531106";
            }
            else
            {
                Cfg.source_selection = 0;
                Cfg.image_source     = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106";
            }
            switch (image_size.SelectedIndex)
            {
            case 0: Cfg.size = 1; break;

            case 1: Cfg.size = 2; break;

            case 2: Cfg.size = 4; break;

            case 3: Cfg.size = 8; break;

            case 4: Cfg.size = 16; break;

            default: Cfg.size = 1; break;
            }
            Cfg.Save();
            Autostart.Set(Cfg.autostart);
            this.Close();
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            if (File.Exists(Application.StartupPath + @"\trace.log"))
            {
                File.Delete(Application.StartupPath + @"\trace.log");
            }
            Trace.Listeners.Add(new TextWriterTraceListener(Application.StartupPath + @"\trace.log"));
            Trace.AutoFlush = true;

            try
            {
                Cfg.Load();
            }
            catch
            {
                return;
            }
            Cfg.image_folder = Application.StartupPath + @"\images";
            Cfg.Save();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
        }
        private void settingsForm_Load(object sender, EventArgs e)
        {
            Cfg.Load();
            version_number.Text = Cfg.version;
            cloud_name.Text     = Cfg.cloud_name;
            autostart.Checked   = Cfg.autostart;
            interval.Value      = Cfg.interval;
            image_zoom.Value    = Cfg.zoom;
            if (Cfg.source_selection == 1)
            {
                radioButton_CDN.Checked = true;
                label4.Visible          = true;
                cloud_name.Visible      = true;
            }
            else
            {
                radioButton_Orgin.Checked = true;
                label4.Visible            = false;
                cloud_name.Visible        = false;
            }

            switch (Cfg.size)
            {
            case 1: image_size.SelectedIndex = 0; break;

            case 2: image_size.SelectedIndex = 1; break;

            case 4: image_size.SelectedIndex = 2; break;

            case 8: image_size.SelectedIndex = 3; break;

            case 16: image_size.SelectedIndex = 4; break;

            default: image_size.SelectedIndex = 0; break;
            }
        }
Esempio n. 15
0
 public settingsForm()
 {
     InitializeComponent();
     Cfg.Load();
 }
Esempio n. 16
0
        //All logic pertaining to starting the service
        private void startLogic()
        {
            if (!serviceRunning)
            {
                //notifyIcon1.ShowBalloonTip(200, "", "EarthLive# Service Started", ToolTipIcon.Warning);
                Cfg.Load();
                if (Cfg.source_select == "cdn")
                {
                    Random rd       = new Random();
                    int    selector = rd.Next(1, 5);
                    switch (selector)
                    {
                    case 1: scraper.pic_url = Cfg.cdn1_addr; break;

                    case 2: scraper.pic_url = Cfg.cdn2_addr; break;

                    case 3: scraper.pic_url = Cfg.cdn3_addr; break;

                    case 4: scraper.pic_url = Cfg.cdn4_addr; break;

                    default: scraper.pic_url = Cfg.cdn1_addr; break;
                    }
                }
                else
                {
                    scraper.pic_url = Cfg.origin_addr;
                }
                //scraper.image_folder = Cfg.image_folder;
                scraper.image_folder    = Application.StartupPath + @"\images";
                scraper.max_number      = Cfg.max_number;
                button_start.Enabled    = false;
                button_stop.Enabled     = true;
                button_settings.Enabled = false;
                scraper.InitFolder();
                scraper.UpdateImage();
                timer1.Interval = Cfg.interval * 1000 * 60;
                timer1.Start();

                switch (Cfg.display_mode)
                {
                case 0:
                    Wallpaper.SetDefaultStyle();
                    if (scraper.saved_path.Length > 0)
                    {
                        Wallpaper.Set(scraper.saved_path);
                    }
                    break;

                case 1:
                    if (scraper.saved_path.Length > 0)
                    {
                        Wallpaper.Set(scraper.saved_path);
                    }
                    break;

                case 2:
                    break;

                default:
                    break;
                }
                ;
                serviceRunning         = true;
                runningLabel.Text      = "    Running";
                runningLabel.ForeColor = Color.DarkGreen;
            }
            else if (serviceRunning)
            {
                MessageBox.Show("Service already running");
            }
            contextMenuSetter();
        }
Esempio n. 17
0
 private void MyTimer_Tick(object sender, EventArgs e)
 {
     Scraper.ImageHost = Cfg.GetRandomCdnUrl();
     Scraper.UpdateImage();
     SetWallpaper();
 }