Exemplo n.º 1
0
        private TailConfig LoadSessionFile(string filepath)
        {
            TailConfig tailConfig = null;

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(TailConfig));
                using (XmlTextReader reader = new XmlTextReader(filepath))
                {
                    _currenTailConfig = new Uri(reader.BaseURI).LocalPath;
                    tailConfig        = serializer.Deserialize(reader) as TailConfig;
                }
                return(tailConfig);
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                while (ex.InnerException != null)
                {
                    ex        = ex.InnerException;
                    errorMsg += "\n" + ex.Message;
                }
                MessageBox.Show(this, "Failed to open session xml file, please ensure it is valid file:\n\n   " + filepath + "\n\n" + errorMsg, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Exemplo n.º 2
0
        private void _saveDefaultBtn_Click(object sender, EventArgs e)
        {
            TailConfigForm_Save(sender, e);
            TailConfig tailConfig = new TailConfig();

            tailConfig.TailFiles.Add(TailFileConfig);
            MainForm.Instance.SaveConfig(tailConfig, string.Empty);
        }
Exemplo n.º 3
0
        private int OpenFileSelection(string[] filenames)
        {
            if (_defaultTailConfig == null)
            {
                TailConfig tailConfig  = null;
                string     defaultPath = GetDefaultConfigPath();
                if (!string.IsNullOrEmpty(defaultPath))
                {
                    tailConfig = LoadSessionFile(defaultPath);
                }

                if (tailConfig != null && tailConfig.TailFiles.Count > 0)
                {
                    _defaultTailConfig       = tailConfig.TailFiles[0];
                    _defaultTailConfig.Title = null;
                }
                else
                {
                    _defaultTailConfig = new TailFileConfig();
                }
            }

            int filesOpened = 0;

            foreach (string filename in filenames)
            {
                string configPath = "";
                try
                {
                    if (string.IsNullOrEmpty(Path.GetDirectoryName(filename)))
                    {
                        configPath = Directory.GetCurrentDirectory();
                    }
                }
                catch
                {
                }

                TailForm       mdiForm    = new TailForm();
                TailFileConfig tailConfig = _defaultTailConfig;
                tailConfig.FilePath = filename;
                mdiForm.LoadConfig(tailConfig, configPath);
                if (mdiForm.IsDisposed)
                {
                    continue;
                }

                _mruMenu.AddFile(filename);

                mdiForm.MdiParent = this;
                mdiForm.Show();
                ++filesOpened;
                Application.DoEvents();
            }
            return(filesOpened);
        }
Exemplo n.º 4
0
        public void SaveConfig(TailConfig tailConfig, string filepath)
        {
            if (string.IsNullOrEmpty(filepath))
            {
                string defaultPath = GetDefaultConfigPath();
                if (string.IsNullOrEmpty(defaultPath))
                {
                    defaultPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SnakeTail\\";
                    if (!Directory.Exists(defaultPath))
                    {
                        Directory.CreateDirectory(defaultPath);
                    }

                    defaultPath += "SnakeTail.xml";
                }

                filepath = defaultPath;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(TailConfig));

            try
            {
                using (XmlTextWriter writer = new XmlTextWriter(filepath, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
                    xmlnsEmpty.Add("", "");
                    serializer.Serialize(writer, tailConfig, xmlnsEmpty);
                }

                _defaultTailConfig = null;  // Force reload incase we saved a new default config
            }
            catch (System.Exception ex)
            {
                string errorMsg = ex.Message;
                while (ex.InnerException != null)
                {
                    ex        = ex.InnerException;
                    errorMsg += "\n" + ex.Message;
                }
                MessageBox.Show(this, "Failed to save session xml file, please ensure it is valid location:\n\n   " + filepath + "\n\n" + errorMsg, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        public void SaveConfig(TailConfig tailConfig, string filepath)
        {
            if (string.IsNullOrEmpty(filepath))
            {
                string defaultPath = GetDefaultConfigPath();
                if (string.IsNullOrEmpty(defaultPath))
                {
                    defaultPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SnakeTail\\";
                    if (!Directory.Exists(defaultPath))
                        Directory.CreateDirectory(defaultPath);

                    defaultPath += "SnakeTail.xml";
                }

                filepath = defaultPath;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(TailConfig));
            try
            {
                using (XmlTextWriter writer = new XmlTextWriter(filepath, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
                    xmlnsEmpty.Add("", "");
                    serializer.Serialize(writer, tailConfig, xmlnsEmpty);
                }

                _defaultTailConfig = null;  // Force reload incase we saved a new default config
            }
            catch(System.Exception ex)
            {
                string errorMsg = ex.Message;
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                    errorMsg += "\n" + ex.Message;
                }
                MessageBox.Show(this, "Failed to save session xml file, please ensure it is valid location:\n\n   " + filepath + "\n\n" + errorMsg, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 6
0
        private void SaveSession(string filepath)
        {
            TailConfig tailConfig = new TailConfig();
            if (_MDITabControl.Visible)
                tailConfig.SelectedTab = _MDITabControl.SelectedIndex;
            else
                tailConfig.SelectedTab = -1;
            tailConfig.WindowSize = Size;
            tailConfig.WindowPosition = DesktopLocation;
            tailConfig.MinimizedToTray = _trayIcon.Visible;
            tailConfig.AlwaysOnTop = TopMost;

            List<Form> childForms = new List<Form>();

            // We first loop through the tabpages to store in proper TabPage order
            foreach (TabPage tagPage in _MDITabControl.TabPages)
            {
                Form tailForm = tagPage.Tag as Form;
                if (tailForm != null)
                    childForms.Add(tailForm);
            }

            // Then we loop through all forms (includes free floating)
            foreach (Form childForm in Application.OpenForms)
            {
                if (childForms.IndexOf(childForm) == -1)
                    childForms.Add(childForm);
            }

            // Save all forms and store in proper order
            foreach (Form childForm in childForms)
            {
                ITailForm tailForm = childForm as ITailForm;
                if (tailForm != null)
                {
                    TailFileConfig tailFile = new TailFileConfig();
                    tailForm.SaveConfig(tailFile);
                    tailConfig.TailFiles.Add(tailFile);
                }
            }

            SaveConfig(tailConfig, filepath);

            if (String.IsNullOrEmpty(_currenTailConfig))
                _mruMenu.AddFile(filepath);
            else if (_currenTailConfig != filepath)
                _mruMenu.RenameFile(_currenTailConfig, filepath);

            _currenTailConfig = filepath;

            UpdateTitle();
        }
Exemplo n.º 7
0
        private bool LoadSession(string filepath)
        {
            TailConfig tailConfig = LoadSessionFile(filepath);

            if (tailConfig == null)
            {
                return(false);
            }

            _mruMenu.AddFile(filepath);

            if (!tailConfig.MinimizedToTray)
            {
                Size            = tailConfig.WindowSize;
                DesktopLocation = tailConfig.WindowPosition;
            }

            UpdateTitle();

            List <string> eventLogFiles = EventLogForm.GetEventLogFiles();

            Application.DoEvents();

            foreach (TailFileConfig tailFile in tailConfig.TailFiles)
            {
                Form mdiForm = null;

                int index = eventLogFiles.FindIndex(delegate(string arrItem) { return(arrItem.Equals(tailFile.FilePath)); });
                if (index >= 0)
                {
                    mdiForm = new EventLogForm();
                }
                else
                {
                    mdiForm = new TailForm();
                }

                if (mdiForm != null)
                {
                    ITailForm tailForm       = mdiForm as ITailForm;
                    string    tailConfigPath = Path.GetDirectoryName(filepath);

                    mdiForm.Text = tailFile.Title;
                    if (!tailFile.Modeless)
                    {
                        mdiForm.MdiParent     = this;
                        mdiForm.ShowInTaskbar = false;
                        AddMdiChildTab(mdiForm);
                        if (tailForm != null)
                        {
                            tailForm.LoadConfig(tailFile, tailConfigPath);
                        }
                        if (mdiForm.IsDisposed)
                        {
                            _MDITabControl.TabPages.Remove(mdiForm.Tag as TabPage);
                            continue;
                        }
                    }
                    mdiForm.Show();

                    if (tailConfig.SelectedTab == -1 || tailFile.Modeless)
                    {
                        if (tailFile.WindowState != FormWindowState.Maximized)
                        {
                            mdiForm.DesktopLocation = tailFile.WindowPosition;
                            mdiForm.Size            = tailFile.WindowSize;
                        }
                        if (mdiForm.WindowState != tailFile.WindowState)
                        {
                            mdiForm.WindowState = tailFile.WindowState;
                        }
                    }

                    if (tailFile.Modeless)
                    {
                        if (tailForm != null)
                        {
                            tailForm.LoadConfig(tailFile, tailConfigPath);
                        }
                    }
                }
                Application.DoEvents();
            }

            if (tailConfig.SelectedTab != -1 && _MDITabControl.TabPages.Count > 0)
            {
                foreach (Form childForm in MdiChildren)
                {
                    childForm.WindowState = FormWindowState.Minimized;
                }

                _MDITabControl.SelectedIndex = tailConfig.SelectedTab;
                _MDITabControl.Visible       = true;
                (_MDITabControl.SelectedTab.Tag as Form).WindowState = FormWindowState.Maximized;
            }

            if (tailConfig.MinimizedToTray)
            {
                _trayIcon.Visible = true;
                WindowState       = FormWindowState.Minimized;
                Visible           = false;
            }
            else if (tailConfig.AlwaysOnTop)
            {
                alwaysOnTopToolStripMenuItem.Checked = true;
                TopMost = true;
            }

            return(true);
        }
Exemplo n.º 8
0
        private void SaveSession(string filepath)
        {
            TailConfig tailConfig = new TailConfig();

            if (_MDITabControl.Visible)
            {
                tailConfig.SelectedTab = _MDITabControl.SelectedIndex;
            }
            else
            {
                tailConfig.SelectedTab = -1;
            }
            tailConfig.WindowSize      = Size;
            tailConfig.WindowPosition  = DesktopLocation;
            tailConfig.MinimizedToTray = _trayIcon.Visible;
            tailConfig.AlwaysOnTop     = TopMost;

            List <Form> childForms = new List <Form>();

            // We first loop through the tabpages to store in proper TabPage order
            foreach (TabPage tagPage in _MDITabControl.TabPages)
            {
                Form tailForm = tagPage.Tag as Form;
                if (tailForm != null)
                {
                    childForms.Add(tailForm);
                }
            }

            // Then we loop through all forms (includes free floating)
            foreach (Form childForm in Application.OpenForms)
            {
                if (childForms.IndexOf(childForm) == -1)
                {
                    childForms.Add(childForm);
                }
            }

            // Save all forms and store in proper order
            foreach (Form childForm in childForms)
            {
                ITailForm tailForm = childForm as ITailForm;
                if (tailForm != null)
                {
                    TailFileConfig tailFile = new TailFileConfig();
                    tailForm.SaveConfig(tailFile);
                    tailConfig.TailFiles.Add(tailFile);
                }
            }

            SaveConfig(tailConfig, filepath);

            if (String.IsNullOrEmpty(_currenTailConfig))
            {
                _mruMenu.AddFile(filepath);
            }
            else if (_currenTailConfig != filepath)
            {
                _mruMenu.RenameFile(_currenTailConfig, filepath);
            }

            _currenTailConfig = filepath;

            UpdateTitle();
        }
Exemplo n.º 9
0
 private void _saveDefaultBtn_Click(object sender, EventArgs e)
 {
     TailConfigForm_Save(sender, e);
     TailConfig tailConfig = new TailConfig();
     tailConfig.TailFiles.Add(TailFileConfig);
     MainForm.Instance.SaveConfig(tailConfig, string.Empty);
 }