Exemplo n.º 1
0
 public void LoadFrom(ModelElement otherModel)
 {
     foreach (AssemblyElement assembly in otherModel.Assemblies.Values)
     {
         TrimAssembly newAssembly = new TrimAssembly(assembly.Key, assembly.IncludeStatus);
         _assemblies.Add(newAssembly.Name, newAssembly);
         foreach (KeyValuePair<String, TypeForwarderElement> typeForwarder in assembly.TypeForwarders)
         {
             TrimTypeForwarder newTypeForwarder = new TrimTypeForwarder(typeForwarder.Value.AssemblyName, typeForwarder.Value.TypeName, typeForwarder.Value.IncludeStatus);
             newAssembly.TypeForwarders.Add(newTypeForwarder.Key, newTypeForwarder);
         }
         foreach (KeyValuePair<String, TypeElement> type in assembly.Types)
         {
             TrimType newType = new TrimType(type.Value.Key, type.Value.IncludeStatus, type.Value.VisibilityOverride, type.Value.SecurityTransparencyStatus);
             newAssembly.Types.Add(newType.Key, newType);
             foreach (KeyValuePair<String, MemberElement> member in type.Value.Members)
             {
                 TrimMember newMember = new TrimMember(newType, member.Value.Name, member.Value.ReturnType, member.Value.MemberType, member.Value.IncludeStatus, member.Value.VisibilityOverride, member.Value.SecurityTransparencyStatus);
                 newType.Members.Add(newMember.Key, newMember);
             }
         }
     }
 }
Exemplo n.º 2
0
 public override AssemblyElement CreateAssemblyElement(ModelElement model, string assemblyName, IncludeStatus includeStatus)
 {
     IncludeSet includeSet = (IncludeSet)model;
     TrimAssembly trimAssembly = new TrimAssembly(assemblyName, includeStatus); ;
     includeSet.AddAssembly(trimAssembly);
     return trimAssembly;
 }
Exemplo n.º 3
0
 public void LoadFrom(ModelElement otherModel)
 {
     AddElementsFrom(otherModel, true);
 }
Exemplo n.º 4
0
 public override AssemblyElement CreateAssemblyElement(ModelElement model, string assemblyName, IncludeStatus includeStatus)
 {
     CodeAssemblyElement assembly = new CodeAssemblyElement(includeStatus, assemblyName);
     (model as CodeModelElement).m_assemblies.Add(assemblyName, assembly);
     return assembly;
 }
Exemplo n.º 5
0
 public override AssemblyElement CreateAssemblyElement(ModelElement model, string assemblyName, IncludeStatus includeStatus)
 {
     includeStatus = AdjustIncludeStatus(includeStatus);
     ThinAssembly assembly = new ThinAssembly(_thinModel, assemblyName, includeStatus, null);
     _thinModel.Assemblies.Add(assembly.Name, assembly);
     return assembly;
 }
