Ejemplo n.º 1
0
        /// <summary>
        /// Fill the primary key of the file
        /// </summary>
        /// <param name="record">Record to fill</param>
        /// <param name="fields">Fiels from where take the values</param>
        private IList <ValidationResult> FillPrimaryKey(IVisionRecord record, IDictionary <string, object> fields)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var result = new List <ValidationResult>();
            var key    = FileDefinition.Keys.First(x => x.IsUnique);

            foreach (var field in key.Fields)
            {
                var name = field.GetDotnetName();
                if (fields.ContainsKey(name))
                {
                    var fieldValue = fields[name];
                    record.SetValue(field.Name, fieldValue);
                }
                else
                {
                    result.Add(new ValidationResult("Key field missing", new string[] { field.Name }));
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Fill a vision record from a given dictionary
 /// </summary>
 /// <param name="record">Record to fill</param>
 /// <param name="fields">Dictionary with propery value</param>
 private void FillRecord(IVisionRecord record, IDictionary <string, object> fields)
 {
     // Load properties
     foreach (var propertyName in fields.Keys)
     {
         var propertyValue = fields[propertyName];
         // look for the property with that name
         var field = FileDefinition.Fields
                     .SingleOrDefault(x => x.GetDotnetName().Equals(propertyName, StringComparison.InvariantCultureIgnoreCase));
         if (field != null)
         {
             record.SetValue(field.Name, propertyValue);
         }
     }
 }