} // End of ImplWriteValue (...) protected virtual void ImplWriteValue(TextWriter tw, IEnumerable value) { tw.Write('['); if (value != null) { String itemSep = String.Empty; IValueUnit vu = null; foreach (Object item in value) { tw.Write(itemSep); if ((vu = item as IValueUnit) != null) { _Write(tw, vu); } else { ImplDispatchWriteValue(tw, item); } itemSep = ","; } } tw.Write(']'); } // End of ImplWriteValue (...)
private void _Write(TextWriter tw, IValueUnit valueUnit) { tw.Write('{'); String itemSep = String.Empty; IValueUnit subUnit = null; foreach (IValueItem valueItem in valueUnit) { tw.Write(itemSep); tw.Write('"'); tw.Write(valueItem.Key); tw.Write('"'); tw.Write(':'); if ((subUnit = valueItem.Value as IValueUnit) == null) { ImplDispatchWriteValue(tw, valueItem.Value); } else { _Write(tw, subUnit); } itemSep = ","; } tw.Write('}'); } // End of _Write (...)
protected override InterfaceType ImplDeserialize( IValueUnit valueUnit, IRepositorySerializationContext context) { if (valueUnit == null) { return(default(InterfaceType)); } IValueUnit ctxVu = null; IValueUnit tmpVu = valueUnit; IValueItem tmpVi = null; if (tmpVu.Count == 2 && context.Metadata == context.Hierarchy.Peek()) { if ((tmpVi = tmpVu ["$Metadata"]) != null && (ctxVu = tmpVi.Value as IValueUnit) != null && (tmpVi = tmpVu ["$Data"]) != null && (tmpVu = tmpVi.Value as IValueUnit) != null) { valueUnit = tmpVu; if (context.Metadata.Count == 0) { foreach (IValueItem ctxItem in ctxVu) { context.Metadata.Add(ctxItem.Key, ctxItem.Value); } } } } return(base.ImplDeserialize(valueUnit, context)); } // End of ImplDeserialize (...)
} // End of ImplRead (...) protected override void ImplWrite(TextWriter tw, IValueUnit root) { if (tw == null) { return; } if (root == null) { return; } _Write(tw, root); } // End of ImplWrite (...)
} // End of ImplParseUnit (...) protected override IValueUnit ImplRead(TextReader textReader) { IValueUnit retVal = null; JsonScanner.TokenBase token = JsonScanner.Singleton.ScanToken(textReader); if (token != JsonScanner.CurlyOpenToken.Singleton) { return(null); // Unespected token } retVal = ImplParseUnit(out token, textReader); return(token == JsonScanner.CurlyCloseToken.Singleton ? retVal : null); } // End of ImplRead (...)
protected override void ImplSerialize(out IValueUnit retVal, InterfaceType instance, SerializationContextType context) { IHierarchicalMetadataProvider <IValueUnit, IValueItemBase> ctx = null; IValueUnit curCtxLvl = null; ctx = context as IHierarchicalMetadataProvider <IValueUnit, IValueItemBase>; curCtxLvl = ctx.Hierarchy.Peek() as IValueUnit; if (curCtxLvl != null && ctx != null && ctx.Metadata != null) { curCtxLvl.Add("SerializationManager", GetType().AssemblyQualifiedName); } retVal = ImplFactory.Serialize(instance, context); } // End of ImplSerialize (...)
protected override void ImplWrite ( TextWriter tw, IValueUnit source, IRepositorySerializationContext context ) { if ( context.SerializeMetadata && context.Metadata != null ) if ( source == null ) source = context.Metadata as IValueUnit; else { IValueUnit wrapperVu = new ValueUnit (); wrapperVu.Add ( "$Metadata", context.Metadata ); wrapperVu.Add ( "$Data", source ); source = wrapperVu; } base.ImplWrite ( tw, source, context ); } // End of ImplWrite (...)
} // End of ImplSerializeEnumerable (...) protected virtual Boolean ImplSerializeItem( out Object serializedItem, Action contextPrologDlg, Action contextEpilogDlg, Object itemValue, IHierarchicalMetadataSerializationContext context) { IValueUnit ctxUnit = null; IValueUnit subUnit = null; if ((ctxUnit = context.Hierarchy.Peek() as IValueUnit) == null) { serializedItem = null; return(false); } if (ImplIsBuiltinType(itemValue.GetType())) { /* ctxts.Add ( null ); */ serializedItem = itemValue; } else if (ImplIsString(itemValue.GetType())) { /* ctxts.Add ( null ); */ serializedItem = itemValue; } //else if ( ImplSerializeEnumerable ( retVal, pd.Name, item as IEnumerable, context ) ) // continue; else if (ImplSerializeObject( out subUnit, contextPrologDlg, contextEpilogDlg, itemValue, //as IValueObjectContract, context)) { serializedItem = subUnit; } else { serializedItem = null; } return(true); } // End of ImplSerializeItem (...)
} // End of ImplSerialize (...) protected override InterfaceType ImplDeserialize(IValueUnit valueUnit, SerializationContextType context) { IValueUnit curCtxLvl = null; SerializationManager <InterfaceType, AdapterType, IValueUnit, SerializationContextType, MyselfType> repoSerMgr = null; IValueItem valueItem = null; if ((curCtxLvl = context.Hierarchy.Peek() as IValueUnit) == null) { return(default(InterfaceType)); } valueItem = curCtxLvl ["SerializationManager"] as IValueItem; if (valueItem != null) { if (GetType().AssemblyQualifiedName.Equals(valueItem.Value)) { return(base.ImplDeserialize(valueUnit, context)); } else { repoSerMgr = Activator.CreateInstance(Type.GetType(valueItem.Value.ToString())) as SerializationManager <InterfaceType, AdapterType, IValueUnit, SerializationContextType, MyselfType>; if (repoSerMgr != null) { return(repoSerMgr.Deserialize(valueUnit, context)); } } } return(default(InterfaceType)); } // End of ImplDeserialize (...)
} // End of ImplDeserializeItem (...) protected virtual Type ImplGetItemType(IHierarchicalMetadataSerializationContext context) { if (context == null) { return(null); } IValueItem itemCtxtVi = null; IValueUnit itemCtxtVu = context.Hierarchy.Peek() as IValueUnit; if (itemCtxtVu == null) { return(null); } if ((itemCtxtVi = itemCtxtVu ["TypeGuid"]) == null) { return(null); } GuidTypeMapping.Item tmp = GuidTypeMapping.Singleton [ new Guid(itemCtxtVi.Value as String)]; return(tmp == null ? null : tmp.Type); } // End of ImplGetItemType (...)
//protected override Boolean ImplAddSequenceItem ( SequenceType sequence, Object item ) //{ // if ( !(item is SequenceItemType) ) return false; // SequenceItemType kvp = (SequenceItemType) item; // try { sequence.Add ( kvp.Key, kvp.Value ); } // catch { return false; } // return true; //} // End of ImplAddSequenceItem (...) protected override Boolean ImplDeserializeItem( out Object retVal, Object item, IHierarchicalMetadataSerializationContext context) { retVal = null; IValueItem curCtxtLvlVi = null; KeyValuePair <SequenceKeyType, SequenceValueType> kvp; IValueUnit kvpVu; IValueUnit kvpCtxtLvl = null; SequenceKeyType kvpKey = default(SequenceKeyType); SequenceValueType kvpValue = default(SequenceValueType); IValueItem valueItem = null; if (context == null) { return(false); } if ((kvpVu = item as IValueUnit) == null) { return(false); } if (kvpVu.Count != 2) { return(false); } if ((kvpCtxtLvl = context.Hierarchy.Peek() as IValueUnit) == null) { return(false); } // Deserialize the Key if ((valueItem = kvpVu [nameof(kvp.Key)]) == null) { return(false); } if ((curCtxtLvlVi = kvpCtxtLvl [nameof(kvp.Key)]) == null) { context.Hierarchy.Push(null); } else { context.Hierarchy.Push(curCtxtLvlVi.Value as IValueUnit); } try { if (!base.ImplDeserializeItem(out Object key, valueItem.Value, context)) { return(false); } kvpKey = (SequenceKeyType)key; } finally { context.Hierarchy.Pop(); } // Deserialize the Value if ((valueItem = kvpVu [nameof(kvp.Value)]) == null) { return(false); } if ((curCtxtLvlVi = kvpCtxtLvl [nameof(kvp.Value)]) == null) { context.Hierarchy.Push(null); } else { context.Hierarchy.Push(curCtxtLvlVi.Value as IValueUnit); } try { if (!base.ImplDeserializeItem(out Object value, valueItem.Value, context)) { return(false); } kvpValue = (SequenceValueType)value; } finally { context.Hierarchy.Pop(); } kvp = new KeyValuePair <SequenceKeyType, SequenceValueType> (kvpKey, kvpValue); retVal = kvp; return(true); } // End of ImplDeserializeItem (...)
public RepositorySerializationContext(IValueUnit metadata) : base(metadata) { }
protected CompositedIdObject(IValueUnit valueUnit, IHierarchicalMetadataSerializationContext context) : base(valueUnit, context) { _Reset(); }
} // End of Class ContainedObjectFactory protected override IContainedObject ImplDeserialize<SerializationContextType> ( IValueUnit serialization, SerializationContextType context ) => new ContainedObject ( serialization, context as IHierarchicalMetadataSerializationContext );
public DerivedObject ( IValueUnit valueUnit, IHierarchicalMetadataSerializationContext context ) : base ( valueUnit, context ) { }
} // End of Custom Constructor protected Entity(IValueUnit valueUnit, IHierarchicalMetadataSerializationContext context) : base(valueUnit, context) { }
protected override Boolean ImplSerializeEnumerable( out ArrayList values, IEnumerable objValue, IHierarchicalMetadataSerializationContext context) { values = new ArrayList(); if (objValue == null) { return(false); } if (context == null) { return(false); } IValueSequence valueSeq = context.Hierarchy.Peek() as IValueSequence; if (valueSeq == null) { return(false); } IList ctxts = valueSeq.Value as IList; if (ctxts == null) { return(false); } IValueUnit ctxUnit = null; Type instType = null; context.Hierarchy.Pop(); if ((ctxUnit = context.Hierarchy.Peek() as IValueUnit) == null) { return(false); } // Add SerMgr key if ((instType = typeof(SequenceType)).IsGenericType) { ctxUnit.Add("SerializationManager", GetType().GetGenericTypeDefinition().AssemblyQualifiedName); ArrayList typeParamGuids = new ArrayList(); foreach (Type par in instType.GenericTypeArguments) { typeParamGuids.Add(par.GetTypeGuid().ToString()); } ctxUnit.Add("SerializationManagerInstanceTypeParamGuids", new ValueSequence(typeParamGuids)); } else { return(false);// ctxUnit.Add ( "SerializationManager", instType.AssemblyQualifiedName ); } context.Hierarchy.Push(valueSeq); foreach (KeyValuePair <SequenceKeyType, SequenceValueType> kvp in objValue) { ValueUnit kvpValueUnit = new ValueUnit(); Object tmpValue = null; ctxts.Add(ctxUnit = new ValueUnit()); context.Hierarchy.Push(ctxUnit); ImplSerializeItem( out tmpValue, //delegate ( IValueUnit vu ) { ctxUnit.Add ( nameof ( kvp.Key ), vu ); }, delegate() { ValueUnit vu = new ValueUnit(); ctxUnit.Add(nameof(kvp.Key), vu); context.Hierarchy.Push(vu); }, delegate() { context.Hierarchy.Pop(); }, kvp.Key, context); kvpValueUnit.Add(new ValueItem(nameof(kvp.Key), tmpValue)); ImplSerializeItem( out tmpValue, //delegate ( IValueUnit vu ) { ctxUnit.Add ( nameof ( kvp.Value ), vu ); }, delegate() { ValueUnit vu = new ValueUnit(); ctxUnit.Add(nameof(kvp.Value), vu); context.Hierarchy.Push(vu); }, delegate() { context.Hierarchy.Pop(); }, kvp.Value, context); kvpValueUnit.Add(new ValueItem(nameof(kvp.Value), tmpValue)); values.Add(kvpValueUnit); context.Hierarchy.Pop(); } return(true); } // End of ImplSerializeEnumerable (...)
protected virtual Boolean ImplDeserializeItem <ContextType> ( out Object retVal, Object item, Func <IValueItemBase> getCurrentContextDlg, ContextType context) where ContextType : ISerializationContext { retVal = null; //Type itemType = null; //NumericStringValue numericString = null; IConvertibleString cnvStr = null; ISerializable <IValueUnit> serMgr = null; ValueDomObjectSerializationManagerCollection serMgrColl = null; ObjectSerializationManagerDescr serMgrDescr = null; IValueUnit subCtxtLvl = null; IValueUnit subUnit = null; String typeName = null; IValueItem valueItem = null; if (item == null) { retVal = null; } else if (ImplIsBuiltinType(item.GetType())) { retVal = item; } //else if ( ImplIsString ( item.GetType () ) ) // if ( (itemType = ImplGetItemType ( context )) == null ) // retVal = item; // else if ( itemType == typeof ( String ) ) // retVal = item; // else // retVal = ImpConvertToType ( item, itemType ); //else if ( (numericString = item as NumericStringValue) != null ) // retVal = ImpConvertToType ( numericString, ImplGetItemType ( context ) ); else if (ImplIsString(item.GetType())) { retVal = ImpConvertToType(item, ImplGetItemType(context)); } else if ((cnvStr = item as IConvertibleString) != null) { retVal = ImpConvertToType(cnvStr, ImplGetItemType(context)); } else if ((subUnit = item as IValueUnit) == null) { return(false); } //propValue = pd.GetValue ( InitDto ); //if ( _DeserializeEnumerable ( ref propValue, pd, valueItem.Value, context ) ) // continue; //else // propValue = valueItem.Value; else if (getCurrentContextDlg == null) { return(false); } else if ((subCtxtLvl = getCurrentContextDlg() as IValueUnit) == null) { return(false); } else if ((valueItem = subCtxtLvl ["SerializationManager"] as IValueItem) == null) { return(false); } else if (valueItem.Value == null) { return(false); } else if ((typeName = valueItem.Value.ToString()) == null) { return(false); } else if ((serMgrColl = ValueDomObjectSerializationManagerCollection.Singleton) == null) { return(false); } else if ((serMgrDescr = serMgrColl [typeName]) == null) { return(false); } else if ((serMgr = serMgrDescr.SerializationManager) == null) { return(false); } else { retVal = serMgr.Deserialize(subUnit, context); } return(true); } // End of ImplDeserializeItem (...)
} // End of ImplSerializeEnumerable (...) protected virtual Boolean ImplSerializeEnumerable( out ArrayList values, IEnumerable objValue, IHierarchicalMetadataSerializationContext context) { values = new ArrayList(); if (objValue == null) { return(false); } if (context == null) { return(false); } IValueSequence valueSeq = context.Hierarchy.Peek() as IValueSequence; if (valueSeq == null) { return(false); } IList ctxts = ((IValueItemBase)valueSeq).Value as IList; if (ctxts == null) { return(false); } IValueUnit ctxUnit = null; Type itemType = null; Type serMgrType = null; IValueUnit subUnit = null; context.Hierarchy.Pop(); try { if ((ctxUnit = context.Hierarchy.Peek() as IValueUnit) == null) { return(false); } else if ((serMgrType = GetType()).IsGenericType) { ctxUnit.Add("SerializationManager", serMgrType.GetGenericTypeDefinition().AssemblyQualifiedName); ArrayList typeParamGuids = new ArrayList(); foreach (Type par in serMgrType.GenericTypeArguments) { typeParamGuids.Add(par.GetTypeGuid().ToString()); } ctxUnit.Add("SerializationManagerInstanceTypeParamGuids", new ValueSequence(typeParamGuids)); } else { ctxUnit.Add("SerializationManager", serMgrType.AssemblyQualifiedName); } } finally { context.Hierarchy.Push(valueSeq); } foreach (Object item in objValue) { if (ImplIsBuiltinType(itemType = item.GetType())) { ValueUnit vu = new ValueUnit(); vu.Add(new ValueItem("TypeGuid", itemType.GetTypeGuid().ToString())); ctxts.Add(vu); values.Add(item); } else if (ImplIsString(item.GetType())) { ctxts.Add(null); values.Add(item); } //else if ( ImplSerializeEnumerable ( retVal, pd.Name, item as IEnumerable, context ) ) // continue; else if (ImplSerializeObject( out subUnit, //delegate ( IValueUnit vu ) { ctxts.Add ( vu ); }, delegate() { ValueUnit vu = new ValueUnit(); ctxts.Add(vu); context.Hierarchy.Push(vu); }, delegate() { context.Hierarchy.Pop(); }, item, //as IValueObjectContract, context)) { values.Add(subUnit); } } return(true); } // End of ImplSerializeEnumerable (...)