Esempio n. 1
0
        private static object[] GetValues(SimpleJobFactory factory, ParameterInfo[] pars)
        {
            var vals = new  object[pars.Length];
            int i    = 0;

            foreach (var item in pars)
            {
                var paramType = item.ParameterType;
                //TODO: what if paramtype is array/ienumerable??
                if (paramType != typeof(string) && paramType.GetTypeInfo().IsClass)
                {
                    var itemClass  = factory.ConstructedObject(paramType);
                    var t          = itemClass.GetType();
                    var propsClass = factory.GetOwnProperties(t, t.Name);
                    foreach (var prClass in propsClass)
                    {
                        Console.WriteLine($"{prClass.Name} ({prClass.ParameterType.Name})");
                    }
                    vals[i++] = itemClass;
                    //TODO: add propertied for this object
                    //e.g DBTableData
                }
                else
                {
                    //todo: add optional and default value
                    Console.WriteLine($"please give value for ({item.ParameterType.Name}){item.Name} ");
                    vals[i++] = Convert.ChangeType(Console.ReadLine(), item.ParameterType);
                }
            }
            return(vals);
        }
Esempio n. 2
0
        private static int GenerateJobDefinition()
        {
            var factory = new SimpleJobFactory();

            var job    = GetFullObject <ISimpleJob>(factory);
            var choice = AddDataSimpleJob.ExitChoice;

            do
            {
                Console.WriteLine($"{(int)AddDataSimpleJob.ExitChoice}. Exit");
                Console.WriteLine($"{(int)AddDataSimpleJob.AddReceiver}. Add Receiver");
                Console.WriteLine($"{(int)AddDataSimpleJob.AddTransformer}. Add transformer");
                Console.WriteLine($"{(int)AddDataSimpleJob.AddSender}. Add Sender");
                choice = (AddDataSimpleJob)int.Parse(Console.ReadLine());

                switch (choice)
                {
                case AddDataSimpleJob.ExitChoice:
                    break;

                case AddDataSimpleJob.AddReceiver:
                    var rec = GetFullObject <IReceive>(factory);
                    job.Receivers.Add(job.Receivers.Count, rec);
                    break;

                case AddDataSimpleJob.AddTransformer:
                    var tr = GetFullObject <IFilterTransformer>(factory);
                    job.FiltersAndTransformers.Add(job.FiltersAndTransformers.Count, tr);
                    break;

                case AddDataSimpleJob.AddSender:
                    var s = GetFullObject <ISend>(factory);
                    job.Senders.Add(job.Senders.Count, s);
                    break;

                default:
                    Console.WriteLine("not yet implemented");
                    break;
                }
            } while (choice != AddDataSimpleJob.ExitChoice);



            var serialized = job.SerializeMe();

            File.WriteAllText("a.txt", serialized);
            Process.Start("notepad.exe", "a.txt");
            return(0);
        }
Esempio n. 3
0
        private static T GetFullObject <T>(SimpleJobFactory factory)
        {
            var t = typeof(T);
            int i = 1;

            foreach (var name in factory.NamesOfObjects(t))
            {
                Console.WriteLine($"{i++}){name}");
            }
            Console.Write($"Please enter {t.Name} id");
            var nr = int.Parse(Console.ReadLine());

            var nameSelected = factory.NamesOfObjects(t)[nr - 1];

            var pars = factory.GetOwnProperties(t, nameSelected);
            var vals = GetValues(factory, pars);
            var obj  = factory.GetObject(t, nameSelected, vals);

            return((T)obj);
        }
Esempio n. 4
0
 public void SetUp()
 {
     factory = new SimpleJobFactory();
 }
Esempio n. 5
0
 public MefJobFactory(SimpleJobFactory simpleFactory, CompositionContainer container)
 {
     _simpleFactory = simpleFactory;
     _container     = container;
 }