Esempio n. 1
0
        public override JToken ToJToken(ApiVersion version, ResultFormat format)
        {
            var jobj = base.ToJToken(version, format);

            if (Name != null && format != ResultFormat.Ids)
            {
                jobj["name"] = Name;
            }

            if (Mbox != null)
            {
                jobj["mbox"] = Mbox.ToString();
            }

            if (Mbox_SHA1SUM != null)
            {
                jobj["mbox_sha1sum"] = Mbox_SHA1SUM;
            }

            if (OpenId != null)
            {
                jobj["openid"] = OpenId.ToString();
            }

            if (Account != null)
            {
                jobj["account"] = Account.ToJToken(version, format);
            }

            return(jobj);
        }
Esempio n. 2
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string)
     {
         if (Mbox.TryParse(value as string, out Mbox mbox))
         {
             return(mbox);
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
Esempio n. 3
0
 public static bool TryParse(string value, out Mbox mbox)
 {
     mbox = null;
     try
     {
         mbox = new Mbox(value);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 4
0
 public string GetIfi()
 {
     if (this.Mbox != null)
     {
         return(Mbox.ToString());
     }
     if (this.Mbox_SHA1SUM != null)
     {
         return(Mbox_SHA1SUM);
     }
     if (this.Account != null)
     {
         return(this.Account.ToJson());
     }
     if (this.OpenId != null)
     {
         return(OpenId._iriString);
     }
     return(null);
 }
Esempio n. 5
0
        /// <summary>
        /// Adds Agent to Person object
        /// </summary>
        /// <param name="agent">Agent Object with a single identifier, It is not a Person Object, nor is it a Group.</param>
        public void Add(Agent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }

            if (agent.ObjectType == Data.ObjectType.Group)
            {
                throw new ArgumentException("Groups are not allowed within an Person Object.");
            }
            if (agent.Name != null)
            {
                Name.Add(agent.Name);
            }
            if (agent.Account != null)
            {
                Account.Add(agent.Account);
                return;
            }

            if (agent.Mbox != null)
            {
                Mbox.Add(agent.Mbox);
                return;
            }

            if (!string.IsNullOrWhiteSpace(agent.Mbox_SHA1SUM))
            {
                Mbox_sha1sum.Add(agent.Mbox_SHA1SUM);
                return;
            }

            if (agent.OpenId != null)
            {
                OpenId.Add(agent.OpenId);
                return;
            }
        }
Esempio n. 6
0
        public Agent(JToken jobj, ApiVersion version) : base(jobj, version)
        {
            GuardType(jobj, JTokenType.Object);

            var objectType = jobj["objectType"];

            if (objectType != null)
            {
                GuardType(objectType, JTokenType.String);
                ParseObjectType(objectType, OBJECT_TYPE);
            }

            var name = jobj["name"];

            if (name != null)
            {
                GuardType(name, JTokenType.String);
                Name = jobj.Value <string>("name");
            }

            var mbox = jobj["mbox"];

            if (mbox != null)
            {
                GuardType(mbox, JTokenType.String);
                try
                {
                    Mbox = new Mbox(mbox.Value <string>());
                }
                catch (MboxFormatException ex)
                {
                    throw new JsonTokenModelException(mbox, ex);
                }
            }

            var mbox_sha1sum = jobj["mbox_sha1sum"];

            if (mbox_sha1sum != null)
            {
                GuardType(mbox_sha1sum, JTokenType.String);
                Mbox_SHA1SUM = mbox_sha1sum.Value <string>();
            }

            var openid = jobj["openid"];

            if (openid != null)
            {
                GuardType(openid, JTokenType.String);
                try
                {
                    OpenId = new Iri(openid.Value <string>());
                }
                catch (IriFormatException ex)
                {
                    throw new JsonTokenModelException(openid, ex);
                }
            }

            var account = jobj["account"];

            if (account != null)
            {
                GuardType(account, JTokenType.Object);
                Account = new Account(account, version);
            }
        }