// List of DLL results, empty if no DLLs were found
        // else list of results. bool = true no error, false error.  String contains error string, or result string
        public List <Tuple <bool, string, string> > ActionCommand(string dllname, string cmd, string[] paras)
        {
            List <Tuple <bool, string, string> > resultlist = new List <Tuple <bool, string, string> >();

            if (dllname.Equals("All", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (EDDDLLCaller caller in DLLs)
                {
                    resultlist.Add(AC(caller, cmd, paras));
                }
            }
            else
            {
                EDDDLLCaller caller = FindCaller(dllname);
                if (caller != null)
                {
                    resultlist.Add(AC(caller, cmd, paras));
                }
                else
                {
                    resultlist.Add(new Tuple <bool, string, string>(false, dllname, "Cannot find DLL "));
                }
            }

            return(resultlist);
        }
        // search directory for *.dll,
        // return loaded, failed, new dlls not in the allowed/disallowed list
        // alloweddisallowed list is +allowed,-disallowed..
        // all Csharp assembly DLLs are loaded - only ones implementing *EDDClass class causes it to be added to the DLL list
        // only normal DLLs implementing EDDInitialise are kept loaded

        public Tuple <string, string, string> Load(string dlldirectory, string ourversion, string[] inoptions,
                                                   EDDDLLInterfaces.EDDDLLIF.EDDCallBacks callbacks, string alloweddisallowed)
        {
            string loaded  = "";
            string failed  = "";
            string newdlls = "";

            if (!Directory.Exists(dlldirectory))
            {
                failed = "DLL Folder does not exist";
            }
            else
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(dlldirectory, "*.dll", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

                string[] allowedfiles = alloweddisallowed.Split(',');

                foreach (FileInfo f in allFiles)
                {
                    EDDDLLCaller caller = new EDDDLLCaller();

                    System.Diagnostics.Debug.WriteLine("Try to load " + f.FullName);

                    string filename = System.IO.Path.GetFileNameWithoutExtension(f.FullName);

                    bool isallowed = alloweddisallowed.Equals("All", StringComparison.InvariantCultureIgnoreCase) || allowedfiles.Contains("+" + filename, StringComparer.InvariantCultureIgnoreCase);

                    if (isallowed)                                                           // if allowed..
                    {
                        if (caller.Load(f.FullName))                                         // if loaded okay
                        {
                            if (caller.Init(ourversion, inoptions, dlldirectory, callbacks)) // must init
                            {
                                DLLs.Add(caller);
                                loaded = loaded.AppendPrePad(filename, ",");
                            }
                            else
                            {
                                string errstr = caller.Version.HasChars() ? (": " + caller.Version.Substring(1)) : "";
                                failed = failed.AppendPrePad(filename + errstr, ",");
                            }
                        }
                    }
                    else
                    {
                        if (!allowedfiles.Contains("-" + filename, StringComparer.InvariantCultureIgnoreCase))   // is not disallowed, its new, ask
                        {
                            newdlls = newdlls.AppendPrePad(filename, ",");
                        }
                    }
                }
            }

            return(new Tuple <string, string, string>(loaded, failed, newdlls));
        }
        // return loaded, failed, notallowed
        public Tuple <string, string, string> Load(string directory, string ourversion, string dllfolder, EDDDLLIF.EDDCallBacks callbacks, string allowed)
        {
            string loaded     = "";
            string failed     = "";
            string notallowed = "";

            if (!Directory.Exists(directory))
            {
                failed = "DLL Folder does not exist";
            }
            else
            {
                FileInfo[] allFiles = Directory.EnumerateFiles(directory, "*.dll", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

                string[] allowedfiles = allowed.Split(',');

                foreach (FileInfo f in allFiles)
                {
                    string filename = System.IO.Path.GetFileNameWithoutExtension(f.FullName);

                    EDDDLLCaller caller = new EDDDLLCaller();

                    if (caller.Load(f.FullName))                                                                                                                              // if loaded (meaning it loaded, and its got EDDInitialise)
                    {
                        if (allowed.Equals("All", StringComparison.InvariantCultureIgnoreCase) || allowedfiles.Contains(filename, StringComparer.InvariantCultureIgnoreCase)) // if allowed..
                        {
                            if (caller.Init(ourversion, dllfolder, callbacks))                                                                                                // must init
                            {
                                dlls.Add(caller);
                                loaded = loaded.AppendPrePad(caller.Name, ",");
                            }
                            else
                            {
                                string errstr = caller.Version.HasChars() ? (": " + caller.Version.Substring(1)) : "";
                                failed = failed.AppendPrePad(caller.Name + errstr, ",");
                            }
                        }
                        else
                        {
                            notallowed = notallowed.AppendPrePad(caller.Name, ",");
                        }
                    }
                }
            }

            return(new Tuple <string, string, string>(loaded, failed, notallowed));
        }
        private Tuple <bool, string, string> AC(EDDDLLCaller caller, string cmd, string[] paras)
        {
            string r = caller.ActionCommand(cmd, paras);

            if (r == null)
            {
                return(new Tuple <bool, string, string>(false, caller.Name, "DLL does not implement ActionCommand"));
            }
            else if (r.Length > 0 && r[0] == '+')
            {
                return(new Tuple <bool, string, string>(true, caller.Name, r.Mid(1)));
            }
            else
            {
                return(new Tuple <bool, string, string>(false, caller.Name, r.Mid(1)));
            }
        }
        // item1 = true if found, item2 = true if caller implements.
        public Tuple <bool, bool> ActionJournalEntry(string dllname, EDDDLLInterfaces.EDDDLLIF.JournalEntry nje)
        {
            if (dllname.Equals("All", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (EDDDLLCaller caller in DLLs)
                {
                    caller.ActionJournalEntry(nje);
                }

                return(new Tuple <bool, bool>(true, true));
            }
            else
            {
                EDDDLLCaller caller = FindCaller(dllname);
                return(caller != null ? new Tuple <bool, bool>(true, caller.ActionJournalEntry(nje)) : new Tuple <bool, bool>(false, false));
            }
        }
示例#6
0
        // search directory for *.dll,
        // return loaded, failed, new dlls not in the allowed/disallowed list, disabled
        // alloweddisallowed list is +allowed,-disallowed..
        // all Csharp assembly DLLs are loaded - only ones implementing *EDDClass class causes it to be added to the DLL list
        // only normal DLLs implementing EDDInitialise are kept loaded

        public Tuple <string, string, string, string> Load(string[] dlldirectories, bool[] disallowautomatically, string ourversion, string[] inoptions,
                                                           EDDDLLInterfaces.EDDDLLIF.EDDCallBacks callbacks, ref string alloweddisallowed)
        {
            string loaded   = "";
            string failed   = "";
            string disabled = "";
            string newdlls  = "";

            for (int i = 0; i < dlldirectories.Length; i++)
            {
                var dlldirectory = dlldirectories[i];

                if (dlldirectory != null)
                {
                    if (!Directory.Exists(dlldirectory))
                    {
                        failed = failed.AppendPrePad("DLL Folder " + dlldirectory + " does not exist", ",");
                    }
                    else
                    {
                        FileInfo[] allFiles = Directory.EnumerateFiles(dlldirectory, "*.dll", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

                        string[] allowedfiles = alloweddisallowed.Split(',');

                        foreach (FileInfo f in allFiles)
                        {
                            EDDDLLCaller caller = new EDDDLLCaller();

                            System.Diagnostics.Debug.WriteLine("Try to load " + f.FullName);

                            string filename = System.IO.Path.GetFileNameWithoutExtension(f.FullName);

                            bool isallowed = alloweddisallowed.Equals("All", StringComparison.InvariantCultureIgnoreCase) ||
                                             allowedfiles.Contains("+" + f.FullName, StringComparer.InvariantCultureIgnoreCase) ||    // full name is now used
                                             allowedfiles.Contains("+" + filename, StringComparer.InvariantCultureIgnoreCase);        // filename previously used

                            bool isdisallowed = allowedfiles.Contains("-" + f.FullName, StringComparer.InvariantCultureIgnoreCase) || // full name is now used
                                                allowedfiles.Contains("-" + filename, StringComparer.InvariantCultureIgnoreCase);     // filename previously used

                            if (isdisallowed)                                                                                         // disallowed
                            {
                                disabled = disabled.AppendPrePad(f.FullName, ",");
                            }
                            else if (isallowed)                                                      // if allowed..
                            {
                                if (caller.Load(f.FullName))                                         // if loaded okay
                                {
                                    if (caller.Init(ourversion, inoptions, dlldirectory, callbacks)) // must init
                                    {
                                        DLLs.Add(caller);
                                        loaded = loaded.AppendPrePad(filename, ",");        // just use short name for reporting
                                    }
                                    else
                                    {
                                        string errstr = caller.Version.HasChars() ? (": " + caller.Version.Substring(1)) : "";
                                        failed = failed.AppendPrePad(f.FullName + errstr, ","); // long name for failure
                                    }
                                }
                            }
                            else
                            {
                                if (disallowautomatically[i])
                                {
                                    alloweddisallowed = alloweddisallowed.AppendPrePad("-" + f.FullName, ",");
                                    disabled          = disabled.AppendPrePad(f.FullName, ",");
                                }
                                else
                                {
                                    newdlls = newdlls.AppendPrePad(f.FullName, ",");
                                }
                            }
                        }
                    }
                }
            }

            return(new Tuple <string, string, string, string>(loaded, failed, newdlls, disabled));
        }