Ejemplo n.º 1
0
        // file name is set only if it's a file
        public edit_log_settings_form(string settings, edit_type edit = edit_type.edit) {
            old_settings_ = new log_settings_string(settings);
            settings_ = new log_settings_string(settings);
            edit_ = edit;
            InitializeComponent();

            hide_tabs(typeTab);
            hide_tabs(fileTypeTab);
            cancel.Left = -100;
            load_settings();
            if (edit == edit_type.add) {
                Text = "Open Log";
                util.postpone(() => type.Focus(), 1);
                util.postpone(() => {
                    // 1.8.11+ I can preload a config after the constructor. In that case, I should not open the dropdown
                    // 1.8.7+ if it's anything else than file, we have preset some settings - just let the user see them 
                    //        (such as, when user drops an sqlite file, and we fill pretty much all details)
                    bool any_presets = settings_.type != log_type.file
                        // ... in this case, it's a file, with its name set
                        || settings_.name != "" ;
                    if ( !any_presets)
                        type.DroppedDown = true;
                    else 
                        util.bring_to_top(this);
                }, 200);
            }
            if (edit == edit_type.edit && typeTab.SelectedIndex == 1 && remoteMachineName.Text.Trim() != "")
                util.postpone(() => remotePassword.Focus(), 1);

            new Thread(check_event_log_thread) {IsBackground = true}.Start();
        }
Ejemplo n.º 2
0
        public test_log_view()
        {
            InitializeComponent();

            string file   = @"C:\john\code\buff\lw-tests\small.log";
            string syntax = "$time[0,12] $ctx1[13,10] $level[24,5] $class[' ','- '] $msg";

            var sett = new log_settings_string("");

            sett.type.set(log_type.file);
            sett.name.set(file);
            sett.syntax.set(syntax);

            lv_      = new log_view(this, "testing 123");
            lv_.Dock = DockStyle.Fill;
            this.Controls.Add(lv_);
            lv_.show_name = false;

            lv_.set_log(new log_reader(new log_parser(new file_text_reader(sett))));
            var filter = new List <raw_filter_row>();

            lv_.set_filter(filter);

            app.inst.edit_mode = app.edit_mode_type.always;
//            app.inst.edit_mode = app.edit_mode_type.with_space;
        }
Ejemplo n.º 3
0
        public void load_config(string config_file)
        {
            Debug.Assert(edit_ == edit_type.add);
            var config = parse_config.load_config_file(config_file).ToString();

            settings_     = new log_settings_string(config);
            old_settings_ = new log_settings_string(config);
            load_settings();
        }
Ejemplo n.º 4
0
        static public text_reader create_text_reader(log_settings_string settings) {
            Debug.Assert(settings.guid != "");

            switch (settings.type.get()) {
            case log_type.file:        return new file_text_reader(settings);
            case log_type.event_log:   return new event_log_reader(settings);
            case log_type.debug_print: return new debug_text_reader(settings);
            default:
                Debug.Assert(false);
                return null;
            }

        }
Ejemplo n.º 5
0
        // file name is set only if it's a file
        public edit_log_settings_form(string settings, edit_type edit = edit_type.edit)
        {
            old_settings_ = new log_settings_string(settings);
            settings_     = new log_settings_string(settings);
            edit_         = edit;
            InitializeComponent();
            fileName.Text       = settings_.type == log_type.file ? settings_.name : "";
            type.Enabled        = edit == edit_type.add;
            browserFile.Enabled = edit == edit_type.add;

            hide_tabs(typeTab);
            hide_tabs(fileTypeTab);
            cancel.Left            = -100;
            friendlyName.Text      = settings_.friendly_name;
            fileType.SelectedIndex = file_type_to_index(settings_.file_type);
            reversed.Checked       = settings_.reverse;

            update_syntax();
            ifLine.Checked = settings_.line_if_line;

            partSeparator.Text = settings_.part_separator;

            xmlDelimeter.Text = settings_.xml_delimiter;

            csvHasHeader.Checked = settings_.cvs_has_header;
            csvSeparator.Text    = settings_.cvs_separator_char;

            remoteMachineName.Text = settings_.event_remote_machine_name;
            remoteDomain.Text      = settings_.event_remote_domain;
            remoteUserName.Text    = settings_.event_remote_user_name;
            remotePassword.Text    = settings_.event_remote_password;
            selectedEventLogs.Text = settings_.event_log_type.get().Replace("|", "\r\n");

            type.SelectedIndex = type_to_index();
            if (edit == edit_type.add)
            {
                Text = "Open Log";
                settings_.guid.set(Guid.NewGuid().ToString());
                util.postpone(() => type.Focus(), 1);
                util.postpone(() => type.DroppedDown = true, 200);
            }
            if (edit == edit_type.edit && typeTab.SelectedIndex == 1 && remoteMachineName.Text.Trim() != "")
            {
                util.postpone(() => remotePassword.Focus(), 1);
            }

            new Thread(check_event_log_thread)
            {
                IsBackground = true
            }.Start();
        }
