Ejemplo n.º 1
0
        /// <inheritdoc />
        public string ToString(BatchTransfer transfer)
        {
            var jsonTransfer = new JObject {
                ["transfer"] = transfer.Mode.ToString().ToLowerInvariant()
            };

            var objectItemsToken = new JArray();

            jsonTransfer["objects"] = objectItemsToken;

            foreach (BatchObject objectValue in transfer.Objects)
            {
                objectItemsToken.Add(this.ProcessBatchObject(objectValue));
            }

            return(jsonTransfer.ToString(Formatting.Indented));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public BatchTransfer TransferFromString(string json)
        {
            var transfer = new BatchTransfer {
                Objects = new List <IBatchObject>()
            };

            JObject jsonObject = JObject.Parse(json);

            if (Enum.TryParse((string)jsonObject["transfer"], true, out TransferMode mode))
            {
                transfer.Mode = mode;
            }

            foreach (JToken item in jsonObject["objects"])
            {
                IBatchObject batchObject = new BatchObject();
                if (item["error"] != null)
                {
                    var batchObjectError =
                        new BatchObjectError
                    {
                        ErrorCode    = (int)item["error"]["code"],
                        ErrorMessage = (string)item["error"]["message"]
                    };
                    batchObject = batchObjectError;
                }
                else
                {
                    batchObject = this.ProcessBatchObjectJson(item);
                }

                batchObject.Id = new ObjectId((string)item["oid"], (long)item["size"]);

                transfer.Objects.Add(batchObject);
            }

            return(transfer);
        }