コード例 #1
0
        internal async Task <HashSet <Confirmation> > GetConfirmations()
        {
            if (!HasValidDeviceID)
            {
                return(null);
            }

            uint time = await GetSteamTime().ConfigureAwait(false);

            if (time == 0)
            {
                return(null);
            }

            string confirmationHash = GenerateConfirmationHash(time, "conf");

            if (string.IsNullOrEmpty(confirmationHash))
            {
                return(null);
            }

            await LimitConfirmationsRequestsAsync().ConfigureAwait(false);

            using IDocument htmlDocument = await WebHandler.GetConfirmations(DeviceID, confirmationHash, time).ConfigureAwait(false);

            if (htmlDocument == null)
            {
                return(null);
            }

            HashSet <Confirmation> result = new HashSet <Confirmation>();

            List <IElement> confirmationNodes = htmlDocument.SelectNodes("//div[@class='mobileconf_list_entry']");

            if (confirmationNodes.Count == 0)
            {
                return(result);
            }

            foreach (IElement confirmationNode in confirmationNodes)
            {
                string idText = confirmationNode.GetAttributeValue("data-confid");

                if (string.IsNullOrEmpty(idText))
                {
                    return(null);
                }

                if (!ulong.TryParse(idText, out ulong id) || (id == 0))
                {
                    return(null);
                }

                string keyText = confirmationNode.GetAttributeValue("data-key");

                if (string.IsNullOrEmpty(keyText))
                {
                    return(null);
                }

                if (!ulong.TryParse(keyText, out ulong key) || (key == 0))
                {
                    return(null);
                }

                string creatorText = confirmationNode.GetAttributeValue("data-creator");

                if (string.IsNullOrEmpty(creatorText))
                {
                    return(null);
                }

                if (!ulong.TryParse(creatorText, out ulong creator) || (creator == 0))
                {
                    return(null);
                }

                string typeText = confirmationNode.GetAttributeValue("data-type");

                if (string.IsNullOrEmpty(typeText))
                {
                    return(null);
                }

                if (!Enum.TryParse(typeText, out EType type) || (type == EType.Unknown))
                {
                    return(null);
                }

                if (!Enum.IsDefined(typeof(EType), type))
                {
                    return(null);
                }

/*				if (acceptedType.HasValue && (acceptedType.Value != type)) {
 *                                      continue;
 *                              }
 */
                result.Add(new Confirmation(id, key, creator, type));
            }

            return(result);
        }