Ejemplo n.º 6
0
        public file_text_reader(log_settings_string sett) : base(sett) {
            string file = sett.name;
            buffer_ = new byte[max_read_in_one_go];
            try {
                // get absolute path - normally, this should be the absolute path, but just to be sure
                file_ = new FileInfo(file).FullName;
            } catch {
                file_ = file;
            }

            var thread = app.inst.use_file_monitoring_api ? new Thread(read_all_file_thread_file_monitoring_api) {IsBackground = true}
                                                          : new Thread(read_all_file_thread) {IsBackground = true};
            thread.Start();
        }
Ejemplo n.º 7
0
        // these are the settings that are to be saved in the context
        static public log_settings_string get_context_dependent_settings(text_reader reader, log_settings_string_readonly settings) {
            log_settings_string result;
            if (reader is file_text_reader) 
                result = settings.sub(new []{ settings.syntax.get(), settings.aliases, settings.description_template });
            else
                result = new log_settings_string( settings.ToString());

            result.is_open_first_time.reset();
            result.apply_column_positions_to_me.reset();
            result.column_positions.reset();
            result.available_columns.reset();

            return result;
        }
Ejemplo n.º 8
0
        static public text_reader create_text_reader(log_settings_string settings)
        {
            Debug.Assert(settings.guid != "");

            switch (settings.type.get())
            {
            case log_type.file:        return(new file_text_reader(settings));

            case log_type.event_log:   return(new event_log_reader(settings));

            case log_type.debug_print: return(new debug_text_reader(settings));

            default:
                Debug.Assert(false);
                return(null);
            }
        }
Ejemplo n.º 9
0
        public static bool is_file_line_by_line(string file_name, string sett)
        {
            file_name = file_name.ToLower();
            var all = new log_settings_string(sett);

            switch (all.file_type.get())
            {
            case file_log_type.line_by_line:
                return(true);

            case file_log_type.best_guess:
                // best guess
                return(guess_file_type(file_name) == file_log_type.line_by_line);

            default:
                return(false);
            }
        }
Ejemplo n.º 10
0
        // file name is set only if it's a file
        public edit_log_settings_form(string settings, edit_type edit = edit_type.edit) {
            old_settings_ = new log_settings_string(settings);
            settings_ = new log_settings_string(settings);
            edit_ = edit;
            InitializeComponent();
            fileName.Text =  settings_.type == log_type.file ? settings_.name : "" ;
            type.Enabled = edit == edit_type.add;
            browserFile.Enabled = edit == edit_type.add;

            hide_tabs(typeTab);
            hide_tabs(fileTypeTab);
            cancel.Left = -100;
            friendlyName.Text = settings_.friendly_name;
            fileType.SelectedIndex = file_type_to_index( settings_.file_type );
            reversed.Checked = settings_.reverse;

            update_syntax();
            ifLine.Checked = settings_.line_if_line;
            
            partSeparator.Text = settings_.part_separator;

            xmlDelimeter.Text = settings_.xml_delimiter;

            csvHasHeader.Checked = settings_.cvs_has_header;
            csvSeparator.Text = settings_.cvs_separator_char;

            remoteMachineName.Text = settings_.event_remote_machine_name;
            remoteDomain.Text = settings_.event_remote_domain;
            remoteUserName.Text = settings_.event_remote_user_name;
            remotePassword.Text = settings_.event_remote_password;
            selectedEventLogs.Text = settings_.event_log_type.get() .Replace("|", "\r\n");

            type.SelectedIndex = type_to_index();
            if (edit == edit_type.add) {
                Text = "Open Log";
                settings_.guid .set( Guid.NewGuid().ToString());
                util.postpone(() => type.Focus(), 1);
                util.postpone(() => type.DroppedDown = true, 200);
            }
            if (edit == edit_type.edit && typeTab.SelectedIndex == 1 && remoteMachineName.Text.Trim() != "")
                util.postpone(() => remotePassword.Focus(), 1);

            new Thread(check_event_log_thread) {IsBackground = true}.Start();
        }
