Exemple #1
0
        public void RemoveAssembly()
        {
            Discovery dis = new Discovery();

            dis.AddAssembly("UnitTest.dll");
            Assert.AreEqual(1, dis.Assemblies.Count);
            dis.RemoveAssembly("UnitTest.dll");
            Assert.AreEqual(0, dis.Assemblies.Count);
        }
Exemple #2
0
        public void GetMemberByAttributeTypeValue()
        {
            Discovery  discovery = new Discovery();
            MemberInfo property  = discovery.GetMemberInType(typeof(TestClassWithMethods), new MyAttribute("Property"));
            MemberInfo field     = discovery.GetMemberInType(typeof(TestClassWithMethods), new MyAttribute("Field"));

            Assert.AreEqual("Property", property.Name);
            Assert.AreEqual("Field", field.Name);
        }
Exemple #3
0
 public void Initialize()
 {
     dis = new Discovery();
     dis.AddAssembly(Assembly.GetExecutingAssembly());
 }
Exemple #4
0
        private static int Main(string[] args)
        {
            ControlEventHandler eventHandler = new ControlEventHandler(Handler);

            SetConsoleCtrlHandler(eventHandler, true);

            Discovery dis       = new Discovery();
            Assembly  assembly  = Assembly.GetExecutingAssembly();
            string    directory = Path.GetDirectoryName(assembly.Location);

            foreach (string file in Directory.GetFiles(directory, "*.dll"))
            {
                dis.AddAssembly(file);
            }
            string exeName     = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase);
            Type   commandType = dis.GetClass(typeof(NamedAttribute), new NamedAttribute(exeName));

            if (commandType == null)
            {
                WriteOutput(string.Format("Coult not find Command '{0}' to execute", exeName));
                return(-4);
            }
            CommandLineParser parser = new CommandLineParser(commandType, args);

            if (args.Length == 0 || args[0] == "/?" || args[0] == "--help")
            {
                Console.WriteLine(parser.Usage);
                return(-1);
            }
            if (args.Length == 1 && (args[0] == "/v" || args[0] == "-v" || args[0] == "--v"))
            {
                Version ver = Assembly.GetExecutingAssembly().GetName().Version;
                Console.WriteLine(exeName + " version " + ver.ToString());
                return(0);
            }
            try
            {
                ICommand com = (ICommand)parser.Parse();
                if (com is Commandlet)
                {
                    commandlet = (Commandlet)com;
                    commandlet.ExecutableName      = exeName;
                    commandlet.ExecutableDirectory = directory;
                }
                com.Execute();
                if (com.Outputs != null)
                {
                    foreach (object res in com.Outputs)
                    {
                        WriteOutput(res.ToString());
                    }
                }
                if (com.Result != null)
                {
                    return(Int32.Parse(com.Result));
                }
                else
                {
                    return(0);
                }
            }
            catch (CommandLineArgumentException ex)
            {
                WriteOutput(ex.Message + "\r\n");
                WriteOutput(parser.Usage);
                return(-1);
            }
            catch (ApplicationException ex)
            {
                WriteOutput(ex.Message);
                return(-3);
            }
            catch (Exception ex)
            {
                commandlet.Exception(ex);
                while (ex != null)
                {
                    WriteOutput(ex.Message + "\r\n" + ex.StackTrace);
                    ex = ex.InnerException;
                }
                return(-2);
            }
        }
 public void RemoveAssembly()
 {
     Discovery dis = new Discovery();
     dis.AddAssembly("UnitTest.dll");
     Assert.AreEqual(1, dis.Assemblies.Count);
     dis.RemoveAssembly("UnitTest.dll");
     Assert.AreEqual(0, dis.Assemblies.Count);
 }
 public void Initialize()
 {
     dis = new Discovery();
     dis.AddAssembly(Assembly.GetExecutingAssembly());
 }
 public void Inheritence()
 {
     Discovery discovery = new Discovery();
     MemberInfo[] properties = discovery.GetMembersInType(typeof(TestClassInherited), (typeof(MyAttribute)));
     Assert.AreEqual(2, properties.Length);
 }
 public void GetMemberByAttributeTypeValue()
 {
     Discovery discovery = new Discovery();
     MemberInfo property = discovery.GetMemberInType(typeof(TestClassWithMethods), new MyAttribute("Property"));
     MemberInfo field = discovery.GetMemberInType(typeof(TestClassWithMethods), new MyAttribute("Field"));
     Assert.AreEqual("Property", property.Name);
     Assert.AreEqual("Field", field.Name);
 }