Exemplo n.º 1
0
        public void Performance_Tracing_To_File()
        {
            TracerConfig.Reset(@"file c:\temp\trace_uTest.txt; * *");
            Action acc = GenerateTraces;

            acc.Profile(50 * 1000, "Could trace {0} with {frequency} traces/s in {time}s");
        }
Exemplo n.º 2
0
        public void FullDataRun(Application app, FileUtils util, PerformanceUtils utilPerf, QueryUtils utilQuery, Server server)
        {
            util.Cleanup("results");

            util.ReadCrimes(app);

            var crimeSourceFull = util.GetFullStream(app);

            utilQuery.DataQuery(crimeSourceFull, out var severityAverageFull);

            var tracerConfig = new TracerConfig()
            {
                DisplayCtiEvents = false,
                SingleLine       = true,
                TraceName        = "",
                TracerKind       = TracerKind.FileFull
            };

            var outputStream = app.DefineStreamableSink <double>(typeof(TracerFactory),
                                                                 tracerConfig,
                                                                 EventShape.Point,
                                                                 StreamEventOrder.FullyOrdered);

            using (severityAverageFull.Bind(outputStream).Run("process"))
            {
                utilPerf.MonitorPerformance(server, "performance/performanceFull.txt");
                System.Threading.Thread.Sleep(200);
            }
        }
Exemplo n.º 3
0
        public void Performance_Static_Traces_To_Null_Device()
        {
            TracerConfig.Reset("null; * *");
            Action acc = GenerateStaticTraces;

            acc.Profile(500 * 1000, "Could trace {0} with {frequency} traces/s in {time}s");
        }
Exemplo n.º 4
0
        public void Performance_Tracing_To_DebugOutput()
        {
            TracerConfig.Reset(@"DebugOutput; * *");
            Action acc = GenerateTraces;

            acc.Profile(50 * 1000, "Could trace {0} with {frequency} traces/s in {time}s");
        }
Exemplo n.º 5
0
        public void Performance_Tracing_To_Null_Device_Not_Matching()
        {
            TracerConfig.Reset("null; xxx *");
            Action acc = GenerateTraces;

            acc.Profile(500 * 1000, "Could trace {0} with {frequency} traces/s in {time}s");
        }
Exemplo n.º 6
0
        public void Trace_Only_Exceptions()
        {
            TracerConfig.Reset("null;* Exception");
            StringListTraceListener stringTracer = new StringListTraceListener();

            TracerConfig.Listeners.Add(stringTracer);

            const int Runs = 20;

            for (int i = 0; i < Runs; i++)
            {
                string exStr = "Ex Nr" + i;
                try
                {
                    using (Tracer tr1 = new Tracer(myType, "Enclosing Method"))
                    {
                        using (Tracer tracer = new Tracer(myType, "Thread Method"))
                        {
                            throw new NotImplementedException(exStr);
                        }
                    }
                }
                catch (Exception)
                { }
                Assert.AreEqual(i + 1, stringTracer.Messages.Count);
                Assert.IsTrue(stringTracer.Messages[i].Contains(exStr),
                              String.Format("Got {0} but did not find substring {1}", stringTracer.Messages[i], exStr));
            }
        }
Exemplo n.º 7
0
        public void Trace_From_ManyThreads()
        {
            TracerConfig.Reset("null;* *");
            StringListTraceListener stringTracer = new StringListTraceListener();

            TracerConfig.Listeners.Add(stringTracer);

            List <Thread> threads          = new List <Thread>();
            int           Threads          = 5;
            int           GenerateCount    = 10 * 1000;
            int           LinesPerGenerate = 5;

            for (int i = 0; i < Threads; i++)
            {
                Thread t = new Thread(new ParameterizedThreadStart(GenerateTraces));
                t.IsBackground = true;
                t.Start(GenerateCount);
                threads.Add(t);
            }

            threads.ForEach((t) => t.Join());

            Assert.AreEqual(Threads * GenerateCount * LinesPerGenerate, stringTracer.Messages.Count);
            HashSet <int> threadIds = new HashSet <int>();

            foreach (var line in stringTracer.Messages)
            {
                threadIds.Add(int.Parse(line.Substring(20, 4)));
            }

            Assert.AreEqual(Threads, threadIds.Count);
        }
