Ejemplo n.º 1
0
        public void TestKeepAlive()
        {
            PrivateObject privateObject = new PrivateObject(EDDI.Instance);
            EDDIMonitor   monitor       = ((List <EDDIMonitor>)privateObject
                                           .GetFieldOrProperty("monitors"))
                                          .FirstOrDefault(m => m.MonitorName() == "Journal monitor");

            privateObject.Invoke("EnableMonitor", new object[] { monitor.MonitorName() });
            monitor.Stop();
            Assert.AreEqual(1, ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).Count());

            privateObject.Invoke("DisableMonitor", new object[] { monitor.MonitorName() });
            Assert.AreEqual(0, ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).Count());

            privateObject.Invoke("EnableMonitor", new object[] { monitor.MonitorName() });
            monitor.Stop();

            Thread.Sleep(3000);
            Assert.AreEqual(1, ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).Count());

            Thread.Sleep(3000);
            Assert.AreEqual(1, ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).Count());

            Thread.Sleep(3000);
            Assert.AreEqual(1, ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).Count());

            Thread.Sleep(3000);
            Assert.AreEqual(1, ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).Count());

            ((ConcurrentBag <EDDIMonitor>)privateObject.GetFieldOrProperty("activeMonitors")).TryTake(out EDDIMonitor activeMonitor);
            Assert.AreEqual(monitor, activeMonitor);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find all monitors
        /// </summary>
        private List <EDDIMonitor> findMonitors()
        {
            DirectoryInfo      dir      = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            List <EDDIMonitor> monitors = new List <EDDIMonitor>();
            Type pluginType             = typeof(EDDIMonitor);

            foreach (FileInfo file in dir.GetFiles("*Monitor.dll", SearchOption.AllDirectories))
            {
                Logging.Debug("Checking potential plugin at " + file.FullName);
                try
                {
                    Assembly assembly = Assembly.LoadFrom(file.FullName);
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (type.IsInterface || type.IsAbstract)
                        {
                            continue;
                        }
                        else
                        {
                            if (type.GetInterface(pluginType.FullName) != null)
                            {
                                Logging.Debug("Instantiating monitor plugin at " + file.FullName);
                                EDDIMonitor monitor = type.InvokeMember(null,
                                                                        BindingFlags.CreateInstance,
                                                                        null, null, null) as EDDIMonitor;
                                monitors.Add(monitor);
                            }
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                    // Ignore this; probably due to CPU architecture mismatch
                }
                catch (ReflectionTypeLoadException ex)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (Exception exSub in ex.LoaderExceptions)
                    {
                        sb.AppendLine(exSub.Message);
                        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                        if (exFileNotFound != null)
                        {
                            if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                            {
                                sb.AppendLine("Fusion Log:");
                                sb.AppendLine(exFileNotFound.FusionLog);
                            }
                        }
                        sb.AppendLine();
                    }
                    Logging.Warn("Failed to instantiate plugin at " + file.FullName + ":\n" + sb.ToString());
                }
            }
            return(monitors);
        }