Exemplo n.º 1
0
        private void CompareInterfaces()
        {
            IEnumerable <string> referenceInterfaces = ReferenceType.GetInterfaces().Select(@interface => @interface.GetCompareableName()).ToList();
            IEnumerable <string> newInterfaces       = NewType.GetInterfaces().Select(@interface => @interface.GetCompareableName()).ToList();

            // missing interfaces
            foreach (string @interface in referenceInterfaces.Except(newInterfaces))
            {
                ComparerResult.AddRemovedItem(ResultContext.Interface, @interface, Severity.Error);
            }

            // new interfaces
            foreach (string @interface in newInterfaces.Except(referenceInterfaces))
            {
                ComparerResult.AddAddedItem(ResultContext.Interface, @interface, Severity.Warning);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the active assemblies to a plugin file
        /// </summary>
        private static void AddAssembliesToPluginFile(string PluginFolder, string PluginClass, Xml.XmlDocument PluginLibrary, Type[] PluginTypes)
        {
            if (System.IO.Directory.Exists(PluginFolder))
            {
                foreach (string PluginFile in System.IO.Directory.GetFiles(PluginFolder, "*.dll"))
                {
                    bool   FoundOne    = false;
                    string OldFileName = PluginFile.Substring(PluginFile.LastIndexOf("\\") + 1);
                    string NewFileName = ".\\plugins\\tmp\\"; //huangxy

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                    NewFileName += OldFileName + ".tmp";

                    File.Copy(PluginFile, NewFileName, true);

                    System.Reflection.Assembly PluginAssembly = System.Reflection.Assembly.LoadFile(Path.GetFullPath(NewFileName));
                    System.Type[] types = null;
                    try
                    {
                        types = PluginAssembly.GetTypes();
                    }catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }
                    if (types == null)
                    {
                        continue;
                    }
                    foreach (System.Type NewType in types)
                    {
                        bool Found = false;

                        foreach (System.Type InterfaceType in NewType.GetInterfaces())
                        {
                            foreach (System.Type DesiredType in PluginTypes)
                            {
                                if (InterfaceType == DesiredType)
                                {
                                    string ClassName = NewType.Name.ToLower();
                                    if (NewType.Namespace != null)
                                    {
                                        ClassName = NewType.Namespace.ToLower() + "." + ClassName;
                                    }

                                    FoundOne = true;
                                    Xml.XmlElement NewNode = PluginLibrary.CreateElement("plugin");
                                    NewNode.SetAttribute("library", OldFileName);
                                    NewNode.SetAttribute("interface", DesiredType.Name);
                                    NewNode.SetAttribute("name", NewType.Name.ToLower());
                                    NewNode.SetAttribute("fullname", ClassName);
                                    NewNode.AppendChild(PluginLibrary.CreateTextNode(NewFileName));

                                    Xml.XmlElement Parent = (Xml.XmlElement)PluginLibrary.SelectSingleNode("/plugins/active[@type='" + PluginClass + "']");
                                    if (Parent == null)
                                    {
                                        Parent = PluginLibrary.CreateElement("active");
                                        Parent.SetAttribute("type", PluginClass);
                                        PluginLibrary.SelectSingleNode("/plugins").AppendChild(Parent);
                                    }
                                    Parent.AppendChild(NewNode);
                                    Parent.SetAttribute("updated", System.DateTime.Now.ToString());

                                    Found = true;
                                    break;
                                }
                                if (Found)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (!FoundOne)
                    {
                        Xml.XmlElement NewNode = PluginLibrary.CreateElement("plugin");
                        NewNode.AppendChild(PluginLibrary.CreateTextNode(NewFileName));

                        PluginLibrary.SelectSingleNode("/plugins/retired").AppendChild(NewNode);
                        PluginLibrary.DocumentElement.SetAttribute("updated", System.DateTime.Now.ToString());
                    }
                }
            }
        }