Ejemplo n.º 1
0
        /// <summary>
        /// Uses the helper library to execute a search by display/external id.
        /// </summary>
        static void UseLibrary()
        {
            // Declare variables for our vault connection.
            Vault vault;
            MFilesServerApplication application;

            // The default connection (localhost, tcp, current Windows user) will suffice.
            var connectionDetails = new ConnectionDetails();

            // Connect to the vault.
            connectionDetails.ConnectToVaultAdministrative(
                Program.sampleVaultGuid,
                out vault, out application);

            // Create the basic search conditions collection.
            var searchConditions = new SearchConditions();

            // Add a condition for the display Id.
            searchConditions.AddDisplayIdSearchCondition(Program.customerDisplayId);

            // Search.
            var results = vault.ObjectSearchOperations.SearchForObjectsByConditions(searchConditions,
                                                                                    MFSearchFlags.MFSearchFlagNone, SortResults: false);

            // Output the number of items matching (should be one in each object type, at a maximum).
            Console.WriteLine($"There were {results.Count} objects with the display Id of {Program.customerDisplayId}:");

            Console.WriteLine($"Complete.");

            // Ensure we're disconnected.
            application.Disconnect(vault);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses the helper library to execute a segmented search.
        /// </summary>
        static void UseLibrary()
        {
            // Declare variables for our vault connection.
            Vault vault;
            MFilesServerApplication application;

            // The default connection (localhost, tcp, current Windows user) will suffice.
            var connectionDetails = new ConnectionDetails();

            // Connect to the vault.
            connectionDetails.ConnectToVaultAdministrative(
                Program.sampleVaultGuid,
                out vault, out application);

            // Load the object types from the vault.
            Console.WriteLine("Loading object types...");
            var objectTypes = vault
                              .ObjectTypeOperations
                              .GetObjectTypes()
                              .Cast <ObjType>()
                              .ToList();

            Console.WriteLine($"Iterating over {objectTypes.Count} object types...");

            // Iterate over the object types to count the objects.
            foreach (var objectType in objectTypes)
            {
                // Create the basic search conditions collection.
                var searchConditions = new SearchConditions();

                // Add a condition for the object type we're interested in.
                searchConditions.AddObjectTypeIdSearchCondition(objectType.ID);

                // Count the items in this object type, including deleted ones.
                // This will execute the search in segments (i.e. items 0-1000, then 1001-2000),
                // but will "flatten" the results into a collection of ObjectVersion objects.
                var countIncludingDeleted = vault.ObjectSearchOperations
                                            .SearchForObjectsByConditionsSegmented_Flat(searchConditions)
                                            .Count();

                // Output the stats.
                Console.WriteLine($"\t{objectType.NamePlural}:");
                Console.WriteLine($"\t\tTotal: {countIncludingDeleted} (included deleted)");
            }

            Console.WriteLine($"Complete.");

            // Ensure we're disconnected.
            application.Disconnect(vault);
        }