Beispiel #1
0
        private DataReference CreateDataReference(JToken item)
        {
            string        refersTo = (string)item["refersTo"];
            DataReference result   = new DataReference(DataReference.CurrentContext(), refersTo);

            result.DebugInfo = GetDebugInfo(item);

            return(result);
        }
        public InjectObjectFactoryContext(IDictionary <string, object> context)
        {
            _current = DataReference.CurrentContext();

            _field = typeof(DataReference).GetField("_contextScope",
                                                    BindingFlags.Static |
                                                    BindingFlags.NonPublic);

            _field.SetValue(null, context);
        }
Beispiel #3
0
        private static void ProcessInputFile(string filename, IValidationProvider validationProvider)
        {
            Log.Instance.Info("Processing File {0}", filename);

            var            inputStream = new StreamReader(filename);
            JsonTextReader reader      = new JsonTextReader(inputStream);

            var obj = JToken.ReadFrom(reader);

            var validationResult = validationProvider.Validate(obj);


            Log.Instance.Info("Valid: {0}", validationResult.IsValid);

            if (!validationResult.IsValid)
            {
                validationResult.PrintValidationMessages(Log.Instance);
                return;
            }

            var           contextToken  = obj["context"];
            var           context       = DataReference.CurrentContext();
            ObjectFactory objectFactory = new ObjectFactory();

            foreach (var item in contextToken.Children())
            {
                string type = (string)item["type"];
                string name = (string)item.TryGet("name");

                Console.WriteLine("{0}:{1}", name ?? "<unnamed>", type);

                if (name != null)
                {
                    var contextItem = objectFactory.Create(item);
                    if (contextItem != null)
                    {
                        context[name] = contextItem;
                    }
                }
            }

            var ouputToken = obj["output"];

            IList <IRootOutput> outputs = new List <IRootOutput>();

            foreach (var item in ouputToken)
            {
                string type = (string)item["type"];

                Log.Instance.Trace("{0}:{1}", "output", type);

                var outputItem = (IRootOutput)objectFactory.Create(item);

                outputs.Add(outputItem);
            }

            var toExecute = outputs.ToList();

            if (!toExecute.Any())
            {
                Log.Instance.Warn("No root outputs found. No output will be generated. Choose one of (fileOutput)");
            }
            else
            {
                toExecute.ForEach(p => p.Evaluate());
            }

            inputStream.Dispose();
        }