Пример #1
0
        private void openFiles(object sender, EventArgs e)
        {
            //.atom
            string command   = string.Empty;
            int    editorIdx = 0;

            this.cb_editor.Invoke(new MethodInvoker(delegate
            {
                editorIdx = cb_editor.SelectedIndex;
            }));
            switch (editorIdx)
            {
            case 0:
            {
                // atom
                command = atom_path;
                break;
            }

            case 1:
            {
                // notepad++
                command = "start notepad++";
                break;
            }

            case 2:
            {
                // sublime
                command = "start " + sublime_path;
                break;
            }

            default:
            {
                // I think we can use sublime as default
                break;
            }
            }

            if (Sender.file != string.Empty)
            {
                ez_Srv srv = SR.servers.Where(el => el.btn.Text == Sender.server).First();
                ez_Loc loc = srv.locations.Where(el => el.btn.Text == Sender.location).First();
                command += " " + "\"" + loc.path + @"\" + Sender.file + "\"";
            }
            else if (Sender.location != string.Empty)
            {
                ez_Srv srv = SR.servers.Where(el => el.btn.Text == Sender.server).First();
                ez_Loc loc = srv.locations.Where(el => el.btn.Text == Sender.location).First();

                foreach (ez_File f in loc.files)
                {
                    command += " " + "\"" + loc.path + @"\" + f.fi.Name + "\"";
                }
            }
            else if (Sender.server != string.Empty)
            {
                ez_Srv srv = SR.servers.Where(el => el.btn.Text == Sender.server).First();

                foreach (ez_Loc l in srv.locations)
                {
                    foreach (ez_File f in l.files)
                    {
                        command += " " + "\"" + l.path + @"\" + f.fi.Name + "\"";
                    }
                }
            }
            else
            {
                foreach (ez_Srv s in SR.servers)
                {
                    foreach (ez_Loc l in s.locations)
                    {
                        foreach (ez_File f in l.files)
                        {
                            command += " " + "\"" + l.path + @"\" + f.fi.Name + "\"";
                        }
                    }
                }
            }

            // run CMD to open file(s) in text editor
            runPowershell(command);
        }