Exemplo n.º 8
0
        public void PartDataRun(Application app, FileUtils util, PerformanceUtils utilPerf, QueryUtils utilQuery,
                                Server server, int noOfTries, int howMany, int seqLength)
        {
            while (noOfTries != 0)
            {
                util.TruncateCrimes(app, howMany, seqLength);

                var crimeSourcePart = util.GetPartStream(app);

                utilQuery.DataQuery(crimeSourcePart, out var severityAveragePart);

                var tracerConfig2 = new TracerConfig()
                {
                    DisplayCtiEvents = false,
                    SingleLine       = true,
                    TraceName        = "",
                    TracerKind       = TracerKind.FilePartial
                };

                var outputStream2 = app.DefineStreamableSink <double>(typeof(TracerFactory),
                                                                      tracerConfig2,
                                                                      EventShape.Point,
                                                                      StreamEventOrder.FullyOrdered);

                using (severityAveragePart.Bind(outputStream2).Run("process"))
                {
                    utilPerf.MonitorPerformance(server, "performance2/performancePart" + new Random().Next(100) + ".txt");
                    System.Threading.Thread.Sleep(200);
                }
                noOfTries--;
            }
        }
Exemplo n.º 9
0
        public void Performance_Tracing_Is_Off()
        {
            TracerConfig.Reset(null);

            Action acc = GenerateTraces;

            acc.Profile(5 * 1000 * 1000, "Could trace {0} with {frequency} traces/s in {time}s");
        }
Exemplo n.º 10
0
        public void Can_Trace_Info()
        {
            TracerConfig.Reset("null;* *");
            Tracer t = new Tracer();

            t.Info("Hello world {0}", "test");
            t.Warning("");
            t.Error("");
            t.Dispose();
        }
Exemplo n.º 11
0
        public void Trace_Static_Messages_To_DebugOutput()
        {
            TracerConfig.Reset("debugoutput");
            const string MethodName = "Trace_Static_Messages_To_DebugOutput";

            Tracer.Info(Level.L1, myType, MethodName, "Info {0}", "world");
            Tracer.Warning(Level.L2, myType, MethodName, "Warning {0}", "world");
            Tracer.Error(Level.L3, myType, MethodName, "Error {0}", "world");
            Tracer.Error(Level.L4, myType, MethodName, new Exception("Test Exception"));
            Tracer.Error(Level.L5, myType, MethodName, new Exception("Other Test Exception"), "Error {0}", "world");
        }
Exemplo n.º 12
0
        public void Trace_Instance_Messages_To_DebugOutput()
        {
            TracerConfig.Reset("debugoutput");

            using (Tracer t = new Tracer(myType, "Test_Method"))
            {
                t.Info("Info message");
                t.Warning("Warning message");
                t.Error("Error message");
            }
        }
