示例#1
0
        static void Main(string[] args)
        {
            var subscription = ObservableEventListener.FromTraceEvent <UsbTraceParser.UsbTraceEventParser, UsbTraceParser.UsbPortCompleteUrbFunctionControlTransferData>()
                               //.Where(evt => evt.fid_USBPORT_Device.idVendor == 0x4949 && evt.fid_USBPORT_Device.idProduct == 0x8888)
                               .Do(evt =>
            {
                var urb = evt.fid_USBPORT_URB;
                Console.WriteLine($"{urb.fid_URB_Setup_bmRequestType:X02}, {urb.fid_URB_Setup_bRequest:X02}, {urb.fid_URB_Setup_wLength}, {evt.fid_URB_TransferDataLength}");
            })
                               .Subscribe();

            using (subscription)
            {
                Console.ReadLine();
            }
        }
示例#2
0
        static public TelemetryPipe CollectETWEvents(this TelemetryPipe pipe, IEnumerable <ETWProvider> providers, Dictionary <string, string> additionalProperties = null, bool isFilteringOnlyOwnProcess = true)
        {
            var pid = Process.GetCurrentProcess().Id;

            pipe.RegisterObserver(ObservableEventListener
                                  .FromTraceEvent(providers.Select(x => x.Name).ToArray())
                                  .Where(ev => !isFilteringOnlyOwnProcess || ev.ProcessID == pid)
                                  .Select(ev => new TelemetryEvent()
            {
                Type            = "event",
                Data            = FromTraceEvent(ev, additionalProperties),
                PublishDateTime = ev.TimeStamp
            }));

            return(pipe);
        }
示例#3
0
        static void Main(string[] args)
        {
            var cts       = new CancellationTokenSource();
            var container = new SubscriptionContainer();

            ObservableEventListener.FromTraceEvent("DocumentDBClient")
            .Buffer(TimeSpan.FromSeconds(1), 1000, cts.Token)
            .LogTo(xs =>
            {
                var d1 = xs.LogToFile("log.txt", x => $"[{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}][{x.Level}]{x.DumpPayload()}", Encoding.UTF8, autoFlush: true);
                var d2 = xs.LogToConsole();
                var d3 = xs.LogToFile("log.json", e => e.ToJson(), Encoding.UTF8, autoFlush: true);
                return(new[] { d1, d2, d3 });
            })
            .AddTo(container);

            Console.ReadLine();

            cts.Cancel();
            container.Dispose();
        }
示例#4
0
        static void Main2(string[] args)
        {
            // in ApplicationStart, prepare two parts.
            var cts       = new CancellationTokenSource();
            var container = new SubscriptionContainer();

            // configure log
            ObservableEventListener.FromTraceEvent("DocumentDBClient")
            .Buffer(TimeSpan.FromSeconds(1), 1000, cts.Token)
            .LogTo(xs =>
            {
                var d1 = xs.LogToFile("log.txt", x => $"[{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}][{x.Level}]{x.DumpPayload()}", Encoding.UTF8, autoFlush: true);
                var d2 = xs.LogToConsole();
                return(new[] { d1, d2 });
            })
            .AddTo(container);

            // Application Running....
            Console.ReadLine();

            // End of Application(Form_Closed/Application_End/Main's last line/etc...)
            cts.Cancel();        // Cancel publish rest of buffered events.
            container.Dispose(); // Wait finish of subscriptions's buffer event.
        }