Exemplo n.º 1
0
        /// <summary>
        /// Discovers this all instanced of <typeparamref name="T"/> within the discovery location.
        /// </summary>
        public void Discover()
        {
            Logger.Debug("Discovering {0}'s in '{1}' and all sub directories.", typeof(T).Name, DiscoveryLocation);

            var results = new List <T>();

            // This behavior only to support usage of glimpse[@discoverLocation] attribute. Remove "if" block in Glimpse 2.0 in favor of "else" if it is decided that discovery location is not required
            if (!DiscoveryLocation.Equals(BaseDirectory))
            {
                foreach (var file in Directory.GetFiles(DiscoveryLocation, "*.dll", SearchOption.AllDirectories))
                {
                    try
                    {
                        Assembly assembly = Assembly.LoadFrom(file);

                        GetConcreteTypes(assembly, results);
                    }
                    catch (Exception exception)
                    {
                        Logger.Error(Resources.DiscoverLoadAssembly, exception, file);
                    }
                }
            }
            else
            {
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try
                    {
                        GetConcreteTypes(assembly, results);
                    }
                    catch (Exception exception)
                    {
                        string assemblyLocation;
                        try
                        {
                            assemblyLocation = assembly.Location;
                        }
                        catch (NotSupportedException)
                        {
                            assemblyLocation = "in-memory";
                        }

                        Logger.Error(Resources.DiscoverLoadAssembly, exception, assemblyLocation);
                    }
                }
            }

            if (results.Count > 0)
            {
                Items.Clear();

                foreach (var result in results)
                {
                    Logger.Debug(string.Format(Resources.DiscoverableCollectionDiscover, typeof(T).Name, result.GetType()));
                }

                Items.AddRange(results);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Discovers this all instanced of <typeparamref name="T"/> within the discovery location.
        /// </summary>
        public void Discover()
        {
            var results = new List <T>();

            // This behavior only to support usage of glimpse[@discoverLocation] attribute. Remove "if" block in Glimpse 2.0 in favor of "else" if it is decided that discovery location is not required
            if (!DiscoveryLocation.Equals(BaseDirectory))
            {
                foreach (var file in Directory.GetFiles(DiscoveryLocation, "*.dll", SearchOption.AllDirectories))
                {
                    try
                    {
                        Assembly assembly = Assembly.LoadFrom(file);

                        GetConcreteTypes(assembly, results);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            else
            {
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try
                    {
                        GetConcreteTypes(assembly, results);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (results.Count > 0)
            {
                Items.Clear();

                Items.AddRange(results);
            }
        }