Exemplo n.º 13
0
 public void Leave_Method_WithException()
 {
     TracerConfig.Reset("debugoutput");
     try
     {
         using (Tracer t = new Tracer(myType, "Leave_Method_WithException"))
         {
             throw new InvalidCastException("test ex");
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 14
0
        public void Inject_Fault_After_File_Open()
        {
            DoSomeLogic();
            TracerConfig.Reset("null");
            Tracer.TraceEvent += (severity, typemethod, time, message) =>
            {
                if (severity == Tracer.MsgType.Instrument)
                {
                    throw new IOException("Hi this is an injected fault");
                }
            };

            Assert.Throws <IOException>(() => DoSomeLogic());
        }
Exemplo n.º 15
0
        public void Performance_Of_Action_Delegate()
        {
            int called = 0;

            TracerConfig.Reset("null;* Level1");
            Action prof = () =>
            {
                Tracer.Execute(MessageTypes.Info, Level.L1, myType, () => called++);
            };
            const int Runs = 1000 * 1000;

            prof.Profile(Runs, "Could execute {0} trace callbacks with {frequency} calls/s in {time}s");
            Assert.AreEqual(Runs, called);
            Console.WriteLine("Executed {0}", called);
        }
Exemplo n.º 16
0
        public void Every_Thread_Prints_His_Exception_Only_Once()
        {
            TracerConfig.Reset("null");
            StringListTraceListener stringTracer = new StringListTraceListener();

            TracerConfig.Listeners.Add(stringTracer);
            ThreadStart method = () =>
            {
                try
                {
                    using (Tracer tr1 = new Tracer(myType, "Enclosing Method"))
                    {
                        using (Tracer tracer = new Tracer(myType, "Thread Method"))
                        {
                            throw new NotImplementedException(Thread.CurrentThread.Name);
                        }
                    }
                }
                catch (Exception)
                { }
            };

            List <Thread> threads     = new List <Thread>();
            const int     ThreadCount = 3;
            List <string> threadNames = new List <string>();

            for (int i = 0; i < ThreadCount; i++)
            {
                Thread t          = new Thread(method);
                string threadName = "Tracer Thread " + i;
                t.Name = threadName;
                threadNames.Add(threadName);
                t.Start();
                threads.Add(t);
            }

            threads.ForEach(t => t.Join());

            var exLines = stringTracer.GetMessages(line => line.Contains("Exception"));

            Assert.AreEqual(ThreadCount, exLines.Count);
            for (int i = 0; i < threadNames.Count; i++)
            {
                Assert.IsTrue(exLines.Any(traceLine => traceLine.Contains(threadNames[i])),
                              String.Format("Thread with name {0} not found in output", exLines[i]));
            }
            Assert.AreEqual(ThreadCount * 5, stringTracer.Messages.Count);
        }
Exemplo n.º 17
0
        public void When_Level1_And_Error_IsEnabled_NothingElse_Must_Pass()
        {
            TracerConfig.Reset("null;* l1+error");
            StringListTraceListener stringTracer = new StringListTraceListener();

            TracerConfig.Listeners.Add(stringTracer);

            GenerateLevelTraces(Level.L1);

            try
            {
                Assert.AreEqual(4, stringTracer.Messages.Count);
            }
            finally
            {
                ExceptionHelper.WhenException(() => stringTracer.Messages.ForEach((str) => Console.Write(str)));
            }
        }
Exemplo n.º 18
0
        public void Can_Inject_Faults()
        {
            TracerConfig.Reset("null");
            GenerateLevelTraces(Level.All);

            Tracer.TraceEvent += (msgType, typemethod, time, msg) =>
            {
                if (msgType == Tracer.MsgType.Error)
                {
                    throw new InvalidOperationException("Injectect Fault");
                }
            };

            Assert.Throws <InvalidOperationException>(() => GenerateLevelTraces(Level.All));

            TracerConfig.Reset(null);
            GenerateLevelTraces(Level.All);
        }
Exemplo n.º 19
0
        public void Events_Can_Survive_TraceConfig_Reset()
        {
            TracerConfig.Reset("null");

            Tracer.TraceEvent += (msgType, typemethod, time, msg) =>
            {
                if (msg == "Error trace")
                {
                    throw new InvalidOperationException("Injectect Fault");
                }
            };

            Assert.Throws <InvalidOperationException>(() => GenerateLevelTraces(Level.All));
            TracerConfig.Reset("null", false);
            Assert.Throws <InvalidOperationException>(() => GenerateLevelTraces(Level.All));
            TracerConfig.Reset("null", true);
            GenerateLevelTraces(Level.All);
        }
Exemplo n.º 20
0
        public void When_Level2_IsEnabled_NoOtherTracesArrive()
        {
            TracerConfig.Reset("null;* level2");
            StringListTraceListener stringTracer = new StringListTraceListener();

            TracerConfig.Listeners.Add(stringTracer);

            GenerateLevelTraces(Level.L1);

            try
            {
                Assert.AreEqual(0, stringTracer.Messages.Count);
            }
            finally
            {
                ExceptionHelper.WhenException(() => stringTracer.Messages.ForEach((str) => Console.Write(str)));
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Appends a secondary query to the specified query and starts it.
        /// </summary>
        /// <param name="primaryQuery">Primary query to append to.</param>
        /// <returns>The secondary query.</returns>
        private static Query ComposeSecondaryQuery(Query primaryQuery)
        {
            // Create a stream based on the output of the primary query.
            var inputstream = primaryQuery.ToStream <AnnotatedValue>();

            // Specify the secondary query logic: Select only a specific sensor.
            var filtered = from e in inputstream
                           where e.DeviceID == "0"
                           select e;

            // Find the maximum of all sensor values within 5 second windows -
            // provided the window contains one or more events.
            var result = from win in filtered.TumblingWindow(TimeSpan.FromSeconds(5), HoppingWindowOutputPolicy.ClipToWindowEnd)
                         select new { Max = win.Max(e => e.ValueDelta) };

            // Display the result of this query in the console window, but with
            // a different tracer name.
            var tracerConfig = new TracerConfig()
            {
                DisplayCtiEvents = false,
                SingleLine       = true,
                TraceName        = "MaxDeltas",
                TracerKind       = TracerKind.Console
            };

            // Turn this into a query and start it.
            // This call does not need an application object, because it is
            // already determined by the primary query.
            //
            // The secondary query will start feeding from the result
            // of the primary query, after the primary query has already
            // been started and producing events. The secondary query will
            // receive the last CTI emitted by the primary query, plus at least
            // those events produced by the primary query that overlapped with
            // this CTI.
            var query = result.ToQuery("OneSensorMaxDelta", string.Empty, typeof(TracerFactory), tracerConfig, EventShape.Interval, StreamEventOrder.FullyOrdered);

            query.Start();

            return(query);
        }
Exemplo n.º 22
0
        public void Inject_Fault_During_Stream_Read()
        {
            TracerConfig.Reset("null");

            DoSomeLogic();

            int lineCount = 0;

            Tracer.TraceEvent += (severity, typemethod, time, message) =>
            {
                if (severity == Tracer.MsgType.Information && message.Contains("Got line from"))
                {
                    lineCount++;
                    if (lineCount == 2)
                    {
                        throw new IOException("Exception during read of second line");
                    }
                }
            };

            Assert.Throws <IOException>(() => DoSomeLogic());
        }
Exemplo n.º 23
0
        public CommandData Parse(string[] args)
        {
            CommandData cmdArgs = new CommandData();

            myArgs = args;

            for (myParseIdx = 0; myParseIdx < args.Length; myParseIdx++)
            {
                string        curArg  = MakeArgLowerCase(args[myParseIdx]);
                List <string> hookCmd = null;

                curArg = TranslateShortToLong(curArg);
                switch (curArg)
                {
                case "corflags":
                    cmdArgs.Command = Commands.CorFlags;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd);
                    break;

                case "cwd":
                    var rootDir = NextOptionForArgument();
                    if (rootDir.Count == 0)
                    {
                        cmdArgs.InvalidComandLineSwitch = "cwd";
                        break;
                    }

                    cmdArgs.Cwd = rootDir[0];
                    break;

                case "diff":
                    cmdArgs.Command = Commands.Diff;
                    DoNotExpectAdditionalParameters(cmdArgs);
                    break;

                case "in":
                    AddQuery(cmdArgs.Queries2, cmdArgs);
                    break;

                case "old":
                    AddQuery(cmdArgs.Queries1, cmdArgs);
                    break;

                case "old2":
                    AddQuery(cmdArgs.OldFiles2, cmdArgs);
                    break;

                case "searchin":
                    AddQuery(cmdArgs.SearchInQuery, cmdArgs);
                    break;

                case "new":
                    AddQuery(cmdArgs.Queries2, cmdArgs);
                    break;

                case "imbalance":
                    cmdArgs.EventSubscriptionImbalance = true;
                    break;

                case "trace":
                    TracerConfig.Reset("console;* Level1");
                    break;

                case WhoUsesMethodCommand.Argument:
                    cmdArgs.Command = Commands.MethodUsage;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }

                    string potentialQuery = hookCmd[0];
                    if (potentialQuery.Contains("("))
                    {
                        cmdArgs.TypeAndInnerQuery = potentialQuery;
                    }
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd.GetRange(1, hookCmd.Count - 1));
                    break;

                case WhoUsesTypeCommand.Argument:
                    cmdArgs.Command = Commands.WhoUsesType;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }

                    cmdArgs.TypeQuery = hookCmd[0];
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd.GetRange(1, hookCmd.Count - 1));
                    break;

                case WhoUsesFieldCommand.Argument:
                    cmdArgs.Command = Commands.WhoUsesField;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    cmdArgs.TypeAndInnerQuery = hookCmd[0];
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd.GetRange(1, hookCmd.Count - 1));
                    break;

                case WhoUsesEventCommand.Argument:
                    cmdArgs.Command = Commands.WhoUsesEvent;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    cmdArgs.TypeAndInnerQuery = hookCmd[0];
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd.GetRange(1, hookCmd.Count - 1));
                    break;

                case WhoImplementsInterfaceCommand.Argument:
                    cmdArgs.Command = Commands.WhoImplementsInterface;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }

                    cmdArgs.TypeQuery = hookCmd[0];
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd.GetRange(1, hookCmd.Count - 1));
                    break;

                case WhoUsesStringConstantCommand.Argument:
                    cmdArgs.Command = Commands.WhoUsesStringConstant;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }

                    cmdArgs.StringConstant = hookCmd[0];
                    if (hookCmd.Count > 1)
                    {
                        AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd.GetRange(1, hookCmd.Count - 1));
                    }
                    break;

                case "word":
                    cmdArgs.WordMatch = true;
                    break;

                case "case":
                    cmdArgs.CaseSensitiveMatch = true;
                    break;

                case GetFileInfoCommand.Argument:
                    cmdArgs.Command = Commands.GetFileInfo;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd);
                    break;

                case "whoreferences":
                    cmdArgs.Command = Commands.WhoReferences;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    AddQuery(cmdArgs.Queries1, cmdArgs, hookCmd);
                    break;

                case "getpdbs":
                    cmdArgs.Command = Commands.DownloadPdbs;
                    hookCmd         = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    AddQuery(cmdArgs.Queries1, cmdArgs, new List <string> {
                        hookCmd[0]
                    });
                    if (hookCmd.Count > 1)
                    {
                        cmdArgs.PdbDownloadDir = hookCmd[1];
                    }
                    if (hookCmd.Count > 2)
                    {
                        cmdArgs.InvalidComandLineSwitch = String.Format("The argument {0} is not valid for this command", hookCmd[2]);
                    }
                    break;

                case "showrebuildtargets":
                    cmdArgs.Command = Commands.ShowRebuildTargets;
                    DoNotExpectAdditionalParameters(cmdArgs);
                    break;

                case "showstrongname":
                    cmdArgs.Command = Commands.ShowStrongName;
                    AddQuery(cmdArgs.Queries1, cmdArgs);
                    break;

                case "showreferences":
                    cmdArgs.Command = Commands.ShowReferences;
                    AddQuery(cmdArgs.Queries1, cmdArgs);
                    break;

                case "verbose":
                    cmdArgs.Verbose = true;
                    break;

                case "excel":
                    cmdArgs.OutputToExcel = true;
                    hookCmd = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    cmdArgs.ExcelOutputFileName = hookCmd[0];
                    break;

                case "threads":
                    hookCmd = NextOptionForArgument();
                    if (hookCmd.Count == 0)
                    {
                        break;
                    }
                    int newThreadCount = 0;
                    if (int.TryParse(hookCmd[0], out newThreadCount) && newThreadCount > 0)
                    {
                        cmdArgs.ThreadCount = newThreadCount;
                    }
                    else
                    {
                        cmdArgs.InvalidComandLineSwitch = hookCmd[0];
                    }
                    break;

                case "fileinfo":
                    cmdArgs.WithFileInfo = true;
                    break;

                default:
                    cmdArgs.UnknownCommandLineSwitch = curArg;
                    break;
                }
            }

            return(cmdArgs);
        }
