public void Write(ExtendedBinaryWriter writer, IFieldSerializer keySerializer,
                              IFieldSerializer valueSerializer)
            {
                writer.Write((byte)_action);

                switch (_action)
                {
                case NotifyCollectionChangedAction.Add:
                    keySerializer.Serialize(_items[0].Key, writer);
                    valueSerializer.Serialize(_items[0].Value, writer);
                    break;

                case NotifyCollectionChangedAction.Replace:
                    keySerializer.Serialize(_items[0].Key, writer);
                    valueSerializer.Serialize(_items[0].Value, writer);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    keySerializer.Serialize(_items[0].Key, writer);
                    break;

                case NotifyCollectionChangedAction.Reset:
                {
                    writer.Write7BitEncodedInt(_items.Count);
                    foreach (KeyValuePair <TKey, TValue> item in _items)
                    {
                        keySerializer.Serialize(item.Key, writer);
                        valueSerializer.Serialize(item.Value, writer);
                    }

                    break;
                }
                }
            }
Beispiel #2
0
        private void InitializeStorage()
        {
            lock (_syncRoot)
            {
                if (!_isStorageInitialized)
                {
                    _columnStorage = new ColumnStorage(_metadata, DirectoryPath,
                                                       _access, PartitionID, _memeorymMappedFileFactory);

                    _columns = _metadata.GetPartitionColumns(PartitionID, _columnStorage, _config).ToArray();

                    if (_metadata.TimestampColumnID.HasValue)
                    {
                        _timestampColumn =
                            (IFixedWidthColumn)_columns[_metadata.TimestampColumnID.Value].Column;
                    }

                    _fieldSerializer = _metadata.GetSerializer(_columns);
                    _txSupport       = new FileTxSupport(PartitionID, _columnStorage, _metadata, StartDate, EndDate);

                    Thread.MemoryBarrier();
                    _isStorageInitialized = true;
                }
            }
        }
Beispiel #3
0
        public static IFieldSerializer ReadFieldSerializer(string name, IFieldSerializer serializer, XmlElement parentElement)
        {
            XmlElement node = (XmlElement)parentElement.GetElementsByTagName(name)[0];

            serializer.ReadFields(node);
            return(serializer);
        }
Beispiel #4
0
 public SyncSourceProperty(int index, Type propertyType, Func <object> getter, IFieldSerializer fieldSerializer) :
     base(index)
 {
     PropertyType     = propertyType;
     _getter          = getter;
     _fieldSerializer = fieldSerializer;
 }
Beispiel #5
0
        protected virtual void SerializeField(Field field, JsonTextWriter writer)
        {
            IFieldSerializer fieldSerializer = this.GetFieldSerializer(field);

            fieldSerializer.EnableRenderedValues = Context.PageMode.IsExperienceEditorEditing;
            fieldSerializer.Serialize(field, writer);
        }
 public SourceRemoveCommand(ExtendedBinaryReader reader, IFieldSerializer keyDeserializer)
 {
     keyDeserializer.Deserialize(reader, fixup =>
     {
         _key         = (TKey)fixup;
         _keyResolved = true;
     });
 }
 public InterpolationState(SyncTargetProperty syncTargetProperty, SyncTargetRoot syncTargetRoot,
                           IFieldSerializer fieldSerializer)
 {
     _synchronizedValue  = syncTargetProperty.Property;
     _syncTargetProperty = syncTargetProperty;
     _syncTargetRoot     = syncTargetRoot;
     _fieldSerializer    = fieldSerializer;
 }
 public ObservableDictionarySyncSource(SyncSourceRoot syncSourceRoot, int referenceId,
                                       ObservableDictionary <TKey, TValue> baseObject,
                                       IFieldSerializerResolver fieldSerializerResolver) : base(syncSourceRoot, referenceId, baseObject)
 {
     _keySerializer                = fieldSerializerResolver.FindMatchingSerializer(typeof(TKey));
     _valueSerializer              = fieldSerializerResolver.FindMatchingSerializer(typeof(TValue));
     BaseObject.CollectionChanged += OnCollectionChanged;
     AddNewItemReferences(BaseObject.ToList());
 }
Beispiel #9
0
 public SyncTargetProperty(int index, Action <object> setter, Func <object> getter,
                           SyncTargetRoot syncTargetRoot,
                           IFieldSerializer fieldSerializer) : base(index)
 {
     _setter          = setter;
     _getter          = getter;
     _syncTargetRoot  = syncTargetRoot;
     _fieldSerializer = fieldSerializer;
     _state           = IgnoreState.Instance;
 }
Beispiel #10
0
        protected virtual IFieldSerializer GetFieldSerializer(Field field)
        {
            IFieldSerializer result = GetFieldSerializerPipeline.GetResult(new GetFieldSerializerPipelineArgs()
            {
                Field          = field,
                ItemSerializer = this
            });

            Assert.IsNotNull(result, "fieldSerializer != null");
            return(result);
        }
