Exemplo n.º 1
0
 internal void RestoreFromDTOPostProcess(XrmDb clonedDB)
 {
     foreach (var row in this.MainDict.Values)
     {
         row.RestoreFromDTOPostProcess(clonedDB);
     }
 }
Exemplo n.º 2
0
        internal static object ConvertToDbValue(object value, XrmDb db)
        {
            if (value is OptionSetValue osv)
            {
                return(osv.Value);
            }
            if (value is Money money)
            {
                return(money.Value);
            }
            if (value is EntityReference reference && db.IsValidEntity(reference.LogicalName))
            {
                return(db.GetDbRow(reference, false));
            }
            if (value is IEnumerable <Entity> entities)
            {
                return(entities
                       .Where(e => db.IsValidEntity(e.LogicalName))
                       .Select(e => db.GetDbRow(e))
                       .ToArray());
            }
#if XRM_MOCKUP_365
            if (value is OptionSetValueCollection optionsets)
            {
                return(new OptionSetValueCollection(optionsets));
            }
#endif
            return(value);
        }
Exemplo n.º 3
0
        public IXrmDb Clone()
        {
            var clonedTables = this.TableDict.ToDictionary(x => x.Key, x => x.Value.Clone());
            var clonedDB     = new XrmDb(this.EntityMetadata, this.OnlineProxy)
            {
                TableDict = clonedTables
            };

            return(clonedDB);
        }
Exemplo n.º 4
0
        internal static DbRow FromEntity(Entity xrmEntity, XrmDb db, bool withReferenceChecks = true)
        {
            IEnumerable <KeyValuePair <string, object> > columns = xrmEntity.Attributes;

            if (withReferenceChecks == true)   // Convert EntityReferences to actual references if db is given
            {
                columns = columns.Select(a => ConvertToDbKeyValue(a, db));
            }

            return(new DbRow(db[xrmEntity.LogicalName], xrmEntity.Id, columns));
        }
Exemplo n.º 5
0
        internal void RestoreFromDTOPostProcess(XrmDb clonedDB)
        {
            //Since there is no guarantee that data is recreated in a usefull order, we have to set the db row in a postprocess step.
            var keyesToIterate = new List <string>(this.Columns.Keys);

            foreach (var columnKey in keyesToIterate)
            {
                if (this.Columns[columnKey] is DbRow)
                {
                    var tmpRef = (DbRow)this.Columns[columnKey];
                    var dbRow  = clonedDB[tmpRef.Metadata.LogicalName][tmpRef.Id];
                    this.Columns[columnKey] = dbRow;
                }
            }
        }
Exemplo n.º 6
0
        public static XrmDb RestoreSerializableDTO(XrmDb current, DbDTO model)
        {
            var clonedTables = model.Tables.ToDictionary(x => x.Key, x => DbTable.RestoreSerializableDTO(new DbTable(current.EntityMetadata[x.Key]), x.Value));
            var clonedDB     = new XrmDb(current.EntityMetadata, current.OnlineProxy)
            {
                TableDict = clonedTables
            };

            foreach (var table in clonedTables)
            {
                table.Value.RestoreFromDTOPostProcess(clonedDB);
            }

            return(clonedDB);
        }
Exemplo n.º 7
0
 internal static object ConvertToDbValue(object value, XrmDb db)
 {
     if (value is OptionSetValue osv)
     {
         return(osv.Value);
     }
     if (value is Money money)
     {
         return(money.Value);
     }
     if (value is EntityReference reference)
     {
         return(db.GetDbRow(reference));
     }
     return(value);
 }
Exemplo n.º 8
0
 internal static KeyValuePair <string, object> ConvertToDbKeyValue(KeyValuePair <string, object> xrmAttribute, XrmDb db)
 {
     return(new KeyValuePair <string, object>(xrmAttribute.Key, ConvertToDbValue(xrmAttribute.Value, db)));
 }
Exemplo n.º 9
0
 internal static DbRow MakeDBRowRef(EntityReference reference, XrmDb db)
 {
     return(new DbRow(db[reference.LogicalName], reference.Id, new List <KeyValuePair <string, object> >()));
 }