Exemplo n.º 1
0
        internal IEntityList GetEntetiesAfterFiltering(Dictionary <string, string> fieldsAndValues)
        {
            IFactory factory = null;

            switch (EntityType)
            {
            case EntityType.Defect:
            {
                factory = Connection.GetFactory <IBug>();
                break;
            }

            case EntityType.Requirement:
            {
                factory = Connection.GetFactory <IRequirement>();
                break;
            }
            }
            if (factory != null)
            {
                IListConfiguration listConfiguration = factory.NewListConfiguration();
                foreach (var fieldAndValue in fieldsAndValues)
                {
                    listConfiguration.Filter[fieldAndValue.Key] = fieldAndValue.Value;
                }
                return(factory.NewList(listConfiguration));
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to create an instance of <see cref="IListConfiguration.RequestType"/>.
        /// </summary>
        /// <param name="source"></param>
        /// <exception cref="NullReferenceException">
        /// An instance of <see cref="IModelFactory"/> could not be created by <see cref="ActivatorUtilities.GetServiceOrCreateInstance"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// No model factories or factory methods have been defined in <see cref="IListConfiguration.ModelActivatorConfiguration"/>.
        /// </exception>
        /// <returns></returns>
        public object CreateInstance(IListConfiguration source)
        {
            var configuration = source.ModelActivatorConfiguration;

            if (configuration.Method != null)
            {
                return(configuration.Method(source.RequestType));
            }

            // TODO: Add some sort of null check for httpContextAccessor?

            if (configuration.Factory != null)
            {
                return(configuration.Factory(httpContextAccessor.HttpContext.RequestServices, source.RequestType));
            }

            if (configuration.FactoryType != null)
            {
                var factory = ActivatorUtilities.GetServiceOrCreateInstance(httpContextAccessor.HttpContext.RequestServices, configuration.FactoryType) as IModelFactory;
                if (factory == null)
                {
                    throw new NullReferenceException($"Unable to create an instance of '{configuration.FactoryType.FullName}'.");
                }

                return(factory.Create(source.RequestType));
            }

            throw new ArgumentException($"No suitable factory methods defined", nameof(source.ModelActivatorConfiguration));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of <see cref="ModelPropertyVisitor"/>
 /// </summary>
 /// <param name="configuration">Filter Configuration</param>
 /// <param name="model">Value of the model property</param>
 /// <param name="routeValueDictionary">RouteValueDictionary to populate</param>
 public ModelPropertyVisitor(IListConfiguration configuration,
                             object model,
                             RouteValueDictionary routeValueDictionary) : base(routeValueDictionary)
 {
     this.configuration        = configuration;
     this.model                = model;
     this.routeValueDictionary = routeValueDictionary;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Activates <see cref="ISearch"/> type properties on the provided <paramref name="model"/>.
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="model"></param>
 protected virtual void ActivateSearchProperties(IListConfiguration configuration, object model)
 {
     foreach (var searchConfiguration in configuration.SearchConfigurations)
     {
         var value = ActivateSearchProperty(searchConfiguration);
         searchConfiguration.RequestProperty.SetValue(model, value);
     }
 }
Exemplo n.º 5
0
 public GenericSearchModelBinder(IListConfiguration configuration,
                                 IModelActivator modelActivator,
                                 IModelPropertyActivator modelPropertyActivator,
                                 IModelCache modelCache,
                                 IModelBinder fallbackModelBinder)
 {
     this.configuration          = configuration;
     this.modelActivator         = modelActivator;
     this.modelPropertyActivator = modelPropertyActivator;
     this.modelCache             = modelCache;
     this.fallbackModelBinder    = fallbackModelBinder;
 }
        private IListConfiguration GetListConfiguration(string name, IContainer container)
        {
            IListConfiguration listConfig = container.Configuration.GetListConfiguration(name);

            if (listConfig == null)
            {
                listConfig      = new ListConfiguration();
                listConfig.Name = name;
                container.Configuration.AddListConfiguration(listConfig);
            }

            return(listConfig);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Attempts to activate all relevant search, sort, pagination, and other specified
        /// properties of the <paramref name="model"/>.
        /// </summary>
        /// <param name="configuration">Relevant <see cref="IListConfiguration"/> for the <paramref name="model"/> type.</param>
        /// <param name="model">Instance of the model type.</param>
        /// <exception cref="ArgumentNullException">Provided <paramref name="configuration"/> is null.</exception>
        /// <exception cref="ArgumentNullException">Provided <paramref name="model"/> is null.</exception>
        public void Activate(IListConfiguration configuration, object model)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration), "Provided configuration is null");
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "Provided model is null.");
            }

            ActivateSearchProperties(configuration, model);
            ActivateSortDirection(configuration.SortDirectionConfiguration, model);
            ActivateSortColumn(configuration.SortColumnConfiguration, model);
            ActivatePage(configuration.PageConfiguration, model);
            ActivateRows(configuration.RowsConfiguration, model);
            ActivateProperties(configuration.PropertyConfigurations, model);
        }
        private IListConfiguration ConfigureList(XmlNode configNode, IContainer container)
        {
            string             listName   = configNode.Attributes["name"].Value;
            IListConfiguration listConfig = GetListConfiguration(listName, container);

            listConfig.Name = listName;

            foreach (XmlNode listNode in configNode)
            {
                if (listNode.Name == "item")
                {
                    ListItemConfiguration listItemConfig = new ListItemConfiguration();
                    listConfig.ListItemConfigurations.Add(listItemConfig);
                    ConfigureElement(listNode, listItemConfig, container, null);
                }
            }

            container.Configuration.AddListConfiguration(listConfig);
            return(listConfig);
        }
        private void ConfigureElement(XmlNode node, ElementConfiguration config, IContainer container, Type valueType)
        {
            config.Type = valueType;

            if (node.Attributes["value"] != null)
            {
                string propertyValueString = node.Attributes["value"].Value;

                ValueConfiguration propertyValueConfig = new ValueConfiguration();
                propertyValueConfig.Value = propertyValueString;
                config.Value = propertyValueConfig;

                if (node.Attributes["type-converter"] != null)
                {
                    string typeConverterString = node.Attributes["type-converter"].Value;
                    Type   typeConverterType   = ResolveType(typeConverterString);

                    TypeConverter typeConverter = (TypeConverter)Activator.CreateInstance(typeConverterType);
                    propertyValueConfig.TypeConverter = typeConverter;
                }

                if (node.Attributes["type"] != null)
                {
                    string typeString = node.Attributes["type"].Value;
                    Type   type       = ResolveType(typeString);

                    config.Type = type;
                }
            }

            if (node.Attributes["object"] != null)
            {
                string propertyObjectName = node.Attributes["object"].Value;
                IObjectConfiguration propertyObjectConfig = GetObjectConfiguration(propertyObjectName, container);

                config.Value = propertyObjectConfig;

                //done
                if (node.Attributes["instance-mode"] != null)
                {
                    string instanceModeString = node.Attributes["instance-mode"].Value;
                    config.InstanceMode = (InstanceMode)InstanceMode.Parse(typeof(InstanceMode), instanceModeString);
                }
            }

            if (node.Attributes["list"] != null)
            {
                string             propertyListName   = node.Attributes["list"].Value;
                IListConfiguration propertyListConfig = GetListConfiguration(propertyListName, container);

                config.Value = propertyListConfig;
                config.Type  = typeof(IList);
            }

            if (node.Attributes["factory"] != null)
            {
                string itemFactoryName = node.Attributes["factory"].Value;
                IFactoryConfiguration propertyFactoryConfig = GetFactoryConfiguration(itemFactoryName, container);

                config.Value = propertyFactoryConfig;
            }
        }
        public IContainer Configure(XmlElement xmlRoot)
        {
            IContainer container = new Container();

            XmlElement o = xmlRoot;

            if (o == null)
            {
                return(container);
            }

            ArrayList objectConfigurations  = new ArrayList();
            ArrayList listConfigurations    = new ArrayList();
            ArrayList factoryConfigurations = new ArrayList();


            foreach (XmlNode configNode in o)
            {
                if (configNode.Name == "object")
                {
                    IObjectConfiguration objectConfig = ConfigureObject(configNode, container);

                    objectConfigurations.Add(objectConfig);
                }

                if (configNode.Name == "list")
                {
                    IListConfiguration listConfig = ConfigureList(configNode, container);

                    listConfigurations.Add(listConfig);
                }

                if (configNode.Name == "factory")
                {
                    IFactoryConfiguration factoryConfig = ConfigureFactory(configNode, container);

                    factoryConfigurations.Add(factoryConfig);
                }
            }

            foreach (FactoryConfiguration factoryConfig in factoryConfigurations)
            {
                FillFactoryParameterTypes(factoryConfig);
                if (factoryConfig.Object != null)
                {
                    factoryConfig.Type = factoryConfig.Object.Type;
                }

                bool       isStatic        = factoryConfig.Object == null;
                MethodInfo bestMethodMatch = MatchMethods(factoryConfig, factoryConfig.Type, factoryConfig.MethodName, isStatic)
                ;
                if (bestMethodMatch == null)
                {
                    throw new Exception(string.Format("Can not find Method for type '{0}' that matches your parameters", factoryConfig.Type));
                }
                factoryConfig.Method = bestMethodMatch;
            }


            foreach (ObjectConfiguration objectConfig in objectConfigurations)
            {
                FillCtorParameterTypes(objectConfig);

                if (objectConfig.InstanceValue is FactoryConfiguration)
                {
                    FactoryConfiguration factory = objectConfig.InstanceValue as FactoryConfiguration;
                    objectConfig.Type = factory.Method.ReturnType;
                }
                else
                {
                    ConstructorInfo bestCtorMatch = MatchConstructors(objectConfig);
                    if (bestCtorMatch == null)
                    {
                        throw new Exception(string.Format("Can not find CTOR for type '{0}' that matches your parameters", objectConfig.Type));
                    }
                    objectConfig.Constructor = bestCtorMatch;
                }
            }

            foreach (ListConfiguration listConfig in listConfigurations)
            {
                FillItemTypes(listConfig);
            }


            //cache configuration


            return(container);
        }
 public object CreateInstance(IListConfiguration source)
 {
     throw new NotImplementedException();
 }
 public void AddListConfiguration(IListConfiguration config)
 {
     this.listConfigurations[config.Name] = config;
 }
 public static string[] ItemPropertyPathFor(this IListConfiguration configuration, string requestPropertyName)
 {
     return(configuration.SearchConfigurations.ItemPropertyPathFor(requestPropertyName));
 }
 public static PropertyInfo ResultPropertyFor(this IListConfiguration configuration, string requestPropertyName)
 {
     return(configuration.SearchConfigurations.ResultPropertyFor(requestPropertyName));
 }
 public void AddListConfiguration(IListConfiguration config)
 {
     this.listConfigurations[config.Name] = config;
 }