Exemplo n.º 24
0
 public void AA_Enable_File()
 {
     TracerConfig.Reset("file");
 }
Exemplo n.º 25
0
 public void AAZ_Disable()
 {
     TracerConfig.Reset(null);
 }
Exemplo n.º 26
0
 public void Dispose()
 {
     TracerConfig.Reset(myOldTraceCfg);
 }
Exemplo n.º 27
0
        public void Demo_Show_Leaving_Trace_With_Exception()
        {
            TracerConfig.Reset("console");

            SomeMethod();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Main routine.
        /// </summary>
        internal static void Main()
        {
            // Creating an embedded server.
            //
            // NOTE: replace "Default" with the instance name you provided
            // during StreamInsight setup.
            using (Server server = Server.Create("Default"))
            {
                // Comment out if you want to create a service host and expose
                // the server's endpoint:

                //ServiceHost host = new ServiceHost(server.CreateManagementService());

                //host.AddServiceEndpoint(
                //    typeof(IManagementService),
                //    new WSHttpBinding(SecurityMode.Message),
                //    "http://localhost/MyStreamInsightServer");

                // To enable remote connection / debugging, you also need to uncomment the
                // lines "host.Open()" and "host.Close()".
                // In addition, the URI needs to be provisioned for the
                // account that runs this process (unless Administrator). To do this, open
                // an admin shell and execute the following command, using the respective
                // user credentials:
                // netsh http add urlacl url=http://+:80/MyStreamInsightServer user=<domain\username>

                //host.Open();

                // Configuration of the data generator input adapter.
                var generatorConfig = new GeneratorConfig()
                {
                    CtiFrequency          = 1,
                    EventInterval         = 500,
                    EventIntervalVariance = 450,
                    DeviceCount           = 5,
                    MaxValue = 100
                };

                // Configuration of the tracer output adapter.
                var tracerConfig = new TracerConfig()
                {
                    DisplayCtiEvents = false,
                    SingleLine       = true,
                    TraceName        = "Deltas",
                    TracerKind       = TracerKind.Console
                };

                try
                {
                    var myApp = server.CreateApplication("DeviceReadings");

                    // Create an input stream directly from the adapter,
                    // requesting point events from the simulator.
                    var inputstream = CepStream <GeneratedEvent> .Create("input", typeof(GeneratorFactory), generatorConfig, EventShape.Point);

                    // Compute the delta of consecutive values, using a count window
                    // and a user-defined aggregate.
                    // Use group & apply to compute this for each device separately.
                    var deltas = from e in inputstream
                                 group e by e.DeviceId into eachGroup
                                 from win in eachGroup.CountByStartTimeWindow(2, CountWindowOutputPolicy.PointAlignToWindowEnd)
                                 select new { ValueDelta = win.Delta(e => e.Value), SourceID = eachGroup.Key };

                    // Annotate the original values with the delta events by joining them.
                    // The aggregate over the count window produces a point event at
                    // the end of the window, which coincides with the second event in
                    // the window, so that they can be joined.
                    var annotatedValues = from left in inputstream
                                          join right in deltas
                                          on left.DeviceId equals right.SourceID
                                          select new { DeviceID = left.DeviceId, left.Value, right.ValueDelta };

                    // Turn this logic into a query, outputting to the tracer output adapter.
                    var primaryQuery = annotatedValues.ToQuery(
                        myApp,
                        "Deltas",
                        string.Empty,
                        typeof(TracerFactory),
                        tracerConfig,
                        EventShape.Point,
                        StreamEventOrder.FullyOrdered);

                    // Start the query now.
                    primaryQuery.Start();

                    // Append and start another query through Dynamic Query Composition,
                    // passing the primary query object.
                    var secondaryQuery = ComposeSecondaryQuery(primaryQuery);

                    // Wait for keystroke to end.
                    Console.ReadLine();

                    // Stop both queries.
                    primaryQuery.Stop();
                    secondaryQuery.Stop();

                    Console.WriteLine("Query stopped. Press enter to exit application.");
                    Console.ReadLine();

                    //host.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Main routine.
        /// </summary>
        internal static void Main()
        {
            // Creating an embedded server.
            //
            // NOTE: replace "Default" with the instance name you provided
            // during StreamInsight setup.
            using (Server server = Server.Create("Default"))
            {
                // Comment out if you want to create a service host and expose
                // the server's endpoint:

                //ServiceHost host = new ServiceHost(server.CreateManagementService());

                //host.AddServiceEndpoint(
                //    typeof(IManagementService),
                //    new WSHttpBinding(SecurityMode.Message),
                //    "http://localhost/MyStreamInsightServer");

                // To enable remote connection / debugging, you also need to uncomment the
                // lines "host.Open()" and "host.Close()".
                // In addition, the URI needs to be provisioned for the
                // account that runs this process (unless Administrator). To do this, open
                // an admin shell and execute the following command, using the respective
                // user credentials:
                // netsh http add urlacl url=http://+:80/MyStreamInsightServer user=<domain\username>

                //host.Open();

                try
                {
                    Application myApp = server.CreateApplication("DeviceReadings");

                    // Configuration of the data generator input adapter.
                    var generatorConfig = new GeneratorConfig()
                    {
                        CtiFrequency          = 1,
                        EventInterval         = 500,
                        EventIntervalVariance = 450,
                        DeviceCount           = 5,
                        MaxValue = 100
                    };

                    // Define a source stream based on an adapter implementation, which requests point events from the simulator
                    var inputStream = myApp.DefineStreamable <GeneratedEvent>(typeof(GeneratorFactory), generatorConfig, EventShape.Point, null);

                    // Configuration of the tracer output adapter 1.
                    var tracerConfig1 = new TracerConfig()
                    {
                        DisplayCtiEvents = false,
                        SingleLine       = true,
                        TraceName        = "Deltas",
                        TracerKind       = TracerKind.Console
                    };

                    var outputStream1 = myApp.DefineStreamableSink <AnnotatedValue>(typeof(TracerFactory),
                                                                                    tracerConfig1,
                                                                                    EventShape.Point,
                                                                                    StreamEventOrder.FullyOrdered);

                    // Configuration of the tracer output adapter 2.
                    var tracerConfig2 = new TracerConfig()
                    {
                        DisplayCtiEvents = false,
                        SingleLine       = true,
                        TraceName        = "MaxDeltas",
                        TracerKind       = TracerKind.Console
                    };

                    var outputStream2 = myApp.DefineStreamableSink <float>(typeof(TracerFactory),
                                                                           tracerConfig2,
                                                                           EventShape.Interval,
                                                                           StreamEventOrder.FullyOrdered);

                    // Annotate the original values with the delta events by joining them.
                    // The aggregate over the count window produces a point event at
                    // the end of the window, which coincides with the second event in
                    // the window, so that they can be joined.
                    var annotatedValues = inputStream.Multicast(s =>
                                                                from left in s
                                                                join right in
                                                                (from e in s
                                                                 group e by e.DeviceId into eachGroup
                                                                 from win in eachGroup.CountWindow(2)
                                                                 select new { ValueDelta = win.Delta(e => e.Value), SourceID = eachGroup.Key }
                                                                )
                                                                on left.DeviceId equals right.SourceID
                                                                select new AnnotatedValue()
                    {
                        DeviceID = left.DeviceId, Value = left.Value, ValueDelta = right.ValueDelta
                    });

                    var filtered = from e in annotatedValues
                                   where e.DeviceID == "0"
                                   select e;

                    var maxDelta = from win in filtered.TumblingWindow(TimeSpan.FromSeconds(5))
                                   select win.Max(e => e.ValueDelta);

                    // Hydra is used to bind multiple queries
                    using (annotatedValues.Bind(outputStream1).With(maxDelta.Bind(outputStream2)).Run())
                    {
                        // Wait for keystroke to end.
                        Console.WriteLine("Press enter to stop.");
                        Console.ReadLine();
                    }

                    Console.WriteLine("Process stopped. Press enter to exit application.");
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 30
0
 public TraceReset(string newTraceCfg)
 {
     myOldTraceCfg = TracerConfig.Reset(newTraceCfg);
 }