/// <summary> /// Start a new poller /// </summary> /// <param name="poller"></param> public void PollConfirmations(ConfirmationPoller poller) { PollConfirmationsStop(); if (poller == null || poller.Duration <= 0) { return; } if (this.Session.Confirmations == null) { this.Session.Confirmations = new ConfirmationPoller(); } this.Session.Confirmations = poller; _pollerCancellation = new CancellationTokenSource(); var token = _pollerCancellation.Token; Task.Factory.StartNew(() => PollConfirmations(token), token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
/// <summary> /// Clear the session /// </summary> public void Clear() { this.OAuthToken = null; this.UmqId = null; this.Cookies = new CookieContainer(); this.Confirmations = null; }
/// <summary> /// Convert json data into session /// </summary> /// <param name="json"></param> private void FromJson(string json) { var tokens = JObject.Parse(json); var token = tokens.SelectToken("steamid"); if (token != null) { this.SteamId = token.Value<string>(); } token = tokens.SelectToken("cookies"); if (token != null) { this.Cookies = new CookieContainer(); var match = Regex.Match(token.Value<string>(), @"([^=]+)=([^;]*);?", RegexOptions.Singleline); while (match.Success == true) { this.Cookies.Add(new Cookie(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim(), "/", ".steamcommunity.com")); match = match.NextMatch(); } } token = tokens.SelectToken("oauthtoken"); if (token != null) { this.OAuthToken = token.Value<string>(); } //token = tokens.SelectToken("umqid"); //if (token != null) //{ // this.UmqId = token.Value<string>(); //} token = tokens.SelectToken("confs"); if (token != null) { this.Confirmations = ConfirmationPoller.FromJSON(token); } }
/// <summary> /// Create a new ConfirmationPoller from a JToken /// </summary> /// <param name="tokens">existing JKToken</param> /// <returns></returns> public static ConfirmationPoller FromJSON(JToken tokens) { if (tokens == null) { return null; } var poller = new ConfirmationPoller(); var token = tokens.SelectToken("duration"); if (token != null) { poller.Duration = token.Value<int>(); } token = tokens.SelectToken("action"); if (token != null) { poller.Action = (PollerAction)token.Value<int>(); } token = tokens.SelectToken("ids"); if (token != null) { poller.Ids = token.ToObject<List<string>>(); } return (poller.Duration != 0 ? poller : null); }