示例#1
0
        /// <summary>
        /// Uses the helper library to execute a search.
        /// </summary>
        static async Task UseLibrary()
        {
            // Connect to the online knowledgebase.
            // Note that this doesn't require authentication.
            var client = new MFWSClient("http://kb.cloudvault.m-files.com");

            // Execute a quick search for the query term.
            var results = await client.ObjectSearchOperations.SearchForObjectsByStringAsync(Program.queryTerm);

            Console.WriteLine($"There were {results.Length} results returned.");

            // Get the object property values (not necessary, but shows how to retrieve multiple sets of properties in one call).
            var properties = await client.ObjectPropertyOperations.GetPropertiesOfMultipleObjectsAsync(results.Select(r => r.ObjVer).ToArray());

            // Iterate over the results and output them.
            for (var i = 0; i < results.Length; i++)
            {
                // Output the object version details.
                var objectVersion = results[i];
                Console.WriteLine($"\t{objectVersion.Title}");
                Console.WriteLine($"\t\tType: {objectVersion.ObjVer.Type}, ID: {objectVersion.ObjVer.ID}");

                // Output the properties.
                var objectProperties = properties[i];
                foreach (var property in objectProperties)
                {
                    Console.WriteLine($"\t\tProperty: {property.PropertyDef}, Value: {property.TypedValue.Value}");
                }
            }
        }
示例#2
0
        /// <summary>
        /// Uses the helper library to execute a search.
        /// </summary>
        static async Task UseLibrary()
        {
            // Connect to the online knowledgebase.
            // Note that this doesn't require authentication.
            var client = new MFWSClient("http://kb.cloudvault.m-files.com");

            // Execute a quick search for the query term.
            var results = await client.ObjectSearchOperations.SearchForObjectsByStringAsync(Program.queryTerm);

            // Iterate over the results and output them.
            Console.WriteLine($"There were {results.Length} results returned.");
            foreach (var objectVersion in results)
            {
                Console.WriteLine($"\t{objectVersion.Title}");
                Console.WriteLine($"\t\tType: {objectVersion.ObjVer.Type}, ID: {objectVersion.ObjVer.ID}");

                // Create a folder for the files to go in.
                var folderPath =
                    new System.IO.DirectoryInfo(System.IO.Path.Combine(Program.downloadFolder, objectVersion.ObjVer.ID.ToString()));
                if (false == folderPath.Exists)
                {
                    folderPath.Create();
                }

                // Download the files.
                foreach (var file in objectVersion.Files)
                {
                    // Generate a unique file name.
                    var fileName = System.IO.Path.Combine(folderPath.FullName, file.ID + "." + file.Extension);

                    // Download the file data.
                    await client.ObjectFileOperations.DownloadFileAsync(objectVersion.ObjVer.Type,
                                                                        objectVersion.ObjVer.ID,
                                                                        objectVersion.Files[0].ID,
                                                                        fileName,
                                                                        objectVersion.ObjVer.Version);

                    Console.WriteLine($"\t\t\tFile: {file.Name} output to {fileName}");
                }
            }
        }
示例#3
0
        /// <summary>
        /// Uses the helper library to retrieve an object checkout status.
        /// </summary>
        static async Task UseLibrary()
        {
            // Connect to the online knowledgebase.
            // Note that this doesn't require authentication.
            var client = new MFWSClient("http://kb.cloudvault.m-files.com");

            // Search for automatic filling of properties document.
            var results = await client.ObjectSearchOperations.SearchForObjectsByStringAsync("automatic filling of properties");

            if (0 == results.Length)
            {
                // Could not find the object.
                Console.WriteLine($"\tDocument not found.");
                return;
            }

            // Whilst the checkout status is available in the ObjectVersion directly,
            // let's retrieve it to show the standard call.
            // Get the checkout status.
            var checkoutStatus = await client.ObjectOperations.GetCheckoutStatusAsync(results[0].ObjVer.Type, results[0].ObjVer.ID);

            // Output it.
            Console.WriteLine($"\tCheckout status is: {checkoutStatus}");
        }
