Exemple #1
0
        /// <summary>
        /// Gets stream of embedded resource file in specified assembly or already added assemblies
        /// </summary>
        public static Stream GetResource(string resourceName, Assembly assembly = null)
        {
            if (assembly != null)
            {
                if (!Assemblies.Contains(assembly))
                {
                    AddAssembly(assembly);
                }
            }
            var key = string.Empty;

            if (ContainsFile(resourceName, out key))
            {
                return(Resources[key].GetResourceStream(resourceName));
            }
            else //if (!ResourceFiles.ContainsFile(resourceName, out key))
            {
                var msg = "Could not find '" + resourceName + "' file in any resource assemblies";
                if (assembly != null)
                {
                    msg += " including " + assembly.FullName + " assembly";
                }

                Logs.Error(msg);
                throw new FileNotFoundException(msg);
            }
        }
        bool HandleAssemblyParsed(ParserResult <IKVM.Reflection.Assembly> result)
        {
            HandleParserResult(result);

            if (result.Output.GetReferencedAssemblies().Any(ass => ass.Name == "Mono.Android") &&
                Options.Compilation.Platform != TargetPlatform.Android)
            {
                Console.Error.WriteLine("Assembly references Mono.Android.dll, plase specify target platform as Android.");

                result.Kind = ParserResultKind.Error;
                return(false);
            }

            if (result.Kind != ParserResultKind.Success)
            {
                return(false);
            }

            //NOTE: this can happen if multiple generators are running
            if (!Assemblies.Contains(result.Output))
            {
                Assemblies.Add(result.Output);
            }

            return(true);
        }
 public void ScanAssembly(Assembly assembly)
 {
     if (!Assemblies.Contains(assembly))
     {
         Assemblies.Add(assembly);
     }
 }
