예제 #1
0
        private static Dictionary <string, Record> GetMap(RecordSet recordSet)
        {
            var map = new Dictionary <string, Record>();

            foreach (var record in recordSet)
            {
                string id = GetId(record);
                if (id != null)
                {
                    map.Add(id, record);
                }
            }

            return(map);
        }
예제 #2
0
        internal ApiUpdate(Api api, EntitySchema entity, RecordSet records, ApiUpdateMode mode)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            _api    = api;
            Entity  = entity;
            Mode    = mode;
            Records = records ?? new RecordSet();
        }
예제 #3
0
        public static RecordSetChanges Create(RecordSet original, RecordSet modified)
        {
            if (original == null)
            {
                throw new ArgumentNullException(nameof(original));
            }
            if (modified == null)
            {
                throw new ArgumentNullException(nameof(modified));
            }

            var originalMap = GetMap(original);
            var modifiedMap = GetMap(modified);

            var deleted         = originalMap.Keys.Where(p => !modifiedMap.ContainsKey(p)).ToList();
            var newRecords      = new List <Record>();
            var modifiedRecords = new List <Record>();

            foreach (var modifiedRecord in modified)
            {
                string id = GetId(modifiedRecord);

                Record originalRecord;
                if (id != null && originalMap.TryGetValue(id, out originalRecord))
                {
                    if (!AreEqual(originalRecord, modifiedRecord))
                    {
                        modifiedRecords.Add(modifiedRecord);
                    }
                }
                else
                {
                    newRecords.Add(modifiedRecord);
                }
            }

            return(new RecordSetChanges(new RecordSet(newRecords), new RecordSet(modifiedRecords), deleted));
        }
예제 #4
0
파일: Api.cs 프로젝트: windygu/weapi-net
 public ApiUpdate CreateUpdate(EntitySchema entity, RecordSet records)
 {
     return(new ApiUpdate(this, entity, records, ApiUpdateMode.Update));
 }
예제 #5
0
 private RecordSetChanges(RecordSet @new, RecordSet modified, IList <string> deleted)
 {
     New      = @new;
     Modified = modified;
     Deleted  = deleted;
 }