Ejemplo n.º 1
0
        /// <summary>
        /// Analyzes all assemblies in output folder.
        /// </summary>
        /// <param name="analyzer">The analyzer.</param>
        /// <param name="assemblyFileList">The assembly file list.</param>
        /// <param name="assemblies">The assemblies.</param>
        private void AnalyzeWeavableAssemblies(IILAnalyzer analyzer, List <ITaskItem> weavableAssemblies, List <AssemblyElement> assemblies)
        {
            foreach (ITaskItem item in weavableAssemblies)
            {
                try
                {
                    AssemblyElement assembly = AnalyzeAssembly(analyzer, item);

                    if (assembly != null)
                    {
                        assemblies.Add(assembly);
                    }
                }
                catch (ILAnalyzerException ex)
                {
                    Log.LogErrorFromException(ex, true);
                }
                catch (ArgumentException ex)
                {
                    Log.LogErrorFromException(ex, true);
                }
                catch (FileNotFoundException ex)
                {
                    Log.LogErrorFromException(ex, true);
                }
                catch (BadImageFormatException ex)
                {
                    Log.LogErrorFromException(ex, false);
                }
            }
        }
 public override void AddInstruction(AssemblyElement element)
 {
     AddInstructions(new List <AssemblyElement>()
     {
         element
     });
 }
Ejemplo n.º 3
0
        public void Finish()
        {
            int counter    = 0;
            int maxCounter = ExecBlocks.Count;

            foreach (BaseExecBlockContext execBlock in ExecBlocks)
            {
                if (_verbose)
                {
                    Console.Write($"\r{++counter}/{maxCounter} lazy references resolved");
                }
                for (int i = 0; i < execBlock.Body.Count; ++i)
                {
                    AssemblyElement element = execBlock.Body[i];
                    if (element is LazyReferenceAtomInstructions nodeInstructions)
                    {
                        LoadStateFromSnapshot(nodeInstructions.AssemblyBuilderSnapshot);
                        List <AssemblyElement> instructions = GetDatSymbolReferenceInstructions(nodeInstructions.ReferenceContext);
                        execBlock.Body.RemoveAt(i);
                        execBlock.Body.InsertRange(i, instructions);
                    }

                    if (element is PushVar pushVar && pushVar.Symbol.IsStringLiteralSymbol())
                    {
                        pushVar.Symbol.Name = NewStringSymbolName();
                        AddSymbol(pushVar.Symbol);
                    }
                }
            }
            if (_verbose)
            {
                Console.WriteLine("");
            }
        }
        public void TestMarkdownOutput()
        {
            reader.MoveToContent();
            IElement element = new AssemblyElement(reader).Create("assembly");

            Assert.AreEqual("### TestDoc", element.ToMarkdown());
        }
        public void ToElementForAssemblyReturnsTheCorrectAssembly()
        {
            Assembly        expected = typeof(TypeWithAllElements).Assembly;
            AssemblyElement actual   = expected.ToElement();

            Assert.Equal(new AssemblyElement(expected), actual);
        }
Ejemplo n.º 6
0
        public static Dictionary <Type, List <PropertyInfo> > GetProperties()
        {
            lock (SyncObject)
            {
                Stopwatch   sw             = Stopwatch.StartNew();
                List <Task> tasksContainer = new List <Task>();
                if (_properties != null)
                {
                    sw.Stop();
                    Trace.WriteLine(string.Format("Total time taken to search assemblys: {0}ms", sw.ElapsedMilliseconds));
                    return(FindProperties._properties);
                }

                FindProperties._properties = new Dictionary <Type, List <PropertyInfo> >();
                var assemblyElements = AssemblySection.GetAssemblies();

                foreach (AssemblyElement assemblyElement in assemblyElements)
                {
                    AssemblyElement element = assemblyElement;
                    Task            task    = Task.Factory.StartNew(() => SearchAssemblyTask(element));
                    tasksContainer.Add(task);
                }

                Task.WaitAll(tasksContainer.ToArray());
                sw.Stop();
                Trace.WriteLine(string.Format("Total time taken to search assemblies: {0}ms", sw.ElapsedMilliseconds));
                return(FindProperties._properties);
            }
        }
Ejemplo n.º 7
0
        public TrimAssembly GetAssemblyElement(String assemblyName)
        {
            AssemblyElement result = null;

            _assemblies.TryGetValue(assemblyName, out result);
            return(result as TrimAssembly);
        }
        public override TypeElement CreateTypeElement(AssemblyElement assembly, string typeName, IncludeStatus includeStatus, VisibilityOverride visibilityOverride, SecurityTransparencyStatus securityTransparencyStatus)
        {
            CodeTypeElement type = new CodeTypeElement(includeStatus, visibilityOverride, securityTransparencyStatus, typeName);

            (assembly as CodeAssemblyElement).m_types.Add(typeName, type);
            return(type);
        }
