Ejemplo n.º 1
0
        private void CreateParentTabPageAtIndex(string path, int?index, string parentName = null, string text = null)
        {
            try
            {
                int tabPosition = index ?? CountParentTabs() + 1;
                //Creates a new tab for a new log
                Classes.LogTabPage tab = new Classes.LogTabPage()
                {
                    Text = text ?? Path.GetFileName(path), Name = path, Tag = "File", TailFollowed = true, PositionIndex = tabPosition, ImageIndex = 0
                };

                tab.SetWatcher(path);
                TabControlParent.TabPages.Add(tab);
                TabControlParent.SelectedTab = tab;

                Classes.ListViewNF ListViewText = new Classes.ListViewNF {
                    Parent = tab, Dock = DockStyle.Fill, View = View.Details,
                };

                ListViewText.Columns.Add("Line", 50, HorizontalAlignment.Left);
                ListViewText.Columns.Add("Text", 1000, HorizontalAlignment.Left);
                ListViewText.FullRowSelect    = true;
                ListViewText.ContextMenuStrip = contextMenuStrip1;
                ListViewText.MultiSelect      = true;
                ListViewText.Name             = "ListViewText";//used to find listview later

                //SelectedTabPage = tab;
                TabViewChange(tab);
                tab.InitialLoad();

                FileLengthTB.Text = ListViewText.Items.Count.ToString() + " lines"; //Grabs the Number of lines in a file
                // long FileSizeValue = new FileInfo(path).Length; //Create the long for the file size value
                // FileSizeTB.Text = (FileSizeValue / 1024) + " KB"; //Convert File size from bytes to KB

                if (!String.IsNullOrWhiteSpace(parentName))
                {
                    TabPage    folder            = GetFolderByName(parentName);
                    TabControl subTabPageControl = folder.Controls.Find("SubTabControl", true).FirstOrDefault() as TabControl;
                    subTabPageControl.TabPages.Add(tab);
                }
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
            }
        }
Ejemplo n.º 2
0
        private void initialWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TabControl TabControlParent = this.Parent as TabControl;

            try
            {
                string path     = this.Name;
                string tempPath = "./Assets/TempFiles/" + tempFileName;
                File.Copy(path, tempPath, true);
                using (var fs = new FileStream(tempPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var sr = new StreamReader(fs))
                    {
                        List <string> file = new List <string>();
                        while (!sr.EndOfStream)
                        {
                            file.Add(sr.ReadLine());
                        }

                        string[] lines = file.ToArray();
                        if (lines.Length < 1 || lines == null)
                        {
                            this.ImageIndex = 2;
                            return;
                        }
                        var        ListViewControl = this.Controls.Find("ListViewText", true);
                        ListViewNF ListViewText    = ListViewControl[0] as ListViewNF;

                        var            ItemsCount = ListViewText.Items.Count;
                        ListViewItem[] itemArray  = new ListViewItem[lines.Length];
                        for (var i = 0; i < lines.Length; i++)
                        {
                            ListViewItem item = new ListViewItem((i + 1).ToString());
                            item.SubItems.Add(lines[i]);
                            itemArray[i] = item;
                        }
                        if (ListViewText.InvokeRequired)
                        {
                            ListViewText.Invoke(new MethodInvoker(delegate
                            {
                                if (ItemsCount == 0 || lines.Length < ItemsCount)
                                {
                                    ListViewText.Items.Clear();
                                    ListViewText.Items.AddRange(itemArray);
                                }
                                else
                                {
                                    ListViewText.Items.AddRange(itemArray);
                                }
                            }));
                        }
                        else
                        {
                            if (ItemsCount == 0 || lines.Length < ItemsCount)
                            {
                                ListViewText.Items.Clear();
                                ListViewText.Items.AddRange(itemArray);
                            }
                            else
                            {
                                ListViewText.Items.AddRange(itemArray);
                            }
                        }
                    }
            }
            catch (IOException IOex)
            {
                Console.WriteLine(IOex.Message);
                if (this.InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.ImageIndex = 2;
                    }));
                }
                else
                {
                    this.ImageIndex = 2;
                }
            }
            if (TailFollowed)
            {
                ScrollToBottom();
            }
        }