set() public method

public set ( string name, string val ) : void
name string
val string
return void
示例#1
0
 private void on_settings_changed(string name)
 {
     if (name != "name")
     {
         settings_.set("name", friendly_name);
     }
 }
 public void merge_settings(settings_as_string_readonly other_sett, bool edited_syntax_now)
 {
     if (edited_syntax_now)
     {
         if (default_settings_.get("syntax") == "")
         {
             default_settings_.set("syntax", other_sett.get("syntax"));
         }
     }
     default_settings_.set("aliases", other_sett.get("aliases"));
     default_settings_.set("description_template", other_sett.get("description_template"));
 }
示例#3
0
        // 'other' overrides all we have
        public settings_as_string merge_copy(settings_as_string_readonly other)
        {
            settings_as_string merged = new settings_as_string(ToString());

            var other_names = other.names();

            foreach (string name in other_names)
            {
                merged.set(name, other.get(name));
            }

            return(merged);
        }
        private void load_save(bool load, string prefix)
        {
            app.load_save(load, ref name, prefix + ".name", "Default");

            string settings_str = default_settings_.ToString();

            if (load)
            {
                app.load_save(load, ref settings_str, prefix + ".default_settings");
                default_settings_ = new settings_as_string(settings_str);

                if (settings_str == "")
                {
                    // ... 1.4.8- kept the old name for persistenting
                    app.load_save(load, ref settings_str, prefix + ".default_syntax");
                    if (settings_str != "")
                    {
                        default_settings_.set("syntax", settings_str);
                    }
                }
            }
            else
            {
                app.load_save(load, ref settings_str, prefix + ".default_settings");
            }

            int view_count = views.Count;

            app.load_save(load, ref view_count, prefix + ".view_count", 0);
            if (load)
            {
                views.Clear();
                while (views.Count < view_count)
                {
                    views.Add(new ui_view());
                }
            }

            for (int i = 0; i < view_count; ++i)
            {
                views[i].load_save(load, prefix + ".view" + i + ".");
            }

            if (load && views.Count == 0)
            {
                views.Add(new ui_view()
                {
                    is_default_name = true, name = "View_1"
                });
            }
        }
示例#5
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";

            settings_as_string sett = new settings_as_string("");
            sett.set("type", "file");
            sett.set("name", file);
            sett.set("syntax", 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;
        }
示例#6
0
        private ui_context new_file_to_context(string name) {
            var default_ = contexts_.FirstOrDefault(x => x.name == "Default");
            if (!File.Exists(name))
                return default_;

            settings_as_string sett = new settings_as_string("");
            sett.set("type", "file");
            sett.set("name", name);
            return settings_to_context(sett);
        }
示例#7
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 settings_as_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");

                    settings_as_string history_sett = new settings_as_string("");
                    history_sett.set("type", type_str);
                    history_sett.set("name", name);
                    history_sett.set("friendly_name", friendly_name);
                    // create a guid now
                    history_sett.set("guid", Guid.NewGuid().ToString());
                    hist.from_settings(history_sett);
                }

                history_.Add( hist );
            }
            history_ = history_.Where(h => {
                if (h.type == history.entry_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.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();
        }
示例#8
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;

            if (history_.Count < 1)
                history_select(text_.settings);

            var reader_settings_copy = new settings_as_string( text_.settings.ToString() );
            var context_settings_copy = new settings_as_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) == "line-by-line")
                    if (reader_settings_copy.get("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.set("syntax", file_to_syntax);                        
                        // note: if the context already knows syntax, use that
                        else if (context_settings_copy.get("syntax") == "") {
                            string found_syntax = file_text.try_to_find_log_syntax();
                            if (found_syntax != "" && found_syntax != file_text_reader.UNKNOWN_SYNTAX) 
                                context_settings_copy.set("syntax", found_syntax);
                        }
                    }            

            text_.merge_setings( 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.get("description_template") != "")
                description.set_layout( text_.settings.get("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);
                }

            add_reader_to_history();
            app.inst.set_log_file(selected_file_name());
            Text = reader_title() + " - Log Wizard " + version();

            logger.Info("new reader " + history_[logHistory.SelectedIndex].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);
        }
示例#9
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 settings_as_string(sett_.get("guid." + guid)));
     else {
         // at this point, we know it's a ***new*** file
         settings_as_string file_settings = new settings_as_string("");
         file_settings.set("type", "file");
         file_settings.set("name", name);
         file_settings.set("friendly_name", friendly_name);
         file_settings.set("guid", Guid.NewGuid().ToString());
         create_text_reader(file_settings);
     }
 }