Ejemplo n.º 11
0
        // file name is set only if it's a file
        public edit_log_settings_form(string settings, edit_type edit = edit_type.edit)
        {
            old_settings_ = new log_settings_string(settings);
            settings_     = new log_settings_string(settings);
            edit_         = edit;
            InitializeComponent();

            hide_tabs(typeTab);
            hide_tabs(fileTypeTab);
            cancel.Left = -100;
            load_settings();
            if (edit == edit_type.add)
            {
                Text = "Open Log";
                util.postpone(() => type.Focus(), 1);
                util.postpone(() => {
                    // 1.8.11+ I can preload a config after the constructor. In that case, I should not open the dropdown
                    // 1.8.7+ if it's anything else than file, we have preset some settings - just let the user see them
                    //        (such as, when user drops an sqlite file, and we fill pretty much all details)
                    bool any_presets = settings_.type != log_type.file
                                       // ... in this case, it's a file, with its name set
                                       || settings_.name != "";
                    if (!any_presets)
                    {
                        type.DroppedDown = true;
                    }
                    else
                    {
                        util.bring_to_top(this);
                    }
                }, 200);
            }
            if (edit == edit_type.edit && typeTab.SelectedIndex == 1 && remoteMachineName.Text.Trim() != "")
            {
                util.postpone(() => remotePassword.Focus(), 1);
            }

            new Thread(check_event_log_thread)
            {
                IsBackground = true
            }.Start();
        }
Ejemplo n.º 12
0
        // these are the settings that are to be saved in the context
        static public log_settings_string get_context_dependent_settings(text_reader reader, log_settings_string_readonly settings)
        {
            log_settings_string result;

            if (reader is file_text_reader)
            {
                result = settings.sub(new [] { settings.syntax.get(), settings.aliases, settings.description_template });
            }
            else
            {
                result = new log_settings_string(settings.ToString());
            }

            result.is_open_first_time.reset();
            result.apply_column_positions_to_me.reset();
            result.column_positions.reset();
            result.available_columns.reset();

            return(result);
        }
