/// <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.Init(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)); }
/// <summary> /// Inistantiates an instance of the <see cref="ConnectionDialog"/> class. /// </summary> /// <param name="bondInEtwProperties"></param> public ConnectionDialog(BondInEtwProperties bondInEtwProperties) { this.DataContext = bondInEtwProperties; this.bondInEtwProperties = bondInEtwProperties; this.InitializeComponent(); this.fileList = new ObservableCollection<string>(bondInEtwProperties.Files); this.FileList.ItemsSource = this.fileList; }
/// <summary> /// Returns argument values to pass to into the data context's constructor, based on a given connection info. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> Argument values to pass to into the data context's constructor. </returns> public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) { var playback = new Playback(); var bondInEtwProperties = new BondInEtwProperties(cxInfo); try { var bondTypemap = new GeneralPartitionableTypeMap(); var typeMaps = TypeFinder .LoadTypeMaps(TypeCache.ResolveCacheDirectory(bondInEtwProperties.ContextName)) .Where(i => i != typeof(GeneralPartitionableTypeMap)) .Select(Activator.CreateInstance) .OfType <ITypeMap <BinaryEnvelope> >() .Concat(new[] { bondTypemap }) .ToArray(); foreach (var file in bondInEtwProperties.Files) { var file1 = file; ((IPlaybackConfiguration)playback).AddInput( () => BinaryEtwObservable.FromFiles(file1), typeMaps); } Thread.SetData(LocalDataStoreSlot, playback); return(new object[] { playback }); } catch (Exception error) { MessageBox.Show(error.Message, "Error compiling generated code."); } return(new object[0]); }
/// <summary> /// Returns a list of additional namespaces that should be imported automatically into all /// queries that use this driver. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> List of additional namespaces. </returns> public override IEnumerable <string> GetNamespacesToAdd(IConnectionInfo cxInfo) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); IEnumerable <string> result = null; try { var driverDirectory = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).Location); result = GetAssemblyTypes(driverDirectory) .Concat(TypeCache.GetTypes(bondInEtwProperties.ContextName)) .Select(type => type.Namespace) .Where(@namespace => @namespace != null) .Concat(namespaces) .Distinct(); } catch { // Ignore } return(result); }
/// <summary> /// Returns a list of additional assemblies to reference when building queries. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> List of additional assemblies. </returns> public override IEnumerable <string> GetAssembliesToAdd(IConnectionInfo cxInfo) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); IEnumerable <string> result = null; try { var driverDirectory = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).Location); result = GetAssemblyTypes(driverDirectory) .Concat(TypeCache.GetTypes(bondInEtwProperties.ContextName)) .Select(type => type.Assembly) .Concat(assemblies) .Distinct() .Select(assembly => assembly.Location) .ToList(); } catch (Exception error) { // Ignore } return(result); }
/// <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) { 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.Init(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 bondInEtwRegistry = new BondInEtwRegistry(tempFolder); // var stat = bondInEtwRegistry.GetTypeStatistics(bondInEtwProperties.Files); var controller = new EventStatisticController(_typeCache.CacheDirectory); var stat = controller.GetTypeStatistics(_typeCache, bondInEtwProperties.Files[0]); return this.CreateEventTree(stat); }
/// <summary> /// Returns argument values to pass to into the data context's constructor, based on a given connection info. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> Argument values to pass to into the data context's constructor. </returns> public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) { var playback = new Playback(); var bondInEtwProperties = new BondInEtwProperties(cxInfo); try { var bondTypemap = new GeneralPartitionableTypeMap(); var typeMaps = TypeFinder .LoadTypeMaps(TypeCache.ResolveCacheDirectory(bondInEtwProperties.ContextName)) .Where(i => i != typeof(GeneralPartitionableTypeMap)) .Select(Activator.CreateInstance) .OfType<ITypeMap<BinaryEnvelope>>() .Concat(new[] { bondTypemap }) .ToArray(); foreach (var file in bondInEtwProperties.Files) { var file1 = file; ((IPlaybackConfiguration)playback).AddInput( () => BinaryEtwObservable.FromFiles(file1), typeMaps); } Thread.SetData(LocalDataStoreSlot, playback); return new object[] { playback }; } catch (Exception error) { MessageBox.Show(error.Message, "Error compiling generated code."); } return new object[0]; }
/// <summary> /// Returns a list of additional namespaces that should be imported automatically into all /// queries that use this driver. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> List of additional namespaces. </returns> public override IEnumerable<string> GetNamespacesToAdd(IConnectionInfo cxInfo) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); IEnumerable<string> result = null; try { var driverDirectory = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).Location); result = GetAssemblyTypes(driverDirectory) .Concat(TypeCache.GetTypes(bondInEtwProperties.ContextName)) .Select(type => type.Namespace) .Where(@namespace => @namespace != null) .Concat(namespaces) .Distinct(); } catch (Exception error) { // Ignore } return result; }
/// <summary> /// Displays a dialog prompting the user for connection details. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <param name="isNewConnection"> The isNewConnection parameter will be true if the user /// is creating a new connection rather than editing an existing connection. </param> /// <returns> True if the user clicked OK. If it returns false, any changes to the IConnectionInfo object will be rolled back. </returns> public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); return new ConnectionDialog(bondInEtwProperties).ShowDialog() ?? false; }
/// <summary> /// Get connection details. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> text to display in the root Schema Explorer node for a given connection information. </returns> public override string GetConnectionDescription(IConnectionInfo cxInfo) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); return bondInEtwProperties.ContextName; }
/// <summary> /// Displays a dialog prompting the user for connection details. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <param name="isNewConnection"> The isNewConnection parameter will be true if the user /// is creating a new connection rather than editing an existing connection. </param> /// <returns> True if the user clicked OK. If it returns false, any changes to the IConnectionInfo object will be rolled back. </returns> public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); return(new ConnectionDialog(bondInEtwProperties).ShowDialog() ?? false); }
/// <summary> /// Get connection details. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> text to display in the root Schema Explorer node for a given connection information. </returns> public override string GetConnectionDescription(IConnectionInfo cxInfo) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); return(bondInEtwProperties.ContextName); }
/// <summary> /// Returns a list of additional assemblies to reference when building queries. /// </summary> /// <param name="cxInfo"> Connection information, as entered by the user. </param> /// <returns> List of additional assemblies. </returns> public override IEnumerable<string> GetAssembliesToAdd(IConnectionInfo cxInfo) { var bondInEtwProperties = new BondInEtwProperties(cxInfo); IEnumerable<string> result = null; try { var driverDirectory = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).Location); result = GetAssemblyTypes(driverDirectory) .Concat(TypeCache.GetTypes(bondInEtwProperties.ContextName)) .Select(type => type.Assembly) .Concat(assemblies) .Distinct() .Select(assembly => assembly.Location) .ToList(); } catch { // Ignore } return result; }