Exemple #1
0
        public void Visualizer_MapTypeFromAssembly_Should_Map_All_Types()
        {
            string debuggerVisualizerTargetName  = Path.Combine(_thisAssemblyDirectoryName, "TestC.dll");
            string visualizerLocation            = typeof(DynamicObjectSource).Assembly.Location;
            VisualizerAttributeInjector injector = new VisualizerAttributeInjector(visualizerLocation, "11.0");

            injector.MapTypesFromAssembly(_thisAssemblyLocation);
            injector.SaveDebuggerVisualizer(debuggerVisualizerTargetName);

            AssemblyDefinition generatedAssembly    = AssemblyDefinition.ReadAssembly(debuggerVisualizerTargetName);
            IEnumerable <Type> currentAssemblytypes =
                GetType()
                .Assembly
                .GetTypes()
                .Where(typeDef => typeDef.IsPublic && !typeDef.IsInterface && !typeDef.IsAbstract);

            IEnumerable <string> mappedTypeNames = generatedAssembly
                                                   .CustomAttributes
                                                   .SelectMany(p =>
                                                               p.Properties.Where(n => n.Name.Equals("TargetTypeName"))
                                                               .Select(l => l.Argument.Value.ToString()));

            bool allTypesArePresent = currentAssemblytypes
                                      .All(type =>
                                           mappedTypeNames.Any(mappedType => mappedType.Equals(type.AssemblyQualifiedName)));

            Assert.IsTrue(allTypesArePresent);
        }
        private void CreateDebuggerVisualizer()
        {
            try
            {
                Log.Write("Visualizer Assembly location {0}", _dynamicVisualizerDllAssemblyPath);

                VisualizerAttributeInjector attributeInjector = new VisualizerAttributeInjector(_dynamicVisualizerDllAssemblyPath, VisualStudioVer);

                attributeInjector.MapTypesFromAssembly(Assembly);

                string targetInstallationFilePath = Path.Combine(VisualizerDestinationFolder, TargetVisualizerAssemblyName);

                attributeInjector.SaveDebuggerVisualizer(targetInstallationFilePath);

                Log.Write("Assembly {0} Mapped", Assembly);
            }
            catch (Exception e)
            {
                BuildErrorEventArgs errorEvent = new BuildErrorEventArgs("Debugger Visualizer Creator", "", "MapperBuildTask", 0, 0, 0, 0, $"There was an error creating custom debugger visualizers for project {Assembly}", "", "LINQBridgeVs");
                BuildEngine.LogErrorEvent(errorEvent);
                const string errorMessage = "Error creating debugger visualizers";
                Log.Write(e, errorMessage);

                e.Capture(VisualStudioVer, message: errorMessage);
            }
        }
        private void CreateDebuggerVisualizer(string targetInstallationPath, string dynamicVisualizerSourceAssemblyPath)
        {
            Log.Write("Visualizer Assembly location {0}", dynamicVisualizerSourceAssemblyPath);

            VisualizerAttributeInjector attributeInjector = new VisualizerAttributeInjector(dynamicVisualizerSourceAssemblyPath);

            attributeInjector.MapTypesFromAssembly(Assembly);

            string targetInstallationFilePath = Path.Combine(targetInstallationPath, TargetVisualizerAssemblyName);

            attributeInjector.SaveDebuggerVisualizer(targetInstallationFilePath);

            Log.Write("Assembly {0} Mapped", Assembly);
        }
        private void Create3RdPartyVisualizers()
        {
            try
            {
                if (!CommonRegistryConfigurations.Map3RdPartyAssembly(SolutionName, VisualStudioVer))
                {
                    return;
                }

                IEnumerable <string> assemblies = Crawler.FindDependencies(ProjectPath);

                foreach (string assemblyPath in assemblies)
                {
                    string assemblyName;

                    try
                    {
                        assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
                    }
                    catch
                    {
                        continue; //in case it is not a well formed path
                    }
                    //visualizer target name based on visual studio version
                    string targetAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(VisualStudioVer, assemblyName);

                    string targetInstallationFilePath = Path.Combine(VisualizerDestinationFolder, targetAssemblyName);

                    //no need to recreate the 3rd party assembly all the time
                    if (FS.FileSystem.File.Exists(targetInstallationFilePath))
                    {
                        continue;
                    }
                    VisualizerAttributeInjector attributeInjector = new VisualizerAttributeInjector(_dynamicVisualizerDllAssemblyPath, VisualStudioVer);

                    attributeInjector.MapTypesFromAssembly(assemblyPath);

                    attributeInjector.SaveDebuggerVisualizer(targetInstallationFilePath);
                }
            }
            catch (Exception e)
            {
                const string errorMessage = "Error Mapping 3rd Party Assemblies";
                Log.Write(e, errorMessage);
                BuildWarningEventArgs errorEvent = new BuildWarningEventArgs("Debugger Visualizer Creator", "", "MapperBuildTask", 0, 0, 0, 0, $"There was an error creating custom debugger visualizers for 3rd Party Assemblies. Disable it in Tools->Options->BridgeVs->Map3RdPartyAssembly", "", "LINQBridgeVs");
                BuildEngine.LogWarningEvent(errorEvent);
                e.Capture(VisualStudioVer, message: errorMessage);
            }
        }