public override void Start() { var w = this.web; w.Run <xofz.Framework.Timer>(t => { w.Run <EventRaiser>(er => { w.Run <Messages>(messages => { var waitingMessage = messages.Waiting; UiHelpers.Write( this.ui, () => { this.ui.HasteRating = waitingMessage; this.ui.HastePercentage = waitingMessage; }); }); er.Raise( t, nameof(t.Elapsed)); }); t.Start(TimeSpan.FromMinutes(5)); }, "HomeTimer"); }
public void Setup() { if (Interlocked.CompareExchange(ref this.setupIf1, 1, 0) == 1) { return; } var w = this.web; w.Run <EventSubscriber>(subscriber => { subscriber.Subscribe( this.ui, nameof(this.ui.ExitRequested), this.ui_ExitRequested); w.Run <xofz.Framework.Timer>(t => { subscriber.Subscribe( t, nameof(t.Elapsed), this.timer_Elapsed); }, "HomeTimer"); }); w.Run <GlobalSettingsHolder>(s => { var charName = s.CharacterName; UiHelpers.Write( this.ui, () => this.ui.CharacterName = charName); }); w.Run <VersionReader>(vr => { var version = vr.Read(); var coreVersion = vr.ReadCoreVersion(); UiHelpers.Write( this.ui, () => { this.ui.Version = version; this.ui.CoreVersion = coreVersion; }); }); w.Run <Navigator>(n => n.RegisterPresenter(this)); }
private void timer_Elapsed() { var h = this.timerHandlerFinished; h.Reset(); var w = this.web; w.Run < HttpClientFactory, GlobalSettingsHolder, Messages>((factory, settings, messages) => { var errorMessage = messages.Error; string hasteRating; string hastePercentage; using (var client = factory.Create()) { var uri = new StringBuilder() .Append("https://") .Append(settings.Location) .Append(".api.battle.net/wow/character/") .Append(settings.Realm) .Append('/') .Append(settings.CharacterName) .Append("?fields=stats") .Append("&locale=en_US") .Append("&apikey=") .Append(settings.PublicApiKey) .ToString(); client.Timeout = TimeSpan.FromMilliseconds(10000); Task <string> readHasteTask; try { readHasteTask = client.GetStringAsync(uri); readHasteTask.Wait(); } catch { hasteRating = errorMessage; hastePercentage = errorMessage; goto setHaste; } HasteResponseData data; try { var json = readHasteTask.Result; data = JsonConvert.DeserializeObject <HasteResponseData>(json); } catch { hasteRating = errorMessage; hastePercentage = errorMessage; goto setHaste; } hasteRating = data ?.stats ?.hasteRating .ToString() ?? errorMessage; hastePercentage = data ?.stats ?.haste .ToString() ?? errorMessage; if (hastePercentage != errorMessage) { hastePercentage += ' '; hastePercentage += '%'; } setHaste: UiHelpers.Write( this.ui, () => { this.ui.HasteRating = hasteRating; this.ui.HastePercentage = hastePercentage; }); } }); h.Set(); }