Exemple #1
0
        public TTo Map <TFrom, TTo>(TFrom from)
            where TFrom : class
            where TTo : class
        {
            var to = objectFactory.CreateInstance <TTo>();

            InjectSingle(from, to, GetMapping <TFrom, TTo>());
            return(to);
        }
Exemple #2
0
        public void InjectSingle(QueryResult queryResult, TView instance)
        {
            var entity       = _objectFactory.CreateInstance <TEntity>();
            var entityReader = new QueryResultModelReader <TEntity>(_storageModel, queryResult);
            var entityWriter = new ObjectDataModelWriter <TEntity>(entity, _objectFactory);

            _toEntityMapping.Run(entityReader, entityWriter);

            var viewReader = new ObjectDataModelReader <TEntity>(entity);
            var viewWriter = new ObjectDataModelWriter <TView>(instance, _objectFactory);

            _toViewMapping.Run(viewReader, viewWriter);
        }
Exemple #3
0
        public ICompiledScript Compile(IAdvancedScript script)
        {
            ICompiledScript compiledScript = _factory.CreateInstance <ICompiledScript>();

            compiledScript.OriginalScript = script;
            Inputs   = new();
            AllNodes = new();

            foreach (InputNode scriptInput in script.Editor.Inputs.InputNodes)
            {
                ILaminarValue myInputValue = _valueFactory.Get(scriptInput.Value, true);
                myInputValue.Name = scriptInput.GetNameLabel().LabelText.Value;
                compiledScript.Inputs.Add(myInputValue);
                Inputs.Add(scriptInput, myInputValue);
            }

            foreach (INodeContainer triggerNode in script.Editor.TriggerNodes)
            {
                if (triggerNode.Name.OutputConnector.ExclusiveConnection is not null)
                {
                    CompiledNodeWrapper wrappedTrigger = CompiledNodeWrapper.Get(triggerNode, this);
                    compiledScript.AllTriggerNodes.Add(wrappedTrigger);
                    wrappedTrigger.flowOutChains.Add(new CompiledNodeChain(triggerNode.Name, wrappedTrigger.CoreNode.GetNameLabel().FlowOutput, this));
                }
            }

            return(compiledScript);
        }
Exemple #4
0
        public TView MapSingle(QueryResult queryResult)
        {
            var obj = _objectFactory.CreateInstance <TView>();

            InjectSingle(queryResult, obj);
            return(obj);
        }
Exemple #5
0
        private INodeBase PrivateGet <T>() where T : INode
        {
            if (typeof(IFlowNode).IsAssignableFrom(typeof(T)))
            {
                return(_factory.CreateInstance <FlowNode <T> >());
            }

            if (typeof(IActionNode).IsAssignableFrom(typeof(T)))
            {
                return(_factory.CreateInstance <ActionNode <T> >());
            }

            if (typeof(IFunctionNode).IsAssignableFrom(typeof(T)))
            {
                return(_factory.CreateInstance <FunctionNode <T> >());
            }

            if (typeof(ITriggerNode).IsAssignableFrom(typeof(T)))
            {
                return(_factory.CreateInstance <TriggerNode <T> >());
            }

            if (typeof(T) == typeof(InputNode))
            {
                return(_factory.CreateInstance <InputNodeBase>());
            }

            return(_factory.CreateInstance <NodeBase <T> >());
        }
