예제 #1
0
파일: Component.cs 프로젝트: S17L/iGP11
        public Component(
            TObject @object,
            Localizable name,
            IPropertyConfiguration configuration,
            IValidationContext validationContext,
            IEnumerable <IValidator <TObject> > validators,
            IEnumerable <IProperty> properties)
        {
            Object        = @object;
            Name          = name;
            Configuration = configuration;

            _validationContext = validationContext;
            _validators        = validators;
            _properties        = properties?.ToArray() ?? new IProperty[0];
            _properties        = _properties.Where(property => property.Configuration.GroupedBy == null)
                                 .OrderBy(property => property.Configuration.Order)
                                 .ThenBy(property => property.Name)
                                 .Union(_properties.Where(property => property.Configuration.GroupedBy != null)
                                        .OrderBy(property => property.Configuration.GroupedBy.Key)
                                        .GroupBy(property => property.Configuration.GroupedBy.Key)
                                        .SelectMany(group => group.OrderBy(property => property.Configuration.Order)
                                                    .ThenBy(property => property.Name)))
                                 .ToArray();

            _allProperties = GetProperties();
        }
예제 #2
0
 /// <summary>
 /// has column output formatter
 /// </summary>
 /// <typeparam name="TEntity">entity type</typeparam>
 /// <typeparam name="TProperty">property type</typeparam>
 /// <param name="configuration">property configuration</param>
 /// <param name="formatter">column output formatter</param>
 /// <returns>property configuration</returns>
 public static IPropertyConfiguration <TEntity, TProperty> HasColumnOutputFormatter <TEntity, TProperty>(
     this IPropertyConfiguration <TEntity, TProperty> configuration, Func <TProperty, object> formatter)
 {
     if (formatter == null)
     {
         return(configuration.HasOutputFormatter(null));
     }
     return(configuration.HasOutputFormatter((entity, prop) => formatter.Invoke(prop)));
 }
 public ModelPropertyConfiguration(SerializationInfo info, StreamingContext context)
 {
     this.Key = (string)info.GetValue(ControlLibConstants.KEY, typeof(string));
     this.Name = (string)info.GetValue(ControlLibConstants.NAME, typeof(string));
     this.ExternalizationKey = (string)info.GetValue(ControlLibConstants.EXTERNALIZATION_KEY, typeof(string));
     this.PropertyConfiguration = (PropertyConfiguration)info.GetValue(ControlLibConstants.PROPERTY_CONFIGURATION, typeof(PropertyConfiguration));
     this.IsComplexType = (bool)info.GetValue(ControlLibConstants.ISCOMPLEXTYPE, typeof(bool));
     this.IsEnumerable = (bool)info.GetValue(ControlLibConstants.ISENUMERABLE, typeof(bool));
     this.ComplexTypeName = (string)info.GetValue(ControlLibConstants.COMPLEX_TYPENAME, typeof(string));
 }
예제 #4
0
 public ModelPropertyConfiguration(SerializationInfo info, StreamingContext context)
 {
     this.Key  = (string)info.GetValue(ControlLibConstants.KEY, typeof(string));
     this.Name = (string)info.GetValue(ControlLibConstants.NAME, typeof(string));
     this.ExternalizationKey    = (string)info.GetValue(ControlLibConstants.EXTERNALIZATION_KEY, typeof(string));
     this.PropertyConfiguration = (PropertyConfiguration)info.GetValue(ControlLibConstants.PROPERTY_CONFIGURATION, typeof(PropertyConfiguration));
     this.IsComplexType         = (bool)info.GetValue(ControlLibConstants.ISCOMPLEXTYPE, typeof(bool));
     this.IsEnumerable          = (bool)info.GetValue(ControlLibConstants.ISENUMERABLE, typeof(bool));
     this.ComplexTypeName       = (string)info.GetValue(ControlLibConstants.COMPLEX_TYPENAME, typeof(string));
 }
예제 #5
0
 public ModelPropertyConfiguration(string key, string propertyName, string externalizationKey, IPropertyConfiguration propertyConfiguration, bool isComplexType, bool isEnumerable, string complexTypeName)
 {
     this.Key  = key;
     this.Name = propertyName;
     this.ExternalizationKey    = externalizationKey;
     this.PropertyConfiguration = propertyConfiguration;
     this.IsComplexType         = isComplexType;
     this.IsEnumerable          = isEnumerable;
     this.ComplexTypeName       = complexTypeName;
 }
 public ModelPropertyConfiguration(string key, string propertyName, string externalizationKey, IPropertyConfiguration propertyConfiguration, bool isComplexType, bool isEnumerable, string complexTypeName)
 {
     this.Key = key;
     this.Name = propertyName;
     this.ExternalizationKey = externalizationKey;
     this.PropertyConfiguration = propertyConfiguration;
     this.IsComplexType = isComplexType;
     this.IsEnumerable = isEnumerable;
     this.ComplexTypeName = complexTypeName;
 }