Пример #2
0
        private void findFiles(object sender, DoWorkEventArgs e)
        {
            // take input from UI
            string[] servers   = tb_serverList.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            string[] locations = tb_locationList.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            string[] patterns  = tb_patternList.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            bool   textFilter = false;
            string text       = string.Empty;

            this.tb_text.Invoke(new MethodInvoker(delegate
            {
                if (tb_text.Text != string.Empty)
                {
                    textFilter = true;
                }
            }));
            this.tb_text.Invoke(new MethodInvoker(delegate
            {
                text = tb_text.Text;
            }));

            // remove empty lines
            servers   = servers.Where(val => !string.IsNullOrEmpty(val)).Distinct().ToArray();
            locations = locations.Where(val => !string.IsNullOrEmpty(val)).Distinct().ToArray();
            patterns  = patterns.Where(val => !string.IsNullOrEmpty(val)).Distinct().ToArray();

            // delete everything from last search
            SR = new ez_SearchResult();
            this.panel_dynamic.Invoke(new MethodInvoker(delegate
            {
                panel_dynamic.Controls.Clear();
            }));

            // disable scrollbar while generating UI elements (bug workaround)
            this.panel_dynamic.Invoke(new MethodInvoker(delegate
            {
                panel_dynamic.VerticalScroll.Enabled = false;
                panel_dynamic.AutoScroll             = false;
            }));

            int x = 0, y = 6, x_spacing = 15, y_spacing = 33;

            // button for opening all files
            Button b_all = new Button();

            b_all.Location  = new Point(x, y);
            b_all.Name      = "btn_OpenAllFiles";
            b_all.AutoSize  = true;
            b_all.ForeColor = Color.White;
            b_all.Text      = "open all";
            b_all.Font      = new Font("Microsoft Sans Serif", 12f);
            b_all.Click    += new EventHandler(openFiles_click);
            this.panel_dynamic.Invoke(new MethodInvoker(delegate
            {
                panel_dynamic.Controls.Add(b_all);
            }));
            // increment y
            y += y_spacing;

            // find all files
            foreach (string server in servers)
            {
                Button b_srv = new Button();
                b_srv.Location  = new Point(x + x_spacing, y);
                b_srv.Name      = serverTag + server;
                b_srv.Text      = server;
                b_srv.AutoSize  = true;
                b_srv.ForeColor = Color.White;
                b_srv.Text      = server;
                b_srv.Font      = new Font("Microsoft Sans Serif", 12f);
                b_srv.Click    += new EventHandler(openFiles_click);
                this.panel_dynamic.Invoke(new MethodInvoker(delegate
                {
                    panel_dynamic.Controls.Add(b_srv);
                }));
                // increment y
                y += y_spacing;

                // create ez_Srv and save info
                ez_Srv ez_server = new ez_Srv();
                ez_server.btn = b_srv;

                foreach (string location in locations)
                {
                    Button b_loc = new Button();
                    b_loc.Location  = new Point(x + 2 * x_spacing, y);
                    b_loc.Name      = serverTag + server + locationTag + location;
                    b_loc.Text      = location;
                    b_loc.AutoSize  = true;
                    b_loc.ForeColor = Color.White;
                    b_loc.Font      = new Font("Microsoft Sans Serif", 12f);
                    b_loc.Click    += new EventHandler(openFiles_click);
                    this.panel_dynamic.Invoke(new MethodInvoker(delegate
                    {
                        panel_dynamic.Controls.Add(b_loc);
                    }));
                    // increment y
                    y += y_spacing;

                    // create ez_Loc and save it to our ez_Srv
                    ez_Loc ez_location = new ez_Loc();
                    ez_location.btn = b_loc;
                    ez_server.locations.Add(ez_location);

                    try
                    {
                        //local host or server?
                        string path;
                        if (server != "localhost" && server != "local")
                        {
                            path = @"\\" + server + @"\" + location;
                            path = path.Replace(":", "$");
                        }
                        else
                        {
                            path = location;
                        }

                        // save math in ez_Loc
                        ez_location.path = path;

                        DirectoryInfo dir = new DirectoryInfo(path);

                        List <FileInfo> files = new List <FileInfo>();

                        // get all files
                        foreach (string pattern in patterns)
                        {
                            List <FileInfo> fi = dir.GetFiles(pattern).ToList();
                            files.AddRange(fi);
                        }

                        if (files.Count() == 0)
                        {
                            // msg: no files in server -> location matching the patterns
                        }
                        else
                        {
                            // now, foreach file do the shit
                            foreach (var file in files)
                            {
                                if (textFilter)
                                {
                                    if (findTextInFile(file.FullName, text))
                                    {
                                        // create button and checkbox
                                        Button b = new Button();
                                        b.Text      = file.Name;
                                        b.Name      = serverTag + server + locationTag + location + fileTag + file.Name;
                                        b.AutoSize  = true;
                                        b.ForeColor = Color.White;
                                        b.Font      = new Font("Microsoft Sans Serif", 12f);
                                        b.Click    += new EventHandler(openFiles_click);

                                        /*CheckBox c = new CheckBox();
                                         * c.Checked = true;
                                         * c.AutoSize = true;
                                         * c.CheckedChanged += new EventHandler(checkedChanged_click);
                                         *
                                         * // set x si y for checkbox and button
                                         * c.Location = new Point(x + 3*x_spacing, y + y_spacing/4);*/
                                        b.Location = new Point(x + 3 * x_spacing, y); // *4 if checkbox

                                        // increment y
                                        y += y_spacing;

                                        this.panel_dynamic.Invoke(new MethodInvoker(delegate
                                        {
                                            //panel_dynamic.Controls.Add(c);
                                        }));
                                        this.panel_dynamic.Invoke(new MethodInvoker(delegate
                                        {
                                            panel_dynamic.Controls.Add(b);
                                        }));

                                        // create ez_File and save it to our ez_Loc from our ez_Srv
                                        ez_File ez_file = new ez_File();
                                        ez_file.fi  = new FileInfo(file.Name);
                                        ez_file.btn = b;
                                        //ez_file.cb = c;
                                        ez_location.files.Add(ez_file);
                                    }
                                }
                                else
                                {
                                    // create button and checkbox
                                    Button b = new Button();
                                    b.Text      = file.Name;
                                    b.Name      = serverTag + server + locationTag + location + fileTag + file.Name;
                                    b.AutoSize  = true;
                                    b.ForeColor = Color.White;
                                    b.Font      = new Font("Microsoft Sans Serif", 12f);
                                    b.Click    += new EventHandler(openFiles_click);

                                    /*CheckBox c = new CheckBox();
                                     * c.Checked = true;
                                     * c.AutoSize = true;
                                     * c.CheckedChanged += new EventHandler(checkedChanged_click);
                                     *
                                     * // set x si y for checkbox and button
                                     * c.Location = new Point(x + 3*x_spacing, y + y_spacing/4);*/
                                    b.Location = new Point(x + 3 * x_spacing, y); // *4 if checkbox

                                    // increment y
                                    y += y_spacing;

                                    this.panel_dynamic.Invoke(new MethodInvoker(delegate
                                    {
                                        //panel_dynamic.Controls.Add(c);
                                    }));
                                    this.panel_dynamic.Invoke(new MethodInvoker(delegate
                                    {
                                        panel_dynamic.Controls.Add(b);
                                    }));

                                    // create ez_File and save it to our ez_Loc from our ez_Srv
                                    ez_File ez_file = new ez_File();
                                    ez_file.fi  = new FileInfo(file.Name);
                                    ez_file.btn = b;
                                    //ez_file.cb = c;
                                    ez_location.files.Add(ez_file);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw;
                        // msg: no directory
                    }
                }
                SR.servers.Add(ez_server);
            }

            // enable scrollbar after generating UI elements (bug workaround)
            this.panel_dynamic.Invoke(new MethodInvoker(delegate
            {
                panel_dynamic.VerticalScroll.Enabled = true;
                panel_dynamic.AutoScroll             = true;
            }));
        }