Ejemplo n.º 9
0
        public void InitializeThrowsBadImageExceptionOnInvalidInputImage()
        {
            CecilAnalyzerConfiguration configuration     = CecilAnalyzerConfiguration.CreateDefaultConfiguration(string.Empty);
            ILanguageModelAccessor     langModelAccessor = new LanguageModelAccessorMock();

            AssemblyElement ae = ((IILAnalyzer) new CecilILAnalyzer(configuration, langModelAccessor)).ExtractAllTypes(CreateFullPath("InvalidImage.exe"));
        }
        public override TypeForwarderElement CreateTypeForwarderElement(AssemblyElement parent, string assemblyName, string typeName, IncludeStatus includeStatus)
        {
            CodeTypeForwarderElement typeForwarder = new CodeTypeForwarderElement(includeStatus, assemblyName, typeName);

            (parent as CodeAssemblyElement).TypeForwarders.Add(typeForwarder.Key, typeForwarder);
            return(typeForwarder);
        }
Ejemplo n.º 11
0
        public void SutDoesNotEqualAnonymousObject(object other)
        {
            var sut    = new AssemblyElement(this.GetType().Assembly);
            var actual = sut.Equals(other);

            Assert.False(actual);
        }
        public void AssemblyElementTests()
        {
            AssemblyElement assemblyElement = new AssemblyElement(XMLAssemblyElement);

            Assert.AreEqual(XMLAssemblyElement.Element("name").Value, assemblyElement.ElementTextValue);
            Assert.AreEqual($"# {XMLAssemblyElement.Element("name").Value} #", assemblyElement.MarkdownValue);
        }
