/// <summary> /// Subscribe to the bus this way, so that subscriptions can be cleaned up properly. /// </summary> protected void AddSubscription(SubscriberToken token) { if (_tokens == null) { _tokens = new List <SubscriberToken>(); } _tokens.Add(token); }
public Squad(ISquadConfiguration config, CardDeckConfig deckConfig) { Config = config; Deck = new CardDeck(this, deckConfig.GetCards()); var bus = ServiceLocator.Instance.GetService <IMessageBus>(); _token = bus.Subscribe <EntityKilledMessage>(OnEntityKilled); }
public Task <string> DownloadSubscriber(SubscriberToken token) { string url = $"{Constants.GetUserUrl}{token.token}"; HttpRequestMessage request = new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Get }; return(DownloadJson(request)); }
/// <summary> /// Used to log the user in. This is done i two stages: /// First stage: Use the password and email to generate a token using Jyllands-Postens LoginAPI. /// Second stage: Use the token to generate the subscriber using Jyllands-Postens LoginAPI. /// Events are then invoked to notify other classes when a subscriber is logged in/logging in failed. /// </summary> /// <param name="email"></param> /// <param name="password"></param> public async void LoginAsync(string email, string password) { try { SubscriberToken token = JsonConvert.DeserializeObject <SubscriberToken>(await _loginApi.DownloadLoginToken(email, password)); //code = 0 means email and password was correctly entered if (token.error.code == 0) { Subscriber subscriber = JsonConvert.DeserializeObject <Subscriber>(await _loginApi.DownloadSubscriber(token)); //code = 0 once again means no error occured if (subscriber.error.code == 0) { Subscriber = subscriber; LoginEventSucceeded?.Invoke(subscriber); } else { LoginEventErrorOccured?.Invoke(subscriber.error); } } else { LoginEventErrorOccured?.Invoke(token.error); } } catch (Exception ex) { Debug.Print(ex.Message); //Invoke event with a custom error text var error = new Error(); error.friendlyErrorText = "Der opstod en fejl. Måske har du ikke forbindelse til internettet?"; LoginEventErrorOccured?.Invoke(error); } }