コード例 #1
0
ファイル: Subscriber.cs プロジェクト: 0xNF/esk8bst
        public static Subscriber FromPostedSubscriber(PostedSubscribeObject sub)
        {
            Subscriber s = new Subscriber()
            {
                DocumentId = sub.Email.ToLowerInvariant(),
                Matches    = sub.Matches.Select(x => Match.FromPostedMatch(x)).ToList(),
            };

            return(s);
        }
コード例 #2
0
ファイル: PostedSubscribeObject.cs プロジェクト: 0xNF/esk8bst
        public static PostedSubscribeObject FromJson(JObject jobj)
        {
            string email = "";
            List <PostedMatchObject> pmos = new List <PostedMatchObject>();

            if (jobj.TryGetValue("email", out JToken JTEmail))
            {
                email = JTEmail.Value <string>();
                if (String.IsNullOrWhiteSpace(email))
                {
                    throw new Exception("Supplied field's value wasn't valid for fields type");
                }
            }
            else
            {
                throw new Exception("A required field 'email' was missing from this object");
            }


            if (jobj.TryGetValue("matches", out JToken JTMatches))
            {
                if (!(JTMatches is JArray matchArr) || matchArr.Count == 0)
                {
                    throw new Exception("Supplied field's value wasn't valid for fields type");
                }
                foreach (JToken JTMatch in matchArr)
                {
                    JObject           matchObj = JTMatch as JObject;
                    PostedMatchObject pmo      = PostedMatchObject.FromJson(matchObj);
                    if (pmo == null)
                    {
                        throw new Exception("Failed  deserialzing match objects");
                    }
                    pmos.Add(pmo);
                }
            }
            else
            {
                throw new Exception("A required field 'matches' was missing from this object");
            }

            PostedSubscribeObject pso = new PostedSubscribeObject()
            {
                Email   = email,
                Matches = pmos
            };

            return(pso);
        }