Пример #1
0
 private static ITypeDisplayer CreateDefaultDisplayer()
 {
     try {
         // Get the correct order to load displayers...
         string order = ConfigurationSettings.AppSettings["displayer-order"];
         foreach (string d in order.Split(' '))
         {
             ITypeDisplayer displayer = Factories.Displayer.Create(d);
             if (displayer != null)
             {
                 return(displayer);
             }
         }
     }
     catch {
     }
     return(null);
 }
Пример #2
0
        public static ITypeDisplayer CreateDisplayer(TypeReflectorOptions options)
        {
            ITypeDisplayer d = null;

            if (options.Displayer != string.Empty)
            {
                d = Factories.Displayer.Create(options.Displayer);
            }
            else
            {
                d = CreateDefaultDisplayer();
            }

            if (d != null)
            {
                d.MaxDepth = options.MaxDepth;
            }

            return(d);
        }
Пример #3
0
 public static void FindTypes(ITypeDisplayer displayer, TypeLoader loader, IList types)
 {
     try {
         ICollection typesFound = loader.LoadTypes(types);
         Trace.WriteLine(
             string.Format("Types Found: {0}", typesFound.Count.ToString()));
         if (typesFound.Count > 0)
         {
             int curType = 1;
             foreach (Type type in typesFound)
             {
                 displayer.AddType(type, curType++, typesFound.Count);
             }
         }
         else
         {
             displayer.ShowError("Unable to find types.");
         }
     } catch (Exception e) {
         displayer.ShowError(string.Format("Unable to display type: {0}.",
                                           e.ToString()));
     }
 }
Пример #4
0
		public static void FindTypes (ITypeDisplayer displayer, TypeLoader loader, IList types)
		{
			try {
				ICollection typesFound = loader.LoadTypes (types);
				Trace.WriteLine (
					string.Format ("Types Found: {0}", typesFound.Count.ToString()));
				if (typesFound.Count > 0) {
					int curType = 1;
					foreach (Type type in typesFound) {
						displayer.AddType (type, curType++, typesFound.Count);
					}
				}
				else
					displayer.ShowError ("Unable to find types.");
			} catch (Exception e) {
				displayer.ShowError (string.Format ("Unable to display type: {0}.", 
					e.ToString()));
			}
		}
Пример #5
0
        public static void Execute(string[] args)
        {
            InitFactories();

            TypeReflectorOptions options = new TypeReflectorOptions();

            bool quit = false;

            try {
                options.ParseOptions(args);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine("See `{0} --help' for more information", ProgramOptions.ProgramName);
                return;
            }

            foreach (DictionaryEntry de in Factories.Displayer)
            {
                Trace.WriteLine(
                    string.Format("registered displayer: {0}={1}", de.Key,
                                  ((TypeFactoryEntry)de.Value).Type));
            }

            if (options.FoundHelp)
            {
                Console.WriteLine(options.OptionsHelp);
                quit = true;
            }

            if (options.DefaultAssemblies)
            {
                Console.WriteLine("The default search assemblies are:");
                foreach (string s in TypeReflectorOptions.GetDefaultAssemblies())
                {
                    Console.WriteLine("  {0}", s);
                }
                quit = true;
            }

            if (options.Version)
            {
                PrintVersion();
                quit = true;
            }

            if (quit)
            {
                return;
            }

            TraceArray("Explicit Assemblies: ", options.Assemblies);
            TraceArray("Referenced Assemblies: ", options.References);
            TraceArray("Search for Types: ", options.Types);

            TypeLoader loader = CreateLoader(options);

            TraceArray("Actual Search Assemblies: ", loader.Assemblies);
            TraceArray("Actual Search Assemblies: ", loader.References);

            ITypeDisplayer displayer = CreateDisplayer(options);

            if (displayer == null)
            {
                Console.WriteLine("Error: invalid displayer: " + options.Displayer);
                return;
            }

            if (loader.Assemblies.Count == 0 && loader.References.Count == 0 &&
                displayer.AssembliesRequired)
            {
                Console.WriteLine("Error: no assemblies specified.");
                Console.WriteLine("See `{0} --help' for more information",
                                  ProgramOptions.ProgramName);
                return;
            }

            INodeFormatter formatter = CreateFormatter(options);

            if (formatter == null)
            {
                Console.WriteLine("Error: invalid formatter: " + options.Formatter);
                return;
            }

            INodeFinder finder = CreateFinder(options);

            if (finder == null)
            {
                Console.WriteLine("Error: invalid finder: " + options.Finder);
                return;
            }

            displayer.Finder    = finder;
            displayer.Formatter = formatter;
            displayer.Options   = options;

            displayer.InitializeInterface();

            IList types = options.Types;

            if (types.Count == 0)
            {
                types = new string[] { "." }
            }
            ;

            // Find the requested types and display them.
            if (loader.Assemblies.Count != 0 || loader.References.Count != 0)
            {
                FindTypes(displayer, loader, types);
            }

            displayer.Run();
        }