public void EventStatisticCacheGetTypeStatisticsIncorrectFilePathsTest()
        {
            TypeCache typecache = new TypeCache();

            EventStatisticCache cache = new EventStatisticCache();
            cache.GetTypeStatistics(typecache, new[] { @"C:\hello\world.etl", testDataFile });
        }
        public void EventStatisticCacheGetTypeStatisticsFilesInvalidTest()
        {
            TypeCache typecache = new TypeCache();

            EventStatisticCache cache = new EventStatisticCache();
            cache.GetTypeStatistics(typecache, new[] { string.Empty, testDataFile });
        }
        public void EventStatisticCacheCreatesCsvTest()
        {
            TypeCache typecache = new TypeCache();
            typecache.Initialize("test2", new[] { testDataFile });

            EventStatisticCache cache = new EventStatisticCache();
            var result = cache.GetTypeStatistics(typecache, new[] { testDataFile });

            Assert.IsTrue(File.Exists(Path.Combine(Environment.CurrentDirectory, "TestData", Path.GetFileNameWithoutExtension(testDataFile) + ".csv")));

            File.Delete(Path.Combine(Environment.CurrentDirectory, Path.GetFileNameWithoutExtension(testDataFile) + ".csv"));
        }
        public void EventStatisticCacheGetTypeStatisticsHappyPathTest()
        {
            TypeCache typecache = new TypeCache();
            typecache.Initialize("test1", new[] { testDataFile });

            EventStatisticCache cache = new EventStatisticCache();
            var result = cache.GetTypeStatistics(typecache, new[] { testDataFile });

            Assert.AreEqual(3, result.Keys.Count);
            Assert.IsTrue(result.All(a => a.Value.EventCount == 10));

            var typeNames = new[] { "IsoscelesTriangle", "EquilateralTriangle", "RightAngledTriangle" };
            Assert.IsTrue(result.All(a => typeNames.Contains(a.Key.Name)));
        }
        public void MultipleTypesStatsCalculationTest()
        {
            TypeCache typecache = new TypeCache();
            typecache.Initialize("MultipleTypesStatsCalculationTest", new[] { testDataFile });

            Assert.AreEqual(4, typecache.Cache.Count);
            Assert.IsTrue(typecache.Cache.All(a => a != null && a.Manifest != null && a.Type != null));

            EventStatisticCache cache = new EventStatisticCache();
            var result = cache.GetTypeStatistics(typecache, new[] { testDataFile });

            Assert.AreEqual(3, result.Count);

            var values = result.Values.ToArray();
            Assert.AreEqual(10, values[0].EventCount);
            Assert.AreEqual(10, values[1].EventCount);
            Assert.AreEqual(10, values[2].EventCount);

            File.Delete(Path.Combine("TestData", Path.GetFileNameWithoutExtension(testDataFile) + ".csv"));
        }
        public void EventStatisticLoadCsvValuesTest()
        {
            TypeCache typecache = new TypeCache();
            typecache.Initialize("test3", new[] { testDataFile });

            EventStatisticCache cache = new EventStatisticCache();
            var result = cache.GetTypeStatistics(typecache, new[] { testDataFile });

            Assert.IsTrue(File.Exists(Path.Combine(Environment.CurrentDirectory, "TestData", Path.GetFileNameWithoutExtension(testDataFile) + ".csv")));

            File.Delete(Path.Combine(Environment.CurrentDirectory, Path.GetFileNameWithoutExtension(testDataFile) + ".csv"));

            foreach (var item in result)
            {
                switch (item.Key.Name)
                {
                    case "IsoscelesTriangle":
                        Assert.AreEqual(27D, item.Value.AverageByteSize);
                        Assert.AreEqual(270, item.Value.ByteSize);
                        Assert.AreEqual(10, item.Value.EventCount);
                        Assert.AreEqual(0.0370, item.Value.EventsPerSecond);
                        break;

                    case "EquilateralTriangle":
                        Assert.AreEqual(25D, item.Value.AverageByteSize);
                        Assert.AreEqual(250, item.Value.ByteSize);
                        Assert.AreEqual(10, item.Value.EventCount);
                        Assert.AreEqual(0.0370, item.Value.EventsPerSecond);
                        break;

                    case "RightAngledTriangle":
                        Assert.AreEqual(29D, item.Value.AverageByteSize);
                        Assert.AreEqual(290, item.Value.ByteSize);
                        Assert.AreEqual(10, item.Value.EventCount);
                        Assert.AreEqual(0.037, item.Value.EventsPerSecond);
                        break;

                    default:
                        Assert.Fail("Unexpected test result. Test fails.");
                        break;
                }

            }
        }
 public void EventStatisticCacheGetTypeStatisticsNullTypesTest()
 {
     EventStatisticCache cache = new EventStatisticCache();
     cache.GetTypeStatistics(null, testDataFile);
 }
        /// <summary>
        /// Builds an assembly containing a typed data context, and returns data for the Schema Explorer.
        /// </summary>
        /// <param name="cxInfo"> Connection information, as entered by the user </param>
        /// <param name="assemblyToBuild"> Name and location of the target assembly to build </param>
        /// <param name="nameSpace"> The suggested namespace of the typed data context. You must update this
        /// parameter if you don't use the suggested namespace. </param>
        /// <param name="typeName"> The suggested type name of the typed data context. You must update this
        /// parameter if you don't use the suggested type name. </param>
        /// <returns> Schema which will be subsequently loaded into the Schema Explorer. </returns>
        public override List<ExplorerItem> GetSchemaAndBuildAssembly(
            IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            Stopwatch sw = Stopwatch.StartNew();

            nameSpace = @"System.Reactive.Tx";
            typeName = "PlaybackClass";

            var sourceCode = new List<string>();
            var sbContextUsings = new StringBuilder();
            var sbContextProperties = new StringBuilder();

            var dataContext = DataContextTemplate.Replace(@"[usings]", sbContextUsings.ToString())
                                                 .Replace(@"[properties]", sbContextProperties.ToString());

            var bondInEtwProperties = new BondInEtwProperties(cxInfo);
            _typeCache.Initialize(bondInEtwProperties.ContextName, bondInEtwProperties.Files);

            sourceCode.Add(dataContext);

            //Build Assembly - CSharpCodeProvider to compile generated code.

            var outputName = assemblyToBuild.CodeBase;

            using (
                var codeProvider =
                    new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } }))
            {
                string[] assemblies = this.GetAssembliesToAdd(cxInfo).ToArray();

                var compilerOptions = new CompilerParameters(assemblies, outputName, true);

                var results = codeProvider.CompileAssemblyFromSource(compilerOptions, sourceCode.ToArray());

                if (results.Errors.Count > 0)
                {
                    var sbErrors = new StringBuilder();

                    foreach (var error in results.Errors)
                    {
                        sbErrors.Append(error);
                    }

                    MessageBox.Show(sbErrors.ToString(), "Error compiling generated code.");
                }
            }

            var controller = new EventStatisticCache();
            var stat = controller.GetTypeStatistics(_typeCache, bondInEtwProperties.Files);

            sw.Stop();

            Console.WriteLine("Complete operation took {0} milliseconds.", sw.ElapsedMilliseconds);

            return this.CreateEventTree(stat);
        }