public void Collection(CollectionQuery collection, Dictionary <string, int> imageResolutions) { collection .id() .image(pci => pci .altText() .transformedSrc() ) .title() .description() .descriptionHtml() .updatedAt() .products(pc => ProductConnection(pc), first: DefaultQueries.MaxPageSize ); foreach (string alias in imageResolutions.Keys) { collection .image(pci => pci .altText() .transformedSrc(), maxWidth: imageResolutions[alias], maxHeight: imageResolutions[alias], alias: alias ); } }
public void SpeedTesting() { LogManager.GetRepository().Threshold = Level.Off; ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level = Level.Off; ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty); log4net.LogManager.ShutdownRepository(); log4net.LogManager.Shutdown(); if (X.Instance.Debug == false) { return; } var setGuid = Guid.Parse("844d5fe3-bdb5-4ad2-0702-000000000000"); var con = DbContext.Get().Db; var byTime = Time(100, () => { //con.Query<Set>().By(x => x.Id, Op.Eq, setGuid); }); var createQueryTime = Time(100, () => { var q = new CollectionQuery <Set>(con.Config.Configurations); }); var siTime = Time(100, () => { con.Config.Configurations.First().CreateSearchIndex(); }); Console.WriteLine("Average By Time: " + byTime); Console.WriteLine("Average CreateSearchIndex Time: " + siTime); Console.WriteLine("Average Create Query Time: " + createQueryTime); }
public void SpeedTesting() { LogManager.GetRepository().Threshold = Level.Off; ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level = Level.Off; ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty); log4net.LogManager.ShutdownRepository(); log4net.LogManager.Shutdown(); if (X.Instance.Debug == false) return; var setGuid = Guid.Parse("844d5fe3-bdb5-4ad2-0702-000000000000"); var con = DbContext.Get().Db; var byTime = Time(100, () => { //con.Query<Set>().By(x => x.Id, Op.Eq, setGuid); }); var createQueryTime = Time(100, () => { var q = new CollectionQuery<Set>(con.Config.Configurations); }); var siTime = Time(100, () => { con.Config.Configurations.First().CreateSearchIndex(); }); Console.WriteLine("Average By Time: " + byTime); Console.WriteLine("Average CreateSearchIndex Time: " + siTime); Console.WriteLine("Average Create Query Time: " + createQueryTime); }
internal DictionaryProxyState(IDictionary <TKey, TValue> dictionaryToUse) : base(dictionaryToUse) { this.dictionary = dictionaryToUse; this.keys = new CollectionQueryImpl <TKey>(new CollectionState <TKey>(this.dictionary.Keys)); this.values = new CollectionQueryImpl <TValue>(new CollectionState <TValue>(this.dictionary.Values)); }
protected override Task <LoadMoreResult> LoadMoreAsync(CollectionQuery query, object continuationToken) { return(Task.Factory.StartNew(() => { int index = continuationToken == null ? 0 : int.Parse(continuationToken as string); // sleep to simulate a delay in the async code Thread.Sleep(rand.Next((int)MaxDelay.TotalMilliseconds / 2, (int)MaxDelay.TotalMilliseconds)); List <object> batch = new List <object>(); while (batch.Count < LoadBatchSize && index < serverData.Count) { if (query.Filter == null || serverData[index].Value.IndexOf(query.Filter, StringComparison.InvariantCultureIgnoreCase) >= 0) { batch.Add(serverData[index]); } index++; } foreach (var item in batch) { Assert.IsNotNull(item); } var ret = new LoadMoreResult(batch, batch.Count == 0 ? null : index < serverData.Count ? index + "" : null); return ret; })); }
public void Collection(CollectionQuery collection) { collection .id() .title() .updatedAt(); }
protected override async Task <LoadMoreResult> LoadMoreAsync(CollectionQuery query, object continuationToken) { var next = await client.ListTablesSegmentedAsync(query.Filter, continuationToken as TableContinuationToken); var result = new LoadMoreResult(next.Results.Select(r => r as object).ToList(), next.ContinuationToken); return(result); }
public async Task <Product> GetRandom() { Product product = await CollectionQuery .OrderBy(x => Guid.NewGuid()) .FirstOrDefaultAsync(); return(product); }
internal CollectionAdditionOnlyDebugView(CollectionAdditionOnlyImpl <TValue, TCollectionQuery> collection) { this._collection = ((CollectionMutable <TValue, TCollectionQuery>)collection.GetType() #if WINDOWS_PHONE_APP .GetRuntimeField("_mutable") #else .GetField("_mutable") #endif .GetValue(collection)).CQ; }
protected override async Task <LoadMoreResult> LoadMoreAsync(CollectionQuery query, object continuationToken) { BlobResultSegment next; next = await container.ListBlobsSegmentedAsync(query.Filter, true, BlobListingDetails.All, null, (continuationToken as BlobContinuationToken), new BlobRequestOptions(), new Microsoft.WindowsAzure.Storage.OperationContext()); var result = new LoadMoreResult(next.Results.Select(r => r as object).ToList(), next.ContinuationToken); return(result); }
/// <summary> /// Returns a list of up to 100 collections, given the provided paging, sorting and filtering. /// </summary> /// <param name="query">provided paging, sorting and filtering.</param> /// <returns>The new <see cref="CollectionQueryResponse"/>.</returns> public virtual async Task <CollectionQueryResponse> GetQueryCollectionsAsync(CollectionQuery query) { var req = PrepareRequest("collections/query"); HttpContent content = null; if (query != null) { var body = query.ToDictionary(); content = new JsonContent(body); } return(await ExecuteRequestAsync <CollectionQueryResponse>(req, HttpMethod.Post, content)); }
protected override async Task <LoadMoreResult> LoadMoreAsync(CollectionQuery query, object continuationToken) { var next = await client.ListContainersSegmentedAsync(continuationToken as BlobContinuationToken); var result = new LoadMoreResult(next.Results.Where (r => query.Filter == null || (r.Name.IndexOf(query.Filter, StringComparison.InvariantCultureIgnoreCase) >= 0) ).Select(r => new ContainerRecord(r) as object).ToList(), next.ContinuationToken); return(result); }
internal DictionaryWithRolesState(IDictionary <TKey, TValue> dictionary) : base(dictionary) { this.dictionary = dictionary; // Keys this.keys = new CollectionQueryImpl <TKey>(new CollectionState <TKey>(this.dictionary.Keys)); // Values CollectionState <TValue> valuesState = new CollectionState <TValue>(this.dictionary.Values); CollectionQuery <TValueImmutable> valuesIQ = new CollectionImmutableQueryImpl <TValue, TValueQuery, TValueImmutable>(valuesState); this.values = new CollectionQueryOfMutablesImpl <CollectionQueryOfQueries <CollectionQuery <TValueImmutable>, TValueQuery, TValueImmutable>, CollectionQuery <TValueImmutable>, TValue, TValueQuery, TValueImmutable>(valuesIQ, new CollectionQueryOfQueriesImpl <CollectionQuery <TValueImmutable>, TValue, TValueQuery, TValueImmutable>(valuesIQ, valuesState), valuesState); }
public static CollectionQuery <T> QueryParameters <T>(this CollectionQuery <T> query, CollectionQueryParameters queryParameters) { if (queryParameters == null) { return(query); } if (queryParameters.Skip != null) { query.Parameters(p => p.Name("$skip").Value(queryParameters.Skip.Value)); } if (queryParameters.Top != null) { query.Parameters(p => p.Name("$top").Value(queryParameters.Top.Value)); } if (queryParameters.Select != null) { if (queryParameters.Select.Any()) { query.Parameters(p => p.Name("$select").Value(string.Join(", ", queryParameters.Select))); } else { query.Parameters(p => p.Name("$select").Value("*")); } } if (queryParameters.Filter != null) { var sqlFilterBuilder = new SqlFilterBuilder(query.DatabaseDriver); var sqlFilter = sqlFilterBuilder.Build(queryParameters.Filter); query.Parameters(p => p.Name("$filter").Value(sqlFilter)); } if (queryParameters.OrderBy != null) { var sqlOrderByBuilder = new SqlOrderByBuilder(query.DatabaseDriver); var sqlOrderBy = sqlOrderByBuilder.Build(queryParameters.OrderBy); query.Parameters(p => p.Name("$orderby").Value(sqlOrderBy)); } return(query); }
//override public List<long> GetRelevantDocs(string querytext) override public Tuple <long, List <long> > GetRelevantDocs(string querytext) { long matched_query = 0; querytext = querytext.ToLower(); Query query = parser.Parse(querytext); TopDocs results = searcher.Search(query, 10000); long rank = 0; float toprank = 0f; List <long> revevantList = new List <long>(); foreach (ScoreDoc scoreDoc in results.ScoreDocs) { if (scoreDoc.Score < threshHold) { break; } Lucene.Net.Documents.Document doc = searcher.Doc(scoreDoc.Doc); long id = Convert.ToInt64(doc.Get(QID_FN).ToString()); string text = doc.Get(TEXT_FN).ToString(); CollectionQuery cq = collectionProvider.Querys[id]; Dictionary <long, CollectionPassage> cpd = collectionProvider.Passages; if (rank == 0) { toprank = scoreDoc.Score; matched_query = cq.query_id; } rank++; foreach (var pid in cq.passages_id) { if (cpd[pid].is_selected == 1) { revevantList.Add(pid); } } Console.WriteLine(rank.ToString() + ", " + text + "(" + scoreDoc.Score.ToString("0.000") + ":" + (scoreDoc.Score / toprank).ToString("0.000") + ") "); } Console.WriteLine(string.Join(", ", revevantList)); //return revevantList; return(new Tuple <long, List <long> >(matched_query, revevantList)); }
/// <summary>Initializes a new instance of the <see cref="CollectionDataGridViewModel" /> class.</summary> /// <param name="query">Optional collection query</param> /// <param name="db">Database instance.</param> /// <param name="pleaseWaitService">The please wait service.</param> /// <param name="commandManager">The command manager.</param> public CollectionDataGridViewModel( CollectionQuery query, IDatabaseAsync db, IPleaseWaitService pleaseWaitService, ICommandManager commandManager) : base(false) { Argument.IsNotNull(() => db); Argument.IsNotNull(() => pleaseWaitService); _db = db; _pleaseWaitService = pleaseWaitService; Query = query; DataPager = new DatabaseDataPager <Card>(FilterCollection, 100, db); // Search command SearchCommand = new Command(() => IsDataGridSearchVisible = !IsDataGridSearchVisible); commandManager.RegisterCommand(Commands.General.Search, SearchCommand, this); }
protected override async Task <LoadMoreResult> LoadMoreAsync(CollectionQuery query, object continuationToken) { var tableQuery = new TableQuery(); tableQuery.FilterString = query.Filter; try { var next = await table.ExecuteQuerySegmentedAsync(tableQuery, continuationToken as TableContinuationToken); var result = new LoadMoreResult(next.Results.Select(r => r as object).ToList(), next.ContinuationToken); return(result); } catch (StorageException ex) { var result = new LoadMoreResult(new List <object>(), null); return(result); } }
/// <summary>Initializes a new instance of the <see cref="BrowserQueryBuilderViewModel" /> class.</summary> /// <param name="currentQuery">Query to edit.</param> /// <param name="collectionQueryManager">The collection query manager.</param> public BrowserQueryBuilderViewModel( CollectionQuery currentQuery, CollectionQueryManagerService collectionQueryManager) : base(false) { Argument.IsNotNull(() => collectionQueryManager); Argument.IsNotNull(() => currentQuery); _collectionQueryManager = collectionQueryManager; CurrentQuery = currentQuery; RadioController = new RadioController(this); _filterBuilderViewModel = TypeFactory.Default.CreateInstanceWithParametersAndAutoCompletion( typeof(FilterBuilderViewModel), CurrentQuery) as FilterBuilderViewModel; SaveCommand = new TaskCommand(OnSaveCommandExecuteAsync, OnSaveCommandCanExecute); CancelCommand = new Command(OnCancelCommandExecute); }
public async Task <IActionResult> ExecuteCollectionQuery(CollectionQuery query) { try { var result = await _mediator .Send(query); return(Ok(result)); } catch (Exception ex) { string message = ex.Message; if (ex.GetType() == typeof(Exception)) { return(BadRequest(new { message = ex.Message })); } if (ex.GetType() == typeof(EntityNotFoundException)) { message = ((EntityNotFoundException)ex).Message; } return(NotFound(new { message = message })); } }
/// <summary>Updates database values for the specified query.</summary> /// <param name="query">The query.</param> /// <returns></returns> public async Task UpdateAsync(CollectionQuery query) { await _db.UpdateAsync(query).ConfigureAwait(false); }
/// <summary>Creates the specified current query.</summary> /// <param name="query">The current query.</param> /// <returns></returns> public async Task CreateAsync(CollectionQuery query) { await _db.InsertAsync(query).ConfigureAwait(false); CollectionQueries.Queries.Add(query); }
/// <summary> /// Will override default <see cref="Enumerable.ToArray{T}(IEnumerable{T})"/> when the target object reference type is of <see cref="CollectionQuery{T}"/> or sub-type. /// This method just calls <see cref="ToArrayCWR"/>. /// </summary> /// <typeparam name="T">The type of elements in collection.</typeparam> /// <param name="collectionQ">The <see cref="CollectionQuery{T}"/>.</param> /// <returns>The array containing same elements as <paramref name="collectionQ"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="collectionQ"/> is <c>null</c>.</exception> public static T[] ToArray <T>(this CollectionQuery <T> collectionQ) { return(ToArrayCWR(collectionQ)); }
/// <summary> /// This method is only for demo purposes /// </summary> public async Task <int> GetBookCountAsync() { return(await CollectionQuery.CountAsync()); }
internal CollectionMutableDebugView(CollectionMutableImpl <TValue, TCollectionQuery> collection) { this._collection = collection.CQ; }
internal CollectionQueryDebugView(CollectionQueryImpl <TValue> collection) { this._collection = collection; }
internal CollectionWithRolesDebugView(CollectionWithRolesImpl <TMutableQueryRole, TQueriesQueryRole, TImmutableQueryRole, TValue, TValueQuery, TValueImmutable> collection) { this._collection = collection.MQ.IQ; }
internal CollectionQueryOfQueriesDebugView(CollectionQueryOfQueriesImpl <TImmutableQueryRole, TValue, TValueQuery, TValueImmutable> collection) { this._collection = collection.IQ; }
public void LoadMoreBasic() { int expectedNumberOfItems = 95; CliMessagePump pump = new CliMessagePump(ConsoleProvider.Current, (k) => { }); TestLoadMoreDataSource dataSource = new TestLoadMoreDataSource(pump, expectedNumberOfItems, TimeSpan.FromMilliseconds(50)); var query = new CollectionQuery(0, 7, null); List <object> viewedData = new List <object>(); pump.Start(); // the first call to GetDataView should return an empty result that indicates that the view is incomplete // because it is still loading data var initialDataView = dataSource.GetDataView(query); Assert.IsFalse(initialDataView.IsViewComplete); Assert.IsFalse(initialDataView.IsViewEndOfData); Assert.AreEqual(0, initialDataView.Items.Count); // Since we're simulating the server call and we know the max amount of time it can take wait twice that long Thread.Sleep(dataSource.MaxDelay + dataSource.MaxDelay); // Now there should be a full page of data available to us var nextAttemptDataView = dataSource.GetDataView(query); Assert.AreEqual(query.Take, nextAttemptDataView.Items.Count); Assert.IsTrue(nextAttemptDataView.IsViewComplete); Assert.IsFalse(nextAttemptDataView.IsViewEndOfData); viewedData.AddRange(nextAttemptDataView.Items); query.Skip += query.Take; // now ask for data in a tight loop. Sometimes we will get more data, sometimes we'll get an empty page // while more data is being loaded while (nextAttemptDataView.IsViewEndOfData == false) { nextAttemptDataView = dataSource.GetDataView(query); Console.WriteLine(nextAttemptDataView.Items.Count + " items, viewComplete == " + nextAttemptDataView.IsViewComplete); if (nextAttemptDataView.Items.Count < query.Take && nextAttemptDataView.IsViewEndOfData == false) { Thread.Sleep(10); Assert.IsFalse(nextAttemptDataView.IsViewComplete); } else if (nextAttemptDataView.Items.Count == query.Take) { Assert.IsTrue(nextAttemptDataView.IsViewComplete); } else if (nextAttemptDataView.Items.Count > query.Take) { Assert.Fail(nextAttemptDataView.Items.Count + " should never exceed " + query.Take); } viewedData.AddRange(nextAttemptDataView.Items); query.Skip += nextAttemptDataView.Items.Count; } int nextExpectedId = 0; foreach (var item in viewedData) { Assert.IsNotNull(item); Console.WriteLine(item); Assert.AreEqual(nextExpectedId++, ((Item)item).Id); } Assert.AreEqual(expectedNumberOfItems, viewedData.Count); console.InputQueue.Enqueue(new ConsoleKeyInfo(' ', ConsoleKey.Escape, false, false, false)); }
internal CollectionImmutableQueryDebugView(CollectionQuery <TValueImmutable> collectionIQ) { this._collection = collectionIQ; }