Example #1
0
        /// <summary>
        /// Requests the <see cref="ValidateUrl"/> and updates user registration.
        /// </summary>
        /// <param name="key">Given license key or email of the subscription.</param>
        /// <param name="url">Current website URL.</param>
        /// <param name="data">Received and validate data.</param>
        /// <returns></returns>
        bool TryRequestUserValidation(string key, string url, out ValidationData data)
        {
            if (!string.IsNullOrEmpty(key) && url != null)
            {
                var req = (HttpWebRequest)WebRequest.Create(string.Format(ValidateUrl, key, url));
                req.Timeout = 5 * 1000;

                try
                {
                    using var r = (HttpWebResponse)req.GetResponse();

                    if (r.StatusCode == HttpStatusCode.OK)
                    {
                        using var reader = new StreamReader(r.GetResponseStream());

                        data = ValidationData.FromJson(reader.ReadToEnd(), key);
                        return(true);
                    }
                }
                catch { }
            }

            //
            data = default;
            return(false);
        }