示例#10
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(settings_as_string log_settings) {
            string context_name = log_settings.get("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.get("type")) {
            case "file":
                string file = log_settings.get("name");
                Debug.Assert(file != "");
                new_ctx.name = Path.GetFileNameWithoutExtension(new FileInfo(file).Name);
                break;
            case "event_log":
                new_ctx.name = least_unused_context_name("Event Log");
                break;
            case "debug_print":
                new_ctx.name = least_unused_context_name("Debug");
                break;
            default:
                Debug.Assert(false);
                return;
            }

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

            update_contexts_combos_in_all_forms();
        }
示例#11
0
 public event_log_reader(settings_as_string sett) : base(sett) {
     settings.on_changed += on_settings_changed;
     sett.set("name", friendly_name);
     reverse_ = settings.get("event.reversed", "0") != "0"; 
 }
        // 'other' overrides all we have
        public settings_as_string merge_copy(settings_as_string_readonly other) {
            settings_as_string merged = new settings_as_string(ToString());

            var other_names = other.names();
            foreach ( string name in other_names)
                merged.set(name, other.get(name));

            return merged;
        }
示例#13
0
 public event_log_reader(settings_as_string sett) : base(sett)
 {
     settings.on_changed += on_settings_changed;
     sett.set("name", friendly_name);
     reverse_ = settings.get("event.reversed", "0") != "0";
 }
        private void load_save(bool load, string prefix) {
            app.load_save(load, ref name, prefix + ".name", "Default" );

            string settings_str = default_settings_.ToString();
            if (load) {
                app.load_save(load, ref settings_str, prefix + ".default_settings");
                default_settings_ = new settings_as_string(settings_str);

                if (settings_str == "") {
                    // ... 1.4.8- kept the old name for persistenting
                    app.load_save(load, ref settings_str, prefix + ".default_syntax");
                    if (settings_str != "")
                        default_settings_.set("syntax", settings_str);
                }
            }
            else
                app.load_save(load, ref settings_str, prefix + ".default_settings");

            int view_count = views.Count;
            app.load_save(load, ref view_count, prefix + ".view_count", 0);
            if (load) {
                views.Clear();
                while ( views.Count < view_count)
                    views.Add( new ui_view());
            }

            for (int i = 0; i < view_count; ++i) 
                views[i].load_save(load, prefix + ".view" + i + ".");

            if ( load && views.Count == 0)
                views.Add( new ui_view() { is_default_name = true, name = "View_1" });
        }
示例#15
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;

            if (history_.Count < 1)
                history_select(text_.unique_id);

            var reader_settings_copy = new settings_as_string( text_.settings.ToString() );
            var context_settings_copy = new settings_as_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) == "line-by-line")
                    if (reader_settings_copy.get("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.set("syntax", file_to_syntax);
                            context_settings_copy.set("syntax_type", "file_to_syntax");
                        }
                        // note: if the context already knows syntax, use that
                        else if (context_settings_copy.get("syntax") == "") {
                            string found_syntax = file_text.try_to_find_log_syntax();
                            if (found_syntax != "" && found_syntax != file_text_reader.UNKNOWN_SYNTAX) {
                                context_settings_copy.set("syntax", found_syntax);
                                context_settings_copy.set("syntax_type", "try_to_find_syntax");
                            }
                        }
                    }            

            text_.merge_setings( context_settings_copy.ToString());

            // note: we recreate the log, so that cached filters know to rebuild
            log_parser_ = new log_parser(text_);
            on_new_log_parser();

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

            Text = reader_title() + " - Log Wizard " + version();
            add_reader_to_history();

            load_bookmarks();
            logger.Info("new reader " + history_[logHistory.SelectedIndex].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);
        }
示例#16
0
        private int history_select(string unique_name, string friendly_name = "") {
            ++ignore_change_;
            bool needs_save = false;
            logHistory.SelectedIndex = -1;

            bool found = false;
            for (int i = 0; i < history_.Count && !found; ++i)
                if (history_[i].unique_name == unique_name) {
                    found = true;
                    bool is_sample = unique_name.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) {
                // if we end up here, it can only be a file! - we don't allow selecting anything else that we don't already have in history
                Debug.Assert(File.Exists(unique_name));
                // 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();
                settings_as_string hist_sett = new settings_as_string("");
                hist_sett.set("type", "file");
                hist_sett.set("name", unique_name);
                hist_sett.set("friendly_name", friendly_name);
                // FIXME perhaps GUID as well?
                new_.from_string(hist_sett.ToString());
                history_.Add(new_);
                logHistory.Items.Add(history_.Last().ui_friendly_name);
                logHistory.SelectedIndex = logHistory.Items.Count - 1;
            }
            --ignore_change_;

            if (needs_save)
                save();
            return logHistory.SelectedIndex;
        }