Exemplo n.º 1
0
        /// <summary>
        /// Loads the carrier dictionary from the specified assembly.
        /// </summary>
        /// <param name="assembly">The assembly to consider.</param>
        /// <param name="extensionDefinition">The extension definition to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns></returns>
        private int LoadCarrierDictionaryFromAssembly(
            Assembly assembly,
            IBdoExtensionDefinition extensionDefinition,
            IBdoLog log = null)
        {
            if (assembly == null)
            {
                return(-1);
            }

            // we load the carrier dictionary from the assembly

            IBdoCarrierDictionaryDto dictionaryDto = (IBdoCarrierDictionaryDto)ExtractDictionaryFromAssembly <BdoCarrierDefinitionDto>(assembly, log);

            // we feach carrier classes

            var types = assembly.GetTypes().Where(p => typeof(IBdoCarrier).IsAssignableFrom(p) && !p.IsAbstract);
            int count = 0;

            foreach (Type type in types)
            {
                IBdoCarrierDefinitionDto definitionDto = new BdoCarrierDefinitionDto();

                // we update definition from carrier attribute

                if (type.GetCustomAttribute(typeof(BdoCarrierAttribute)) is BdoCarrierAttribute carrierAttribute)
                {
                    UpdateDictionary(definitionDto, carrierAttribute);
                }
                definitionDto.ItemClass = type.FullName;
                definitionDto.LibraryId = extensionDefinition?.Dto?.Id;

                // we create the detail specification from detail property attributes

                foreach (PropertyInfo property in type.GetProperties().Where(p => p.GetCustomAttributes(typeof(DetailPropertyAttribute)).Any()))
                {
                    definitionDto.DetailSpec.Add(ElementSpecFactory.Create(property.Name, property.PropertyType));
                }

                // we build the runtime definition

                IBdoCarrierDefinition itemDefinition = new BdoCarrierDefinition(extensionDefinition, definitionDto)
                {
                    RuntimeType = type
                };

                if (dictionaryDto != null)
                {
                    // retrieve the definition index

                    // update definition with index
                }

                _store.Add <IBdoCarrierDefinition>(itemDefinition);

                count++;
            }

            return(count);
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 internal IDbQuery QuerySelectCountryWithCode(string code)
 {
     return(this.UseQuery("GetCountryWithCode", p =>
                          DbFluent.SelectQuery(Table("Country"))
                          .From(
                              DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                                   JoinCondition("Country_RegionalDirectorate")))
                          .WithFields(Tuple("SelectCountry"))
                          .AddIdField(DbFluent.FieldAsParameter(nameof(DbCountry.Code), "code"))
                          .UsingParameters(ElementSpecFactory.Create("code", DataValueTypes.Text))
                          )
            .WithParameters(
                ElementFactory.CreateScalar("code", code)));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the task dictionary from the specified assembly.
        /// </summary>
        /// <param name="assembly">The assembly to consider.</param>
        /// <param name="extensionDefinition">The extension definition to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns></returns>
        private int LoadTaskDictionaryFromAssembly(
            Assembly assembly,
            IBdoExtensionDefinition extensionDefinition,
            IBdoLog log = null)
        {
            if (assembly == null)
            {
                return(-1);
            }

            // we load the carrier dictionary from the assembly

            IBdoTaskDictionaryDto dictionaryDto = (IBdoTaskDictionaryDto)ExtractDictionaryFromAssembly <BdoTaskDefinitionDto>(assembly, log);

            // we feach task classes

            int count = 0;

            var types = assembly.GetTypes().Where(p => typeof(IBdoTask).IsAssignableFrom(p));

            foreach (Type type in types)
            {
                IBdoTaskDefinitionDto definitionDto = new BdoTaskDefinitionDto();

                if (type.GetCustomAttributes(typeof(BdoTaskAttribute)).FirstOrDefault() is BdoTaskAttribute taskAttribute)
                {
                    UpdateDictionary(definitionDto, taskAttribute);
                }
                definitionDto.ItemClass = type.FullName;
                definitionDto.LibraryId = extensionDefinition?.Dto?.Id;

                foreach (PropertyInfo property in type.GetProperties().Where(p => p.GetCustomAttributes(typeof(TaskInputAttribute)).Any()))
                {
                    definitionDto.InputSpecification.Add(ElementSpecFactory.Create(property.Name, property.PropertyType));
                }

                foreach (PropertyInfo property in type.GetProperties().Where(p => p.GetCustomAttributes(typeof(TaskOutputAttribute)).Any()))
                {
                    definitionDto.OutputSpecification.Add(ElementSpecFactory.Create(property.Name, property.PropertyType));
                }

                // we build the runtime definition

                IBdoTaskDefinition itemDefinition = new BdoTaskDefinition(extensionDefinition, definitionDto)
                {
                    RuntimeType = type
                };

                if (dictionaryDto != null)
                {
                    // retrieve the definition index

                    // update definition with index
                }

                _store.Add <IBdoTaskDefinition>(itemDefinition);

                count++;
            }

            return(count);
        }