示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#6
0
        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);
        }