Exemple #1
0
        private static void ProcessType(Type t)
        {
            CameraManager manager = (CameraManager)Activator.CreateInstance(t, null);

            if (manager.Enabled)
            {
                try
                {
                    if (manager.SanityCheck())
                    {
                        manager.CameraThumbnailProduced += CameraManager_CameraThumbnailProduced;
                        cameraManagers.Add(manager);
                        log.InfoFormat("Initialized {0} camera manager.", manager.CameraTypeFriendlyName);
                    }
                    else
                    {
                        log.InfoFormat("{0} camera manager failed sanity check.", manager.CameraTypeFriendlyName);
                    }
                }
                catch (FileNotFoundException)
                {
                    log.InfoFormat("{0} camera manager is missing dependencies.", manager.CameraTypeFriendlyName);
                }
            }
            else
            {
                log.InfoFormat("{0} camera manager is disabled.", manager.CameraTypeFriendlyName);
            }
        }
        /// <summary>
        /// Try to add an instantiated camera manager object to our rooster.
        /// </summary>
        private static void AddCameraManager(CameraManager manager)
        {
            try
            {
                if (!manager.Enabled)
                {
                    log.InfoFormat("{0} camera manager is disabled.", manager.CameraTypeFriendlyName);
                    return;
                }

                if (manager.SanityCheck())
                {
                    manager.CameraThumbnailProduced += CameraManager_CameraThumbnailProduced;
                    cameraManagers.Add(manager);
                    log.InfoFormat("Initialized {0} camera manager.", manager.CameraTypeFriendlyName);
                }
                else
                {
                    log.InfoFormat("{0} camera manager failed sanity check.", manager.CameraTypeFriendlyName);
                }
            }
            catch (FileNotFoundException e)
            {
                log.InfoFormat("{0} camera manager is missing dependencies. {1}", manager.CameraTypeFriendlyName, e.Message);
            }
            catch (Exception e)
            {
                log.InfoFormat("Error while initializing {0}. {1}", manager.CameraTypeFriendlyName, e.Message);
            }
        }
Exemple #3
0
        /// <summary>
        /// Find and instanciate types implementing the CameraManager base class.
        /// </summary>
        public static void LoadCameraManagers()
        {
            List <Assembly> assemblies = new List <Assembly>();

            string dir = Path.GetDirectoryName(Application.ExecutablePath);
            IEnumerable <string> files = Directory.GetFiles(dir, "Kinovea.Camera.*.dll");

            foreach (string filename in files)
            {
                AddAssembly(filename, assemblies);
            }

            // Register the camera managers.
            foreach (Assembly a in assemblies)
            {
                try
                {
                    foreach (Type t in a.GetTypes())
                    {
                        if (t.BaseType == null || t.BaseType.Name != "CameraManager" || t.IsAbstract)
                        {
                            continue;
                        }

                        ConstructorInfo ci = t.GetConstructor(System.Type.EmptyTypes);
                        if (ci == null)
                        {
                            continue;
                        }

                        CameraManager manager = (CameraManager)Activator.CreateInstance(t, null);

                        if (manager.Enabled)
                        {
                            if (manager.SanityCheck())
                            {
                                manager.CameraThumbnailProduced += CameraManager_CameraThumbnailProduced;
                                cameraManagers.Add(manager);
                                log.InfoFormat("Initialized {0} camera manager.", manager.CameraTypeFriendlyName);
                            }
                            else
                            {
                                log.InfoFormat("{0} camera manager failed sanity check.", manager.CameraTypeFriendlyName);
                            }
                        }
                        else
                        {
                            log.InfoFormat("{0} camera manager is disabled.", manager.CameraTypeFriendlyName);
                        }
                    }
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (Exception exception in ex.LoaderExceptions)
                    {
                        log.ErrorFormat(exception.Message.ToString());
                    }
                }
            }
        }