Example #1
0
 public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
 {
     if (data != null)
     {
         return(true, new HourList(data.ToString()));
     }
     return(false, null);
 }
Example #2
0
        /// <summary>
        /// Reads ChangeResult back from JSON
        /// </summary>
        public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
        {
            if (data is JsonDataMap map && map["OK"].AsBool())
            {
                return(true, new ChangeResult(map));
            }

            return(false, null);
        }
Example #3
0
        public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
        {
            if (data is JsonDataMap map)
            {
                return(true, new Amount(map["iso"].AsString(), map["val"].AsDecimal()));
            }

            return(false, null);
        }
Example #4
0
        public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
        {
            if (data is string str)
            {
                if (TryParse(str, out var got))
                {
                    return(true, got);
                }
            }

            return(false, null);
        }
Example #5
0
        public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
        {
            if (data is JsonDataMap map)
            {
                if (
                    Atom.TryEncode(map["iso"].AsString(), out var iso) &&
                    decimal.TryParse(map["val"].AsString(), NumberStyles.Any, INVARIANT, out var val)
                    )
                {
                    return(true, new Amount(iso, val));
                }
            }

            return(false, null);
        }
Example #6
0
 public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
 {
     throw new NotImplementedException();
 }
Example #7
0
            public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
            {
                if (data is JsonDataMap map)
                {
                    Utc           = map["utc"].AsLong(0).FromMillisecondsSinceUnixEpochStart();
                    Session       = map["ssn"].AsString();
                    App           = map["app"].AsAtom();
                    AppInstance   = map["ain"].AsGUID(Guid.Empty);
                    Host          = map["h"].AsString();
                    Type          = map["t"].AsString();
                    ID            = map["id"].AsGUID(Guid.Empty);
                    DirectorName  = map["dir"].AsString();
                    CallerAddress = map["cad"].AsString();
                    CallerAgent   = map["cag"].AsString();
                    CallerPort    = map["cpr"].AsString();

                    if (map["items"] is JsonDataMap items)
                    {
                        m_Items = new ConcurrentDictionary <string, object>(items);
                    }

                    return(true, this);
                }
                return(false, this);
            }
Example #8
0
File: Doc.cs Project: rstonkus/azos
 /// <summary>
 /// Override to perform custom deserialization from Json.
 /// The default implementation delegates the work to JsonReader class
 /// </summary>
 /// <param name="data">Data to deserialize, must be JsonDataMap to succeed</param>
 /// <param name="fromUI">True is passed when the deserialization is coming from a datagram supplied by user interface</param>
 /// <param name="options">Specifies how to bind names</param>
 /// <returns>Tuple of (bool match, IJsonReadable self)</returns>
 public virtual (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
 {
     if (data is JsonDataMap map)
     {
         JsonReader.ToDoc(this, map, fromUI, options);
         return(true, this);
     }
     return(false, this);
 }
Example #9
0
 public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
 => data is JsonDataMap map ? (true, Addressee.From(map))
Example #10
0
            public (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
            {
                if (data == null)
                {
                    return(false, this);
                }

                var str = data as string;

                if (str == null)
                {
                    str = data.ToString();
                }

                Text   = str;
                Length = str.Length;
                return(true, this);
            }
Example #11
0
        /// <summary>
        /// Custom binder inserts bin[] content supplied at the top-map level as provided using multipart data encoding.
        /// The binder "inserts" the byte[] inside the message attachment graph
        /// </summary>
        public override (bool match, IJsonReadable self) ReadAsJson(object data, bool fromUI, JsonReader.DocReadOptions?options)
        {
            if (!(data is JsonDataMap map))
            {
                return(false, this);
            }
            Content = JsonReader.ToDoc <Message>(map, fromUI, options);

            for (var i = 0; i < Content.Attachments.Length; i++)
            {
                var attachment = Content.Attachments[i];
                if (attachment.Content != null && attachment.Content.Length > 0)
                {
                    continue;
                }
                var oob = AmorphousData[$"attachment-{i}"] as byte[];//out-of-band content attachment
                if (oob != null)
                {
                    attachment.Content = oob;
                }
            }

            return(true, this);
        }