예제 #7
0
 public StringProperty(
     Expression expression,
     Localizable name,
     string initial,
     IPropertyConfiguration configuration,
     ITokenReplacer tokenReplacer,
     IValidationContext validationContext,
     Func <string> getter,
     Action <string> setter,
     IEnumerable <IValidator <string> > validators)
     : base(expression, name, initial, configuration, validationContext, getter, setter, validators)
 {
     _tokenReplacer = tokenReplacer;
 }
 /// <summary>
 /// Singleton ESI4TIndexManager static constructor
 /// </summary>
 static GenericStorageExtensionIndexManager()
 {
     try
     {
         string ElasticIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig");
         propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(ElasticIndexConfigPath)
                             as IPropertyConfiguration;
         GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + ElasticIndexConfigPath);
     }
     catch (Exception ex)
     {
         GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw ex;
     }
     GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting ESI4TIndexManager.ESI4TIndexManager()");
 }
예제 #9
0
 /// <summary>
 /// Singleton MI4TIndexManager static constructor
 /// </summary>
 static MI4TIndexManager()
 {
     try
     {
         string MongoDBIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig");
         propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath)
                             as IPropertyConfiguration;
         containerLock = new object();
         GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + MongoDBIndexConfigPath);
     }
     catch (Exception ex)
     {
         GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw ex;
     }
     GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting MI4TIndexManager.MI4TIndexManager()");
 }
 /// <summary>
 /// Singleton ESI4TIndexManager static constructor
 /// </summary>
 static ESI4TIndexManager()
 {
     try
     {
         string ElasticIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig");
         propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(ElasticIndexConfigPath)
                             as IPropertyConfiguration;
         containerLock = new object();
         ESI4TLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + ElasticIndexConfigPath);
     }
     catch (Exception ex)
     {
         ESI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw ex;
     }
     ESI4TLogger.WriteLog(ELogLevel.DEBUG, "Exiting ESI4TIndexManager.ESI4TIndexManager()");
 }
예제 #11
0
        private static PropertyConfiguration Combine(IPropertyConfiguration first, PropertyConfiguration second)
        {
            if (first.IsEditable)
            {
                second.IsEditable = first.IsEditable;
            }

            if (first.GroupedBy != null)
            {
                second.GroupedBy = first.GroupedBy;
            }

            if (first.HasDisabledValidation)
            {
                second.HasDisabledValidation = true;
            }

            if (first.IsDirectoryPath)
            {
                second.IsDirectoryPath = true;
            }

            if (first.IsTokenizable)
            {
                second.IsTokenizable = true;
            }

            if (first.Order.HasValue)
            {
                second.Order = first.Order;
            }

            if (first.ShortDescription != null)
            {
                second.ShortDescription = first.ShortDescription;
            }

            if (first.LongDescription != null)
            {
                second.LongDescription = first.LongDescription;
            }

            return(second);
        }
예제 #12
0
        public Property(
            Expression expression,
            Localizable name,
            TValue initial,
            IPropertyConfiguration configuration,
            IValidationContext validationContext,
            Func <TValue> getter,
            Action <TValue> setter,
            IEnumerable <IValidator <TValue> > validators)
        {
            Name          = name;
            Configuration = configuration;

            _expression        = expression;
            _initial           = initial;
            _validationContext = validationContext;
            _getter            = getter;
            _setter            = setter;
            _validators        = validators;
        }