Ejemplo n.º 13
0
        private AssemblyElement AnalyzeSources()
        {
            AssemblyElement asm = new AssemblyElement();

            asm.Name     = _assemblyName;
            asm.FileName = "...";

            List <string> refs = new List <string>();

            refs.Add(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll");
            refs.Add(@"C:\WINDOWS\assembly\GAC_32\vjslib\2.0.0.0__b03f5f7f11d50a3a\vjslib.dll");

            if (_weavableAssemblies != null)
            {
                refs.AddRange(_weavableAssemblies);
            }

            if (_referencedAssemblies != null)
            {
                refs.AddRange(_referencedAssemblies);
            }

            AssemblyContext rc = new AssemblyContext(refs);

            SourceAnalyzer     sa    = GetSourceAnalyzer(_codeLanguage);
            List <TypeElement> types = sa.Analyze(rc, _sources);

            asm.Types.AddRange(types);

            return(asm);
        }
Ejemplo n.º 14
0
        public void AnalyzerThrowsExceptionIfFileDoesntExists()
        {
            CecilAnalyzerConfiguration configuration     = CecilAnalyzerConfiguration.CreateDefaultConfiguration(string.Empty);
            ILanguageModelAccessor     langModelAccessor = new LanguageModelAccessorMock();

            AssemblyElement ae = ((IILAnalyzer) new CecilILAnalyzer(configuration, langModelAccessor)).ExtractAllTypes("c:\\this_file_doesnt_exist");
        }
Ejemplo n.º 15
0
        public override TypeForwarderElement CreateTypeForwarderElement(AssemblyElement parent, string assemblyName, string typeName, IncludeStatus includeStatus)
        {
            TrimAssembly      trimAssembly  = (TrimAssembly)parent;
            TrimTypeForwarder typeForwarder = new TrimTypeForwarder(assemblyName, typeName, includeStatus);

            trimAssembly.TypeForwarders.Add(typeForwarder.Key, typeForwarder);
            return(typeForwarder);
        }
Ejemplo n.º 16
0
        public override TypeElement CreateTypeElement(AssemblyElement assembly, string typeName, IncludeStatus includeStatus, VisibilityOverride visibilityOverride, SecurityTransparencyStatus securityTransparencyStatus)
        {
            TrimAssembly trimAssembly = (TrimAssembly)assembly;

            TrimType typeIncludeInfo = new TrimType(typeName, includeStatus, visibilityOverride, securityTransparencyStatus);

            trimAssembly.Types.Add(typeIncludeInfo.Key, typeIncludeInfo);
            return(typeIncludeInfo);
        }
Ejemplo n.º 17
0
 public void SutIsReflectionElement()
 {
     // Fixture setup
     // Exercise system
     var sut = new AssemblyElement(this.GetType().Assembly);
     // Verify outcome
     Assert.IsAssignableFrom<IReflectionElement>(sut);
     // Teardown
 }
Ejemplo n.º 18
0
        public void SutDoesNotEqualDifferentInstanceOfSameType()
        {
            var sut   = new AssemblyElement(this.GetType().Assembly);
            var other = new AssemblyElement(typeof(Version).Assembly);

            var actual = sut.Equals(other);

            Assert.False(actual);
        }
Ejemplo n.º 19
0
        public void ShouldThrowExceptionParametersAreNullWhenLoading()
        {
            EntitiesAccessor target = EntitiesAccessor.Instance;

            string filename = null;

            AssemblyElement        ae = target.LoadAssemblyElement(filename);
            ConfigurationContainer cc = target.LoadConfiguration(filename);
            WeaveSpecification     ws = target.LoadWeaveSpecification(filename);
        }
Ejemplo n.º 20
0
        private void StoreAssemblyElement(AssemblyElement asm)
        {
            string filename = @"C:\CPS\StarLight\Examples\PacmanTwo\obj\StarLight\" + asm.Name + ".xml";

            using (TextWriter writer = File.CreateText(filename))
            {
                XmlSerializer xs = new XmlSerializer(typeof(AssemblyElement));
                xs.Serialize(writer, asm);
            }
        }
Ejemplo n.º 21
0
        public void SutEqualsOtherIdenticalInstance()
        {
            var a = this.GetType().Assembly;
            var sut = new AssemblyElement(a);
            var other = new AssemblyElement(a);

            var actual = sut.Equals(other);

            Assert.True(actual);
        }
Ejemplo n.º 22
0
 public void AcceptNullVisitorThrows()
 {
     // Fixture setup
     var sut = new AssemblyElement(this.GetType().Assembly);
     // Exercise system
     // Verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Accept((IReflectionVisitor<object>)null));
     // Teardown
 }
Ejemplo n.º 23
0
        public void SutIsReflectionElement()
        {
            // Fixture setup
            // Exercise system
            var sut = new AssemblyElement(this.GetType().Assembly);

            // Verify outcome
            Assert.IsAssignableFrom <IReflectionElement>(sut);
            // Teardown
        }
Ejemplo n.º 24
0
        public void SutEqualsOtherIdenticalInstance()
        {
            var a     = this.GetType().Assembly;
            var sut   = new AssemblyElement(a);
            var other = new AssemblyElement(a);

            var actual = sut.Equals(other);

            Assert.True(actual);
        }
Ejemplo n.º 25
0
        public void ShouldThrowExceptionWhenFileNotFound()
        {
            EntitiesAccessor target = EntitiesAccessor.Instance;

            string filename = "doesnotexists.xml";

            AssemblyElement        ae = target.LoadAssemblyElement(filename);
            ConfigurationContainer cc = target.LoadConfiguration(filename);
            WeaveSpecification     ws = target.LoadWeaveSpecification(filename);
        }
Ejemplo n.º 26
0
 public void AssemblyIsCorrect()
 {
     // Fixture setup
     var expectedAssembly = this.GetType().Assembly;
     var sut = new AssemblyElement(expectedAssembly);
     // Exercise system
     Assembly actualAssembly = sut.Assembly;
     // Verify outcome
     Assert.Equal(expectedAssembly, actualAssembly);
     // Teardown
 }
Ejemplo n.º 27
0
        public void GetHashCodeReturnsCorrectResult(Type containedType)
        {
            var a   = containedType.Assembly;
            var sut = new AssemblyElement(a);

            var actual = sut.GetHashCode();

            var expected = a.GetHashCode();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 28
0
        public void AcceptNullVisitorThrows()
        {
            // Fixture setup
            var sut = new AssemblyElement(this.GetType().Assembly);

            // Exercise system
            // Verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Accept((IReflectionVisitor <object>)null));
            // Teardown
        }
Ejemplo n.º 29
0
        public void VisitAssemblyElementReturnsCorrectResult()
        {
            var sut             = new ReflectionVisitor();
            var assemblyElement =
                new AssemblyElement(this.GetType().Assembly);

            var actual = sut.Visit(assemblyElement);

            var expected = sut;

            Assert.Same(expected, actual);
        }
Ejemplo n.º 30
0
        public void AssemblyIsCorrect()
        {
            // Fixture setup
            var expectedAssembly = this.GetType().Assembly;
            var sut = new AssemblyElement(expectedAssembly);
            // Exercise system
            Assembly actualAssembly = sut.Assembly;

            // Verify outcome
            Assert.Equal(expectedAssembly, actualAssembly);
            // Teardown
        }
Ejemplo n.º 31
0
        public void AssemblyTest()
        {
            AssemblyConfig target = new AssemblyConfig();

            AssemblyElement val = null; // TODO: Assign to an appropriate value for the property

            target.Assembly = val;


            Assert.AreEqual(val, target.Assembly, "Composestar.StarLight.Entities.Configuration.AssemblyConfig.Assembly was not set " +
                            "correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 32
0
        public void TypesTest()
        {
            AssemblyElement target = new AssemblyElement();

            System.Collections.Generic.List <Composestar.StarLight.Entities.LanguageModel.TypeElement> val = null; // TODO: Assign to an appropriate value for the property

            target.Types = val;


            Assert.AreEqual(val, target.Types, "Composestar.StarLight.Entities.LanguageModel.AssemblyElement.Types was not set co" +
                            "rrectly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 33
0
        public void NameTest()
        {
            AssemblyElement target = new AssemblyElement();

            string val = null; // TODO: Assign to an appropriate value for the property

            target.Name = val;


            Assert.AreEqual(val, target.Name, "Composestar.StarLight.Entities.LanguageModel.AssemblyElement.Name was not set cor" +
                            "rectly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 34
0
        private List <AssemblyElement> GenerateAssemblies(int assemblyCount, int typeCount, int fieldCount, int methodCount, int parameterCount)
        {
            List <AssemblyElement> result = new List <AssemblyElement>();

            for (int i = 0; i < assemblyCount; i++)
            {
                AssemblyElement ae = new AssemblyElement();
                ae.Name     = String.Format("Assembly{0:00}, Version=0.0.0.0", i);
                ae.FileName = "";
                ae.Types    = GenerateTypes(typeCount, fieldCount, methodCount, parameterCount);

                result.Add(ae);
            }

            return(result);
        }
Ejemplo n.º 35
0
        public void AcceptCallsTheCorrectVisitorMethodAndReturnsTheCorrectInstance()
        {
            // Fixture setup
            var expected = new DelegatingReflectionVisitor<int>();
            var sut = new AssemblyElement(this.GetType().Assembly);
            var visitor = new DelegatingReflectionVisitor<int>
            {
                OnVisitAssemblyElement = e =>
                    e == sut ? expected : new DelegatingReflectionVisitor<int>()
            };

            // Exercise system
            var actual = sut.Accept(visitor);
            // Verify outcome
            Assert.Same(expected, actual);
            // Teardown
        }
        private static void SearchAssemblyTask(AssemblyElement assemblyElement)
        {
            try
            {
                var assembly = Assembly.Load(assemblyElement.Assembly);

                var types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    var propertyInfos = type.GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        var customAttributes = propertyInfo.GetCustomAttributes(typeof(FieldNotVisibleInWebEditAttribute), true);
                        if (customAttributes.Count() > 0)
                        {
                            lock (FindProperties._properties)
                            {
                                if (FindProperties._properties.ContainsKey(type))
                                {
                                    FindProperties._properties[type].Add(propertyInfo);
                                }
                                else
                                {
                                    FindProperties._properties.Add(type, new List<PropertyInfo>() { propertyInfo });
                                }
                            }
                        }

                    }
                }
            }
            catch (FileNotFoundException notFound)
            {
                throw new FileNotFoundException(string.Format("PageProperties: Could not find {0}", notFound.FileName));
            }
        }
Ejemplo n.º 37
0
 public void SutDoesNotEqualAnonymousObject(object other)
 {
     var sut = new AssemblyElement(this.GetType().Assembly);
     var actual = sut.Equals(other);
     Assert.False(actual);
 }
Ejemplo n.º 38
0
        public void SutDoesNotEqualDifferentInstanceOfSameType()
        {
            var sut = new AssemblyElement(this.GetType().Assembly);
            var other = new AssemblyElement(typeof(Version).Assembly);

            var actual = sut.Equals(other);

            Assert.False(actual);
        }
Ejemplo n.º 39
0
        public void GetHashCodeReturnsCorrectResult(Type containedType)
        {
            var a = containedType.Assembly;
            var sut = new AssemblyElement(a);

            var actual = sut.GetHashCode();

            var expected = a.GetHashCode();
            Assert.Equal(expected, actual);
        }