Example #1
0
        public CaptureHost(string path, IStreamResource streamResource)
        {
            if (streamResource == null)
            {
                throw new ArgumentNullException(nameof(streamResource));
            }

            var task = new Task(() =>
            {
                try
                {
                    using (var writer = new CaptureFileWriter(path))
                    {
                        using (_listener = new PromiscuousListener(streamResource))
                        {
                            _listener.Sample += (sender, args) =>
                            {
                                writer.WriteSample(args.Sample);

                                OnSampleReceived();
                            };

                            _listener.Listen();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            });

            //Start up this awesome task
            task.Start();
        }
        public CaptureHost(string path, IMasterContext masterContext)
        {
            if (masterContext == null) throw new ArgumentNullException(nameof(masterContext));

            _masterContext = masterContext;

            var task = new Task(() =>
            {
                try
                {
                    using (var writer = new CaptureFileWriter(path))
                    {
                        //Get the port
                        var port = masterContext.Master.Transport.GetStreamResource();

                        using (_listener = new PromiscuousListener(port))
                        {
                            _listener.Sample += (sender, args) =>
                            {
                                writer.WriteSample(args.Sample);

                                OnSampleReceived();
                            };

                            _listener.Listen();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            });

            //Start up this awesome task
            task.Start();
        }