Exemple #6
0
        private void RaiseEvent <TEvent>(IEnumerable <Type> eventHandlers, TEvent args) where TEvent : IEvent, new()
        {
            foreach (var eventHandlerType in eventHandlers)
            {
                var eventHandler = _objectFactory.CreateInstance <IHandle <TEvent> >(eventHandlerType);
                eventHandler.Handle(args);

                if (args.StopProcessing)
                {
                    break;
                }
            }
        }
        public bool RaiseRequestProcessingEvent(PiccoloContext context)
        {
            var args = new RequestProcessingEvent {
                Context = context
            };
            var stopRequestProcessing = false;

            foreach (var eventHandlerType in _eventHandlers.RequestProcessing)
            {
                var eventHandler = _objectFactory.CreateInstance <IHandle <RequestProcessingEvent> >(eventHandlerType);
                eventHandler.Handle(args);

                stopRequestProcessing = args.StopRequestProcessing;

                if (args.StopEventProcessing)
                {
                    break;
                }
            }

            return(stopRequestProcessing);
        }
		public static IInterceptableList CreateProxy(Type baseType, IObjectFactory objectFactory,params object[] ctorArgs)
		{
			if (objectFactory == null)
				throw new Exception("apa");

			Type proxyType = GetProxyType(baseType);

			IInterceptableList result = (IInterceptableList) objectFactory.CreateInstance(proxyType, ctorArgs);
			if (result == null)
				result = (IInterceptableList) Activator.CreateInstance(proxyType, ctorArgs);

			//attach the an interceptor to the list
			//result.SetInterceptor(new ListInterceptor());


			return result;
		}
Exemple #9
0
        private bool TryGetObjectFactoryInstance(IObjectFactory objectFactory, out object createdInstance)
        {
            if (objectFactory == null)
            {
                createdInstance = null;
                return(false);
            }

            createdInstance = objectFactory.CreateInstance(ServiceProvider);

            object childInstance;

            if (TryGetObjectFactoryInstance(createdInstance as IObjectFactory, out childInstance))
            {
                createdInstance = childInstance;
            }
            return(true);
        }
        private void LoadImages()
        {
            ImageItems.Clear();

            foreach (var discItem in Discs)
            {
                var discImages = contentCrawler.LoadDiscImages(discItem.SourcePath).ToList();
                if (discImages.Count > 1)
                {
                    throw new InvalidOperationException($"Disc '{discItem.SourcePath}' contains multiple images. Only one image per disc (cover image) is currently supported.");
                }

                var imageFile = imageFileFactory.CreateInstance();
                if (discImages.Count == 1)
                {
                    imageFile.Load(discImages.Single(), false);
                }

                ImageItems.Add(new DiscImageViewItem(discItem, DiscImageType.Cover, imageFile));
            }
        }
        public static IInterceptableList CreateProxy(Type baseType, IObjectFactory objectFactory, params object[] ctorArgs)
        {
            if (objectFactory == null)
            {
                throw new Exception("apa");
            }

            Type proxyType = GetProxyType(baseType);

            IInterceptableList result = (IInterceptableList)objectFactory.CreateInstance(proxyType, ctorArgs);

            if (result == null)
            {
                result = (IInterceptableList)Activator.CreateInstance(proxyType, ctorArgs);
            }

            //attach the an interceptor to the list
            //result.SetInterceptor(new ListInterceptor());


            return(result);
        }
        private object GetPayloadValidator(Type requestHandlerType, string verb)
        {
            var attribute = requestHandlerType.GetAttribute <ValidateWithAttribute>();

            if (attribute == null)
            {
                return(null);
            }

            var validatorInterfaces = attribute.ValidatorType.GetInterfaces().Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IPayloadValidator <>)).ToList();

            if (validatorInterfaces.Any() == false)
            {
                throw new InvalidPayloadValidatorException(ExceptionMessageBuilder.BuildInvalidPayloadValidatorMessage(attribute.ValidatorType, requestHandlerType));
            }

            if (validatorInterfaces.Any(x => x.GetGenericArguments().First() == requestHandlerType.GetMethodParameterType(verb)) == false)
            {
                throw new InvalidPayloadValidatorException(ExceptionMessageBuilder.BuildInvalidPayloadValidatorMessage(attribute.ValidatorType, requestHandlerType));
            }

            return(_objectFactory.CreateInstance <object>(attribute.ValidatorType));
        }
 public static T CreateInstance <T>(this IObjectFactory factory)
 {
     return((T)factory.CreateInstance(typeof(T)));
 }