Beispiel #11
0
        public static void Write(IFieldSerializer fieldSerializer, string name, XmlElement parent)
        {
            XmlDocument document = parent.OwnerDocument;

            if (document == null)
            {
                return;
            }
            XmlElement element = document.CreateElement(name);

            fieldSerializer.AppendFields(element);
            parent.AppendChild(element);
        }
        public ObservableDictionarySyncTarget(int referenceId, Type baseType, ExtendedBinaryReader reader,
                                              SyncTargetRoot syncTargetRoot, IFieldSerializerResolver fieldDeserializerResolver) : base(referenceId)
        {
            _syncTargetRoot = syncTargetRoot;
            _clock          = _syncTargetRoot.Clock;

            base.BaseObject = Activator.CreateInstance(baseType);
            BaseObject.CollectionChanged += OnCollectionChanged;

            _keySerializer   = fieldDeserializerResolver.FindMatchingSerializer(typeof(TKey));
            _valueSerializer = fieldDeserializerResolver.FindMatchingSerializer(typeof(TValue));

            _syncTargetRoot.EndRead += EndRead;
            Read(reader);
        }
            public SourceReplaceCommand(ExtendedBinaryReader reader, IFieldSerializer keyDeserializer,
                                        IFieldSerializer valueDeserializer)
            {
                keyDeserializer.Deserialize(reader, fixup =>
                {
                    _key         = (TKey)fixup;
                    _keyResolved = true;
                });

                valueDeserializer.Deserialize(reader, fixup =>
                {
                    _value         = (TValue)fixup;
                    _valueResolved = true;
                });
            }
            public SourceClearCommand(ExtendedBinaryReader reader, IFieldSerializer keyDeserializer,
                                      IFieldSerializer valueDeserializer)
            {
                int count = reader.Read7BitEncodedInt();

                for (var i = 0; i < count; i++)
                {
                    var keyValuePair = new BoxedKeyValuePair();

                    keyDeserializer.Deserialize(reader, fixup => { keyValuePair.Key = (TKey)fixup; });

                    valueDeserializer.Deserialize(reader, fixup => { keyValuePair.Value = (TValue)fixup; });

                    _keyValuePairs.Add(keyValuePair);
                }
            }
Beispiel #15
0
        public static void FromBsonValue(this BsonValue bsonValue, string fieldName, IContentElement contentItem, IContentSchema schema)
        {
            if (bsonValue == BsonNull.Value)
            {
                return;
            }

            if (contentItem.Fields.TryGetValue(fieldName, out ContentField? contentField))
            {
                if (schema.Fields.TryGetValue(fieldName, out ContentSchemaField? schemaField))
                {
                    IFieldSerializer fieldSerializer = MongoFieldManager.Default.GetByType(contentField.GetType());

                    fieldSerializer.Read(schemaField, contentField, bsonValue);
                }
            }
        }
Beispiel #16
0
        public RecordLoader(XmlNameTable nameTable, TableSnapshot <TRecord> table, Action <RowId> register)
        {
            Debug.Assert(nameTable != null);
            Debug.Assert(register != null);

            this.table       = table;
            this.register    = register;
            this.serializers = new Dictionary <string, IFieldSerializer <TRecord> >(XmlHelper.AtomComparer);
            foreach (IField <TRecord> field in this.table.Fields)
            {
                IFieldSerializer <TRecord> serializer = field as IFieldSerializer <TRecord>;
                if (serializer != null)
                {
                    string fieldName = nameTable.Add(field.Name);
                    this.serializers.Add(fieldName, serializer);
                }
            }
        }
Beispiel #17
0
 // Saves the table
 private static void SaveRecords <TRecord>(XmlWriter writer, TableSnapshot <TRecord> table) where TRecord : struct
 {
     foreach (RowId rowId in table.Rows)
     {
         TRecord data;
         table.GetData(rowId, out data);
         writer.WriteStartElement(table.Name, CircuitProject.PersistenceNamespace);
         foreach (IField <TRecord> field in table.Fields)
         {
             IFieldSerializer <TRecord> serializer = field as IFieldSerializer <TRecord>;
             if (serializer != null && serializer.NeedToSave(ref data))
             {
                 writer.WriteStartElement(field.Name, CircuitProject.PersistenceNamespace);
                 writer.WriteString(serializer.GetTextValue(ref data));
                 writer.WriteEndElement();
             }
         }
         writer.WriteEndElement();
     }
 }
Beispiel #18
0
        public static BsonValue ToBsonValue(this ContentField contentField)
        {
            IFieldSerializer fieldSerializer = MongoFieldManager.Default.GetByType(contentField.GetType());

            return(fieldSerializer.Write(contentField));
        }
 private ConfigTypeInfo(FieldInfo fieldInfo, IFieldSerializer fieldSerializer)
 {
     this.fieldInfo       = fieldInfo;
     this.fieldSerializer = fieldSerializer;
 }
Beispiel #20
0
 public void Register(Type fieldType, IFieldSerializer fieldSerializer)
 {
     _fields.Add(fieldType, fieldSerializer);
 }
 public void AddSerializer(IFieldSerializer serializer)
 {
     _serializers.Add(serializer);
 }