Ejemplo n.º 1
0
        public IObjectState Decode(IDictionary <string, object> data,
                                   ParseDecoder decoder)
        {
            IDictionary <string, object> serverData = new Dictionary <string, object>();
            var    mutableData = new Dictionary <string, object>(data);
            string objectId    = extractFromDictionary <string>(mutableData, "objectId", (obj) =>
            {
                return(obj as string);
            });
            DateTime?createdAt = extractFromDictionary <DateTime?>(mutableData, "createdAt", (obj) =>
            {
                return(ParseDecoder.ParseDate(obj as string));
            });
            DateTime?updatedAt = extractFromDictionary <DateTime?>(mutableData, "updatedAt", (obj) =>
            {
                return(ParseDecoder.ParseDate(obj as string));
            });

            if (mutableData.ContainsKey("ACL"))
            {
                serverData["ACL"] = extractFromDictionary <ParseACL>(mutableData, "ACL", (obj) =>
                {
                    return(new ParseACL(obj as IDictionary <string, object>));
                });
            }

            if (createdAt != null && updatedAt == null)
            {
                updatedAt = createdAt;
            }

            // Bring in the new server data.
            foreach (var pair in mutableData)
            {
                if (pair.Key == "__type" || pair.Key == "className")
                {
                    continue;
                }

                var value = pair.Value;
                serverData[pair.Key] = decoder.Decode(value);
            }

            return(new MutableObjectState
            {
                ObjectId = objectId,
                CreatedAt = createdAt,
                UpdatedAt = updatedAt,
                ServerData = serverData
            });
        }
Ejemplo n.º 2
0
        public IObjectState Decode(IDictionary <string, object> data, ParseDecoder decoder)
        {
            IDictionary <string, object> serverData = new Dictionary <string, object> {
            };
            Dictionary <string, object> mutableData = new Dictionary <string, object>(data);
            DateTime?createdAt = ExtractFromDictionary <DateTime?>(mutableData, "createdAt", (obj) => ParseDecoder.ParseDate(obj as string));
            DateTime?updatedAt = ExtractFromDictionary <DateTime?>(mutableData, "updatedAt", (obj) => ParseDecoder.ParseDate(obj as string));

            if (mutableData.ContainsKey("ACL"))
            {
                serverData["ACL"] = ExtractFromDictionary(mutableData, "ACL", (obj) => new ParseACL(obj as IDictionary <string, object>));
            }

            if (createdAt != null && updatedAt is null)
            {
                updatedAt = createdAt;
            }

            foreach (KeyValuePair <string, object> pair in mutableData)
            {
                if (pair.Key == "__type" || pair.Key == "className")
                {
                    continue;
                }

                serverData[pair.Key] = decoder.Decode(pair.Value);
            }

            return(new MutableObjectState
            {
                ObjectId = ExtractFromDictionary(mutableData, "objectId", (obj) => obj as string),
                CreatedAt = createdAt,
                UpdatedAt = updatedAt,
                ServerData = serverData
            });
        }