using static MFiles.Grpc.Samples.MFilesValues; namespace MFiles.Grpc.Samples.Recipes; /// /// Recipe "read-object": an object's latest version and its properties as typed values. /// Arguments: [object ID, default 437] [object type, default 0 (document)] /// public static class ReadObject { public static async Task RunAsync(MFilesSettings settings, string[] args) { int id = RecipeHelpers.IntArg(args, 0, 437); int objectType = RecipeHelpers.IntArg(args, 1, 0); await using var connection = await MFilesConnection.ConnectAsync(settings, RecipeHelpers.ClientName); // [START read-object] // Property names, by ID. A real application caches these (they change rarely). var propertyDefs = new IRPCPropertyDefs.IRPCPropertyDefsClient(connection.CallInvoker); var names = (await propertyDefs.GetPropertyDefsAsync(new GetPropertyDefsRequest())) .PropertyDefs.ToDictionary(p => p.Id, p => p.Name); // The latest version and its properties in one call. var objects = new IRPCObjectOperations.IRPCObjectOperationsClient(connection.CallInvoker); var response = await objects.GetObjectInfoAndPropertiesAsync(new GetObjectInfoAndPropertiesRequest { ObjId = ObjId(objectType, id), LatestVersion = true, }); Console.WriteLine(RecipeHelpers.Describe(response.ObjectInfo)); foreach (var property in response.PropertyArray) { string name = names.GetValueOrDefault(property.PropertyDef, "?"); Console.WriteLine($" {name} ({property.PropertyDef}): {RecipeHelpers.FormatValue(property.Value)}"); } // [END read-object] } }