//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(); }
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; setwallpaper.Checked = Cfg.setwallpaper; interval.Value = Cfg.interval; image_zoom.Value = Cfg.zoom; api_key.Text = Cfg.api_key; api_secret.Text = Cfg.api_secret; Save_Texture.Checked = Cfg.saveTexture; Save_Max_Count.Value = Cfg.saveMaxCount; Directory_Display.Text = Cfg.saveDirectory; if (Cfg.source_selection == 1) { radioButton_CDN.Checked = true; panel2.Enabled = true; } else { radioButton_Orgin.Checked = true; panel2.Enabled = false; } if (Cfg.saveTexture) { panel3.Enabled = true; } else { panel3.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; } }
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; } 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()); }
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; } }
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()); }
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; }
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()); }
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; retry_interval.Value = Cfg.retry_interval; delete_timeout.Value = Cfg.delete_timeout; 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.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; } }
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; } }
public settingsForm() { InitializeComponent(); Cfg.Load(); }
//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(); }