Exemple #1
0
        /// <summary>
        /// Create an instance of the specified class & return it
        /// </summary>
        /// <param name="plugin"></param>
        /// <param name="extensionPoint"></param>
        /// <returns></returns>

        public static object GetExtensionPointClassInstance(
            ExtensionPoint extensionPoint)
        {
            Plugin plugin = extensionPoint.Plugin;

            foreach (string assemblyName in plugin.RunTimeLibraries)
            {             // look for class in each assembly associated with plugin
                string assemblyPath = assemblyName;

                Assembly assembly = null;
                if (!Path.IsPathRooted(assemblyPath))                 // if not rooted look in plugin dir for assembly
                {
                    AssemblyName an = new AssemblyName();
                    an.CodeBase = plugin.Directory + @"\" + assemblyPath;
                    try { assembly = Assembly.Load(an); }
                    catch (Exception ex) { string msg = ex.Message; } // fall through on exception

                    if (assembly == null)                             // if not found try startup binary path
                    {
                        an.CodeBase = ClientDirs.StartupDir + @"\" + assemblyPath;
                        try { assembly = Assembly.Load(an); }
                        catch (Exception ex) { string msg = ex.Message; }                         // fall through on exception
                    }
                }

                if (assembly == null)                 // if not found in plugin dir try assemblyPath as is
                {
                    AssemblyName an = new AssemblyName();
                    an.CodeBase = assemblyPath;
                    assembly    = Assembly.Load(an);
                }

                Type type = assembly.GetType(extensionPoint.Class, false, true); // get the type not thowing exception if fails & ignoring case
                if (type == null)                                                // if failed try getting with fully qualified name throwing exception if fails
                {
                    foreach (Type t in assembly.GetTypes())
                    {
                        if (String.Compare(t.Name, extensionPoint.Class, true) == 0)
                        {
                            type = t;
                            break;
                        }
                    }
                }
                if (type != null)
                {
                    object instance = assembly.CreateInstance(type.FullName);                     // create instance object
                    return(instance);
                }
            }

            throw new Exception("Can't find assembly for class: " + extensionPoint.Class);
        }
Exemple #2
0
/// <summary>
/// Update & Load client assembly containing class as necessary
/// </summary>
/// <param name="className"></param>

        public static void LoadClientAssembly
            (string className)
        {
            if (ClientAssembliesLoaded == null)
            {
                ClientAssembliesLoaded = new Dictionary <string, object>();
            }

            ExtensionPoint ep = GetExtensionPointByClassName(className);

            if (ep == null)
            {
                return;
            }
            Plugin p = ep.Plugin;

            foreach (string assemblyName in p.RunTimeLibraries)
            {
                if (ClientAssembliesLoaded.ContainsKey(assemblyName))
                {
                    continue;                               // just continue if already loaded
                }
                string clientAssemblyPath =                 // path to assembly on client
                                            ClientDirs.StartupDir + @"\" + Path.GetFileName(assemblyName);
                string clientVersion = SystemUtil.GetAssemblyVersion(clientAssemblyPath);

                //string serverAssemblyPath = assemblyName; // path to assembly on server
                //if (!Path.IsPathRooted(serverAssemblyPath)) // if not rooted look in plugin dir for assembly
                //  serverAssemblyPath = p.Directory + @"\" + assemblyName;

                //bool serverAssemblyExists = File.Exists(serverAssemblyPath);
                //if (!serverAssemblyExists) // if not there try in server startup path
                //{
                //  serverAssemblyPath = ProcessState.ServerStartupPath + @"\" + assemblyName;
                //  serverAssemblyExists = File.Exists(serverAssemblyPath);
                //}

                //if (serverAssemblyExists)
                //{ // if found on server see if same version on client otherwise assume standard part of client assembly sets
                //  AssemblyName an = AssemblyName.GetAssemblyName(serverAssemblyPath);
                //  string serverVersion = an.Version.ToString();

                //  if (clientVersion != serverVersion) // download newer assembly if needed
                //    Client.PutFile(serverAssemblyPath, clientAssemblyPath);
                //}

                SystemUtil.LoadAssembly(clientAssemblyPath);

                ClientAssembliesLoaded[assemblyName] = null;                 // add to dict of loaded assemblies
            }
            return;
        }