예제 #13
0
        public void PreProcessProperties(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IProperties props, String beanName, Object service, Type beanType,
                                         IList <IPropertyConfiguration> propertyConfigs, ISet <String> ignoredPropertyNames, IPropertyInfo[] properties)
        {
            if (properties == null)
            {
                properties = PropertyInfoProvider.GetProperties(service.GetType());
            }
            foreach (IPropertyInfo prop in properties)
            {
                if (!prop.IsWritable)
                {
                    continue;
                }
                PropertyAttribute propertyAttribute = prop.GetAnnotation <PropertyAttribute>();
                if (propertyAttribute == null)
                {
                    continue;
                }
                if (ignoredPropertyNames.Contains(prop.Name))
                {
                    // do not handle this property
                    continue;
                }
                if (PropertyAttribute.DEFAULT_VALUE.Equals(propertyAttribute.Name) && PropertyAttribute.DEFAULT_VALUE.Equals(propertyAttribute.DefaultValue))
                {
                    if (propertyAttribute.Mandatory)
                    {
                        String propName            = prop.Name;
                        bool   propertyInitialized = false;
                        // check if the mandatory property field has been initialized with a value
                        for (int a = propertyConfigs.Count; a-- > 0;)
                        {
                            IPropertyConfiguration propertyConfig = propertyConfigs[a];
                            if (propName.Equals(propertyConfig.GetPropertyName()))
                            {
                                propertyInitialized = true;
                                break;
                            }
                        }
                        if (!propertyInitialized)
                        {
                            throw new Exception("Mandatory property '" + propName + "' not initialized");
                        }
                    }
                    continue;
                }
                Object value = props != null?props.GetString(propertyAttribute.Name) : null;

                if (value == null)
                {
                    String stringValue = propertyAttribute.DefaultValue;
                    if (PropertyAttribute.DEFAULT_VALUE.Equals(stringValue))
                    {
                        if (propertyAttribute.Mandatory)
                        {
                            throw new BeanContextInitException("Could not resolve mandatory environment property '" + propertyAttribute.Name + "'");
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        value = props.ResolvePropertyParts(stringValue);
                    }
                }
                value = ConversionHelper.ConvertValueToType(prop.PropertyType, value);
                prop.SetValue(service, value);
            }
        }
예제 #14
0
        private Component <TObject> CreateComponent <TObject>(TObject @object, Localizable name, IPropertyConfiguration configuration, AssemblingContext assemblingContext)
        {
            var nameAttribute = GetAttribute <ComponentNameAttribute>(@object.GetType());

            if (nameAttribute != null)
            {
                name = nameAttribute.Value;
            }

            return(new Component <TObject>(
                       @object,
                       name,
                       configuration,
                       _validationContext,
                       GetAttributes <IValidator <TObject> >(@object.GetType()),
                       GetProperties(@object, assemblingContext).ToArray()));
        }
예제 #15
0
 public override bool IsApplicable(IPropertyConfiguration configuration)
 {
     return(configuration.IsDirectoryPath);
 }
예제 #16
0
        public Stream GetContentFromMongoDB(MI4TServiceRequest <SearchRequest> request)
        {
            string resultJSON = string.Empty;

            MI4TLogger.WriteLog(ELogLevel.INFO, "Entering into GetContentFromMongoDB");
            try
            {
                if (request != null && request.ServicePayload != null)
                {
                    string MongoDBIndexConfigPath = Utility.GetConfigurationValue("IndexServiceConfig");
                    propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath)
                                        as IPropertyConfiguration;
                    containerLock = new object();
                    string result           = string.Empty;
                    var    connectionString = propConfiguration.GetString(MI4TServicesConstants.mongoDB_URL);
                    var    client           = new MongoClient(connectionString);
                    var    server           = client.GetServer();
                    var    database         = server.GetDatabase(propConfiguration.GetString(MI4TServicesConstants.dbName));
                    var    collection       = database.GetCollection <MongoDBModelSearch>(propConfiguration.GetString(MI4TServicesConstants.tableName));

                    var andList = new List <IMongoQuery>();
                    foreach (DictionaryEntry entry in request.ServicePayload.Filters)
                    {
                        MI4TLogger.WriteLog(ELogLevel.INFO, "Reading request.ServicePayload.Filters");
                        switch (request.ServicePayload.QueryType.ToUpper())
                        {
                        case "AND":
                            andList.Add(Query.EQ(entry.Key.ToString(), entry.Value.ToString()));
                            break;

                        case "OR":
                            andList.Add(Query.Or(Query.EQ(entry.Key.ToString(), entry.Value.ToString())));
                            break;

                        default:
                            andList.Add(Query.Not(Query.EQ(entry.Key.ToString(), entry.Value.ToString())));
                            break;
                        }
                    }
                    var query = Query.And(andList);
                    MI4TLogger.WriteLog(ELogLevel.INFO, "Query generated");
                    //Map/Reduce
                    var map =
                        "function() {" +
                        "    for (var key in this) {" +
                        "        emit(key, { count : 1 });" +
                        "    }" +
                        "}";

                    var reduce =
                        "function(key, emits) {" +
                        "    total = 0;" +
                        "    for (var i in emits) {" +
                        "        total += emits[i].count;" +
                        "    }" +
                        "    return { count : total };" +
                        "}";

                    var mr = collection.MapReduce(map, reduce);
                    foreach (var document in mr.GetResults())
                    {
                        document.ToJson();
                    }

                    MI4TLogger.WriteLog(ELogLevel.INFO, "Calling collection.FindOne(query)");
                    //  var entity = collection.Find(query).ToListAsync();
                    var result1 = collection.FindAs <MongoDBModelSearch>(query);
                    resultJSON = result1.ToJson();

                    MI4TLogger.WriteLog(ELogLevel.INFO, "OUTPUT: " + resultJSON);
                }
            }
            catch (Exception ex)
            {
                MI4TLogger.WriteLog(ELogLevel.ERROR, "ERROR: " + ex.Message + ex.StackTrace);
            }
            return(new MemoryStream(Encoding.UTF8.GetBytes(resultJSON)));
        }
예제 #17
0
 public virtual bool IsApplicable(IPropertyConfiguration configuration)
 {
     return(true);
 }