/// <summary>
 /// Удаляет файлы лога
 /// </summary>
 private static void DeleteLogFiles(IGazpromApplication gazprom)
 {
     foreach (var v in new DirectoryInfo(gazprom.PathManager.LogPath).GetFiles(String.Format("*.{0}", FileLogWriter.Extension)))
     {
         v.Delete();
     }
 }
        /// <summary>
        /// Открывает текущий файл лога
        /// </summary>
        private static void OpenLogFile(IGazpromApplication gazprom)
        {
            DirectoryInfo di = new DirectoryInfo(gazprom.PathManager.LogPath);

            if (!di.Exists)
            {
                return;
            }

            string   mask = String.Format("{0}*.{1}", GazpromHelper.LogFileName, FileLogWriter.Extension);
            FileInfo fi   = di.GetFiles(mask).TakeRecent();

            if (fi == null)
            {
                return;
            }

            try
            {
                Process.Start(fi.FullName);
            }
            catch
            {
                //
            }
        }
 /// <summary>
 /// Записывает техническую информацию в лог
 /// </summary>
 public static void WriteRuntimeInfoToLog(IGazpromApplication gazprom)
 {
     foreach (string s in gazprom.GetRuntimeInfo())
     {
         gazprom.Logger.Write(LogLevel.Error, s, GazpromLogCategories.Runtime);
     }
 }
Ejemplo n.º 4
0
        public SessionTimeMonitoringObject(IGazpromApplication gazprom)
            : base("Время текущей сессии", (int)MonitoringObjectCategory.Other)
        {
            _watch = new Stopwatch();

            _gazprom                = gazprom;
            _gazprom.AfterRun      += (state) => { _watch.Start(); };
            _gazprom.AfterShutdown += (state) => { _watch.Stop(); _watch.Reset(); };
        }
        /// <summary>
        /// Записывает комментарий в лог
        /// </summary>
        private static void WriteLogComment(IGazpromApplication gazprom, object param)
        {
            string comment = (string)param;

            if (!String.IsNullOrEmpty(comment))
            {
                gazprom.Logger.Write(LogLevel.Error, Common.GetSafeLogComment(comment), GazpromLogCategories.Comments);
            }
        }
Ejemplo n.º 6
0
        //[InjectionProperty(Required = false)]
        //private ITraceWindowSource TraceSource
        //{
        //  set { _traceSource = value; }
        //}

        #endregion

        public MainForm()
            : base(true)
        {
            InitializeComponent();

            //this.SetLogoIcon();
            this.SetLogoImages(picTop, status);
            UpdateCaption();

            tslblStatusState.SetLogoForeColor();
            tslblStatusNetwork.SetLogoForeColor();

            imgServices.Images.Add(Images.OK);
            imgServices.Images.Add(Images.Error);
            imgServices.Images.Add(Images.Extension);
            imgServices.Images.Add(Images.Extension.MakeGrayscale());
            imgServices.Images.Add(Images.Find);
            imgServices.Images.Add(Images.Warning);

            lblExtensionsWarning.ImageIndex = ImageIndexWarning;
            lblMonitorWarning.ImageIndex    = ImageIndexWarning;

            ListViewGroupCollection lvgc = lvwMonitor.Groups;

            lvgc.Clear();
            foreach (MonitoringObjectCategory mt in RuntimeHelper.GetEnumElements <MonitoringObjectCategory>())
            {
                lvgc.Add(mt.ToString(), mt.GetString());
            }

            _gazprom                = null;
            _settingsForm           = null;
            _aboutForm              = null;
            _inputForm              = new InputForm();
            _stateTimer             = new ToolStripStateTimer(tslblStatusState, TimeSpan.FromSeconds(2));
            _stateTimer.DefaultText = StatusStateReady;
            _stateTimer.UpdateStateText();

            _chordHandler = new ChordKeyHandler(this);
            _actions      = new Dictionary <int, HotKeyAction>();
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.L, Keys.F), HotKeyAction.OpenLogFolder);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.L, Keys.D), HotKeyAction.DeleteLogFiles);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.L, Keys.O), HotKeyAction.OpenLogFile);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.L, Keys.W), HotKeyAction.LogComment);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.L, Keys.R), HotKeyAction.LogRuntimeInfo);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.D, Keys.N), HotKeyAction.NetworkControl);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.S, Keys.E), HotKeyAction.ShowExtensionFilter);
            _actions.Add(_chordHandler.AddChord(Keys.Control, Keys.L, Keys.C), HotKeyAction.LogControl);
            _chordHandler.ChordPressed += OnChordPressed;

            _menuMain = null;
            //_traceSource = null;
        }
        /// <summary>
        /// Выполняет указанное действие горячей клавиши
        /// </summary>
        public static void Run(HotKeyAction action, IGazpromApplication gazprom, object param)
        {
            if (_locks[action])
            {
                //Trace.WriteLine(String.Format("DiagnosticAction {0} is LOCKED", action));
                return;
            }

            if (ThreadRequired(action))
            {
                ThreadPool.QueueUserWorkItem(p => { RunCore(action, gazprom, param); });
            }
            else
            {
                RunCore(action, gazprom, param);
            }
        }
        /// <summary>
        /// Выполняет указанное действие горячей клавиши
        /// </summary>
        private static void RunCore(HotKeyAction action, IGazpromApplication gazprom, object param)
        {
            _locks[action] = true;
            try
            {
                Console.Beep();
                switch (action)
                {
                case HotKeyAction.OpenLogFolder:
                    OpenLogFolder(gazprom);
                    break;

                case HotKeyAction.LogRuntimeInfo:
                    WriteRuntimeInfoToLog(gazprom);
                    break;

                case HotKeyAction.LogComment:
                    WriteLogComment(gazprom, param);
                    break;

                case HotKeyAction.DeleteLogFiles:
                    DeleteLogFiles(gazprom);
                    break;

                case HotKeyAction.NetworkControl:
                    NetworkControl(gazprom);
                    break;

                case HotKeyAction.OpenLogFile:
                    OpenLogFile(gazprom);
                    break;

                case HotKeyAction.LogControl:
                    LogControl(gazprom);
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Ошибка при выполнении действия {0}\r\n\r\n{1}", action, e.Message), ApplicationServices.GetApplicationName());
            }
            finally
            {
                _locks[action] = false;
            }
        }
 /// <summary>
 /// Включение/отключение логгера
 /// </summary>
 private static void LogControl(IGazpromApplication gazprom)
 {
     gazprom.Logger.Enabled = !gazprom.Logger.Enabled;
 }
 /// <summary>
 /// Управление сетевым обменом
 /// </summary>
 private static void NetworkControl(IGazpromApplication gazprom)
 {
     Gazprom.NetworkForceDisable = !Gazprom.NetworkForceDisable;
     gazprom.Logger.Write(Gazprom.NetworkForceDisable ? LogLevel.Warning : LogLevel.Debug, String.Format("Сетевой обмен отключен : {0}", Gazprom.NetworkForceDisable.GetString()));
 }
 /// <summary>
 /// Открывает папку, содержащую логи сервера
 /// </summary>
 private static void OpenLogFolder(IGazpromApplication gazprom)
 {
     Process.Start(gazprom.PathManager.LogPath);
 }