Пример #1
0
        //new public void Reload()
        //{
        //    base.Reload();
        //    Log_SettingsLoaded(null, null);
        //}

        void Log_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e)
        {
            if (string.IsNullOrEmpty(PreWorkDir))
            {
                PreWorkDir = Regex.Replace(Cliver.Log.AppDir, @":.*", @":\" + PrefWorkDirName, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (System.Threading.Thread.CurrentThread.GetApartmentState() == System.Threading.ApartmentState.STA)
                {
                    if (!LogMessage.AskYesNo("A folder where the application will store log data is not specified. By default it will be created in the following path:\r\n" + PreWorkDir + "\r\nClick Yes if you agree, click No if you want to specify another location.", true, false))
                    {
                        System.Windows.Forms.FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
                        f.Description = "Specify a folder where the application will store log data.";
                        while (f.ShowDialog(/*MainForm.This*/) != System.Windows.Forms.DialogResult.OK)
                        {
                            ;
                        }
                        PreWorkDir = f.SelectedPath;
                    }
                }
                else
                {
                    LogMessage.Inform("A folder where the application will store log data is: " + PreWorkDir + ".\nIt can be changed in the app's settings");
                }
                Save();
            }
        }
Пример #2
0
 private void bReset_Click(object sender, EventArgs e)
 {
     if (LogMessage.AskYesNo("Do you really want to reset properties to their default values?", false))
     {
         this.splitContainer.Panel2.Controls.Clear();
         listConfigTabs.Items.Clear();
         Config.Reset();
         //Config.Save();
         ConfigForm_Load(null, null);
     }
 }
Пример #3
0
 private void StartButton_Click(object sender, EventArgs e)
 {
     if (buttonStart.Text != "Stop")
     {
         start_session();
     }
     else
     {
         if (!LogMessage.AskYesNo("Terminating Session. Are you sure to proceed?", true))
         {
             return;
         }
         Session.Close();
     }
 }
Пример #4
0
        private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (UnchangableDomainPartNumber <= 1)
            {
                if (!LogMessage.AskYesNo("UnchangableDomainPartNumber is < 2. That will make the bot crawl through external links of sites. This may consume all RAM on your comp and hang the app. Are you sure to proceed?", false))
                {
                    Cliver.Bot.Log.Main.Exit("Exit since UnchangableDomainPartNumber < 2");
                }
            }

            if (MaxPageCountPerSite < 0)
            {
                if (!LogMessage.AskYesNo("MaxPageCountPerSite is < 0. That will make the bot crawl through all links of the site independently on their quantity. This may consume all RAM on your comp and hang the app. Are you sure to proceed?", false))
                {
                    Cliver.Bot.Log.Main.Exit("MaxPageCountPerSite is < 0");
                }
            }
        }
Пример #5
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (closing)//looped by Application.Exit();
     {
         return;
     }
     if (buttonStart.Text == "Stop" && !LogMessage.AskYesNo("Terminating Session. Are you sure to proceed?", true))
     {
         e.Cancel = true;
         return;
     }
     Session.Close();
     try
     {
         closing = true;
         //Application.Exit();//on Win10 gives a system error (proabably due to loop while closing window)
     }
     catch { }
     // Environment.Exit(0);//on Win10 gives a system error (proabably due to loop while closing window)
 }
Пример #6
0
        private void Save_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (Session.This != null)
                {
                    LogMessage.Inform("You cannot change settings while the bot is running.");
                    return;
                }
                foreach (ConfigControlItem cci in listConfigTabs.Items)
                {
                    if (!cci.CC.GetData())
                    {
                        listConfigTabs.SelectedItem = cci;
                        return;
                    }
                }
                //string storage_dir = null;
                //if (Cliver.Config.ReadOnly)
                //{
                //FolderBrowserDialog d = new FolderBrowserDialog();
                //d.Description = "The current config was open as read-only and must be saved in another location. Please select a folder.";
                //d.SelectedPath = Log.GetAppCommonDataDir();
                //if (d.ShowDialog() != DialogResult.OK)
                //    return;
                //storage_dir = d.SelectedPath;
                //}
                //Config.Save(storage_dir);

                if (Bot.Config.ReadOnly && !LogMessage.AskYesNo("The current config was loaded from a not default location and will replace the config stored in the default location. Are you sure to proceed?", false))
                {
                    return;
                }
                Bot.Config.Save();
                Close();
            }
            catch (Exception ex)
            {
                LogMessage.Error(ex);
            }
        }
Пример #7
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (closing)//looped by Application.Exit();
     {
         return;
     }
     if (buttonStart.Text == "Stop" && !LogMessage.AskYesNo("Terminating Session. Are you sure to proceed?", true))
     {
         e.Cancel = true;
         return;
     }
     Session.Close();
     try
     {
         closing = true;
         Application.Exit();
     }
     catch { }
     Environment.Exit(0);
     //Thread.Sleep(1000);
     //System.Diagnostics.Process.GetCurrentProcess().Kill();
 }
Пример #8
0
        internal static bool GetCachedFile(string url, string post_parameters, out byte[] binary, out string response_url, out string cached_file)
        {
            //if (!Settings.General.flagUseFilesFromCache || url == null)
            //{
            //    binary = null;
            //    response_url = null;
            //    return false;
            //}
            lock (static_lock_variable)
            {
                if (cache_map == null)
                {
                    if (!restore_cache() && !LogMessage.AskYesNo("Could not restore cache! Continue with no cache?", false))
                    {
                        Log.Exit("Could not restore cache.");
                    }
                }
            }
            lock (cache_map)
            {
                try
                {
                    string url_post = get_url_with_post(url, post_parameters);

                    CacheInfo ci = null;
                    if (custom_cache != null)
                    {
                        string url_key = custom_cache.CreateUrlKey(url_post);
                        cache_map.TryGetValue(url_key, out ci);
                    }
                    if (ci == null)
                    {
                        cache_map.TryGetValue(url_post, out ci);
                    }
                    if (ci == null)
                    {
                        binary       = null;
                        response_url = null;
                        cached_file  = null;
                        return(false);
                    }
                    cached_file = Log.RootDir + "\\" + ci.path;
                    binary      = File.ReadAllBytes(cached_file);
                    if (ci.response_url != null)
                    {
                        response_url = ci.response_url;
                    }
                    else
                    {
                        response_url = url;
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    Log.Main.Error(e);
                    binary       = null;
                    response_url = null;
                    cached_file  = null;
                    return(false);
                }
            }
        }