Exemple #3
0
/// <summary>
/// Return true if specified method reference (ExtensionPointId.MethodName) is part
/// of a valid extension point
/// </summary>
/// <param name="methodRef"></param>
/// <returns></returns>

        public static bool IsMethodExtensionPoint(
            string methodRef)
        {
            ExtensionPoint ep = GetMethodExtensionPoint(methodRef);

            if (ep != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
/// <summary>
/// Load plugin definitions
/// </summary>
/// <param name="pluginRootDir"></param>
/// <returns></returns>

        public static int LoadDefinitions(string pluginRootDir)
        {
            if (PluginList != null)
            {
                return(PluginList.Count);
            }
            PluginList = new List <Plugin>();

            string[] dirs = Directory.GetDirectories(pluginRootDir);
            foreach (string dir in dirs)
            {
                if (Lex.EndsWith(dir, @"\TargetResultsViewerNetwork") || // obsolete
                    Lex.EndsWith(dir, @"\RgroupMatrix"))                 // disabled
                {
                    continue;                                            // ignore
                }
                string fileName = dir + @"\plugin.xml";
//				ClientLog.Message("Loading Plugin: " + fileName); // debug
                if (!File.Exists(fileName))
                {
                    continue;
                }
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fileName);
                    XmlNodeList nodes = doc.GetElementsByTagName("plugin");                     // get all plugins in file
                    if (nodes == null || nodes.Count == 0)
                    {
                        return(0);
                    }

                    foreach (XmlNode node in nodes)
                    {
                        Plugin p = new Plugin();
                        p.Directory = dir;


                        foreach (XmlAttribute attr in node.Attributes)
                        {
                            if (Lex.Eq(attr.Name, "Id"))
                            {
                                p.Id = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Name"))
                            {
                                p.Name = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Class"))
                            {
                                p.Class = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Provider-Name"))
                            {
                                p.ProviderName = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Version"))
                            {
                                p.Version = attr.Value;

                                if (Lex.Eq(attr.Value, "Hidden"))
                                {
                                    p.Visible = false;                                                               // temp workaround to hide a plugin
                                }
                            }

                            else if (Lex.Eq(attr.Name, "Enabled"))
                            {
                                bool.TryParse(attr.Value, out p.Enabled);
                            }

                            else if (Lex.Eq(attr.Name, "Visible"))
                            {
                                bool.TryParse(attr.Value, out p.Visible);
                            }

                            else
                            {
                                throw new Exception("Unrecognized attribute: " + attr.Name);
                            }
                        }

                        if (p.Id == "")
                        {
                            throw new Exception("Id missing");
                        }

                        if (p.Class == "")
                        {
                            throw new Exception("Class name missing");
                        }

                        XmlNodeList libraryNodes = node.SelectNodes(".//library");                         // get library nodes (case sensitive)
                        if (libraryNodes.Count == 0)
                        {
                            libraryNodes = node.SelectNodes(".//Library");
                        }
                        if (libraryNodes.Count == 0)
                        {
                            libraryNodes = node.SelectNodes(".//LIBRARY");
                        }

                        foreach (XmlNode node2 in libraryNodes)
                        {
                            if (node2.Attributes == null || node2.Attributes.Count < 1 ||
                                !Lex.Eq(node2.Attributes[0].Name, "Name"))
                            {
                                throw new Exception("Runtime Library Name missing");
                            }
                            p.RunTimeLibraries.Add(node2.Attributes[0].Value);
                        }

                        if (p.RunTimeLibraries.Count == 0)
                        {
                            throw new Exception("Runtime library missing");
                        }

                        XmlNodeList eNodes = node.SelectNodes(".//extension");                         // get extension point nodes
                        if (eNodes == null || eNodes.Count == 0)
                        {
                            throw new Exception("Extension points missing");
                        }

                        foreach (XmlNode eNode in eNodes)
                        {
                            ExtensionPoint ep = new ExtensionPoint();
                            ep.Plugin = p;

                            foreach (XmlAttribute attr in eNode.Attributes)
                            {
                                if (Lex.Eq(attr.Name, "Point"))
                                {
                                    if (Lex.Ne(attr.Value, "Mobius.Action") && Lex.Ne(attr.Value, "Mobius.ClientDialog") &&
                                        Lex.Ne(attr.Value, "Mobius.Method"))
                                    {
                                        throw new Exception("Invalid extension point type " + attr.Value);
                                    }
                                    ep.Type = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "Id"))
                                {
                                    ep.Id = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "Class"))
                                {
                                    ep.Class = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "MenuBarPath"))
                                {
                                    if (Lex.Ne(attr.Value, "Tools"))
                                    {
                                        throw new Exception("Unsupported MenubarPath " + attr.Value);
                                    }
                                    ep.MenuBarPath = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "CommandLineCommand"))
                                {
                                    ep.CommandName = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "MethodName"))
                                {
                                    ep.MethodName = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "Label"))
                                {
                                    ep.Label = attr.Value;
                                }

                                else
                                {
                                    throw new Exception("Unrecognized extension point attribute: " + attr.Name);
                                }
                            }

                            if (ep.Id == "")
                            {
                                throw new Exception("Extension point Id missing");
                            }
                            if (ep.Type == "")
                            {
                                throw new Exception("Extension point type missing");
                            }
                            if (ep.Class == "")
                            {
                                if (p.Class != "")
                                {
                                    ep.Class = p.Class;                                                // use plugin class if defined
                                }
                                else
                                {
                                    throw new Exception("Extension point class name missing");
                                }
                            }

                            fileName = dir + @"\" + ep.Id + ".bmp";
                            if (File.Exists(fileName))
                            {
                                try { ep.Image = Bitmap.FromFile(fileName); }
                                catch (Exception ex) { ex = ex; }
                            }

                            p.ExtensionPoints.Add(ep);                             // add extension point to plugin
                        }

                        PluginList.Add(p);                         // add plugin to list
                    }
                }
                catch (Exception ex)
                {
                    ServicesLog.Message(DebugLog.FormatExceptionMessage(ex));
                    string msg = "Error in file \"" + fileName + "\"\r\n" + ex.Message;
                    throw new Exception(msg, ex);
                }
            }

            PluginCaller.CallRef =             // alloc PluginDao to call up to us
                                   new PluginCaller.CallMethodDelegate(CallStringExtensionPointMethod);

            return(PluginList.Count);
        }