Exemple #14
0
        /// <summary>Maps the give argument dictionary to a new created instance.</summary>
        /// <param name="arguments">The arguments to map.</param>
        /// <returns>The instance of the class, the command line argument were mapped to</returns>
        /// <exception cref="System.IO.InvalidDataException">Option attribute can only be applied to boolean properties</exception>
        /// <exception cref="InvalidDataException">Option attribute can only be applied to boolean properties</exception>
        public T Map(IDictionary <string, CommandLineArgument> arguments)
        {
            var instance = factory.CreateInstance <T>();

            return(Map(arguments, instance));
        }
Exemple #15
0
 public static T CreateInstance <T>(this IObjectFactory factory, params object[] args)
 {
     return((T)factory.CreateInstance(typeof(T), args));
 }
 public INodeContainer Get <T>() where T : INode, new()
 => Get(_factory.CreateInstance <T>());
Exemple #17
0
        public static object MapTo(this Dictionary <string, KeyValuePair <string, string> > values, Type desiredType, IInterpeter interpeter, IObjectFactory f)
        {
            var members      = desiredType.GetValueMembers();
            var constructors = desiredType.CachedGetConstructors();

            var groups    = values.Keys.Select(x => Split(x).First());
            var unmatched = groups.Except(members.Select(x => x.Name.ToUpper()));
            var errors    = unmatched.Except(constructors.SelectMany(c => c.GetParameters().Select(p => p.Name.ToUpper())));

            if (errors.Any())
            {
                var prefix = values[errors.First()].Key.Substring(0, values[errors.First()].Key.Length - errors.First().Length);
                var unused = members.Select(p => p.Name).Where(p => !groups.Contains(p.ToUpper()));
                throw new GherkinException($"The columns:{errors.LogFormat(x => values[x].Key)} are unmatched maybe it is one of these {unused.LogFormat(x => prefix + x)}");
            }

            object resolve(string name, Type t)
            {
                var    keys = values.Keys.Where(k => k.Split().First() == name);
                object item;

                if (keys.One() && keys.First().Split().One())
                {
                    item = interpeter.Get(t, values[name].Value);
                }
                else if (keys.Any(k => k.Split().One()))
                {
                    throw new GherkinException($"You can't specify the object and set properties on the object, columns {keys.LogFormat(x => values[x].Key)} are in conflict");
                }
                else
                {
                    item = keys.ToDictionary(x => x.Recurse(), x => values[x]).MapTo(t, interpeter, f);
                }

                foreach (var k in keys.ToList())
                {
                    values.Remove(k);
                }

                return(item);
            };

            object ret;

            if (unmatched.Any())
            {
                var possibles = constructors.Where(c => unmatched.Except(c.GetParameters().Select(p => p.Name.ToUpper())).None());
                var valid     = possibles.Where(c => c.GetParameters().Where(p => !p.IsOptional).Select(p => p.Name.ToUpper()).Except(groups).None());
                var ctor      = valid.OrderBy(c => c.GetParameters().Count()).Reverse().FirstOrDefault();

                if (ctor == null)
                {
                    throw new GherkinException($"the following fields '{unmatched.LogFormat()}' did not map to any constructor or property.");
                }

                ret = ctor.Invoke(ctor
                                  .GetParameters()
                                  .Select(p => groups.Contains(p.Name.ToUpper())?resolve(p.Name.ToUpper(), p.ParameterType): p.DefaultValue)
                                  .ToArray());
            }
            else
            {
                ret = f.CreateInstance(desiredType);
            }

            foreach (var key in values.Keys.Select(k => Split(k).First()).ToList())
            {
                var prop = members.First(p => p.Name.ToUpper() == key);
                prop.SetValue(ret, resolve(key, prop.Type));
            }

            return(ret);
        }
Exemple #18
0
 public override INodeComponent Clone() => _factory.CreateInstance <Separator>();
Exemple #19
0
 public static IMessageFilter[] GetMessageFilters(IObjectFactory objectFactory)
 {
     return filterTypes.Select(x => (IMessageFilter)objectFactory.CreateInstance(x)).ToArray();
 }