Пример #1
0
 private void OnDiagContextCreated(DiagContext diagContext)
 {
     if (diagContext.Session == Session)
     {
         OnDiagContextCreatedOfCurrentSession(diagContext);
     }
 }
        public ContextProcessInvocationListControl(Control container, DiagContext context)
        {
            Context = context;

            ListView = new MyListView()
            {
                View               = View.Details,
                Parent             = container,
                HeaderStyle        = ColumnHeaderStyle.Nonclickable,
                GridLines          = true,
                AllowColumnReorder = false,
                FullRowSelect      = false,
                Width              = 1200,
                BorderStyle        = BorderStyle.FixedSingle,
                ShowItemToolTips   = true,
                MultiSelect        = false,
                HideSelection      = false,
            };

            ListView.MouseMove  += ListView_MouseMove;
            ListView.MouseLeave += (s, a) => ToolTipSingleton.Remove(ListView);
            ListView.MouseUp    += ListView_MouseUp;

            var fix = 40 + 60 + 60 + 140;

            ListView.Columns.Add("#", 40);
            ListView.Columns.Add("time", 60);

            ListView.Columns.Add("topic", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 2 / 3).TextAlign   = HorizontalAlignment.Right;
            ListView.Columns.Add("process", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 2 / 3).TextAlign = HorizontalAlignment.Left;
            ListView.Columns.Add("kind", 60).TextAlign = HorizontalAlignment.Left;
            ListView.Columns.Add("type", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 2 / 3).TextAlign = HorizontalAlignment.Left;

            ListView.Columns.Add("IN", 140).TextAlign = HorizontalAlignment.Right;
            ListView.Columns.Add("+", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 1 / 5).TextAlign       = HorizontalAlignment.Right;
            ListView.Columns.Add("-", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 1 / 5).TextAlign       = HorizontalAlignment.Right;
            ListView.Columns.Add("store", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 1 / 5).TextAlign   = HorizontalAlignment.Right;
            ListView.Columns.Add("pending", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 1 / 5).TextAlign = HorizontalAlignment.Right;
            ListView.Columns.Add("OUT", (ListView.Width - SystemInformation.VerticalScrollBarWidth - 4 - fix) / 3 * 1 / 5).TextAlign     = HorizontalAlignment.Right;

            ListView.MouseDoubleClick += ListView_MouseDoubleClick;

            _processStatUpdaterTimer = new System.Threading.Timer((state) => UpdateProcessStats());
            _processStatUpdaterTimer.Change(500, System.Threading.Timeout.Infinite);

            context.WholePlaybook.OnProcessInvoked += OnProcessInvoked;

            ListView.ItemSelectionChanged += ListView_ItemSelectionChanged;
        }
Пример #3
0
        public ControlUpdater(DiagContext context, Control container, int interval = 1000, int firstInterval = 100)
        {
            Context   = context;
            Container = container;
            _interval = interval;

            _timer = new Timer()
            {
                Interval = firstInterval,
                Enabled  = false,
            };

            ListView = CreateListView(container);

            _timer.Tick += Timer_Tick;
        }
Пример #4
0
        public ContextSinkListControl(Control container, DiagContext context)
        {
            Container = container;
            Context   = context;

            _updater = new ControlUpdater <TrackedSink>(context, container)
            {
                ItemFilter = ItemFilter,
                AutoUpdateUntilContextLoaded = true,
            };

            _updater.CreateSearchBox(10, 10);

            _updater.ListView.BorderStyle   = BorderStyle.None;
            _updater.ListView.Anchor        = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
            _updater.ListView.Bounds        = new Rectangle(Container.ClientRectangle.Left, Container.ClientRectangle.Top + 40, Container.ClientRectangle.Width, Container.ClientRectangle.Height - 40);
            _updater.ListView.ItemActivate += ListView_ItemActivate;

            _updater.ListView.Columns.Add(new OLVColumn()
            {
                Text                    = "Rows",
                AspectGetter            = x => (x as TrackedSink)?.RowCount,
                AspectToStringConverter = x => ((int?)x)?.FormatToStringNoZero(),
                TextAlign               = HorizontalAlignment.Right,
                HeaderTextAlign         = HorizontalAlignment.Right,
            });

            _updater.ListView.Columns.Add(new OLVColumn()
            {
                Text         = "Location",
                AspectGetter = x => (x as TrackedSink)?.Location,
            });

            _updater.ListView.Columns.Add(new OLVColumn()
            {
                Text         = "Path",
                AspectGetter = x => (x as TrackedSink)?.Path,
            });

            context.WholePlaybook.OnSinkStarted += OnSinkStarted;

            _updater.Start();
        }
Пример #5
0
    public ContextControl(DiagContext context, Control container)
    {
        Context   = context;
        Container = container;
        Container.SuspendLayout();

        try
        {
            ProcessInvocationList = new ContextProcessInvocationListControl(container, context);

            var ioCommandListContainer = new Panel()
            {
                Parent      = container,
                BorderStyle = BorderStyle.FixedSingle,
            };

            IoCommandList = new ContextIoCommandListControl(ioCommandListContainer, context)
            {
                LinkedProcessInvocationList = ProcessInvocationList,
            };

            var sinkListContainer = new Panel()
            {
                Parent      = container,
                BorderStyle = BorderStyle.FixedSingle,
                Width       = 300,
            };

            SinkList = new ContextSinkListControl(sinkListContainer, context);

            ProcessInvocationList.OnSelectionChanged += ProcessInvocationList_OnSelectionChanged;

            container.Resize += Container_Resize;
            Container_Resize(null, EventArgs.Empty);
        }
        finally
        {
            Container.ResumeLayout();
        }
    }
