Beispiel #1
0
        /// <summary>
        /// Merges schemas from two binary types.
        /// </summary>
        private static BinaryObjectSchema MergeSchemas(BinaryType a, BinaryType b)
        {
            if (a == null || a.Schema == null)
            {
                return(b.Schema);
            }

            if (b == null || b.Schema == null)
            {
                return(a.Schema);
            }

            var res = new BinaryObjectSchema();

            foreach (var schema in a.Schema.GetAll())
            {
                res.Add(schema.Key, schema.Value);
            }

            foreach (var schema in b.Schema.GetAll())
            {
                res.Add(schema.Key, schema.Value);
            }

            return(res);
        }
Beispiel #2
0
        /// <summary>
        /// Merge newly sent field metadatas into existing ones.
        /// </summary>
        /// <param name="meta">Binary type to merge.</param>
        public void Merge(BinaryType meta)
        {
            Debug.Assert(meta != null);

            _saved = true;

            var fieldsMap = meta.GetFieldsMap();

            if (fieldsMap.Count == 0)
            {
                return;
            }

            lock (this)
            {
                // 1. Create copies of the old meta.
                var        ids0  = _ids;
                BinaryType meta0 = _meta;

                var newIds = ids0 != null ? new HashSet <int>(ids0) : new HashSet <int>();

                IDictionary <string, BinaryField> newFields = meta0 != null
                    ? new Dictionary <string, BinaryField>(meta0.GetFieldsMap())
                    : new Dictionary <string, BinaryField>(fieldsMap.Count);

                // 2. Add new fields.
                foreach (var fieldMeta in fieldsMap)
                {
                    int fieldId = BinaryUtils.FieldId(meta.TypeId, fieldMeta.Key, null, null);

                    if (!newIds.Contains(fieldId))
                    {
                        newIds.Add(fieldId);
                    }

                    if (!newFields.ContainsKey(fieldMeta.Key))
                    {
                        newFields[fieldMeta.Key] = fieldMeta.Value;
                    }
                }

                // 3. Assign new meta. Order is important here: meta must be assigned before field IDs.
                _meta = new BinaryType(_typeId, _typeName, newFields, _affKeyFieldName, _isEnum,
                                       meta.EnumValuesMap, _marshaller);
                _ids = newIds;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Merge newly sent field metadatas into existing ones.
        /// </summary>
        /// <param name="newMap">New field metadatas map.</param>
        public void Merge(IDictionary <int, Tuple <string, BinaryField> > newMap)
        {
            _saved = true;

            if (newMap == null || newMap.Count == 0)
            {
                return;
            }

            lock (this)
            {
                // 1. Create copies of the old meta.
                var        ids0  = _ids;
                BinaryType meta0 = _meta;

                var newIds = ids0 != null ? new HashSet <int>(ids0) : new HashSet <int>();

                IDictionary <string, BinaryField> newFields = meta0 != null
                    ? new Dictionary <string, BinaryField>(meta0.GetFieldsMap())
                    : new Dictionary <string, BinaryField>(newMap.Count);

                // 2. Add new fields.
                foreach (var newEntry in newMap)
                {
                    if (!newIds.Contains(newEntry.Key))
                    {
                        newIds.Add(newEntry.Key);
                    }

                    if (!newFields.ContainsKey(newEntry.Value.Item1))
                    {
                        newFields[newEntry.Value.Item1] = newEntry.Value.Item2;
                    }
                }

                // 3. Assign new meta. Order is important here: meta must be assigned before field IDs.
                _meta = new BinaryType(_typeId, _typeName, newFields, _affKeyFieldName, _isEnum);
                _ids  = newIds;
            }
        }
        /// <summary>
        /// Merge newly sent field metadatas into existing ones.
        /// </summary>
        /// <param name="newMap">New field metadatas map.</param>
        public void Merge(IDictionary<int, Tuple<string, int>> newMap)
        {
            _saved = true;

            if (newMap == null || newMap.Count == 0)
                return;

            lock (this)
            {
                // 1. Create copies of the old meta.
                var ids0 = _ids;
                BinaryType meta0 = _meta;

                var newIds = ids0 != null ? new HashSet<int>(ids0) : new HashSet<int>();

                IDictionary<string, int> newFields = meta0 != null ?
                    new Dictionary<string, int>(meta0.GetFieldsMap()) : new Dictionary<string, int>(newMap.Count);

                // 2. Add new fields.
                foreach (KeyValuePair<int, Tuple<string, int>> newEntry in newMap)
                {
                    if (!newIds.Contains(newEntry.Key))
                        newIds.Add(newEntry.Key);

                    if (!newFields.ContainsKey(newEntry.Value.Item1))
                        newFields[newEntry.Value.Item1] = newEntry.Value.Item2;
                }

                // 3. Assign new meta. Order is important here: meta must be assigned before field IDs.
                _meta = new BinaryType(_typeId, _typeName, newFields, _affKeyFieldName, _isEnum);
                _ids = newIds;
            }
        }