Exemple #4
0
        private void RegisterHandlers()
        {
            var handlers = Configuration.Instance
                           .GetSection(FrameworkConfigurationSectionName)
                           ?.Get <FrameworkConfiguration>()
                           ?.Handlers;

            if (handlers != null)
            {
                foreach (var handlerElement in handlers)
                {
                    if (Assemblies == null || Assemblies.Contains(handlerElement.Name))
                    {
                        switch (handlerElement.SourceType)
                        {
                        case HandlerSourceType.Type:
                            var type = Type.GetType(handlerElement.Source);
                            RegisterHandlerFromType(type);
                            break;

                        case HandlerSourceType.Assembly:
                            var assembly = Assembly.Load(handlerElement.Source);
                            RegisterHandlerFromAssembly(assembly);
                            break;
                        }
                    }
                }
            }

            RegisterInheritedMessageHandlers();
        }
 /// <summary>
 /// Adds the assembly to the list of required assemblies.
 /// </summary>
 public void AddAssembly(string assemblyName)
 {
     if (!Assemblies.Contains(assemblyName))
     {
         Assemblies.Add(assemblyName);
     }
 }
        void AnalyzePropertyAttr(TypeDefinition typeDef, XamlContext txt, XAttribute attr)
        {
            XamlPropertyName name = XamlPropertyName.Parse(typeDef, attr.Name, txt);

            name.Xmlns = attr.Parent.GetPrefixOfNamespace(name.Xmlns);
            var prop = ResolveProperty(name.TypeDef, name.PropertyName);

            if (prop != null && Assemblies.Contains(prop.DeclaringType.Module.Assembly))
            {
                IXmlLineInfo li   = attr as IXmlLineInfo;
                string       line = txt.lines[li.LineNumber - 1];
                int          end  = line.IndexOf('=', li.LinePosition - 1);
                string       str  = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
                var          r    = new XamlPropertyNameReference()
                {
                    Name = name
                };
                txt.refers.Add(new XamlRef()
                {
                    lineNum = li.LineNumber - 1,
                    index   = li.LinePosition - 1,
                    length  = end - li.LinePosition + 1,
                    name    = name,
                    refer   = r
                });
                ((prop as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r);
            }

            if (name.Xmlns == "x" && name.PropertyName == "Class")
            {
                IXmlLineInfo li       = attr as IXmlLineInfo;
                string       line     = txt.lines[li.LineNumber - 1];
                int          start    = line.IndexOf('=', li.LinePosition - 1) + 2;
                int          end      = line.IndexOf(line[start - 1], start);
                string       fullName = line.Substring(start, end - start);

                TypeDefinition type = txt.context.MainModule.GetType(fullName);
                if (type != null)
                {
                    var n = new XamlClrName()
                    {
                        Namespace = type.Namespace, Name = type.Name
                    };
                    var r = new XamlClrNameReference()
                    {
                        Name = n
                    };
                    txt.refers.Add(new XamlRef()
                    {
                        lineNum = li.LineNumber - 1,
                        index   = start,
                        length  = end - start,
                        name    = n,
                        refer   = r
                    });
                    ((type as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r);
                }
            }
        }
Exemple #7
0
 //This method allows a single dll to be added to the assemblies list that is referenced in the source code that is being compiled.
 //The method makes sure the assemblies are unique in the list.
 public void AddAssemblyLocation(string assembly)
 {
     if (Assemblies.Contains(assembly))
     {
         Assemblies.Remove(assembly);
     }
     Assemblies.Add(assembly);
 }
        private void AddAssembly(Assembly asm)
        {
            if (Assemblies.Contains(asm))
            {
                return;
            }

            Assemblies.Add(asm);
        }
 protected override void OnInitialized()
 {
     base.OnInitialized();
     Assemblies    = Assemblies ?? new List <Assembly>();
     BlockCssFiles = BlockCssFiles ?? new List <string>();
     if (!(BaseType is null) && !Assemblies.Contains(BaseType.Assembly))
     {
         Assemblies.Add(BaseType.Assembly);
     }
 }
Exemple #10
0
        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static XmlMember Find(Type type)
        {
            var re = HelpXml.FirstOrDefault(p => /*p.Type == "T" &&*/ p.Name == type.FullName);

            if (re == null && !Assemblies.Contains(type.Assembly))
            {
                Load(type.Assembly);
            }
            return(re);
        }
Exemple #11
0
 //A method to remove unneeded assmblys from the list
 public bool RemoveAssemblyLocation(string assembly)
 {
     if (Assemblies.Contains(assembly))
     {
         Assemblies.Remove(assembly);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        private XmlDocumentation GetXmlDocumentation(IAssemblySymbol assembly, string preferredCultureName = null)
        {
            if (!_xmlDocumentations.TryGetValue(assembly, out XmlDocumentation xmlDocumentation))
            {
                if (Assemblies.Contains(assembly))
                {
                    Compilation compilation = FindCompilation(assembly);

                    MetadataReference metadataReference = compilation.GetMetadataReference(assembly);

                    if (metadataReference is PortableExecutableReference portableExecutableReference)
                    {
                        string path = portableExecutableReference.FilePath;

                        if (preferredCultureName != null)
                        {
                            path = Path.GetDirectoryName(path);

                            path = Path.Combine(path, preferredCultureName);

                            if (Directory.Exists(path))
                            {
                                string fileName = Path.ChangeExtension(Path.GetFileNameWithoutExtension(path), "xml");

                                path = Path.Combine(path, fileName);

                                if (File.Exists(path))
                                {
                                    xmlDocumentation = XmlDocumentation.Load(path);
                                }
                            }
                        }

                        if (xmlDocumentation == null)
                        {
                            path = Path.ChangeExtension(path, "xml");

                            if (File.Exists(path))
                            {
                                xmlDocumentation = XmlDocumentation.Load(path);
                            }
                        }
                    }
                }

                _xmlDocumentations[assembly] = xmlDocumentation;
            }

            return(xmlDocumentation);
        }
        void HandleAssemblyParsed(ParserResult <IKVM.Reflection.Assembly> result)
        {
            HandleParserResult(result);

            if (result.Kind != ParserResultKind.Success)
            {
                return;
            }

            //NOTE: this can happen if multiple generators are running
            if (!Assemblies.Contains(result.Output))
            {
                Assemblies.Add(result.Output);
            }
        }
Exemple #14
0
        /// <summary>
        /// Adds specified assembly and its embedded resources to registry
        /// </summary>
        public static void AddAssembly(Assembly assembly)
        {
            if (!Assemblies.Contains(assembly))
            {
                Assemblies.Add(assembly);

                var resurces = assembly.GetManifestResourceNames();
                foreach (var resource in resurces)
                {
                    var resourceName = resource.ToLower();
                    if (!Resources.ContainsKey(resourceName))
                    {
                        Resources.Add(resourceName, assembly);
                    }
                }
            }
        }
Exemple #15
0
        public void AddAssembly(string assemblyFilePath)
        {
            if (assemblyFilePath == null)
            {
                throw new ArgumentException("assemblyFilePath cannot be null!");
            }
            if (!Path.IsPathRooted(assemblyFilePath))
            {
                throw new ArgumentException("assemblyFilePath must be absolute!");
            }

            // Make sure we're not adding the same assembly twice.
            assemblyFilePath = PathHelper.Normalize(assemblyFilePath);
            if (!Assemblies.Contains(assemblyFilePath))
            {
                Assemblies.Add(assemblyFilePath);
            }
        }
        public OrleansHttpGatewayOptions AddAssemblies(params Assembly[] assemblies)
        {
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }

            foreach (var a in assemblies)
            {
                if (Assemblies.Contains(a))
                {
                    continue;
                }
                Assemblies.Add(a);
            }

            return(this);
        }
        private RuleResult PreCheck(IMetadataTokenProvider obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "Cannot check a null object");
            }

            Reset();
            AssemblyDefinition assembly = obj.GetAssembly();

            if (!Assemblies.Contains(assembly))
            {
                Assemblies.Clear();
                Assemblies.Add(assembly);
                Engines.Build(Assemblies);
            }
            CurrentTarget = obj;

            return(IgnoreList.IsIgnored(CurrentRule, obj) ? RuleResult.DoesNotApply : RuleResult.Success);
        }
        void AnalyzePropertyElem(TypeDefinition typeDef, XamlContext txt, XElement elem)
        {
            XamlPropertyName name = XamlPropertyName.Parse(typeDef, elem.Name, txt);

            name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns);
            var prop = ResolveProperty(name.TypeDef, name.PropertyName);

            if (prop != null && Assemblies.Contains(prop.DeclaringType.Module.Assembly))
            {
                IXmlLineInfo li   = elem as IXmlLineInfo;
                string       line = txt.lines[li.LineNumber - 1];
                int          end  = line.IndexOf('>', li.LinePosition - 1);
                string       str  = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
                var          r    = new XamlPropertyNameReference()
                {
                    Name = name
                };
                txt.refers.Add(new XamlRef()
                {
                    lineNum = li.LineNumber - 1,
                    index   = li.LinePosition - 1,
                    length  = end - li.LinePosition + 1,
                    name    = name,
                    refer   = r
                });
                ((prop as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r);
            }

            foreach (var i in elem.Elements())
            {
                if (i.Name.LocalName.Contains("."))
                {
                    AnalyzePropertyElem(name.TypeDef, txt, i);
                }
                else
                {
                    AnalyzeElement(txt, i);
                }
            }
        }
Exemple #19
0
        public void AddAssembly(string assemblyFilePath)
        {
            if (assemblyFilePath == null)
            {
                throw new ArgumentException("assemblyFilePath cannot be null!");
            }
            if (!Path.IsPathRooted(assemblyFilePath))
            {
                throw new ArgumentException("assemblyFilePath must be absolute!");
            }

            // Make sure we're not adding the same assembly twice.
            assemblyFilePath = PathHelper.Normalize(assemblyFilePath);
            if (!Assemblies.Contains(assemblyFilePath))
            {
                Assemblies.Add(assemblyFilePath);

                //TODO need better way to update caches
                _processors = null;
                _importers  = null;
                _writers    = null;
            }
        }
Exemple #20
0
        /// <summary>
        /// Searchs an Assembly for registrable Services
        /// </summary>
        /// <param name="assembly">The Assembly that will be part of the search.</param>
        public void ScanAssembly(Assembly assembly)
        {
            if (Assemblies.Contains(assembly))
            {
                return;
            }

            Assemblies.Add(assembly);

            var contextMappings       = assembly.MapTypes <IContext>();
            var serviceMappings       = assembly.MapTypes <IService>();
            var sharedServiceMappings = assembly.MapTypes <ISharedService>();
            var instanceTypes         = assembly.FindInterfaces <IInstance>();
            var factoryTypes          = assembly.FindInterfaces <IFactory>(true);
            var descriptorMappings    = assembly.MapGenericTypes <IModelDescriptor>(true);

            Contexts.AddRange(contextMappings);
            Services.AddRange(serviceMappings);
            SharedServices.AddRange(sharedServiceMappings);
            Instances.AddRange(instanceTypes);
            Factories.AddRange(factoryTypes);
            Descriptors.AddRange(descriptorMappings);
        }
Exemple #21
0
        void RegisterHandlers()
        {
            var handlerElements = ConfigurationReader.Instance
                                  .GetConfigurationSection <FrameworkConfigurationSection>()?
                                  .Handlers;

            if (handlerElements != null)
            {
                foreach (HandlerElement handlerElement in handlerElements)
                {
                    if (Assemblies == null || Assemblies.Contains(handlerElement.Name))
                    {
                        try
                        {
                            switch (handlerElement.SourceType)
                            {
                            case HandlerSourceType.Type:
                                Type type = Type.GetType(handlerElement.Source);
                                RegisterHandlerFromType(type);
                                break;

                            case HandlerSourceType.Assembly:
                                Assembly assembly = Assembly.Load(handlerElement.Source);
                                RegisterHandlerFromAssembly(assembly);
                                break;
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
            }

            RegisterInheritedMessageHandlers();
        }
        void AnalyzeElement(XamlContext txt, XElement elem)
        {
            foreach (var i in elem.Attributes())
            {
                if (i.Name.NamespaceName == "http://www.w3.org/2000/xmlns/")
                {
                    txt.namespaces[i.Name.LocalName] = ParseXmlNs(i.Value, txt);
                }
                else if (i.Name.LocalName == "xmlns")
                {
                    txt.namespaces[""] = ParseXmlNs(i.Value, txt);
                }
            }

            XamlName name = XamlName.Parse(elem.Name, txt);

            name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns);
            if (name.TypeDef == null)
            {
                Logger._Log("> Could not resolve '" + elem.Name.ToString() + "'!");
            }
            else if (Assemblies.Contains(name.TypeDef.Module.Assembly))
            {
                IXmlLineInfo li   = elem as IXmlLineInfo;
                string       line = txt.lines[li.LineNumber - 1];
                int          end  = line.IndexOf(' ', li.LinePosition - 1);
                if (end == -1)
                {
                    end = line.IndexOf('>', li.LinePosition - 1);
                }
                string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
                var    r   = new XamlNameReference()
                {
                    Name = name
                };
                txt.refers.Add(new XamlRef()
                {
                    lineNum = li.LineNumber - 1,
                    index   = li.LinePosition - 1,
                    length  = end - li.LinePosition + 1,
                    name    = name,
                    refer   = r
                });
                ((name.TypeDef as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r);
            }

            foreach (var i in elem.Attributes())
            {
                if (i.Name.NamespaceName != "http://www.w3.org/2000/xmlns/" &&
                    i.Name.LocalName != "xmlns")
                {
                    AnalyzePropertyAttr(name.TypeDef, txt, i);
                }
            }

            foreach (var i in elem.Elements())
            {
                if (i.Name.LocalName.Contains("."))
                {
                    AnalyzePropertyElem(name.TypeDef, txt, i);
                }
                else
                {
                    AnalyzeElement(txt, i);
                }
            }
        }
Exemple #23
0
        public void Initialize(IEnumerable <ProjectAssembly> tracking)
        {
            try
            {
                var pas        = tracking as ProjectAssembly[] ?? tracking.ToArray();
                var opas       = pas.OrderBy(a => a.FullPath).ThenBy(a => a.RelativePath).ToArray();
                var projFolder = ToolboxApp.Project.State.ProjectFolder;
                if (string.IsNullOrWhiteSpace(projFolder))
                {
                    return;
                }

                Assemblies.Clear();

                // Assemblies.AddRange() causes exception?
                foreach (var pa in opas)
                {
                    Assemblies.Add(pa);
                }

                // find assemblies in project folder
                var comparer = new ProjectAssemblyComparer();
                var allFiles = Directory.GetFiles(projFolder, $"*{SupportedFileTypes.AssemblyExtension}", SearchOption.AllDirectories);
                var found    = new List <ProjectAssembly>();

                foreach (var file in allFiles)
                {
                    var rp = file.Replace(projFolder, string.Empty);

                    var assembly = new ProjectAssembly
                    {
                        FullPath     = file,
                        RelativePath = rp,
                        FileName     = Path.GetFileName(file),
                        Directory    = Path.GetDirectoryName(rp)
                    };

                    found.Add(assembly);
                }

                var orderedFound = found.OrderBy(a => a.FullPath).ThenBy(a => a.RelativePath);

                // add assemblies in project folder
                foreach (var assembly in orderedFound)
                {
                    if (!Assemblies.Contains(assembly, comparer))
                    {
                        Assemblies.Add(assembly);
                    }
                }

                // check if project file exists and include assemblies
                if (_fs.FileExist(ToolboxApp.Project.State.XenProjectFilePath))
                {
                    var proj   = new XenProjectFile(_fs);
                    var loaded = proj.Load(ToolboxApp.Project.State.XenProjectFilePath);

                    if (!loaded)
                    {
                        ToolboxApp.Log.Warn($"Unable to load project file: {ToolboxApp.Project.State.XenProjectFilePath}.");
                    }

                    if (proj.Assemblies != null)
                    {
                        foreach (var pa in proj.Assemblies)
                        {
                            var fp = $"{ToolboxApp.Project.State.XenProjectFilePath}{pa.RelativePath}";
                            if (string.IsNullOrWhiteSpace(fp))
                            {
                                continue;
                            }

                            var match = Assemblies.FirstOrDefault(a => a.FullPath == fp);
                            if (match != null)
                            {
                                match.Include = true;
                            }
                        }
                    }
                }
                else
                {
                    ToolboxApp.Log.Info($"{ToolboxApp.Project.State.XenProjectFilePath} doesn't exist.");
                }
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, "Error retrieving project assemblies.");
            }
        }
 public void SetSelectedAssemblies(IEnumerable <Assembly> selectedAssemblies)
 {
     SelectedAssemblies = from v in selectedAssemblies where Assemblies.Contains(v) select v;
 }
Exemple #25
0
 /// <summary>
 /// Checks if specified assembly and its embedded resources were registered
 /// </summary>
 public static bool ContainsAssembly(Assembly assembly)
 {
     return(Assemblies.Contains(assembly));
 }