示例#4
0
        /// <summary>
        /// Uses the helper library to retrieve the value list items.
        /// </summary>
        static async Task UseLibrary()
        {
            // Connect to the online knowledgebase.
            // Note that this doesn't require authentication.
            var client = new MFWSClient("http://kb.cloudvault.m-files.com");

            // Get the object types.
            var objectTypes = await client.ObjectTypeOperations.GetObjectTypesAsync();

            Console.WriteLine($"There are {objectTypes.Count} object types in the vault:");
            foreach (var item in objectTypes)
            {
                // Output basic content.
                System.Console.WriteLine($"\t{item.Name} ({item.NamePlural})");
                System.Console.WriteLine($"\t\tID: {item.ID}");

                // Get the classes.
                var classes = await client.ClassOperations.GetObjectClassesAsync(item.ID);

                Console.WriteLine($"\t\tThere are {classes.Count} classes in the vault:");
                foreach (var c in classes)
                {
                    // Output basic content.
                    System.Console.WriteLine($"\t\t\t{c.Name}");
                    System.Console.WriteLine($"\t\t\t\tID: {c.ID}");

                    // Are there any templates?
                    var classTemplates = (await client.ClassOperations.GetObjectClassAsync(c.ID, true)).Templates;
                    if (null != classTemplates && 0 != classTemplates.Count)
                    {
                        System.Console.WriteLine($"\t\t\t\tTemplates:");
                        foreach (var template in classTemplates)
                        {
                            // Output basic content.
                            System.Console.WriteLine($"\t\t\t\t\t{template.Title}");
                            System.Console.WriteLine($"\t\t\t\t\t\tID: {template.ObjVer.ID}");
                        }
                    }
                }
            }

            // Get the value lists.
            var valueLists = await client.ValueListOperations.GetValueListsAsync();

            Console.WriteLine($"There are {valueLists.Count} value lists in the vault:");
            foreach (var item in valueLists)
            {
                // Output basic content.
                System.Console.WriteLine($"\t{item.Name}");
                System.Console.WriteLine($"\t\tID: {item.ID}");

                // Retrieve the items.
                var valueListItems = await client.ValueListItemOperations.GetValueListItemsAsync(item.ID);

                System.Console.WriteLine($"\t\tItems ({valueListItems.Items.Count}):");

                // Output the items.
                foreach (var valueListItem in valueListItems.Items)
                {
                    System.Console.WriteLine($"\t\t\t{valueListItem.Name}, ID: {valueListItem.ID}");
                }
            }

            // Get the property definitions.
            var propertyDefinitions = await client.PropertyDefOperations.GetPropertyDefsAsync();

            Console.WriteLine($"There are {propertyDefinitions.Count} property definitions in the vault:");
            foreach (var item in propertyDefinitions)
            {
                // Output basic content.
                System.Console.WriteLine($"\t{item.Name}");
                System.Console.WriteLine($"\t\tID: {item.ID}");
            }
        }