Exemplo n.º 6
0
        public void RemoveElementsPresentIn(ModelElement otherModel)
        {
            foreach (KeyValuePair<String, AssemblyElement> assembly in otherModel.Assemblies)
            {
                if (!_assemblies.ContainsKey(assembly.Key))  // Can't remove anything that doesn't exist
                    throw new Exception(String.Format("Invalid assembly defined in exclude list:  {0}", assembly.Value.ToString()));

                if (assembly.Value.IncludeStatus == IncludeStatus.Exclude)
                {
                    _assemblies.Remove(assembly.Key);
                    continue; // Once we have removed the assembly, all nested types are automatically removed so we move to the next assembly
                }
                AssemblyElement currentAssembly = _assemblies[assembly.Key];

                foreach (KeyValuePair<String, TypeForwarderElement> typeForwarder in assembly.Value.TypeForwarders)
                {
                    if (!currentAssembly.TypeForwarders.ContainsKey(typeForwarder.Key))  // Can't remove anything that doesn't exist
                        throw new Exception(String.Format("Invalid type forwarder defined in exclude list: {0}",
                                                                     typeForwarder.Value.ToString()));

                    if (typeForwarder.Value.IncludeStatus == IncludeStatus.Exclude)
                    {
                        currentAssembly.TypeForwarders.Remove(typeForwarder.Key);
                        continue;
                    }
                }

                foreach (KeyValuePair<String, TypeElement> type in assembly.Value.Types)
                {
                    if (!currentAssembly.Types.ContainsKey(type.Key))  // Can't remove anything that doesn't exist
                        throw new Exception(String.Format("Invalid type defined in exclude list: {0}", type.Value.ToString()));

                    if (type.Value.IncludeStatus == IncludeStatus.Exclude)
                    {
                        currentAssembly.Types.Remove(type.Key);
                        continue; // Once we have removed the type, all nested members are automatically removed
                    }
                    TypeElement currentType = currentAssembly.Types[type.Key];

                    foreach (KeyValuePair<String, MemberElement> member in type.Value.Members)
                    {
                        if (!currentType.Members.ContainsKey(member.Key))  // Can't remove anything that doesn't exist
                            throw new Exception(String.Format("Invalid member defined in exclude list: {0}", member.Value.ToString()));

                        if (member.Value.IncludeStatus == IncludeStatus.Exclude)
                        {
                            currentType.Members.Remove(member.Key);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        //public void AnnotateWithSecurity(string mscorlibPath, string inputFileName, string securityAnnotationsFileName)
        //{
        //    AssemblyAnnotations inputAnnotations = new AssemblyAnnotations(mscorlibPath, securityAnnotationsFileName);

        //    foreach (ThinAssembly assembly in Assemblies.Values)
        //    {
        //        foreach (ThinType thinType in assembly.Types.Values)
        //        {
        //            UpdateSecurityTransparencyStatus(thinType, inputAnnotations, thinType.Metadata);
        //            AnnotateMembers(inputAnnotations, thinType);
        //        }
        //    }

        //}

        //public void AnnotateMembers(AssemblyAnnotations inputAnnotations, ThinType thinType)
        //{
        //    INamedTypeDefinition type = thinType.Metadata;
        //    foreach (ThinMember thinMember in thinType.Members.Values)
        //    {
        //        // cannot have nested classes in ThinType
        //        UpdateSecurityTransparencyStatus(thinMember, inputAnnotations, thinMember.Metadata);
        //    }
        //}

        //private void UpdateSecurityTransparencyStatus(ThinType thinType, AssemblyAnnotations inputAnnotations, ITypeDefinitionMember member)
        //{
        //    SecurityAnnotations sa;
        //    if (member != null)
        //    {
        //        sa = inputAnnotations.TryGetAnnotations(FxCopHelper.UniqueMemberId(FxCopHelper.MemberFixupForGenerics(member)));
        //    }
        //    else
        //    {
        //        // For some reason we could not load metadata node for this member (shows up as ...: ~0 matches in
        //        // output of thinner while loading XML
        //        Console.WriteLine("WARNING: NULL MetaData for {0}", thinType.Name);
        //        sa = inputAnnotations.TryGetAnnotations(thinType.Name);
        //    }
        //    if (sa == null)
        //    {
        //        return;
        //    }
        //    if (sa.TreatAsSafe)
        //    {
        //        thinType.SetSecurityTransparencyStatus(SecurityTransparencyStatus.SafeCritical);
        //    }
        //    else if (sa.Critical)
        //    {
        //        thinType.SetSecurityTransparencyStatus(SecurityTransparencyStatus.Critical);
        //    }

        //}

        //private void UpdateSecurityTransparencyStatus(ThinMember thinMember, AssemblyAnnotations inputAnnotations, ITypeDefinitionMember member)
        //{
        //    SecurityAnnotations sa;
        //    if (member != null)
        //    {
        //        sa = inputAnnotations.TryGetAnnotations(FxCopHelper.UniqueMemberId(FxCopHelper.MemberFixupForGenerics(member)));
        //    }
        //    else
        //    {
        //        // For some reason we could not load metadata node for this member (shows up as ...: ~0 matches in
        //        // output of thinner while loading XML
        //        Console.WriteLine("WARNING: NULL MetaData for {0}", thinMember.Name);
        //        sa = inputAnnotations.TryGetAnnotations(thinMember.Name);
        //    }
        //    if (sa == null)
        //    {
        //        return;
        //    }
        //    if (sa.TreatAsSafe)
        //    {
        //        thinMember.SetSecurityTransparencyStatus(SecurityTransparencyStatus.SafeCritical);
        //    }
        //    else if (sa.Critical)
        //    {
        //        thinMember.SetSecurityTransparencyStatus(SecurityTransparencyStatus.Critical);
        //    }

        //}

        // TODO: Consolidate with RemoveElementsPresentIn?
        public ICollection<Element> FindExclusionViolations(ModelElement excludeModel)
        {
            List<Element> result = new List<Element>();
            foreach (KeyValuePair<String, AssemblyElement> assembly in excludeModel.Assemblies)
            {
                if (!_assemblies.ContainsKey(assembly.Key)) continue;
                if (assembly.Value.IncludeStatus == IncludeStatus.Exclude)
                {
                    result.Add(assembly.Value);
                    continue;
                }
                AssemblyElement currentAssembly = _assemblies[assembly.Key];

                foreach (KeyValuePair<String, TypeForwarderElement> typeForwarder in assembly.Value.TypeForwarders)
                {
                    if (!currentAssembly.TypeForwarders.ContainsKey(typeForwarder.Key)) continue;
                    if (typeForwarder.Value.IncludeStatus == IncludeStatus.Exclude)
                    {
                        result.Add(typeForwarder.Value);
                        continue;
                    }
                }

                foreach (KeyValuePair<String, TypeElement> type in assembly.Value.Types)
                {
                    if (!currentAssembly.Types.ContainsKey(type.Key)) continue;
                    if (type.Value.IncludeStatus == IncludeStatus.Exclude)
                    {
                        result.Add(type.Value);
                        continue;
                    }
                    TypeElement currentType = currentAssembly.Types[type.Key];

                    foreach (KeyValuePair<String, MemberElement> member in type.Value.Members)
                    {
                        if (!currentType.Members.ContainsKey(member.Key)) continue;
                        if (member.Value.IncludeStatus == IncludeStatus.Exclude)
                        {
                            result.Add(member.Value);
                        }
                    }
                }
            }
            return result;
        }
Exemplo n.º 8
0
        //public ThinModel DumpApi()
        //{
        //    ThinModel model = new ThinModel();

        //    foreach (ThinAssembly assembly in Assemblies.Values)
        //    {
        //        ThinAssembly newAssembly = new ThinAssembly(assembly.Name, IncludeStatus.Unknown, assembly.Metadata);
        //        model.Assemblies.Add(newAssembly.Name, newAssembly);
        //        foreach (INamedTypeDefinition type in newAssembly.Metadata.Types)
        //        {
        //            if (type.IsPublic)
        //            {
        //                ThinType thinType = new ThinType(newAssembly, type.ToString(), IncludeStatus.Unknown, type, VisibilityOverride.None);
        //                newAssembly.Types.Add(thinType.Name, thinType);

        //                DumpMembers(type, newAssembly, thinType);
        //            }
        //        }
        //    }

        //    return model;
        //}

        public void AddElementsFrom(ModelElement otherModel, bool overwriteExisting)
        {
            foreach (KeyValuePair<String, AssemblyElement> assembly in otherModel.Assemblies)
            {
                if (!_assemblies.ContainsKey(assembly.Key) || overwriteExisting)
                {
                    ThinAssembly newAssembly = new ThinAssembly(this, assembly.Value.Key, assembly.Value.IncludeStatus, null);
                    _assemblies[newAssembly.Key] = newAssembly;
                }

                ThinAssembly currentAssembly = (ThinAssembly)_assemblies[assembly.Key];

                foreach (var typeForwarder in assembly.Value.TypeForwarders)
                {
                    if (!currentAssembly.TypeForwarders.ContainsKey(typeForwarder.Key) || overwriteExisting)
                    {
                        TypeForwarderElement forwarder = typeForwarder.Value;
                        ThinTypeForwarder newTypeForwarder = new ThinTypeForwarder(currentAssembly, forwarder.AssemblyName, forwarder.TypeName,
                                                                                   forwarder.IncludeStatus, null);
                    }
                }
                foreach (KeyValuePair<String, TypeElement> type in assembly.Value.Types)
                {
                    if (!currentAssembly.Types.ContainsKey(type.Key) || overwriteExisting)
                    {
                        ThinType newType = new ThinType(currentAssembly, type.Value.Key,
                                                        type.Value.IncludeStatus, null, type.Value.VisibilityOverride);
                        currentAssembly.Types[newType.Key] = newType;
                    }
                    ThinType currentType = (ThinType)currentAssembly.Types[type.Key];

                    foreach (KeyValuePair<String, MemberElement> member in type.Value.Members)
                    {
                        if (!currentType.Members.ContainsKey(member.Key) || overwriteExisting)
                        {
                            ThinMember newMember = new ThinMember(currentType, member.Value.Name, member.Value.ReturnType, member.Value.MemberType,
                                                                  member.Value.IncludeStatus, null, member.Value.VisibilityOverride);
                            currentType.Members[newMember.Key] = newMember;
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
 abstract public AssemblyElement CreateAssemblyElement(ModelElement model, string assemblyName, IncludeStatus includeStatus);