protected virtual async Task EnsureIsLoadedAsync(CancellationToken cancellationToken = default) { if (_list == null) { if (SourceQuery is not IAsyncEnumerable <T> ) { // Don't call EF's async extension methods if query is not IAsyncEnumerable<T> EnsureIsLoaded(); return; } if (_totalCount == null) { _totalCount = await SourceQuery.CountAsync(cancellationToken); } if (_queryIsPagedAlready) { _list = await SourceQuery.ToListAsync(cancellationToken); } else { _list = await ApplyPaging().ToListAsync(cancellationToken); } } }
public async Task <int> GetTotalCountAsync() { if (!_totalCount.HasValue) { _totalCount = await SourceQuery.CountAsync(); } return(_totalCount.Value); }
public async Task ScanAllAsync(CancellationToken cancel = default) { var sources = await _sourceRepository.GetAsync(SourceQuery.GetAll(), cancel); var buffer = new Byte[32768]; var http = _clientFactory.CreateClient(); http.Timeout = TimeSpan.FromSeconds(5); var now = DateTime.Now; var pageSize = 1000; var totalPages = (Int32)Math.Ceiling(sources.TotalCount / (Double)pageSize); for (var i = 1; i < totalPages; i++) { Parallel.ForEach(sources.Items, source => { if (source.LastScanDate.HasValue && (source.LastScanDate.Value - DateTime.Now).TotalHours < 5) { return; } source.LastScanDate = now; try { _logger.LogInformation($"Try to get live for : {source.Title}"); var stream = http.GetStreamAsync(source.Url) .GetAwaiter() .GetResult(); var tokenSource = new CancellationTokenSource(); tokenSource.CancelAfter(TimeSpan.FromSeconds(5)); var bytesFromStream = stream.ReadAsync(buffer, tokenSource.Token) .GetAwaiter() .GetResult(); source.FrameSize = bytesFromStream; _logger.LogInformation($"Frame for {source.Title} | {source.Url} : {source.FrameSize}"); } catch (Exception e) { _logger.LogError(e, $"Error on source scanning {source.Title}"); } }); await _sourceRepository.UpdateRange(sources.Items, cancel); sources = await _sourceRepository.GetAsync(new SourceQuery(i * pageSize, pageSize), cancel); } _logger.LogInformation("Complete sources scaning"); }
protected void Download(string[] cmdHandles, SourceQuery query, CmdToParam toParam) { foreach (string handle in cmdHandles) { if (config.CheckAutoMode(handle) == AutoMode.AUTO) { Console.WriteLine($"Downloading data for {handle}..."); persistence.Persist(handle, query(toParam(handle))); } } }
//Get Server Query class to JSON string. private static string GetQueryInfo(List <string[]> request, int serverID) { Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID); if (server == null) { return("Server with id " + serverID + " not found"); } SourceQuery query = new SourceQuery(); return(new JavaScriptSerializer().Serialize(query.GetServerInfo(server.QueryParams.IPAddress, server.QueryParams.Port))); }
public async Task <Page <String> > GetAggregationTitlesAsync(SourceQuery query, CancellationToken cancel = default) { var allSources = await GetAllSourcesFromFileAsync(cancel); var aggregateByTitle = allSources.Values.GroupBy(x => x.Title.ToLowerInvariant()) .Select(x => x.Key) .ToList(); return(new Page <String> { TotalCount = aggregateByTitle.Count, Items = aggregateByTitle.Skip(query.Offset) .Take(query.Limit) .ToList() }); }
private async Task EnsureIsLoadedAsync() { if (_list == null) { if (_totalCount == null) { _totalCount = await SourceQuery.CountAsync(); } if (_queryIsPagedAlready) { _list = await SourceQuery.ToListAsync(); } else { _list = await ApplyPaging(SourceQuery).ToListAsync(); } } }
private void EnsureIsLoaded() { if (_list == null) { if (_totalCount == null) { _totalCount = SourceQuery.Count(); } if (_queryIsPagedAlready) { _list = SourceQuery.ToList(); } else { _list = ApplyPaging(SourceQuery).ToList(); } } }
private async Task EnsureIsLoadedAsync(CancellationToken cancellationToken = default) { if (_list == null) { if (_totalCount == null) { _totalCount = await SourceQuery.CountAsync(cancellationToken); } if (_queryIsPagedAlready) { _list = await SourceQuery.ToListAsync(cancellationToken); } else { _list = await ApplyPaging(SourceQuery).ToListAsync(cancellationToken); } } }
protected virtual void EnsureIsLoaded() { if (_list == null) { if (_totalCount == null) { _totalCount = SourceQuery.Count(); } if (_queryIsPagedAlready) { _list = SourceQuery.ToList(); } else { _list = ApplyPaging().ToList(); } } }
public async Task <Page <Source> > GetAsync(SourceQuery query, CancellationToken cancel = default) { var allSources = await GetAllSourcesFromFileAsync(cancel); if (!String.IsNullOrEmpty(query.Search)) { allSources = allSources.Values.Where(x => x.Title.Contains(query.Search, StringComparison.OrdinalIgnoreCase)) .ToDictionary(x => x.Id); } return(new Page <Source> { TotalCount = allSources.Count, Items = allSources.Skip(query.Offset) .Take(query.Limit) .Select(x => x.Value) .ToList() }); }
public Task <Page <String> > GetAggregationTitlesAsync(SourceQuery query, CancellationToken cancel = default) { return(_sourceRepository.GetAggregationTitlesAsync(query, cancel)); }
public async Task SetSourcesToAllChannelsAsync(CancellationToken cancel = default) { // var pageSize = 500; // var channels = await _channelRepository.GetAsync(new ChannelQuery(0, pageSize), cancel); // var totalPages = (Int32) (Math.Ceiling(channels.TotalCount / (Double) pageSize)); // for (var i = 1; i < totalPages; i++) // { // } var allChannels = await _channelRepository.GetAsync(ChannelQuery.GetAll(), cancel); var allSourcesAggregated = await _sourceRepository.GetAggregationByTitleAsync(SourceQuery.GetAll(), cancel); var sources = allSourcesAggregated.Items.ToDictionary(x => x.Title, v => v.Sources); foreach (var channel in allChannels.Items) { if (channel.LockSourceUrl) { continue; } var titleLower = channel.Title.ToLowerInvariant(); List <Source> processingSources = new List <Source>(1); if (sources.ContainsKey(titleLower)) { processingSources = sources[titleLower]; } if (channel.AlternativeTitles.IsNotEmpty()) { foreach (var alternativeTitle in channel.AlternativeTitles) { var alternativeTitleLower = alternativeTitle.ToLowerInvariant(); { if (sources.ContainsKey(alternativeTitleLower)) { processingSources.AddRange(sources[alternativeTitleLower]); } } } } processingSources = processingSources.Where(x => x.FrameSize > 0).ToList(); if (processingSources.IsEmpty()) { continue; } var actualSource = processingSources.OrderBy(x => x.PriorityNumber) .ThenByDescending(x => x.LastScanDate) .ThenByDescending(x => x.FrameSize) .First(); channel.CurrentSourceUrl = actualSource.Url; await _channelRepository.UpdateAsync(channel, cancel); } }
public ISqlExpression?Walk(WalkOptions options, Func <ISqlExpression, ISqlExpression> func) { return(SourceQuery?.Walk(options, func)); }