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);
            }
        }
Example #2
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);
        }
        /// <summary>
        /// Maps the dot net framework types. If the file already exists for a given vs version it won't be
        /// regenerated.
        /// </summary>
        /// <param name="targetFilePath">The target visualizer installation path.</param>
        public void MapDotNetFrameworkTypes(string targetFilePath)
        {
            if (targetFilePath == null)
            {
                throw new ArgumentException(@"Target folder cannot be null", nameof(targetFilePath));
            }

            if (string.IsNullOrEmpty(_dynamicVisualizerDllAssemblyPath))
            {
                throw new ArgumentException(@"Visualizer Assembly Location cannot be null", nameof(_dynamicVisualizerDllAssemblyPath));
            }

            VisualizerAttributeInjector visualizerInjector = new VisualizerAttributeInjector(_dynamicVisualizerDllAssemblyPath, VisualStudioVer);

            //Map all the possible System  types
            IEnumerable <Type> systemLinqTypes = typeof(IOrderedEnumerable <>).Assembly
                                                 .GetTypes()
                                                 .Where(type => type != null &&
                                                        (
                                                            (type.IsClass && type.IsSerializable)
                                                            ||
                                                            type.IsInterface
                                                            ||
                                                            type.Name.Contains("Iterator")
                                                        ) &&
                                                        !(type.Name.Contains("Func") || type.Name.Contains("Action")) &&
                                                        !string.IsNullOrEmpty(type.Namespace));

            //Map all the possible list types
            IEnumerable <Type> systemGenericsTypes = typeof(IList <>).Assembly
                                                     .GetTypes()
                                                     .Where(type => type != null &&
                                                            (
                                                                (type.IsClass && type.IsSerializable)
                                                                ||
                                                                type.IsInterface
                                                            ) &&
                                                            !string.IsNullOrEmpty(type.Namespace) &&
                                                            type.IsPublic)
                                                     .Where(type =>
                                                            !type.Name.Contains("ValueType") &&
                                                            !type.Name.Contains("IFormattable") &&
                                                            !type.Name.Contains("IComparable") &&
                                                            !type.Name.Contains("IConvertible") &&
                                                            !type.Name.Contains("IEquatable") &&
                                                            !type.Name.Contains("Object") &&
                                                            !type.Name.Contains("ICloneable") &&
                                                            !type.Name.Contains("String") &&
                                                            !type.Name.Contains("IDisposable"));

            systemLinqTypes.ForEach(visualizerInjector.MapType);
            systemGenericsTypes.ForEach(visualizerInjector.MapType);

            visualizerInjector.SaveDebuggerVisualizer(targetFilePath);
        }
Example #4
0
        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);
            }
        }
Example #6
0
        public void Visualizer_MapType_Should_Create_DegguberVisualizerAttribute_OfType_IList_In_Target_Assembly()
        {
            string debuggerVisualizerTargetName  = Path.Combine(_thisAssemblyDirectoryName, "TestB.dll");
            string visualizerLocation            = typeof(DynamicObjectSource).Assembly.Location;
            VisualizerAttributeInjector injector = new VisualizerAttributeInjector(visualizerLocation, "11.0");

            injector.MapType(typeof(IList <>));
            injector.SaveDebuggerVisualizer(debuggerVisualizerTargetName);

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

            Assert.IsTrue(mappedTypeNames.Contains(typeof(IList <>).AssemblyQualifiedName), "Mapping was not successful");
        }
        public void Visualizer_MapType_Should_Create_DegguberVisualizerAttribute_OfType_This_In_Target_Assembly()
        {
            var debuggerVisualizerTargetName = Path.Combine(_thisAssemblyDirectoryName, "TestA.dll");
            var visualizerLocation           = typeof(DynamicDebuggerVisualizerObjectSourceV11).Assembly.Location;
            var injector = new VisualizerAttributeInjector(visualizerLocation);

            injector.MapType(GetType());
            injector.SaveDebuggerVisualizer(debuggerVisualizerTargetName);

            var generatedAssembly = AssemblyDefinition.ReadAssembly(debuggerVisualizerTargetName);
            var mappedTypeNames   = generatedAssembly
                                    .CustomAttributes
                                    .SelectMany(p =>
                                                p.Properties.Where(n => n.Name.Equals("TargetTypeName"))
                                                .Select(l => l.Argument.Value));

            Assert.IsTrue(mappedTypeNames.Contains(GetType().AssemblyQualifiedName), "Mapping was not succesful");
        }