public void CreatingDuplicateRealtimeSessionTaskResultsInFaultedTaskIfSessionReclaimIsOff()
        {
            const string duplicateSessionName = "testDuplicateRealtimeSession";

            using (var reader1 = new ETWRealtimeProcessor(duplicateSessionName, true))
            {
                reader1.SubscribeToProvider(TestLogger.Write.Guid, EventLevel.Verbose);
                var t1 = reader1.CreateProcessingTask();
                Assert.AreEqual(TaskStatus.Running, t1.Status);

                using (var reader2 = new ETWRealtimeProcessor(duplicateSessionName, false))
                {
                    reader2.SubscribeToProvider(TestLogger.Write.Guid, EventLevel.Verbose);
                    try
                    {
                        var t2 = reader2.CreateProcessingTask();
                        t2.Wait(); // expect this to fail
                    }
                    catch (AggregateException ex)
                    {
                        Assert.AreEqual(typeof(OperationCanceledException), ex.InnerException.GetType());
                    }
                }
                Assert.AreEqual(TaskStatus.Running, t1.Status);
                reader1.StopProcessing();
                t1.Wait();
            }
        }
        private static void SetupRealtimeProcessor()
        {
            var sessionName = string.Format("{0}-ELT-realtime", Environment.UserName);
            var realtimeSession = new ETWRealtimeProcessor(sessionName);

            bool added = false;
            foreach (var arg in options.Arguments)
            {
                string[] split = arg.Split('!');
                Guid providerID;
                var providers = new List<Guid>();
                var minimumSeverity = EventLevel.Informational;
                long keywords = 0x0;

                if (split[0].Equals("CLR", StringComparison.OrdinalIgnoreCase))
                {
                    providers.Add(ClrTraceEventParser.ProviderGuid);
                }
                else if (split[0].Equals("Kernel", StringComparison.OrdinalIgnoreCase))
                {
                    providers.Add(KernelTraceEventParser.ProviderGuid);
                }
                else if (!Guid.TryParse(split[0], out providerID))
                {
                    // If it's not a GUID it might be an assembly -- we can try that...
                    if (!GetProvidersFromAssembly(split[0], providers))
                    {
                        ShowErrorAndExit("{0} is not a validly formatted GUID, and not a usable assembly", split[0]);
                    }
                }
                else
                {
                    providers.Add(providerID);
                }

                // Ignore if the string is null(won't be), empty, or whitespace -- all these will just mean that we
                // use default severity.
                if (split.Length > 1 && !string.IsNullOrWhiteSpace(split[1]))
                {
                    minimumSeverity = ETWEvent.CharToEventLevel(split[1][0]);
                }

                if (split.Length > 2)
                {
                    string num = split[2];
                    if (num.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                    {
                        num = num.Substring(2);
                    }

                    if (!long.TryParse(num, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out keywords))
                    {
                        ShowErrorAndExit("Keyword value {0} is not a valid hexadecimal number", split[2]);
                    }
                }

                foreach (var id in providers)
                {
                    realtimeSession.SubscribeToProvider(id, minimumSeverity, keywords);
                }
                added = true;
            }

            if (!added)
            {
                ShowErrorAndExit("No providers given to subscribe to!");
            }

            processor = realtimeSession;
        }
        public void CanReadEventsFromRealtimeSession()
        {
            using (var reader = new ETWRealtimeProcessor("testRealtimeSession"))
            {
                reader.SubscribeToProvider(TestLogger.Write.Guid, EventLevel.Verbose);
                reader.EventProcessed += delegate(ETWEvent entry)
                                         {
                                             ValidateEventArgs(entry);
                                             if (reader.Count == 4)
                                             {
                                                 reader.StopProcessing();
                                             }
                                         };
                var processorTask = reader.CreateProcessingTask();
                WriteTestEvents();
                processorTask.Wait();

                Assert.IsTrue(processorTask.IsCompleted);
                Assert.AreEqual(4, reader.Count);
                Assert.AreEqual(0, reader.UnreadableEvents);
            }
        }