public override async Task <int> ExecuteAsync(CommandContext context, ImportCommandSettings settings) { var sourceSettings = _settings.GetSubscription(settings.Subscription); await _apiClient.Authenticate(sourceSettings).ConfigureAwait(false); var reader = new ImportDataReader(); try { var data = reader.ReadExcel(settings.Path); var success = await ProcessDefinitions(settings.Tenant, settings.Environment, data).ConfigureAwait(false); if (!success) { return((int)StatusCodes.UnknownError); } Console.WriteLine($"Successfully imported data to tenant \"{settings.Tenant}\"."); return((int)StatusCodes.Success); } catch (Exception ex) { Console.WriteLine($"Error in importation : {ex.GetBaseException().Message}."); return((int)StatusCodes.UnknownError); } }
public override async Task <int> ExecuteAsync(CommandContext context, AddCommandSettings settings) { var sourceSettings = _settings.GetSubscription(settings.Subscription); await _apiClient.Authenticate(sourceSettings).ConfigureAwait(false); return(await AddUserToRole(_apiClient, settings.Tenant, settings.Username, settings.Role, settings.Environment).ConfigureAwait(false)); }
public override async Task <int> ExecuteAsync(CommandContext context, AddCommandSettings settings) { if (string.IsNullOrWhiteSpace(settings.Name)) { settings.Name = settings.Code; } var sourceSettings = _settings.GetSubscription(settings.Subscription); await _apiClient.Authenticate(sourceSettings).ConfigureAwait(false); return(await CreateTenant(_apiClient, settings.Code, settings.Name).ConfigureAwait(false)); }
public override async Task <int> ExecuteAsync(CommandContext context, ImportCommandSettings settings) { var sourceSettings = _settings.GetSubscription(settings.Subscription); await _apiClient.Authenticate(sourceSettings).ConfigureAwait(false); if (settings.Build) { return(await _zipImporter.ImportAndBuild(settings.Tenant, settings.Environment, settings.Path).ConfigureAwait(false)); } return(await _zipImporter.Import(settings.Tenant, settings.Environment, settings.Path).ConfigureAwait(false)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { string token = await _apiClient.Authenticate(Input.Username, Input.Password); if (!string.IsNullOrEmpty(token)) { HttpContext.Response.Cookies.Append("token", token.Encrypt()); HttpContext.Response.Cookies.Append("user", Input.Username); return(Redirect("~/")); } ModelState.AddModelError(string.Empty, "Invalid username or password."); return(Page()); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Delay(5000); var token = await _apiClient.Authenticate(); while (!stoppingToken.IsCancellationRequested) { try { var portfolio = await _apiClient.GetPortfolio(token); var currencies = await _apiClient.GetCurrencies(token); var euroId = currencies.Single(x => x.Name == "Euro"); var bestCurrencyId = _exchangeTrend.GetBest(); var worstCurrencyId = _exchangeTrend.GetWorst(); if (bestCurrencyId != Guid.Empty && worstCurrencyId != Guid.Empty) { var worstCurrency = portfolio.Currencies.Single(x => x.CurrencyId == worstCurrencyId); if (worstCurrency.Amount == 0M) { worstCurrency = portfolio.Currencies.Single(x => x.CurrencyId == euroId.Id); worstCurrencyId = worstCurrency.CurrencyId; } var buy = new BuyCurrencyRequest { FromCurrencyId = worstCurrencyId, ToCurrencyId = bestCurrencyId, FromAmount = worstCurrency.Amount / 3M }; await _apiClient.BuyCurrency(token, buy); } } catch (Exception ex) { _logger.LogError(ex.Message); } await Task.Delay(1000, stoppingToken); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { if (ModelState.IsValid) { var user = new User { Name = Input.Name, Surname = Input.Surname, Login = Input.Email.Substring(0, Input.Email.IndexOf('@')), Email = Input.Email, PasswordHash = Input.Password, DateRegistered = DateTime.Now }; var result = await _apiClient.AddUserAsync(user); if (result) { string token = await _apiClient.Authenticate(user.Login, Input.Password); if (!string.IsNullOrEmpty(token)) { HttpContext.Response.Cookies.Append("token", token.Encrypt()); HttpContext.Response.Cookies.Append("user", user.Email); return(Redirect("~/")); } return(Redirect("~/Account/Login")); } else { ModelState.AddModelError(string.Empty, "User with this Email address has been already registered"); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }
public bool Authenticate(string email, string password) { return(client.Authenticate(email, password)); }
public override async Task <int> ExecuteAsync(CommandContext context, ApplyCommandSettings settings) { var sourceSettings = _settings.GetSubscription(settings.Subscription); await _apiClient.Authenticate(sourceSettings).ConfigureAwait(false); IEnumerable <Task <(string name, Entity entity)> > processFileTasks = ProcessEntityBehaviours(settings.Path).Union( ProcessDataBehaviours(settings.Path) ); var entities = await Task.WhenAll(processFileTasks).ConfigureAwait(false); var applicationBehaviours = await Task.WhenAll(ProcessApplicationBehaviours(settings.Path)).ConfigureAwait(false); var stateMachines = await Task.WhenAll(ProcessStates(settings.Path)).ConfigureAwait(false); var webComponents = await Task.WhenAll(ProcessWebComponents(settings.Path)).ConfigureAwait(false); var uiBehaviours = await Task.WhenAll(ProcessUIBehaviours(settings.Path)).ConfigureAwait(false); var themes = await Task.WhenAll(ProcessThemes(settings.Path)).ConfigureAwait(false); var queries = await Task.WhenAll(ProcessQueries(settings.Path)).ConfigureAwait(false); var tasks = entities.GroupBy(g => g.name) .Select(g => ApplyEntityChanges(settings.Tenant, settings.Environment, g.Key, new Entity(g.First().entity.Namespace, g.SelectMany(e => e.entity?.EntityBehaviours).ToList(), g.SelectMany(e => e.entity?.DataBehaviours).ToList(), g.SelectMany(e => e.entity?.Usings).ToList()) ) ).ToList(); tasks.AddRange(applicationBehaviours .Select(g => ApplyApplicationBehaviourChanges(settings.Tenant, settings.Environment, g.name, g.entity) )); tasks.AddRange(stateMachines .Select(st => ApplyStateMachineChanges(settings.Tenant, settings.Environment, st.name, st.entity) )); tasks.AddRange(webComponents .Select(g => ApplyWebComponentChanges(settings.Tenant, settings.Environment, g.name, g.entity) )); tasks.AddRange(uiBehaviours .Select(g => ApplyUIBehavioursChanges(settings.Tenant, settings.Environment, g.name, g.entity) )); tasks.AddRange(themes .Select(g => ApplyThemeChanges(settings.Tenant, settings.Environment, g.name, g.entity) )); tasks.AddRange(queries .Select(g => ApplyQueryChanges(settings.Tenant, settings.Environment, g.name, g.entity) )); await Task.WhenAll(tasks).ConfigureAwait(false); var codeDependencies = await ProcessCodeDependencies(settings.Path).ConfigureAwait(false); var fileDependencies = await ProcessFileDependencies(settings.Path).ConfigureAwait(false); await ApplyDependenciesChanges(settings.Tenant, settings.Environment, codeDependencies, fileDependencies).ConfigureAwait(false); if (settings.Build) { await _apiClient.BuildModel(settings.Tenant, settings.Environment).ConfigureAwait(false); } AnsiConsole.MarkupLine($"[green]Successfully applied to tenant \"{settings.Tenant}\" model.[/]"); return((int)StatusCodes.Success); }