using static MFiles.Grpc.Samples.MFilesValues; namespace MFiles.Grpc.Samples.Recipes; /// /// Recipe "search": documents of one class modified in the last N days, newest first. /// Arguments: [class ID, default 1 "Other Document"] [days, default 30] [limit, default 10] /// public static class Search { public static async Task RunAsync(MFilesSettings settings, string[] args) { int classId = RecipeHelpers.IntArg(args, 0, 1); int days = RecipeHelpers.IntArg(args, 1, 30); int limit = RecipeHelpers.IntArg(args, 2, 10); await using var connection = await MFilesConnection.ConnectAsync(settings, RecipeHelpers.ClientName); // [START search] var since = DateTime.UtcNow.AddDays(-days); var request = new SearchObjectsRequest { // One array: all its conditions must match. Conditions = { new SearchConditionArray { Value = { IsObjectType(0), // documents IsNotDeleted(), // Property 100 "Class" is a lookup into value list 1, the classes. PropertyCondition(100, ConditionType.Equal, Lookup(1, classId)), // Property 21 "Last modified" is a timestamp. PropertyCondition(21, ConditionType.GreaterThanOrEqual, Timestamp(since)), }, }, }, // Newest first. The server sorts all matches, then returns the first `limit`. Sorting = new SearchResultsSorting { Rules = new SortRuleValueArray { Values = { new SortRule { Key = 21, Options = new SortRuleFlags { SortDescending = true } } }, }, }, Limit = (uint)limit, }; var search = new IRPCSearch.IRPCSearchClient(connection.CallInvoker); var response = await search.SearchObjectsAsync(request); // [END search] Console.WriteLine($"Documents of class {classId} modified since {since:yyyy-MM-dd}: {response.Results.Count}" + (response.HasMoreResults ? $" (limited to {limit}; more exist)" : "")); foreach (var item in response.Results) Console.WriteLine(" " + RecipeHelpers.Describe(item.Object)); } }