Ejemplo n.º 13
0
        public void load()
        {
            var sett = app.inst.sett;

            int history_count = int.Parse(sett.get("history_count", "0"));

            for (int idx = 0; idx < history_count; ++idx)
            {
                history hist = new history();
                string  guid = sett.get("history." + idx + ".guid");
                if (guid != "")
                {
                    // 1.5.6+ - guid points to the whole settings
                    string settings = sett.get("guid." + guid);
                    if (settings == "")
                    {
                        logger.Debug("history guid removed " + guid);
                        continue; // entry removed
                    }
                    Debug.Assert(settings.Contains(guid));
                    hist.from_settings(new log_settings_string(settings));
                }
                else
                {
                    // old code (pre 1.5.6)
                    string type_str = sett.get("history." + idx + "type", "file");
                    if (type_str == "0")
                    {
                        type_str = "file";
                    }
                    string name          = sett.get("history." + idx + "name");
                    string friendly_name = sett.get("history." + idx + "friendly_name");

                    var history_sett = new log_settings_string("");
                    history_sett.type.set((log_type)Enum.Parse(typeof(log_type), type_str));
                    history_sett.name.set(name);
                    history_sett.friendly_name.set(friendly_name);
                    // create a guid now
                    history_sett.guid.set(Guid.NewGuid().ToString());
                    hist.from_settings(history_sett);
                }

                static_history_.Add(hist);
            }
            static_history_ = static_history_.Where(h => {
                if (h.type == log_type.file)
                {
                    // 1.5.11 - don't include this into the list next time the user opens the app
                    //          (so that he'll see the "Drop me like it's hot" huge message)
                    if (h.name.ToLower().EndsWith("logwizardsetup.sample.log"))
                    {
                        return(false);
                    }
                    // old name of this sample file
                    if (h.name.ToLower().EndsWith("logwizardsetupsample.log"))
                    {
                        return(false);
                    }

                    if (File.Exists(h.name))
                    {
                        // 1.1.5+ - compute md5s for this
                        md5_log_keeper.inst.compute_default_md5s_for_file(h.name);
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }).ToList();
        }
Ejemplo n.º 14
0
 private void on_new_file_log(string name, string friendly_name) {
     string guid = sett_.get("file_to_guid." + name);
     if (guid != "") 
         create_text_reader(new log_settings_string(sett_.get("guid." + guid)));
     else {
         // at this point, we know it's a ***new*** file
         log_settings_string file_settings = new log_settings_string("");
         file_settings.type.set( log_type.file);
         file_settings.name.set(name);
         file_settings.friendly_name.set(friendly_name);
         file_settings.guid.set( Guid.NewGuid().ToString());
         create_text_reader(file_settings);
     }
 }
Ejemplo n.º 15
0
 public database_table_reader(log_settings_string sett) : base(sett) {
     settings.on_changed += on_settings_changed;
     mappings_ = get_db_mappings();
 }
Ejemplo n.º 16
0
        private void on_sqlite_file_drop(string sqlite_db) {
            log_settings_string sqlite_sett = new log_settings_string("");
            sqlite_sett.type.set( log_type.db);
            sqlite_sett.db_connection_string.set("Data Source=\"" + sqlite_db + "\";Version=3;new=False;datetimeformat=CurrentCulture");
            
            // find the log table
            var tables = db_util.sqlite_db_tables(sqlite_db);
            string log_table = "logtable";
            if (tables.Count == 1)
                log_table = tables[0];
            var first_starts_with_log = tables.FirstOrDefault(x => x.ToLower().StartsWith("log"));
            var first_contains_log = tables.FirstOrDefault(x => x.ToLower().Contains("log"));
            if (first_starts_with_log != null)
                log_table = first_starts_with_log;
            else if (first_contains_log != null)
                log_table = first_contains_log;
            sqlite_sett.db_table_name.set( log_table);

            // get the log fields
            var fields = db_util.sqlite_db_table_fields(sqlite_db, log_table);
            if (fields.Count > 0) {
                sqlite_sett.db_fields.set(util.concatenate(fields, "\r\n"));
                var id_field = fields.FirstOrDefault(x => x.ToLower().EndsWith("id") || x.ToLower().EndsWith( "index"));
                if (id_field != null)
                    sqlite_sett.db_id_field.set( id_field);
            }

            do_open_log( sqlite_sett.ToString(), "");
        }
Ejemplo n.º 17
0
 // checks if log is already in history - if so, updates its guid and returns true
 private bool is_log_in_history(ref log_settings_string settings) {            
     switch (settings.type.get()) {
     case log_type.file:
         string name = settings.name;
         var found = history_.FirstOrDefault(x => x.name == name);
         if (found != null) {
             settings = found.write_settings;
             return true;
         }
         break;
     case log_type.db:
         var db_provider = settings.db_provider;
         var db_conn = settings.db_connection_string;
         var found_db = history_.FirstOrDefault(x => x.settings.db_provider == db_provider && x.settings.db_connection_string == db_conn);
         if (found_db != null) {
             settings = found_db.write_settings;
             return true;
         }
         break;
     }
     return false;
 }
Ejemplo n.º 18
0
        private void create_text_reader(log_settings_string settings) {
            bool is_file = settings.type == log_type.file;
            if (text_ != null && text_.settings.guid == settings.guid) {
                if (is_file)
                    merge_notes();
                return;
            }

            if (text_ != null)
                text_.Dispose();

            create_context_for_log( settings);
            text_ = factory.create_text_reader(settings);
            on_new_log();
                
            if (log_parser_.needs_text_syntax) {
                var file_settings = log_parser_.settings;
                if ( file_settings.syntax == find_log_syntax.UNKNOWN_SYNTAX) {
                    set_status("We don't know the syntax of this Log File. We recommend you set it yourself. Press the 'Edit Log Settings' button on the top-right.",
                        status_ctrl.status_type.err);
                    show_source(true);
                }
                else if (!cur_context().has_not_empty_views)
                    set_status("Don't the columns look ok? Perpaps LogWizard did not correctly parse them... If so, Toggle the Source Pane ON (Alt-O), anc click on 'Test'.", status_ctrl.status_type.warn, 15000);
                else if ( !cur_context().has_views)
                    set_status("Why so dull? <a http://www.codeproject.com/Articles/1045528/LogWizard-Filter-your-Logs-Inside-out>Add some colors!</a>");
            } 
            force_initial_refresh_of_all_views();
        }
Ejemplo n.º 19
0
 private void fill_file_default_log_settings(log_settings_string file_settings, string name, string friendly_name) {
     file_settings.type.set( log_type.file);
     file_settings.name.set(name);
     file_settings.friendly_name.set(friendly_name);
     file_settings.guid.set( Guid.NewGuid().ToString());            
 }
Ejemplo n.º 20
0
        private void history_select(log_settings_string settings) {
            ++ignore_change_;
            bool needs_save = false;
            logHistory.SelectedIndex = -1;
            string unique_id = settings.guid;

            bool found = false;
            for (int i = 0; i < history_.Count && !found; ++i)
                if (history_[i].unique_id == unique_id) {
                    found = true;
                    // 1.6.4+ we renamed the logwizard setup sample
                    bool is_sample = settings.name.get().ToLower().EndsWith("logwizardsetup.sample.log") || settings.name.get().ToLower().EndsWith("logwizardsetupsample.log");
                    // if not default form - don't move the selection to the end
                    bool is_default_form = toggled_to_custom_ui_ < 0;
                    if (is_sample || !is_default_form)
                        logHistory.SelectedIndex = i;
                    else {
                        // whatever the user selects, move it to the end
                        history h = history_[i];
                        history_.RemoveAt(i);
                        history_.Add(h);
                        logHistory.Items.RemoveAt(i);
                        logHistory.Items.Add(h.ui_friendly_name);
                        logHistory.SelectedIndex = logHistory.Items.Count - 1;
                        needs_save = true;
                    }
                }

            if (logHistory.SelectedIndex < 0) {
                // FIXME (minor) if not on the default form -> i should not put it last (since that will be automatically loaded at restart)
                history new_ = new history();
                new_.from_settings(settings);
                history_.Add(new_);
                logHistory.Items.Add(history_.Last().ui_friendly_name);
                logHistory.SelectedIndex = logHistory.Items.Count - 1;
            }
            --ignore_change_;

            if (needs_save)
                save();
            return;
        }
Ejemplo n.º 21
0
        private static void parse_log4net_config_file(XmlNode log4net_root, string config_file, log_settings_string config) {
            string dir = new FileInfo(config_file).DirectoryName;
            var appenders = log4net_root.SelectNodes(".//appender");
            foreach (XmlNode appender in appenders) {
                var appender_type = appender.Attributes["type"].Value.ToLower();
                if (appender_type.Contains("file")) {
                    // it's a file
                    var file = appender.SelectSingleNode("./file");
                    if (file != null) {
                        string file_name = file.Attributes["value"].Value.Trim();
                        if (file_name.StartsWith("${"))
                            file_name = file_name.Substring(file_name.IndexOf("}") + 1);
                        if (file_name.StartsWith("\\"))
                            file_name = file_name.Substring(1);

                        if (!Path.IsPathRooted(file_name))
                            file_name = dir + "//" + file_name;

                        config.type.set( log_type.file);
                        config.name.set( file_name);
                        // force recomputing the syntax (in case it was already found)
                        config.syntax.set(file_text_reader.UNKNOWN_SYNTAX);
                    }

                }
                else if (appender_type.Contains("adonet")) {
                    // database
                    var type = appender.SelectSingleNode("./connectionType");
                    var connection_string = appender.SelectSingleNode("./connectionString");
                    var cmd_text = appender.SelectSingleNode("./commandText");
                    if (type != null) {
                        var db_type = type.Attributes["value"].Value;
                        // if we already have the configuration set, it means that we have a file as well - we prefer the file
                        if ( config.name == "")
                            config.type.set( log_type.db);
                        config.db_provider.set( db_util.db_connection_type_to_db_provider(db_type));
                        config.db_connection_string.set( connection_string.Attributes["value"].Value);

                        if (cmd_text != null) {
                            string sql = cmd_text.Attributes["value"].Value.ToLower().Trim();
                            if (sql.StartsWith("insert into")) {
                                var fields = db_util.insert_into_to_db_fields(sql);
                                if (fields.Count > 0) 
                                    config.db_fields.set( util.concatenate(fields, "\r\n") );
                                sql = sql.Substring(11).Trim();
                                int separator = sql.IndexOf("(");
                                if (separator > 0) {
                                    string table_name = sql.Substring(0, separator).Trim();
                                    config.db_table_name.set(table_name);
                                }
                            }
                        }
                    }
                }

                // find out pattern (syntax)
                bool syntax_found = config.syntax != file_text_reader.UNKNOWN_SYNTAX;
                if (!syntax_found) {
                    var pattern = appender.SelectSingleNode("./conversionpattern");
                    var layout = appender.SelectSingleNode("./layout");
                    if (pattern != null) {
                        var value = layout.Attributes["value"].Value;
                        if (value != null)
                            config.syntax.set(value);
                    } else if (layout != null) {
                        var value = layout.Attributes["value"].Value;
                        if (value != null) {
                            // here, the value might be for a non-standard layout - so, try to actually parse it
                            var parsed = parse_log4net_syntax.parse(value);
                            if (parsed != "")
                                config.syntax.set(value);
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        private static void parse_nlog_config_file(XmlNode nlog_root, string config_file, log_settings_string config) {
            string dir = new FileInfo(config_file).DirectoryName;
            var appenders = nlog_root.SelectNodes(".//target");
            foreach (XmlNode appender in appenders) {
                var appender_type = attribute_ending_with(appender, "type") .Value.ToLower();
                if (appender_type.Contains("file")) {
                    var file_name = appender.Attributes["fileName"].Value;
                    if (file_name.StartsWith("${"))
                        file_name = file_name.Substring(file_name.IndexOf("}") + 1);
                    if (file_name.StartsWith("\\") || file_name.StartsWith("/"))
                        file_name = file_name.Substring(1);

                    if (!Path.IsPathRooted(file_name))
                        file_name = dir + "//" + file_name;

                    config.type.set( log_type.file);
                    config.name.set( file_name);

                    var layout = attribute_ending_with(appender, "layout");
                    if (layout != null) {
                        var layout_str = layout.Value;
                        config.syntax.set(layout_str);
                    }
                }
                else if (appender_type.Contains("database")) {
                    var db_type = appender.Attributes[ "dbProvider"].Value;
                    var connection_string = appender.Attributes[ "connectionString"].Value;
                    var cmd_text = appender.Attributes[ "commandText"];
                    // if we already have the configuration set, it means that we have a file as well - we prefer the file
                    if ( config.name == "")
                        config.type.set( log_type.db);
                    config.db_provider.set( db_util.db_connection_type_to_db_provider(db_type));
                    config.db_connection_string.set( connection_string);
                    if (cmd_text != null) {
                        string sql = cmd_text.Value.ToLower().Trim();
                        if (sql.StartsWith("insert into")) {
                            var fields = db_util.insert_into_to_db_fields(sql);
                            if (fields.Count > 0) 
                                config.db_fields.set( util.concatenate(fields, "\r\n") );
                            sql = sql.Substring(11).Trim();
                            int separator = sql.IndexOf("(");
                            if (separator > 0) {
                                string table_name = sql.Substring(0, separator).Trim();
                                config.db_table_name.set(table_name);
                            }
                        }
                    }                    
                }
            }
        }
Ejemplo n.º 23
0
        // reads the config file, and sets as many settings as possible
        //
        public static log_settings_string load_config_file(string config_file) {
            log_settings_string config = new log_settings_string("");
            try {
                var doc = new XmlDocument() ;
                using ( var sr = new StringReader( File.ReadAllText(config_file)))
                    using ( var xtr = new XmlTextReader(sr) { Namespaces = false })
                        doc.Load(xtr);

                var root = doc.DocumentElement;
                var log4net = root.SelectSingleNode("//log4net");
                var nlog = root.SelectSingleNode("//nlog");
                if (root.Name == "log4net")
                    log4net = root;
                else if (root.Name == "nlog")
                    nlog = root;

                if ( log4net != null)
                    parse_log4net_config_file(log4net, config_file, config);
                else if ( nlog != null)
                    parse_nlog_config_file(nlog, config_file, config);
            } catch (Exception e) {
                logger.Error("can't read config file " + config_file + " : " + e.Message);
            }
            return config;
        }
Ejemplo n.º 24
0
        private void whatsupOpen_Click(object sender, EventArgs e) {
            var add = new edit_log_settings_form("", edit_log_settings_form.edit_type.add);
            if (add.ShowDialog(this) == DialogResult.OK) {
                log_settings_string settings = new log_settings_string(add.settings);
                if (is_log_in_history(ref settings)) {
                    // we already have this in history
                    create_text_reader(settings);
                    return;
                }
                var new_ = new history();
                new_.from_settings(settings);

                history_.Add(new_);
                ++ignore_change_;
                logHistory.Items.Add(history_.Last().ui_friendly_name);
                logHistory.SelectedIndex = logHistory.Items.Count - 1;
                --ignore_change_;

                Text = reader_title() + " - Log Wizard " + version();
                create_text_reader(new_.write_settings);
                save();
            }
        }
Ejemplo n.º 25
0
        private void whatsupOpen_Click(object sender, EventArgs e) {
            var add = new edit_log_settings_form("", edit_log_settings_form.edit_type.add);
            if (add.ShowDialog(this) == DialogResult.OK) {
                log_settings_string settings = new log_settings_string(add.settings);
                if (is_log_in_history(ref settings)) {
                    // we already have this in history
                    create_text_reader(settings);
                    return;
                }
                
                var new_ = new history();
                new_.from_settings(settings);
                history_list_.add_history(new_);
                global_ui.last_log_guid = new_.guid;

                // should not be needed
#if old_code
                recreate_history_combo();
                ++ignore_change_;
                logHistory.SelectedIndex = logHistory.Items.Count - 1;
                --ignore_change_;
#endif

                Text = reader_title();
                create_text_reader(new_.write_settings);
                save();
            }
        }
Ejemplo n.º 26
0
        // checks if log is already in history - if so, updates its guid and returns true
        private bool is_log_in_history(ref log_settings_string settings) {
            if (settings.type == log_type.file) {
                string name = settings.name;
                var found = history_.FirstOrDefault(x => x.name == name);
                if (found != null) {
                    settings = found.write_settings;
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 27
0
 public void from_text_reader(text_reader reader)
 {
     settings_ = reader.write_settings;
 }
Ejemplo n.º 28
0
        /* 1.1.25+
            - on new file (that does not match any context)
              - we will create a context matching the name of the file (if one exists, we will automatically select it)
              - by default, we'll never go to the "Default" context
              - the idea is for the uesr not to have to mistakenly delete a context when he's selecting a different type of file,
                (since he would want new filters). thus, just create a new context where he can do anything
        */
        private void create_context_for_log(log_settings_string log_settings) {
            string context_name = log_settings.context;
            if (contexts_.FirstOrDefault(x => x.name == context_name) != null)
                // in this case, I already have a context, and the context exists
                return;

            ui_context log_ctx = settings_to_context(log_settings);
            if (log_ctx.name != "Default")
                // we already have a context
                return;

            ui_context new_ctx = new ui_context();
            contexts_.Add(new_ctx);

            switch (log_settings.type.get()) {
            case log_type.file:
                string file = log_settings.name;
                Debug.Assert(file != "");
                new_ctx.name = Path.GetFileNameWithoutExtension(new FileInfo(file).Name);
                break;
            case log_type.event_log:
                new_ctx.name = least_unused_context_name("Event Log");
                break;
            case log_type.debug_print:
                new_ctx.name = least_unused_context_name("Debug");
                break;
            case log_type.db:
                new_ctx.name = least_unused_context_name("Database");
                break;
            default:
                Debug.Assert(false);
                return;
            }

            Debug.Assert(new_ctx.name != "");
            log_settings.context.set(new_ctx.name);

            update_contexts_combos_in_all_forms();
        }
Ejemplo n.º 29
0
 public void from_settings(log_settings_string sett) {
     settings_ = sett;
 }
Ejemplo n.º 30
0
        private void on_new_file_log(string name, string friendly_name) {
            string guid = sett_.get("file_to_guid." + name);
            if (guid != "") 
                create_text_reader(new log_settings_string(sett_.get("guid." + guid)));
            else {
                // at this point, we know it's a ***new*** file
                log_settings_string file_settings = new log_settings_string("");
                fill_file_default_log_settings(file_settings, name, friendly_name);

                // 1.8.16+ - once we have a context, keep using that (since the user can modify things to it)
                ui_context log_ctx = settings_to_context(file_settings);
                bool already_has_context = log_ctx.name != "Default";
                if (!already_has_context) {
                    // 1.8.11+ see if any config file found
                    var config_file = parse_config.find_config_file(name);
                    if (config_file != "") {
                        file_settings = parse_config.load_config_file(config_file);
                        fill_file_default_log_settings(file_settings, name, friendly_name);
                    }
                }
                create_text_reader(file_settings);
            }
        }
Ejemplo n.º 31
0
 public void from_text_reader(text_reader reader) {
     settings_ = reader.write_settings;
 }
Ejemplo n.º 32
0
        private void on_new_log() {
            string size = text_ is file_text_reader ? " (" + new FileInfo(text_.name).Length + " bytes)" : "";
            set_status_forever("Log: " + text_.name + size);
            dropHere.Visible = false;

            add_reader_to_history();

            var reader_settings_copy = new log_settings_string( text_.settings.ToString() );
            var context_settings_copy = new log_settings_string( settings_to_context(reader_settings_copy).default_settings.ToString());
            context_settings_copy.merge(reader_settings_copy.ToString());
            var file_text = text_ as file_text_reader;
            if (file_text != null) 
                if ( factory.guess_file_type(file_text.name) == file_log_type.line_by_line)
                    if (reader_settings_copy.syntax == file_text_reader.UNKNOWN_SYNTAX ) {
                        // file reader doesn't know syntax
                        // by default - try to find the syntax by reading the header info; otherwise, try to parse it
                        string file_to_syntax = log_to.file_to_syntax(text_.name);
                        if (file_to_syntax != "") 
                            // note: file-to-syntax overrides the context syntax
                            context_settings_copy.syntax .set(file_to_syntax);                        
                        // note: if the context already knows syntax, use that
                        else if (context_settings_copy.syntax == file_text_reader.UNKNOWN_SYNTAX) {
                            string found_syntax = file_text.try_to_find_log_syntax();
                            if (found_syntax != "" && found_syntax != file_text_reader.UNKNOWN_SYNTAX) 
                                context_settings_copy.syntax. set(found_syntax);
                        }
                    }

            text_.write_settings. merge( context_settings_copy);

            // note: we recreate the log, so that cached filters know to rebuild
            log_parser_ = new log_parser(text_);
            log_parser_.on_aliases_changed = on_aliases_changed;
            if ( text_.settings.description_template != "")
                description.set_layout( text_.settings.description_template);

            ui_context log_ctx = settings_to_context( text_.settings );
            bool same_context = log_ctx == cur_context();
            if (!same_context) {
                ++ignore_change_;
                // set_aliases context based on log
                curContextCtrl.SelectedIndex = contexts_.IndexOf(log_ctx);
                --ignore_change_;

                remove_all_log_views();
                on_context_changed();
            }

            full_log_ctrl_.set_filter(new List<raw_filter_row>());
            on_new_log_parser();
            load();

            if (log_parser_.has_multi_line_columns) 
                if (!app.inst.has_shown_details_pane) {
                    app.inst.has_shown_details_pane = true;
                    show_details(global_ui.show_details = true);
                }

            app.inst.set_log_file(selected_file_name());
            Text = reader_title();

            logger.Info("new reader " + cur_history().name);

            // at this point, some file has been dropped
            log_view_for_tab(0).Visible = true;

            notes.Enabled = text_ is file_text_reader;
            if (notes.Enabled) {
                notes.load(notes_keeper.inst.notes_file_for_file(text_.name));
                merge_notes();
            }

            util.postpone(update_list_view_edit, 250);
            util.postpone(check_are_settings_complete, 1500);
        }
Ejemplo n.º 33
0
 protected entry_text_reader_base(log_settings_string sett) : base(sett) {
     util.postpone(() => new Thread(read_entries_thread) {IsBackground = true}.Start(), 1);
 }
Ejemplo n.º 34
0
        private void do_open_log(string initial_settings_str, string config_file) {
            var add = new edit_log_settings_form(initial_settings_str, edit_log_settings_form.edit_type.add);
            if (config_file != "")
                add.load_config(config_file);
            if (add.ShowDialog(this) == DialogResult.OK) {
                log_settings_string settings = new log_settings_string(add.settings);
                if (is_log_in_history(ref settings)) {
                    // we already have this in history
                    create_text_reader(settings);
                    return;
                }
                
                var new_ = new history();
                new_.from_settings(settings);
                history_list_.add_history(new_);
                global_ui.last_log_guid = new_.guid;

                Text = reader_title();
                create_text_reader(new_.write_settings);
                save();
            }            
        }
Ejemplo n.º 35
0
 public debug_text_reader(log_settings_string sett) : base(sett) {
     settings.on_changed += (a) => force_reload();
 }
Ejemplo n.º 36
0
        private ui_context new_file_to_context(string name) {
            var default_ = contexts_.FirstOrDefault(x => x.name == "Default");
            if (!File.Exists(name))
                return default_;

            log_settings_string sett = new log_settings_string("");
            sett.type.set(log_type.file);
            sett.name.set(name);
            return settings_to_context(sett);
        }
Ejemplo n.º 37
0
 public void from_settings(log_settings_string sett)
 {
     settings_ = sett;
 }
Ejemplo n.º 38
0
 public event_log_reader(log_settings_string sett) : base(sett) {
     settings.on_changed += on_settings_changed;
     sett.name. set(friendly_name);
 }
Ejemplo n.º 39
0
        private static void load_contexts(settings_file sett) {
            logger.Debug("loading contexts");

            int history_count = int.Parse( sett.get("history_count", "0"));
            for (int idx = 0; idx < history_count; ++idx) {
                history hist = new history();
                string guid = sett.get("history." + idx + ".guid");
                if (guid != "") {
                    // 1.5.6+ - guid points to the whole settings
                    string settings = sett.get("guid." + guid);
                    if (settings == "") {
                        logger.Debug("history guid removed " + guid);
                        continue; // entry removed
                    }
                    Debug.Assert(settings.Contains(guid));
                    hist.from_settings(new log_settings_string(settings));  
                } else {
                    // old code (pre 1.5.6)
                    string type_str = sett.get("history." + idx + "type", "file");
                    if (type_str == "0")
                        type_str = "file";
                    string name = sett.get("history." + idx + "name");
                    string friendly_name = sett.get("history." + idx + "friendly_name");

                    var history_sett = new log_settings_string("");
                    history_sett.type.set( (log_type) Enum.Parse(typeof (log_type), type_str));
                    history_sett.name.set(name);
                    history_sett.friendly_name.set(friendly_name);
                    // create a guid now
                    history_sett.guid.set(Guid.NewGuid().ToString());
                    hist.from_settings(history_sett);
                }

                history_.Add( hist );
            }
            history_ = history_.Where(h => {
                if (h.type == log_type.file) {
                    // 1.5.11 - don't include this into the list next time the user opens the app
                    //          (so that he'll see the "Drop me like it's hot" huge message)
                    if (h.name.ToLower().EndsWith("logwizardsetup.sample.log"))
                        return false;
                    // old name of this sample file
                    if (h.name.ToLower().EndsWith("logwizardsetupsample.log"))
                        return false;

                    if (File.Exists(h.name))
                        // 1.1.5+ - compute md5s for this
                        md5_log_keeper.inst.compute_default_md5s_for_file(h.name);
                    else
                        return false;
                }
                return true;
            }).ToList();


            int count = int.Parse( sett.get("context_count", "1"));
            for ( int i = 0; i < count ; ++i) {
                ui_context ctx = new ui_context();
                ctx.load("context." + i);
                contexts_.Add(ctx);
            }
            // 1.1.25 - at application start - remove empty contexts (like, the user may have dragged a file, not what he wanted, dragged another)
            contexts_ = contexts_.Where(x => x.has_not_empty_views || x.name == "Default").ToList();
        }
Ejemplo n.º 40
0
 protected text_reader(log_settings_string sett) {
     settings_ = sett;
     settings_.on_changed += on_settings_changed;
     on_settings_changed("");
 }
Ejemplo n.º 41
0
 public database_table_reader(log_settings_string sett) : base(sett)
 {
     settings.on_changed += on_settings_changed;
     mappings_            = get_db_mappings();
 }