コード例 #1
0
        public void AddMessage(string _message, MessageType _type = MessageType.INFO, string _helpImage = null,
                               bool _logThis       = false,
                               Exception exception = null,
                               [CallerFilePathAttribute] string callerPath = "",
                               [CallerMemberName] string callerMember      = "",
                               [CallerLineNumber] int callerLine           = 0,
                               bool _setContinuButtonToVisible             = false,
                               bool _showTimeStamp = true)
        {
            Application.Current.Dispatcher.Invoke(new System.Action(() =>
            {
                LiveLogItem liveLogItem = new LiveLogItem();
                if (_showTimeStamp && _type != MessageType.ATTENTION)
                {
                    liveLogItem.TimeStamp = DateTime.Now.ToString();
                }
                liveLogItem.Message = _message;
                //if (_type == MessageType.ATTENTION)
                //    liveLogItem.Message = _message;
                //else
                //    liveLogItem.Message = DateTime.Now.ToString() + " | " + _message;
                liveLogItem.MessageType = _type;

                if (_helpImage != null)
                {
                    liveLogItem.HelpImage = _helpImage;
                    liveLogItem.Message   = liveLogItem.Message + "\n";
                }

                if (_type == MessageType.ERROR)
                {
                    Status = StatusType.ERROR;
                }

                if (_setContinuButtonToVisible)
                {
                    liveLogItem.ContinueBtnVisibility = Visibility.Visible;
                }
                else
                {
                    liveLogItem.ContinueBtnVisibility = Visibility.Hidden;
                }

                if (CurrentMode != Mode.NO_SCROLL_TO_BOTTOM_MODE)
                {
                    ShouldScrollToBottom = true;
                }
                else if (CurrentMode == Mode.NO_SCROLL_TO_BOTTOM_MODE)
                {
                    ShouldScrollToBottom = false;
                }

                LiveLogs.Add(liveLogItem);
            }));
        }
コード例 #2
0
        private void Proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data == null)
            {
                return;
            }

            Process proc = sender as Process;
            var     sa   = this.Analytics.Services.FirstOrDefault(a => a.ProcessID == proc.Id) ?? new ServiceAnalytics();

            if (sa == null)
            {
                return;
            }

            var s = this.Config.ServiceList.FirstOrDefault(a => a.ID == sa.ServiceID);

            if (s == null)
            {
                return;
            }

            if (this.Config.Notifications.OnConsoleOutput)
            {
                Extensions.Extensions.SendNotification(this.Config.Notifications.PluginId.Value, this.Config.Notifications.InstanceName + ": " + s.Title + "\r\n" + e.Data);
            }

            var service = this.Config.ServiceList.FirstOrDefault(a => a.ID == sa.ServiceID);

            if (service.LogConsoleOutput)
            {
                //Save to harddrive
                if (sa.LastSaved.Date != DateTime.Today)
                {
                    if (service.LogConsoleOutputToDisk && SaveToDisk(service, sa.Output))
                    {
                        sa.Output    = "";
                        sa.LastSaved = DateTime.Now;
                    }
                    else if (service.ResetConsoleOutputDaily)
                    {
                        sa.Output    = "";
                        sa.LastSaved = DateTime.Now;
                    }
                }

                sa.Output += e.Data + "\r\n";
            }

            if (Connection.ServerChannel == null || Connection.Failed)
            {
                return;
            }


            var t = new Task(() =>
            {
                if (DateTime.Now.Subtract(sa.LastPing).TotalSeconds > 10)
                {
                    Connection?.Try(a => a.ActivityPing(sa.ServiceID));
                    sa.LastPing = DateTime.Now;
                }


                if (LiveLogs.Contains(sa.ServiceID))
                {
                    Connection?.Try(a => a.LiveLogsUpdate(sa.ServiceID, e.Data));
                }
            });

            t.Start();
        }