private ApiState StartRequest(ApiState state, Action.IQueryStart action) { state.isLoaded = false; state.isLoading = true; state.isError = false; return(state); }
public async Task <bool> LoginAsync(string pUsername, string pPassword, bool pRememberMe = false) { if (string.IsNullOrWhiteSpace(pUsername) || string.IsNullOrWhiteSpace(pPassword)) { return(false); } Credentials lCredentials = new Credentials { Username = pUsername, Password = pPassword }; ApiState lState = await CheckCredentials(lCredentials); if (lState == null) { return(false); } if (pRememberMe) { await _OptionService.SetOptionAsync(nameof(Credentials), lCredentials); } else { await _OptionService.DeleteOptionAsync(nameof(Credentials)); } _State = lState; return(true); }
private ApiState RequestFailure(ApiState state, Action.IQueryFailure action) { state.isLoaded = true; state.isLoading = false; state.isError = true; state.text = null; state.error = action.error; return(state); }
private ApiState RequestSuccess(ApiState state, Action.IQuerySuccess action) { state.isLoaded = true; state.isLoading = false; state.isError = false; state.text = action.text; state.error = null; return(state); }
// ---------------- Constructor ---------------- /// <summary> /// Constructor. /// </summary> /// <param name="dbPath">The path to the database file.</param> /// <param name="settingsFile">Path to the settings file.</param> public MeditationLoggerApi(string dbPath, string settingsFile) { this.currentSession = null; this.currentState = ApiState.Idle; this.LogbookFileLocation = dbPath; this.LogBook = new LogBook(this.LogbookFileLocation); this.Settings = new SettingsManager(); this.SettingsFileLocation = settingsFile; this.Settings.OnUpdated += Settings_OnUpdated; this.currentStateLock = new object(); }
public void Setup() { // create private container container_ = new DiContainer(); container_.Bind <Reducer>().AsSingle(); // set up mock settings var mockSettings = new Settings { }; container_.Bind <Settings>().FromInstance(mockSettings); // set default state mockApiState_ = new ApiState { }; reducer_ = container_.Resolve <Reducer>(); }
public Task StartAsync(CancellationToken cancellationToken) { Console.WriteLine("STARTING GREEN TIMER"); //Getting a integer back. This is a number of how many api calls are made ... If api call is made it increments by 1 PulseCheckBegin = _piManager.GetPulse(); Console.WriteLine($"PulseCheckerBegin: {PulseCheckBegin}"); apiStatus = ApiState.APICallIsNotMadeFirstTry; // change 10_000 = 10 sec, 60_000 = 1 min // first 10_000 = delay when it should start executing the CheckForAPICallEvert120seconds method // the second 10_000 is when it should execute over and over // press ctrl + shift to check method explanation _timerGreen = new Timer(CheckForAPICallEvery120Seconds, null, 60_000, 60_000); return(Task.CompletedTask); }
void CheckForAPICallEvery120Seconds(object state) { // getting after x seconds how many appi calls are made PulseCheckAfter = _piManager.GetPulse(); // checks if there are api calls made. If they have the same number there is no API call made. if (PulseCheckAfter > PulseCheckBegin) { Console.WriteLine($"PulseCheckerAfter: {PulseCheckAfter}"); apiStatus = ApiState.APICallIsMade; Console.WriteLine("GreenLight Should be on"); Console.WriteLine("Red light should be off"); } //if there is no api call made else { //changing the state and/or turn on red light if (apiStatus == ApiState.APICallIsMade) { apiStatus = ApiState.APICallIsNotMadeFirstTry; } else if (apiStatus == ApiState.APICallIsNotMadeFirstTry) { apiStatus = ApiState.APICallIsNotMadeSecondTry; Console.WriteLine("1 min should be passed"); } else if (apiStatus == ApiState.APICallIsNotMadeSecondTry) { Console.WriteLine("2 mins should be passed"); Console.WriteLine("turned red light on"); _piManager.TurnLightOn(Colors.red); _piManager.TurnLightOff(Colors.green); //Changes timer to 2 minutes so it keeps.. //.. sending a turn red light on message every 2 minutes instead of 1 minute // 20_000 = 20 seconds. // 120_0000 = 120 seconds _timerGreen.Change(120_000, 120_000); } } PulseCheckBegin = _piManager.GetPulse(); Console.WriteLine("Pulse begin: " + PulseCheckBegin + " " + " Pulse afteR: " + PulseCheckAfter + " State: " + apiStatus); }
public ApiState Reduce(ApiState state, IAction action) { // start request for any http request if (action is Action.IQueryStart) { return(StartRequest(state, (Action.IQueryStart)action)); } if (action is Action.IQuerySuccess) { return(RequestSuccess(state, (Action.IQuerySuccess)action)); } if (action is Action.IQueryFailure) { return(RequestFailure(state, (Action.IQueryFailure)action)); } return(state); }
public async Task <bool> IsLoggedInAsync() { if (_State != null) { return(true); } Credentials lCredentials = await _OptionService.GetOptionAsync <Credentials>(nameof(Credentials)); if (lCredentials == null) { return(false); } ApiState lState = await CheckCredentials(lCredentials); if (lState == null) { return(false); } _State = lState; return(true); }
public ApiResult(string message = "", ApiState state = ApiState.Success) { Message = message; State = state; }
public async Task LogoutAsync() { _State = null; await _OptionService.ClearOptionsAsync(); }