public static object DeserializePayloadUsingSpecificSerializer(
            this DescribedSerialization describedSerialization,
            IDeserialize deserializer,
            IDecompress decompressor                    = null,
            TypeMatchStrategy typeMatchStrategy         = TypeMatchStrategy.NamespaceAndName,
            MultipleMatchStrategy multipleMatchStrategy = MultipleMatchStrategy.ThrowOnMultiple)
        {
            new { describedSerialization }.Must().NotBeNull();
            new { deserializer }.Must().NotBeNull();

            var localDecompressor = decompressor ?? new NullCompressor();
            var targetType        = describedSerialization.PayloadTypeRepresentation.ResolveFromLoadedTypes(typeMatchStrategy, multipleMatchStrategy);

            object ret;

            switch (describedSerialization.SerializationDescription.SerializationFormat)
            {
            case SerializationFormat.Binary:
                var rawBytes          = Convert.FromBase64String(describedSerialization.SerializedPayload);
                var decompressedBytes = localDecompressor.DecompressBytes(rawBytes);
                ret = deserializer.Deserialize(decompressedBytes, targetType);
                break;

            case SerializationFormat.String:
                ret = deserializer.Deserialize(describedSerialization.SerializedPayload, targetType);
                break;

            default: throw new NotSupportedException(Invariant($"{nameof(SerializationFormat)} - {describedSerialization.SerializationDescription.SerializationFormat} is not supported."));
            }

            return(ret);
        }
Exemple #2
0
 public void OnEditDeserialize(IDeserialize objDeserialize)
 {
     assemblyMetadata = (AssemblyMetadata)objDeserialize.Deserialize();
     pathVariable     = objDeserialize.ToString();
     HierarchicalAreas.Clear();
     TreeViewLoaded(assemblyMetadata);
     MessageBox.Show(objDeserialize.ToString());
 }
Exemple #3
0
        public static T DeserializePayloadUsingSpecificSerializer <T>(
            this DescribedSerializationBase describedSerializationBase,
            IDeserialize deserializer,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            var result = (T)DeserializePayloadUsingSpecificSerializer(describedSerializationBase, deserializer, assemblyMatchStrategy);

            return(result);
        }
Exemple #4
0
 /// <inheritdoc cref="IDeserializeAsync{T}.DeserializeAsync(Stream, CancellationToken)"/>
 public static ValueTask <T> DeserializeAsync <T>(this IDeserialize <T> deserializer, Stream source, CancellationToken cancellationToken = default)
 {
     if (deserializer is null)
     {
         throw new ArgumentNullException(nameof(deserializer));
     }
     return(deserializer is IDeserializeAsync <T> d
                         ? d.DeserializeAsync(source, cancellationToken)
                         : DefaultMethods.DeserializeAsync(deserializer, source));
 }