示例#5
0
        /// <summary>
        /// Uses the helper library to navigate the view structure.
        /// </summary>
        static async Task UseLibrary()
        {
            // Connect to the online knowledgebase.
            // Note that this doesn't require authentication.
            var client = new MFWSClient("http://kb.cloudvault.m-files.com");

            // Create a stack for the navigation.
            // As we go in/out views and groupings, this will hold where we are.
            Stack <FolderContentItem> navigation = new Stack <FolderContentItem>();

            // Have they selected to quit?
            bool quit = false;

            // Whilst they haven't selected to quit, show the selected contents.
            while (false == quit)
            {
                // Get the view contents (root if no parent).
                // We have to reverse this as, by default, Stack<T> will return data from
                // the top of the stack downwards (newest -> oldest), whereas we want the bottom upwards
                // (oldest -> newest).
                var results = await client.ViewOperations.GetFolderContentsAsync(navigation.Reverse().ToArray());

                // Clear the screen.
                Console.Clear();

                // Get some indication of where we are.
                var navigationString = String.Join(" > ", navigation.Reverse().Select(i => i.GetDisplayName()));

                // Output it to screen.
                Console.WriteLine(navigationString);

                // Output the number returned.
                Console.WriteLine($"There are {results.Items.Count} items:");
                var count = 0;

                // If we can go up a view then give that option.
                if (navigation.Count > 0)
                {
                    Console.WriteLine("\t0: .. (up a view)");
                }

                // Iterate over the results and output them.
                foreach (var item in results.Items)
                {
                    Console.WriteLine($"\t{++count}: {item.FolderContentItemType}: {item.GetDisplayName()}");
                }

                // Ask them where to go next.
                var nextNavItem = Program.GetNextNavigationItem(results, out quit);

                // If they chose to quit then exit out now.
                if (quit)
                {
                    continue;
                }

                // Did they choose to go up a view?
                if (null == nextNavItem)
                {
                    // Remove the top one from the navigation stack ("go back").
                    if (navigation.Count > 0)
                    {
                        navigation.Pop();
                    }
                }
                else
                {
                    // If they chose to go "into" an object then return the history.
                    if (nextNavItem.FolderContentItemType == MFFolderContentItemType.ObjectVersion)
                    {
                        // If it's an unpromoted external object then we can't do anything.
                        if (nextNavItem.ObjectVersion.ObjVer.ID == 0 &&
                            false == string.IsNullOrEmpty(nextNavItem.ObjectVersion.ObjVer.ExternalRepositoryObjectID))
                        {
                            Console.WriteLine("History cannot be viewed on unpromoted objects:.");
                            Console.WriteLine($"\tu{nextNavItem.ObjectVersion.ObjVer.ExternalRepositoryName}:{nextNavItem.ObjectVersion.ObjVer.ExternalRepositoryObjectID}");
                            Console.WriteLine("Press any key to go back to the previous listing.");
                            Console.ReadKey();
                        }
                        else
                        {
                            // Get the history.
                            var versions = await client.ObjectOperations.GetHistoryAsync(new ObjID()
                            {
                                Type = nextNavItem.ObjectVersion.ObjVer.Type,
                                ID   = nextNavItem.ObjectVersion.ObjVer.ID,
                                ExternalRepositoryName     = nextNavItem.ObjectVersion.ObjVer.ExternalRepositoryName,
                                ExternalRepositoryObjectID = nextNavItem.ObjectVersion.ObjVer.ExternalRepositoryObjectID
                            });

                            // Output them.
                            Console.WriteLine($"There are {versions.Count} versions:");
                            foreach (var version in versions)
                            {
                                Console.WriteLine($"{version.ObjVer.Version} (Created: {version.LastModifiedUtc})");
                            }

                            // Allow the user to go out.
                            Console.WriteLine("Press any key to go back to the previous listing.");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        // Add it to the navigation stack ("go in").
                        navigation.Push(nextNavItem);
                    }
                }
            }
        }
示例#6
0
        public static void ExamplesWithWrapperLibrary()
        {
            //Initiate Client
            var client = new MFWSClient(Constants.RestURL);

            var guid = Guid.Parse(Constants.VaultGUID);

            //Authenticate
            client.AuthenticateUsingCredentials(guid, username: Constants.UserName, password: Constants.Password);

            //Search & Get All Employees
            var employees = client.ObjectSearchOperations.SearchForObjectsByConditions(
                new ObjectTypeSearchCondition(Constants.EmployeeObjectId));


            var extSystemEmployeeId = Guid.NewGuid().ToString("N");

            //Create new employee only with mandotory fields
            var createdEmployee = client.ObjectOperations.CreateNewObject(Constants.EmployeeObjectId, new ObjectCreationInfo
            {
                PropertyValues = new PropertyValue[] {
                    //Employee class
                    new PropertyValue {
                        PropertyDef = 100, //Built-in class ID not parametrical
                        TypedValue  = new TypedValue {
                            DataType = MFDataType.Lookup, HasValue = true, Lookup = new Lookup {
                                Version = -1, Item = Constants.EmployeeClassId
                            }
                        }
                    },

                    //Name
                    new PropertyValue {
                        PropertyDef = Constants.NameSurnamePropId,
                        TypedValue  = new TypedValue {
                            DataType = MFDataType.Text, Value = "Gökay Kıvırcıoğlu"
                        }
                    },

                    //Working status
                    new PropertyValue {
                        PropertyDef = Constants.WorkingStatusPropId,
                        TypedValue  = new TypedValue {
                            DataType = MFDataType.Lookup, Lookup = new Lookup {
                                Item = Constants.WorkingStatusActiveId, Version = -1
                            }
                        }
                    },

                    //Set External System' s ID
                    new PropertyValue {
                        PropertyDef = Constants.ExternalIdPropId,
                        TypedValue  = new TypedValue {
                            DataType = MFDataType.Text, Value = extSystemEmployeeId
                        }
                    }
                }
            });

            //find an employee with external id
            var foundEmployees = client.ObjectSearchOperations.SearchForObjectsByConditions(
                new TextPropertyValueSearchCondition(Constants.ExternalIdPropId, extSystemEmployeeId));

            if (foundEmployees.Length == 0)
            {
                throw new Exception("No employees found");
            }

            var foundEmployee = foundEmployees[0];

            //Updating a field
            //Check if the object is checkedout or not?
            var checkOutStatus = client.ObjectOperations.GetCheckoutStatus(foundEmployee.ObjVer);


            if (checkOutStatus.HasValue)
            {
                if (checkOutStatus.Value != MFCheckOutStatus.CheckedOutToMe && checkOutStatus.Value != MFCheckOutStatus.CheckedIn)
                {
                    throw new Exception("Object is checked-out.");
                }
            }

            ObjectVersion CheckedOutObject;

            if (checkOutStatus.Value != MFCheckOutStatus.CheckedOutToMe)
            {
                //Check out if it is not checkedout by our app's user
                CheckedOutObject = client.ObjectOperations.CheckOut(foundEmployee.ObjVer);
            }
            else
            {
                CheckedOutObject = foundEmployee;
            }

            //Add a new field to employee object
            var editedObjectVersion = client.ObjectPropertyOperations.SetProperty(
                CheckedOutObject.ObjVer,
                new PropertyValue
            {
                PropertyDef = Constants.TCKNPropId,
                TypedValue  = new TypedValue {
                    DataType = MFDataType.Text, Value = "32472832270"
                }
            });

            //Update an existing field
            editedObjectVersion = client.ObjectPropertyOperations.SetProperty(
                editedObjectVersion.ObjVer,
                new PropertyValue
            {
                PropertyDef = Constants.NameSurnamePropId,
                TypedValue  = new TypedValue {
                    DataType = MFDataType.Text, Value = "Rıza Gökay Kıvırcıoğlu"
                }
            });

            //Check-In the object
            var editedEmployeeRecord = client.ObjectOperations.CheckIn(editedObjectVersion.ObjVer);

            //Deleting an employee
            var deletedRecord = client.ObjectOperations.DeleteObject(Constants.EmployeeObjectId, editedEmployeeRecord.ObjVer.ID);

            //Destroying a record
            client.ObjectOperations.DestroyObject(Constants.EmployeeObjectId, editedEmployeeRecord.ObjVer.ID, true, -1);
        }