Пример #6
0
        private void OnDiagContextCreatedOfCurrentSession(DiagContext diagContext)
        {
            if (_contextContainerManagers.ContainsKey(diagContext.Name))
            {
                return;
            }

            if (diagContext.Name == "session")
            {
                return;
            }

            var contextContainer = new TabPage(diagContext.Name)
            {
                BorderStyle = BorderStyle.None,
                Tag         = diagContext,
            };

            var contextManager = new ContextControl(diagContext, contextContainer);

            _contextContainerManagers.Add(diagContext.Name, contextManager);

            _tabs.TabPages.Add(contextContainer);
        }
Пример #7
0
        public RowStoreControl(Control container, DiagContext context, TrackedStore store)
        {
            Container = container;
            Context   = context;
            Store     = store;

            SearchBox = new TextBox()
            {
                Parent = container,
                Bounds = new Rectangle(10, 10, 150, 20),
            };

            SearchBox.TextChanged += SearchBox_TextChanged;

            ListView = ControlUpdater <string> .CreateListView(container);

            ListView.Anchor              = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
            ListView.Bounds              = new Rectangle(Container.ClientRectangle.Left, Container.ClientRectangle.Top + 40, Container.ClientRectangle.Width, Container.ClientRectangle.Height - 40);
            ListView.FormatCell         += ListView_FormatCell;
            ListView.UseCellFormatEvents = true;

            ListView.AllColumns.Add(new OLVColumn()
            {
                Text         = "ID",
                AspectGetter = x => (x as StoredRowModel)?.RowUid,
            });
            ListView.AllColumns.Add(new OLVColumn()
            {
                Text         = "Process",
                AspectGetter = x => (x as StoredRowModel).ProcessName,
            });

            ListView.Columns.AddRange(ListView.AllColumns.ToArray());

            _fixColumnCount = ListView.Columns.Count;
        }
Пример #8
0
        private void ListenerCallBack(IAsyncResult result)
        {
            if (_listener == null)
            {
                return;
            }

            try
            {
                var listenerContext = _listener.EndGetContext(result);

                var request  = listenerContext.Request;
                var response = listenerContext.Response;

                var query       = HttpUtility.ParseQueryString(request.Url.Query);
                var sessionId   = query?["sid"];
                var contextName = query?["ctx"] ?? "session";

                if (string.IsNullOrEmpty(sessionId) ||
                    string.IsNullOrEmpty(contextName) ||
                    listenerContext.Request.Url.AbsolutePath != "/diag" ||
                    request.HttpMethod != "POST")
                {
                    var droppedResponse = Encoding.UTF8.GetBytes("DROPPED");
                    listenerContext.Response.StatusCode      = 200;
                    listenerContext.Response.KeepAlive       = false;
                    listenerContext.Response.ContentLength64 = droppedResponse.Length;
                    listenerContext.Response.OutputStream.Write(droppedResponse, 0, droppedResponse.Length);
                    listenerContext.Response.Close();
                    return;
                }

                var now = DateTime.Now;

                if (!_sessionList.TryGetValue(sessionId, out var session))
                {
                    var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "incoming-sessions", now.ToString("yyyy-MM-dd - HH-mm-ss", CultureInfo.InvariantCulture) + " - " + sessionId);
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    File.WriteAllLines(Path.Combine(folder, "session-info.txt"), new[]
                    {
                        "id\t" + sessionId,
                        "started-on\t" + now.ToString("yyyy.MM.dd HH:mm:ss.fff", CultureInfo.InvariantCulture),
                    });

                    session = new DiagSession(sessionId, folder, now);
                    lock (_sessionList)
                    {
                        _sessionList.Add(sessionId, session);
                        _newSessions.Add(session);
                    }
                }

                if (!session.ContextListByName.TryGetValue(contextName, out var context))
                {
                    var folder = Path.Combine(session.DataFolder, contextName.Replace("/", "-", StringComparison.InvariantCultureIgnoreCase));
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    File.WriteAllLines(Path.Combine(folder, "context-info.txt"), new[]
                    {
                        "name\t" + contextName,
                        "started-on\t" + now.ToString("yyyy.MM.dd HH:mm:ss.fff", CultureInfo.InvariantCulture),
                    });

                    context = new DiagContext(session, contextName, now, folder);

                    lock (_sessionList)
                    {
                        session.ContextList.Add(context);
                        session.ContextListByName.Add(contextName, context);

                        _newDiagContexts.Add(context);
                    }
                }

                using (var tempMemoryStream = new MemoryStream())
                {
                    listenerContext.Request.InputStream.CopyTo(tempMemoryStream);
                    tempMemoryStream.Position = 0;

                    context.Stage(tempMemoryStream);
                }

                var acceptedResponse = Encoding.UTF8.GetBytes("ACK");
                listenerContext.Response.StatusCode      = 200;
                listenerContext.Response.KeepAlive       = false;
                listenerContext.Response.ContentLength64 = acceptedResponse.Length;

                listenerContext.Response.OutputStream.Write(acceptedResponse, 0, acceptedResponse.Length);
                listenerContext.Response.Close();
            }
            catch (Exception)
            {
            }
            finally
            {
                _listener.BeginGetContext(ListenerCallBack, null);
            }
        }
Пример #9
0
 public Playbook(DiagContext sessionContext)
 {
     DiagContext = sessionContext;
 }