Exemple #5
0
    private void deserializeAttribute(Newtonsoft.Json.Linq.JObject data, string v)
    {
        Newtonsoft.Json.Linq.JObject dict = data[v] as Newtonsoft.Json.Linq.JObject;
        string classType = (string)dict["type"];

        classType = classType.Substring(classType.IndexOf("::") + 2);
        //UnityEngine.Debug.LogFormat("classType{0}", classType);
        System.Type  ct = System.Type.GetType(classType, true);
        IDeserialize o  = (IDeserialize)Activator.CreateInstance(ct);

        //需要用到反射,但是private数据会获取不到,所以改成public
        this.GetType().GetField(v).SetValue(this, o);
        o.deserialize(dict);
    }
        /// <summary>
        /// Deserializes a stream to the specified type.
        /// </summary>
        public static async ValueTask <T> DeserializeAsync <T>(IDeserialize deserializer, Stream source)
        {
            if (deserializer is null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            string text;

            using (var reader = new StreamReader(source))
                text = await reader.ReadToEndAsync().ConfigureAwait(false);
            return(deserializer.Deserialize <T>(text));
        }
Exemple #7
0
        public SellOrderFactory()
        {
            directoryPath         = new DirectoryPathConfig();
            fileManager           = new FileManager();
            processorFilesRequest = new ProcessorFilesRequest(directoryPath, fileManager);

            serialize              = new JsonSerialize();
            deserialize            = new JsonDeserialize();
            processorFilesResponse = new ProcessorFilesResponse(directoryPath, fileManager, serialize);

            mapProcessFile = new MapProcessFile(directoryPath, fileManager, deserialize);

            processSellOrder = new ProcessSellOrder();
            validateSellOrderBusinessRules = new ValidateSellOrderBusinessRules();

            executionSellOrder = new ExecutionSellOrder(processSellOrder, validateSellOrderBusinessRules);
            handleSellOrder    = new HandleSellOrder(processorFilesRequest, processorFilesResponse, mapProcessFile, executionSellOrder);
        }
Exemple #8
0
        public static object DeserializePayloadUsingSpecificSerializer(
            this DescribedSerializationBase describedSerializationBase,
            IDeserialize deserializer,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            if (describedSerializationBase == null)
            {
                throw new ArgumentNullException(nameof(describedSerializationBase));
            }

            if (deserializer == null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }

            var targetType = describedSerializationBase.PayloadTypeRepresentation.ResolveFromLoadedTypes(assemblyMatchStrategy);

            object result;

            var serializationFormat = describedSerializationBase.GetSerializationFormat();

            switch (serializationFormat)
            {
            case SerializationFormat.Binary:
                var describedSerializationBinary = (BinaryDescribedSerialization)describedSerializationBase;
                var serializedBytes = describedSerializationBinary.SerializedPayload;
                result = serializedBytes == null ? null : deserializer.Deserialize(serializedBytes, targetType);
                break;

            case SerializationFormat.String:
                var describedSerializationString = (StringDescribedSerialization)describedSerializationBase;
                var serializedString             = describedSerializationString.SerializedPayload;
                result = serializedString == null ? null : deserializer.Deserialize(serializedString, targetType);
                break;

            default:
                throw new NotSupportedException(Invariant($"{nameof(SerializationFormat)} - {serializationFormat} is not supported."));
            }

            return(result);
        }
Exemple #9
0
        public static async Task <IWhatsAppApi <T> > Deserialize <T>(this IDeserialize <T> self, Task <string> json) where T : class, IDeserialize <T>, new()
        {
            if (self is null)
            {
                Error = new JsonError {
                    IsError = true, CodeOfError = 4, TextError = "WhatsAppMessage is null"
                };
                var result = new DeserializeMessage <T> {
                    Result = new T(), Error = Error
                };
                return(result);
            }

            var jsonMessage = await json;

            if (string.IsNullOrEmpty(jsonMessage))
            {
                self.Deserialize.Error = new JsonError {
                    IsError = true, CodeOfError = 0, TextError = "Json file is empty"
                };
                return(self.Deserialize);
            }

            try
            {
                self.Deserialize.Result = JsonConvert.DeserializeObject <T>(jsonMessage, Settings);
                self.Deserialize.Error  = Error;
            }
            catch (JsonException)
            {
                self.Deserialize.Result = (T)self;
                self.Deserialize.Error  = new JsonError {
                    IsError = true, CodeOfError = 1, TextError = "Json file is broken"
                };
            }
            self.Deserialize.Result.DateTime = DateTime.Now;
            return(self.Deserialize);
        }
        private async Task LoadConfigForType <T>(ILog log, IDeserialize serializer, IConfiguration configuration, string appDataSubFolderName, Func <T, Task> foundItems)
        {
            if (foundItems == null)
            {
                return;
            }
            var configFolder = System.IO.Path.Combine(configuration.AppDataDirectory.FullName, appDataSubFolderName);

            if (!System.IO.Directory.Exists(configFolder))
            {
                System.IO.Directory.CreateDirectory(configFolder);
            }

            foreach (var file in System.IO.Directory.GetFiles(configFolder))
            {
                try
                {
                    if (System.IO.File.Exists(file))
                    {
                        var json = System.IO.File.ReadAllText(file);
                        if (!string.IsNullOrEmpty(json))
                        {
                            var items = serializer.Deserialize <T>(json);
                            if (items != null)
                            {
                                await foundItems(items);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    log.Error(e, "Could not load config from file:{0}", file);
                }
            }
        }
Exemple #11
0
 public TransportFactory(IDeserialize serializer, IDIContainer container)
 {
     _serializer = serializer;
     _container  = container;
 }
Exemple #12
0
 public SocketProtocol(ISerialize serialize, IDeserialize deserialize, ICrypto crypto)
 {
     Serialize   = serialize;
     Deserialize = deserialize;
     Crypto      = crypto;
 }
 public MapProcessFile(IDirectoryPathConfig directoryPathConfig, IFileManager fileManager, IDeserialize deserialize)
 {
     this.directoryPathConfig = directoryPathConfig;
     this.fileManager         = fileManager;
     this.deserialize         = deserialize;
 }
 public DataLayer(IDeserialize serializer_)
 {
     this.serializer = serializer_;
 }
Exemple #15
0
 public DefaultHttpProtocol(ISerialize serialize, IDeserialize deserialize, ICrypto crypto) : base(serialize, deserialize, crypto)
 {
 }
 public Service(IServiceSecurity serviceSecurity, IDeserialize deserialize, ISerialize serialize)
 {
     this.serviceSecurity = serviceSecurity;
     this.deserialize     = deserialize;
     this.serialize       = serialize;
 }
Exemple #17
0
 public static bool Load(IDeserialize deserializer, ref ObservableModelData obj)
 {
     return(deserializer.Deserialize(ref obj));
 }