示例#1
0
 public DataIntegration(ICollection <FieldDefinition> fields, ICollection <ModelIntegration> models,
                        ICollection <IntegrationExtra> extras,
                        ICollection <AggregateKey> aggregatekeys)
 {
     Fields         = fields ?? new HashSet <FieldDefinition>(new FieldDefinitionComparer());
     Models         = models ?? new HashSet <ModelIntegration>();
     Extras         = extras ?? new HashSet <IntegrationExtra>();
     AggregateKeys  = aggregatekeys ?? new HashSet <AggregateKey>();
     this.PublicKey = ApiAuth.Generate();
 }
示例#2
0
文件: InputSource.cs 项目: sp0x/donut
        /// <summary>
        /// Create a new integration from an object instance
        /// </summary>
        /// <param name="firstInstance"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected Data.DataIntegration CreateIntegrationFromObj(dynamic firstInstance, string name)
        {
            Data.DataIntegration typeDef = null;
            if (firstInstance != null)
            {
                typeDef                = new Data.DataIntegration();
                typeDef.PublicKey      = ApiAuth.Generate();
                typeDef.DataEncoding   = Encoding.CodePage;
                typeDef.DataFormatType = Formatter.Name;
                typeDef.SetFieldsFromType(firstInstance);
            }
            //Apply field options
            foreach (var fieldOpPair in FieldOptions)
            {
                FieldDefinition targetField = typeDef.Fields.FirstOrDefault(x => x.Name == fieldOpPair.Key);
                var             fieldOp     = fieldOpPair.Value;
                if (targetField == null)
                {
                    if (fieldOp.ValueEvaluater != null)
                    {
                        var targetType = fieldOp.ValueEvaluater.ReturnType;
                        var virtField  = targetField = new FieldDefinition(fieldOpPair.Key, targetType);
                        virtField.Extras = new FieldExtras()
                        {
                            IsFake = true
                        };
                        typeDef.Fields.Add(virtField);
                    }
                    else
                    {
                        continue; //Maybe throw?
                    }
                }
                if (fieldOp.IgnoreField)
                {
                    typeDef.Fields.Remove(targetField);
                    continue;
                }
                var ops        = fieldOp;
                var stringName = typeof(String).Name;
                if (ops.IsString)
                {
                    targetField.Type = stringName;
                }
                if (ops.Encoding != null)
                {
                    FieldEncoding.SetEncoding(typeDef, targetField, ops.Encoding);
                }
                if (targetField.Type == stringName && targetField.Extras == null)
                {
                    targetField.DataEncoding = FieldDataEncoding.BinaryIntId;
                    targetField.Extras       = new FieldExtras();
                    //targetField.Extras.Field = targetField;
                }

                if (ops.Duplicates.Count > 0)
                {
                    foreach (var duplicate in ops.Duplicates)
                    {
                        var dupField = new FieldDefinition(duplicate, targetField.Type);
                        typeDef.Fields.Add(dupField);
                    }
                }
            }
            return(typeDef);
        }