Exemplo n.º 1
0
        /// <summary>Launch the custom data source</summary>
        private void LogCustomDataSource(ICustomLogDataSource src, LogDataSourceRunData launch)
        {
            BufferedCustomDataSource buffered_src = null;

            try
            {
                // Close any currently open file
                // Strictly, we don't have to close because OpenLogFile closes before opening
                // however if the user reopens the same process the existing process will hold
                // a lock to the capture file preventing the new process being created.
                Src = null;

                // Set options so that data always shows
                PrepareForStreamedData(launch.OutputFilepath);

                // Launch the process with standard output/error redirected to the temporary file
                buffered_src = new BufferedCustomDataSource(src, launch);

                // Give some UI feedback when the data source ends
                buffered_src.ConnectionDropped += (s, a) =>
                {
                    this.BeginInvoke(() => SetStaticStatusMessage(string.Format("{0} stopped", src.ShortName), Color.Black, Color.LightSalmon));
                };

                // Attach the optional selection changed handler
                if (launch.HandleSelectionChanged != null)
                {
                    SelectionChanged += (s, a) => launch.HandleSelectionChanged(a.Rows);
                }

                // Open the capture file created by buffered_src
                OpenSingleLogFile(buffered_src.Filepath, !buffered_src.TmpFile);
                buffered_src.Start();
                SetStaticStatusMessage("Connected", Color.Black, Color.LightGreen);

                // Pass over the ref
                if (m_buffered_custom_source != null)
                {
                    m_buffered_custom_source.Dispose();
                }
                m_buffered_custom_source = buffered_src;
                buffered_src             = null;
            }
            catch (Exception ex)
            {
                Log.Write(ELogLevel.Error, ex, $"Custom data source failed: {src.ShortName} -> {launch.OutputFilepath}");
                Misc.ShowMessage(this, $"Failed to launch {src.ShortName}.", "Data Source Failed", MessageBoxIcon.Error, ex);
            }
            finally
            {
                if (buffered_src != null)
                {
                    buffered_src.Dispose();
                }
            }
        }
Exemplo n.º 2
0
 public BufferedCustomDataSource(ICustomLogDataSource src, LogDataSourceRunData launch)
     : base(launch.OutputFilepath, launch.AppendOutputFile)
 {
     m_src = src;
     m_buf = new byte[BufBlockSize];
 }