/// <summary> /// Serialize to string /// </summary> /// <returns>Serialized as string</returns> public string Serialize() { IDataId dataId = EnsureDataIdType(_dataId); if ((_serializedData == null) || (dataId != _dataId)) { string s = SerializationFacade.Serialize(this.DataId); System.Text.StringBuilder sb = new System.Text.StringBuilder(); StringConversionServices.SerializeKeyValuePair(sb, "_dataId_", s); StringConversionServices.SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(this.DataId.GetType())); if (_providerName != DataProviderRegistry.DefaultDynamicTypeDataProviderName) { StringConversionServices.SerializeKeyValuePair(sb, "_providerName_", _providerName); } StringConversionServices.SerializeKeyValuePair(sb, "_interfaceType_", TypeManager.SerializeType(_interfaceType)); StringConversionServices.SerializeKeyValuePair(sb, "_dataScope_", DataScopeIdentifier.Serialize()); StringConversionServices.SerializeKeyValuePair(sb, "_localeScope_", LocaleScope.Name); _serializedData = sb.ToString(); } return(_serializedData); }
/// <summary> /// Serializes this instance /// </summary> /// <returns>String representation</returns> public string Serialize() { string serializedSearchToken = SerializationFacade.Serialize(this); string serializedClassName = TypeManager.SerializeType(this.GetType()); string serializedSearchTokenWithClass = string.Format("{0}|{1}", serializedClassName, serializedSearchToken); return(serializedSearchTokenWithClass); }
public static string Serialize(this IDataId dataId) { if (dataId == null) { throw new ArgumentNullException("dataId"); } StringBuilder sb = new StringBuilder(); StringConversionServices.SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(dataId.GetType())); StringConversionServices.SerializeKeyValuePair(sb, "_dataId_", SerializationFacade.Serialize(dataId)); return(sb.ToString()); }
public static string Serialize(this IDataId dataId, IEnumerable <string> propertyNames) { if (dataId == null) { throw new ArgumentNullException(nameof(dataId)); } var sb = new StringBuilder(); SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(dataId.GetType())); SerializeKeyValuePair(sb, "_dataId_", SerializationFacade.Serialize(dataId, propertyNames)); return(sb.ToString()); }
private static SearchToken DeserializeLegacy(string serializedSearchToken) { Verify.ArgumentNotNullOrEmpty(serializedSearchToken, nameof(serializedSearchToken)); Verify.ArgumentCondition(serializedSearchToken.IndexOf('|') > -1, nameof(serializedSearchToken), "Malformed serializedSearchToken - must be formated like '<class name>|<serialized values>'"); string[] parts = serializedSearchToken.Split('|'); string className = parts[0]; string serializedSearchTokenWithoutClassName = parts[1]; Type searchTokenType = TypeManager.GetType(className); SearchToken searchToken = (SearchToken)SerializationFacade.Deserialize(searchTokenType, serializedSearchTokenWithoutClassName); return(searchToken); }
public static IDataId DeserializeLegacy(string serializedId, string serializedVersionId) { Dictionary <string, string> dataIdValues = ParseKeyValueCollection(serializedId); if (!dataIdValues.ContainsKey("_dataIdType_") || !dataIdValues.ContainsKey("_dataId_")) { throw new ArgumentException("The serializedId is not a serialized id", nameof(serializedId)); } string dataIdType = DeserializeValueString(dataIdValues["_dataIdType_"]); string serializedIdString = DeserializeValueString(dataIdValues["_dataId_"]); string serializedVersionIdString = ""; if (!string.IsNullOrEmpty(serializedVersionId)) { Dictionary <string, string> versionValues = ParseKeyValueCollection(serializedVersionId); if (!versionValues.ContainsKey("_dataIdType_") || !versionValues.ContainsKey("_dataId_")) { throw new ArgumentException("The serializedVersionId is not a serialized version id", nameof(serializedVersionId)); } if (dataIdValues["_dataIdType_"] != versionValues["_dataIdType_"]) { throw new ArgumentException("Serialized id and version id have diffrent types", nameof(serializedId)); } serializedVersionIdString = DeserializeValueString(versionValues["_dataId_"]); } Type type = TypeManager.TryGetType(dataIdType); if (type == null) { throw new InvalidOperationException($"The type {dataIdType} could not be found"); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, string.Join("", serializedIdString, serializedVersionIdString)); return(dataId); }
public static IDataId Deserialize(string serializedId, string serializedVersionId) { Dictionary <string, string> dicid = StringConversionServices.ParseKeyValueCollection(serializedId); if ((dicid.ContainsKey("_dataIdType_") == false) || (dicid.ContainsKey("_dataId_") == false)) { throw new ArgumentException("The serializedId is not a serialized id", nameof(serializedId)); } Dictionary <string, string> dicversion = StringConversionServices.ParseKeyValueCollection(serializedVersionId); if ((dicversion.ContainsKey("_dataIdType_") == false) || (dicversion.ContainsKey("_dataId_") == false)) { throw new ArgumentException("The serializedVersionId is not a serialized version id", nameof(serializedVersionId)); } if (dicid["_dataIdType_"] != dicversion["_dataIdType_"]) { throw new ArgumentException("Serialized id and version id have diffrent types", nameof(serializedId)); } string dataIdType = StringConversionServices.DeserializeValueString(dicid["_dataIdType_"]); string serializedIdString = StringConversionServices.DeserializeValueString(dicid["_dataId_"]); string serializedVersionIdString = StringConversionServices.DeserializeValueString(dicversion["_dataId_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, string.Join("", serializedIdString, serializedVersionIdString)); return(dataId); }
public static IDataId Deserialize(string serializedDataId) { Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataId); if ((dic.ContainsKey("_dataIdType_") == false) || (dic.ContainsKey("_dataId_") == false)) { throw new ArgumentException("The serializedDataId is not a serialized data id", "serializedDataId"); } string dataIdType = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string serializedDataIdString = StringConversionServices.DeserializeValueString(dic["_dataId_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, serializedDataIdString); return(dataId); }
private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException) { dataSourceId = null; var dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId); if (!dic.ContainsKey("_dataIdType_") || !dic.ContainsKey("_dataId_") || !dic.ContainsKey("_interfaceType_") || !dic.ContainsKey("_dataScope_") || !dic.ContainsKey("_localeScope_")) { if (throwException) { throw new ArgumentException("The argument is not a serialized " + nameof(DataSourceId), nameof(serializedDataSourceId)); } return(false); } string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]); string dataIdTypeName = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string providerName = dic.ContainsKey("_providerName_") ? StringConversionServices.DeserializeValueString(dic["_providerName_"]) : DataProviderRegistry.DefaultDynamicTypeDataProviderName; string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]); string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]); string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]); Type interfaceType = TypeManager.TryGetType(interfaceTypeName); if (interfaceType == null) { if (throwException) { throw new InvalidOperationException($"The type '{interfaceTypeName}' could not be found"); } return(false); } Type dataIdType = TypeManager.TryGetType(dataIdTypeName); if (dataIdType == null) { if (throwException) { throw new InvalidOperationException($"The type '{dataIdTypeName}' could not be found"); } return(false); } serializedDataId = FixSerializedDataId(serializedDataId, interfaceType); IDataId dataId = SerializationFacade.Deserialize <IDataId>(dataIdType, serializedDataId); CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope); dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo); return(true); }
private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException) { dataSourceId = null; Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId); if ((dic.ContainsKey("_dataIdType_") == false) || (dic.ContainsKey("_dataId_") == false) || (dic.ContainsKey("_interfaceType_") == false) || (dic.ContainsKey("_dataScope_") == false) || (dic.ContainsKey("_localeScope_") == false)) { if (throwException) { throw new ArgumentException("The serializedDataSourceId is not a serialized data source id", "serializedDataSourceId"); } else { return(false); } } string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]); string dataIdType = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string providerName; if (dic.ContainsKey("_providerName_")) { providerName = StringConversionServices.DeserializeValueString(dic["_providerName_"]); } else { providerName = DataProviderRegistry.DefaultDynamicTypeDataProviderName; } string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]); string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]); string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { if (throwException) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } return(false); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, serializedDataId); Type interfaceType = TypeManager.TryGetType(interfaceTypeName); if (interfaceType == null) { if (throwException) { throw new InvalidOperationException(string.Format("The type {0} could not be found", interfaceType)); } return(false); } CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope); dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo); return(true); }