public IDictionary <DateTime, Stat> GetStats(int histoDeepth) { var minDate = DateTime.Today.AddDays(-histoDeepth); var stats = Enumerable.Range(0, histoDeepth + 1) .ToSortedDictionary(d => minDate.AddDays(d), d => new Stat()); var filter = new HostFilteringParameters(minDate); var hosts = this.hostService.LoadHost(filter); foreach (var host in hosts) { stats.GetOrAddValue(host.SubscriptionDate.Date).SubscribedHosts++; foreach (var license in host.Licenses) { stats.GetOrAddValue(license.InstallationDate.Date).CollectedHosts++; foreach (var confirmation in license.Confirmations.Where(s => s.Status == Status.Success)) { stats.GetOrAddValue(confirmation.ResponseDate.Date).AvailableConfirmations++; } } var succesStatus = host.ProcessingStatus.FirstOrDefault(x => x.Message.Contains("activated")); if (succesStatus != null) { stats.GetOrAddValue(succesStatus.StatusDate.Date).ActivatedHosts++; } } return(stats); }
public byte[] GetReportAsMemoryStream(HostFilteringParameters hostFiltringParameters) { var stringBuilder = new StringBuilder(); var hosts = this.hostService.LoadHost(hostFiltringParameters); stringBuilder.AppendLine($"Id;Name;Mail;Site;SubscriptionDate;InstallationId;ProductId;InstallationDate;ConfirmationKey;ConfirmationDate;Status;StatusDate"); foreach (var host in hosts) { var prefix = $"{host.Id};{ host.Name};{ host.Mail};{ host.Site};{host.SubscriptionDate.ToString("dd/MM/yyyy HH:mm:ss")}"; if (host.Licenses.Count > 0) { foreach (var license in host.Licenses) { prefix = $"{prefix};{ license.InstallationId};{ license.ExtendedProductId};{license.InstallationDate.ToString("dd/MM/yyyy HH:mm:ss")}"; var confirmations = license.Confirmations.Where(x => x.Status == Status.Success); if (confirmations.Any()) { foreach (var confirmation in confirmations) { prefix = $"{prefix};{confirmation.Content};{confirmation.ResponseDate}"; var successStatus = host.ProcessingStatus.FirstOrDefault(x => x.Status == Status.Success); if (successStatus != null) { stringBuilder.AppendLine($"{prefix};{successStatus.Message};{successStatus.StatusDate.ToString("dd/MM/yyyy HH:mm:ss")}"); } else { stringBuilder.AppendLine(prefix); } } } else { stringBuilder.AppendLine(prefix); } } } else { var status = host.ProcessingStatus.LastOrDefault(x => !x.Message.Contains("activated")); if (status != null) { stringBuilder.AppendLine($"{prefix};;;;;;{status.Message};{status.StatusDate.ToString("dd/MM/yyyy HH:mm:ss")}"); } else { stringBuilder.AppendLine(prefix); } } } return(Encoding.ASCII.GetBytes(stringBuilder.ToString())); }
public async Task <ActionResult <List <Host> > > GetHost([FromQuery] HostFilteringParameters filter) { this.logger.LogInformation($"Loading hosts where {filter?.ToString()}"); var hosts = await this.hostService.LoadHostAsync(filter); if (hosts.Count == 0) { return(NotFound()); } return(Ok(hosts)); }
public async Task <ActionResult <List <object> > > GetAllStatus(HostFilteringParameters filteringParameters) { filteringParameters.WithLicenses = false; filteringParameters.WithStatus = true; var hosts = await hostService.LoadHostAsync(); if (hosts.Count > 0) { return(Ok(hosts.Select(h => new { h.Name, h.Id, h.ProcessingStatus }))); } return(NotFound()); }
public FileContentResult Get([FromQuery] HostFilteringParameters hostFiltringParameters) { var content = this.hostReportProvider.GetReportAsMemoryStream(hostFiltringParameters); return(File(content, "application/octet-stream", "Hosts.csv")); }
private IQueryable <Host> GetHostQuery(HostFilteringParameters filtringParameters = null) { var query = this.context.Hosts.AsQueryable(); if (filtringParameters == null) { return(query .Include(x => x.ProcessingStatus) .Include(x => x.Licenses) .ThenInclude(l => l.Confirmations) .Include(x => x.Licenses) .ThenInclude(l => l.ActivatedLicense)); } if (filtringParameters.MinDate > DateTime.MinValue) { query = query.Where(x => x.SubscriptionDate >= filtringParameters.MinDate); if (filtringParameters.MaxDate >= filtringParameters.MinDate) { query = query.Where(x => x.SubscriptionDate <= filtringParameters.MaxDate); } } if (!string.IsNullOrEmpty(filtringParameters.Name)) { query = query.Where(x => x.Name.StartsWith(filtringParameters.Name)); } if (!string.IsNullOrEmpty(filtringParameters.Mail)) { query = query.Where(x => x.Mail.StartsWith(filtringParameters.Mail)); } if (!string.IsNullOrEmpty(filtringParameters.Site)) { query = query.Where(x => x.Site.StartsWith(filtringParameters.Site)); } if (!string.IsNullOrEmpty(filtringParameters.Network)) { query = query.Where(x => x.Network.StartsWith(filtringParameters.Network)); } if (filtringParameters.Offset > 0) { query = query.Skip(filtringParameters.Offset); } if (filtringParameters.Limit > 0) { query = query.Take(filtringParameters.Limit); } if (filtringParameters.WithStatus) { query = query.Include(x => x.ProcessingStatus); } if (filtringParameters.WithLicenses) { var temp = query.Include(x => x.Licenses).ThenInclude(x => x.ActivatedLicense); if (filtringParameters.WithConfirmations) { query = temp.Include(x => x.Licenses) .ThenInclude(l => l.Confirmations); } else { query = temp; } } return(query); }
public List <Host> LoadHost(HostFilteringParameters filtringParameters = null) { return(this.LoadHostAsync(filtringParameters).Result); }
public async Task <List <Host> > LoadHostAsync(HostFilteringParameters filtringParameters = null) { var query = this.GetHostQuery(filtringParameters); return(await query.ToListAsync()); }