Beispiel #1
0
        private static ApiKeyInfo ParseApiKeyInfoXml(XElement result)
        {
            DateTimeOffset expiry                = default(DateTimeOffset);
            int            accessMask            = 0;
            var            type                  = ApiKeyType.Invalid;
            ApiKeyInfo     keyInfo               = null;
            IEnumerable <AccountCharacter> chars = new AccountCharacter[0];

            // get the key element in the result
            XElement keyElement = result.Element(ApiConstants.Key);

            if (keyElement != null)
            {
                // get details from the attributes
                foreach (XAttribute attribute in keyElement.Attributes())
                {
                    switch (attribute.Name.LocalName)
                    {
                    case "accessMask":
                        int.TryParse(attribute.Value, out accessMask);
                        break;

                    case "type":
                        Enum.TryParse(attribute.Value, out type);
                        break;

                    case "expires":
                        DateTime temp;
                        expiry = DateTime.TryParse(attribute.Value, out temp)
                                ? new DateTimeOffset(temp, TimeSpan.Zero)
                                : default(DateTimeOffset);
                        break;
                    }
                }

                // get the character rowset that might be present in the result
                XElement characterSet = keyElement.Element(ApiConstants.Rowset);
                if (characterSet != null)
                {
                    chars = GetCharactersFromRowSet(characterSet);
                }

                keyInfo = new ApiKeyInfo {
                    AccessMask = accessMask, ApiType = type, Expires = expiry, Characters = chars
                };
            }

            return(keyInfo);
        }
Beispiel #2
0
        private static ApiKeyInfo ParseApiKeyInfoXml(XElement result)
        {
            DateTimeOffset expiry = default(DateTimeOffset);
            int accessMask = 0;
            var type = ApiKeyType.Invalid;
            ApiKeyInfo keyInfo = null;
            IEnumerable<AccountCharacter> chars = new AccountCharacter[0];

            // get the key element in the result
            XElement keyElement = result.Element(ApiConstants.Key);
            if (keyElement != null)
            {
                // get details from the attributes
                foreach (XAttribute attribute in keyElement.Attributes())
                {
                    switch (attribute.Name.LocalName)
                    {
                        case "accessMask":
                            int.TryParse(attribute.Value, out accessMask);
                            break;
                        case "type":
                            Enum.TryParse(attribute.Value, out type);
                            break;
                        case "expires":
                            DateTime temp;
                            expiry = DateTime.TryParse(attribute.Value, out temp)
                                ? new DateTimeOffset(temp, TimeSpan.Zero)
                                : default(DateTimeOffset);
                            break;
                    }
                }

                // get the character rowset that might be present in the result
                XElement characterSet = keyElement.Element(ApiConstants.Rowset);
                if (characterSet != null)
                {
                    chars = GetCharactersFromRowSet(characterSet);
                }

                keyInfo = new ApiKeyInfo {AccessMask = accessMask, ApiType = type, Expires = expiry, Characters = chars};
            }

            return keyInfo;
        }