/// <summary> /// Adds a <see cref="SearchCondition"/> to the collection to find items with the given owner. /// </summary> /// <param name="searchBuilder">The <see cref="MFSearchBuilder"/> to add the condition to.</param> /// <param name="owner">The owner item.</param> /// <returns>The <paramref name="searchBuilder"/> provided, for chaining.</returns> public static MFSearchBuilder Owner ( this MFSearchBuilder searchBuilder, ObjID objID ) { // Sanity. if (null == objID) { throw new ArgumentNullException(nameof(objID)); } // Get the owner object type. var ownerObjType = searchBuilder .Vault .ObjectTypeOperations .GetObjectType(objID.Type); // Use the other method. return(searchBuilder.AddPropertyValueSearchCondition ( ownerObjType.OwnerPropertyDef, MFDataType.MFDatatypeLookup, // Owner must be single-select objID.ID, MFConditionType.MFConditionTypeEqual )); }
private void OnGUI() { id = EditorGUILayout.TextField("请输入要查询的ID", id); EditorGUILayout.LabelField("查询结果", info); if (GUILayout.Button("确定")) { int objid; try { objid = int.Parse(id); } catch (System.Exception) { info = "输入格式不对请重新输入(1~999int数值)"; return; } if (ObjID.GetObjByID(objid) == null) { info = "未查询到此ID对应的物体"; } else { EditorGUIUtility.PingObject(ObjID.GetObjByID(objid)); info = "查询成功"; } } }
public static bool download_file(Vault Vault, int object_id, string download_path) { bool success = false; try { ObjID objId = new ObjID(); objId.SetIDs((int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument, object_id); objId.Type = 0; ObjectVersion objectVersion; ObjectVersionAndProperties objectVersionAndProperties; objectVersionAndProperties = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(objId, true); objectVersion = objectVersionAndProperties.VersionData; ObjectFiles objectFiles = objectVersion.Files; foreach (ObjectFile objectFile in objectFiles) { Vault.ObjectFileOperations.DownloadFile(objectFile.ID, objectFile.Version, download_path + objectFile.GetNameForFileSystem()); } success = true; } catch (Exception ex) { throw ex; } return(success); }
private void OnGUI() { SerachID = EditorGUILayout.IntField("输入要查询ID", SerachID); if (PreSerachID != SerachID) { if (SerachID == 0) { objDic = ObjID.ObjIDDic; } else { if (ObjID.CheckID(SerachID)) { objDic = new Dictionary <int, GameObject> { { SerachID, ObjID.ObjIDDic[SerachID] } }; } } } scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(this.position.height - 20)); foreach (KeyValuePair <int, GameObject> item in objDic) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(item.Key.ToString(), GUILayout.MaxWidth(100))) { EditorGUIUtility.PingObject(item.Value); } EditorGUILayout.ObjectField(item.Value, typeof(GameObject), true); EditorGUILayout.EndHorizontal(); } GUILayout.EndScrollView(); PreSerachID = SerachID; }
private void SetNacl2PerformRateObj(EventHandlerEnvironment env) { var vault = env.Vault; var objVer = env.ObjVer; var performObjType = vault.ObjectTypeOperations.GetObjectTypeIDByAlias("ObjPerformRate"); if (objVer.Type == performObjType) { //查询项目 var projPropId = vault.PropertyDefOperations.GetPropertyDefIDByAlias("PropProject"); var projObjId = vault.ObjectPropertyOperations.GetProperty(objVer, projPropId).Value.GetValueAsLookup().Item; var projType = vault.ObjectTypeOperations.GetObjectTypeIDByAlias("ObjProject"); var projObjID = new ObjID(); projObjID.SetIDs(projType, projObjId); var projObjVer = vault.ObjectOperations.GetLatestObjVer(projObjID, false); //查询所属公司 var projOwnerPropId = vault.PropertyDefOperations.GetPropertyDefIDByAlias("PropCompany"); var projOwner = vault.ObjectPropertyOperations.GetProperty(projObjVer, projOwnerPropId).Value.DisplayValue; if (projOwner == "中建八局第二建设有限公司") //公司总部 { var nacl = vault.NamedACLOperations.GetNamedACLIDByAlias("NaclPerformRateHead"); vault.ObjectOperations.ChangePermissionsToNamedACL(objVer, nacl, true); } else//分公司 { var nacl = vault.NamedACLOperations.GetNamedACLIDByAlias("NaclPerformRateAll"); vault.ObjectOperations.ChangePermissionsToNamedACL(objVer, nacl, true); } } }
public void SearchConditionIsCorrect() { // Create the search builder. var mfSearchBuilder = this.GetSearchBuilder(); // Add the search condition. var objID = new ObjID(); objID.SetIDs(123, 456); mfSearchBuilder.Owner(objID); // If there's anything other than one condition then fail. if (mfSearchBuilder.Conditions.Count != 1) { Assert.Inconclusive("Only one search condition should exist"); } // Retrieve the just-added condition. var condition = mfSearchBuilder.Conditions[mfSearchBuilder.Conditions.Count]; // Ensure the condition type is correct. Assert.AreEqual(MFConditionType.MFConditionTypeEqual, condition.ConditionType); // Ensure the expression type is correct. Assert.AreEqual(MFExpressionType.MFExpressionTypePropertyValue, condition.Expression.Type); // Ensure the property def is correct. Assert.AreEqual(999, condition.Expression.DataPropertyValuePropertyDef); // Ensure that the typed value is correct. Assert.AreEqual(MFDataType.MFDatatypeLookup, condition.TypedValue.DataType); Assert.AreEqual(456, condition.TypedValue.GetLookupID()); }
internal static MfContact GetContactById(Vault mfVault, MetadataAliases aliases, int contactId) { var objAlias = aliases.Objects["ObjContacts"]; var classAlias = objAlias.ClassDict["ClassContacts"]; var typeId = MfAlias.GetObjType(mfVault, objAlias.Alias); var objId = new ObjID(); objId.SetIDs(typeId, contactId); var objVer = mfVault.ObjectOperations.GetLatestObjVer(objId, false); var accountPDId = MfAlias.GetPropDef(mfVault, classAlias.PropDict["PropAccount"]); var accountTV = mfVault.ObjectPropertyOperations.GetProperty(objVer, accountPDId).Value; var userId = accountTV.GetLookupID(); var contact = new MfContact { UserId = userId, InternalId = objVer.ID, RoleAlias = classAlias.PropDict["PropProjectRole"] }; var roleId = MfAlias.GetPropDef(mfVault, contact.RoleAlias);//mfVault.UserGroupOperations.GetUserGroupIDByAlias(contact.RoleAlias); contact.RoleName = mfVault.ObjectPropertyOperations.GetProperty(objVer, roleId).GetValueAsLocalizedText(); if (!String.IsNullOrEmpty(objAlias.Owner)) { var partTypeId = MfAlias.GetObjType(mfVault, objAlias.Owner); var partType = mfVault.ObjectTypeOperations.GetObjectType(partTypeId); var partOwnerPropId = partType.OwnerPropertyDef; var partyTV = mfVault.ObjectPropertyOperations.GetProperty(objVer, partOwnerPropId).Value; contact.PartName = partyTV.DisplayValue; } return(contact); }
/// <summary> /// Demote a managed object to an unmanaged object. /// </summary> /// <param name="objID">The Id of the object to demote.</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>The ObjectVersion, if it is visible to the user.</returns> public List <ExtendedObjectVersion> DemoteObject(ObjID objID, CancellationToken token = default(CancellationToken)) { // Execute the async method. return(this.DemoteObjectAsync(objID, token) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Retrieves the properties of a single object. Returns the properties on the latest version of the object. /// </summary> /// <param name="objID">The object to retrieve the properties of.</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>A collection of property values for the supplied object.</returns> public PropertyValue[] GetProperties(ObjID objID, CancellationToken token = default(CancellationToken)) { // Execute the async method. return(this.GetPropertiesAsync(objID, token) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Sets a single property on a single object. /// </summary> /// <param name="objId">The object to set the property on.</param> /// <param name="newPropertyValue">The new (or updated) property value.</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>The new object version.</returns> /// <remarks>The object must be checked out to perform this action.</remarks> public ExtendedObjectVersion SetProperty(ObjID objId, PropertyValue newPropertyValue, CancellationToken token = default(CancellationToken)) { // Execute the async method. return(this.SetPropertyAsync(objId, newPropertyValue, token) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Set multiple properties on a single object. /// </summary> /// <param name="objId">The object to set the property on.</param> /// <param name="propertyValues">The property values for the object.</param> /// <param name="replaceAllProperties">If true, <see cref="propertyValues"/> contains all properties for the object (and others will be removed).</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>The new object version.</returns> /// <remarks>If <see cref="replaceAllProperties"/> is true then <see cref="propertyValues"/> must contain values for property 0 (name or title), property 100 (class), property 22 (is single file), and any other mandatory properties for the given class.</remarks> public ExtendedObjectVersion SetProperties(ObjID objId, PropertyValue[] propertyValues, bool replaceAllProperties, CancellationToken token = default(CancellationToken)) { // Execute the async method. return(this.SetPropertiesAsync(objId, propertyValues, replaceAllProperties, token) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Removes a single property from a single object. /// </summary> /// <param name="objId">The object to set the property on.</param> /// <param name="propertyDef">The property to remove.</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>The new object version.</returns> /// <remarks>The object must be checked out to perform this action.</remarks> public ExtendedObjectVersion RemoveProperty(ObjID objId, int propertyDef, CancellationToken token = default(CancellationToken)) { // Execute the async method. return(this.RemovePropertyAsync(objId, propertyDef, token) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
private void OnEnable() { _SerObj = new SerializedObject(target); ID = _SerObj.FindProperty("ID"); _Objid = target as ObjID; //_Objid.InitID(); //_Objid.AddThis(); Debug.Log("OnEnable"); }
public ObjectVersion RemoveObject(ObjID objID) { vault.MetricGatherer.MethodCalled(); TestObjectVersionAndProperties ovap = GetLatestTestObjectVersionAndProperties(objID, false, true); ovap.versionData.deleted = true; return(ovap.VersionData); }
public int GetObjectVersion(MFilesVault vault, int objType, int objId) { var mfVault = MFServerUtility.GetVault(vault); var objID = new ObjID(); objID.SetIDs(objType, objId); var objVer = mfVault.ObjectOperations.GetLatestObjVer(objID, false, false); return(objVer.Version); }
/// <summary> /// Opens a write-only stream to replace the existing file contents. /// </summary> /// <param name="objectFile">The file to update.</param> /// <param name="vault">The vault to download from.</param> /// <param name="objectId">The object to which this file belongs.</param> /// <param name="automaticallyCommitOnDisposal">If true, will automatically save the file contents to the vault when this stream is disposed of.</param> /// <returns>A <see cref="FileUploadStream"/> that can be used to write file data to vault.</returns> /// <remarks>Ensure that the stream is correctly closed and disposed of (e.g. with a <see langword="using"/> statement).</remarks> public static FileUploadStream OpenWrite ( this ObjectFile objectFile, Vault vault, ObjID objectId, bool automaticallyCommitOnDisposal = true ) { return(new FileUploadStream(objectFile.FileVer, objectId, vault, automaticallyCommitOnDisposal)); }
public void FromObjIDCorrectData() { var objID = new ObjID(); objID.SetIDs(101, 2); var directive = objID.ToObjIDTaskDirective(); Assert.AreEqual(101, directive.ObjectTypeID); Assert.AreEqual(2, directive.ObjectID); }
/// <summary> /// Instantiates an <see cref="ObjIDTaskDirective"/> representing <paramref name="objID"/>. /// </summary> /// <param name="objID">The object to represent.</param> /// <param name="displayName">The display name for this directive.</param> public ObjIDTaskDirective(ObjID objID, string displayName = null) : this() { if (null == objID) { throw new ArgumentNullException(nameof(objID)); } this.ObjectID = objID.ID; this.ObjectTypeID = objID.Type; this.DisplayName = displayName; }
public void DisplayID_WithExternalWithOriginal() { var originalId = new ObjID(); originalId.SetIDs(101, 1234); var vaultMock = this.GetVaultMock(); var objectVersionAndPropertiesMock = this.GetObjectVersionAndPropertiesMock(vaultMock, originalId: originalId); var objVerEx = new Common.ObjVerEx(vaultMock.Object, objectVersionAndPropertiesMock.Object); Assert.AreEqual("hello 123ABCDEF123 world", objVerEx.ExpandSimpleConcatenation("hello %DISPLAYID% world")); }
public void TryGetObjID_CorrectData() { var objID = new ObjID(); objID.SetIDs(101, 2); var directive = objID.ToObjIDTaskDirective(); Assert.IsTrue(directive.TryGetObjID(out ObjID o)); Assert.AreEqual(objID.ID, o.ID); Assert.AreEqual(objID.Type, o.Type); }
public static void DownloadDocument() { //Get DocumentId var documentId = TestConstants.DocumentId; //Create ObjID var objID = new ObjID(); //Set Object Type to Document objID.ID = 0; //Set Document Id objID.ID = documentId; LogIntoVault(); //Get Latest Version var latestVersion = loggedInVault.ObjectOperations.GetLatestObjectVersionAndProperties(objID, true); //Get ObjectInfo var objectInfo = latestVersion.VersionData; //Get Files Of Object var files = loggedInVault.ObjectFileOperations.GetFiles(latestVersion.ObjVer); if (files.Count >= 1) { //Clear ObjectTitle For Directory Name var cleanObjectTitle = Helpers.ClearTitle(objectInfo.Title); //Create Download Directory var fullDownloadPath = Path.Combine(TestConstants.DownloadPath, cleanObjectTitle); var di = new DirectoryInfo(fullDownloadPath); if (!di.Exists) { di.Create(); } else { //Clear Previously Downloaded Items foreach (var item in di.EnumerateFiles()) { item.Delete(); } } foreach (ObjectFile item in files) { loggedInVault.ObjectFileOperations.DownloadFile(item.ID, item.Version, Path.Combine(fullDownloadPath, item.GetNameForFileSystem())); } } }
/// <summary> /// Adds files to an existing object. /// </summary> /// <param name="objId">The object to add the file to.</param> /// <param name="token">A cancellation token for the request.</param> /// <param name="files">The files to attach.</param> /// <returns>The updated object version.</returns> public ExtendedObjectVersion AddFiles(ObjID objId, CancellationToken token = default(CancellationToken), params FileInfo[] files) { // Sanity. if (null == objId) { throw new ArgumentNullException(nameof(objId)); } // Execute the other overload. return(this.AddFiles(objId.Type, objId.ID, objectVersion: null, token: token, files: files)); }
protected virtual Mock <ObjectVersionAndProperties> GetObjectVersionAndPropertiesMock ( Mock <Vault> vaultMock, int objectTypeId = 0, int objectId = 123, int version = 1, string externalId = "123ABCDEF123", ObjID originalId = null, Guid?objectGuid = null, params Tuple <int, MFDataType, object>[] propertyValues ) { var objectVersionAndPropertiesMock = new Mock <ObjectVersionAndProperties>(); objectVersionAndPropertiesMock .Setup(o => o.ObjVer) .Returns(() => { var objVer = new ObjVer(); objVer.SetIDs(objectTypeId, objectId, version); return(objVer); }); objectVersionAndPropertiesMock .Setup(o => o.VersionData) .Returns(() => { var data = new Mock <ObjectVersion>(); data.Setup(o => o.DisplayIDAvailable).Returns(!string.IsNullOrWhiteSpace(externalId)); data.Setup(o => o.DisplayID).Returns(externalId); data.Setup(o => o.OriginalObjID).Returns(originalId); if (objectGuid.HasValue) { data.Setup(o => o.ObjectGUID).Returns(objectGuid.Value.ToString("B")); } return(data.Object); }); objectVersionAndPropertiesMock .Setup(o => o.Properties) .Returns(() => { var data = new PropertyValues(); foreach (var tuple in propertyValues ?? new Tuple <int, MFDataType, object> [0]) { var pv = new PropertyValue { PropertyDef = tuple.Item1 }; pv.Value.SetValue(tuple.Item2, tuple.Item3); data.Add(-1, pv); } return(data); }); return(objectVersionAndPropertiesMock); }
/// <summary> /// Gets SAP employee ID from M-Files lookup property. /// </summary> /// <param name="env"></param> /// <param name="employee"></param> /// <returns></returns> private string getSAPObjectID(StateEnvironment env, Lookup employee) { // Get SAPObject object ObjID objID = new ObjID(); objID.Type = employee.ObjectType; objID.ID = employee.Item; ObjectVersionAndProperties employeeObj = env.Vault.ObjectOperations.GetLatestObjectVersionAndProperties(objID, true); // Get SAP SAPObject ID from SAPObject object. return(employeeObj.Properties.GetProperty(SAPObjectIDProperty).GetValueAsLocalizedText()); }
/// <summary> /// 根据ID获取MFiles对象 /// </summary> /// <param name="vault">库</param> /// <param name="objType">对象类型</param> /// <param name="objId">对象ID</param> /// <returns></returns> public static ObjectVersionAndProperties GetVerAndProperties(MFilesAPI.Vault vault, int objType, int objId) { try { var obj = new ObjID(); obj.SetIDs(objType, objId); return(vault.ObjectOperations.GetLatestObjectVersionAndProperties(obj, false, false)); } catch (Exception) { throw; } }
/// <summary> /// Creates a <see cref="FileUploadStream"/> but does not open the upload session. /// </summary> /// <param name="fileToOverwrite">The file to overwrite.</param> /// <param name="objId">The object the file belongs to.</param> /// <param name="vault">The vault to download from.</param> /// <param name="automaticallyCommitOnDisposal">If true, will automatically save the file contents to the vault when this stream is disposed of.</param> public FileUploadStream ( FileVer fileToOverwrite, ObjID objId, Vault vault, bool automaticallyCommitOnDisposal = true ) { // Set properties. this.FileToOverwrite = fileToOverwrite ?? throw new ArgumentNullException(nameof(fileToOverwrite)); this.ObjId = objId ?? throw new ArgumentNullException(nameof(objId)); this.Vault = vault ?? throw new ArgumentNullException(nameof(vault)); this.AutomaticallyCommitOnDisposal = automaticallyCommitOnDisposal; }
public ObjectVersionAndProperties GetOvap(ObjID objId) { List <TestObjectVersionAndProperties> thisObj = ovaps.Where(obj => obj.ObjVer.ID == objId.ID && obj.ObjVer.Type == objId.Type).ToList(); if (thisObj.Count == 0) { return(null); } int maxVersion = thisObj.Max(obj => obj.ObjVer.Version); ObjectVersionAndProperties objectVersionAndProperties = thisObj.SingleOrDefault(obj => obj.ObjVer.Version == maxVersion); return(objectVersionAndProperties); }
public string SetExternalID(EventHandlerEnvironment env) { string response; ResponseMessage message = new ResponseMessage(); try { SetExternalIdRequest requestData; try { requestData = JsonConvert.DeserializeObject <SetExternalIdRequest>(env.Input); } catch (Exception Ex) { SysUtils.ReportErrorToEventLog(Ex); message.Code = 500; message.Description = "Input was not in expected format."; response = JsonConvert.SerializeObject(message); return(response); } var objID = new ObjID(); objID.Type = Convert.ToInt32(requestData.ObjectTypeId); objID.ID = Convert.ToInt32(requestData.InternalId); var vault = env.Vault; vault.ObjectOperations.SetExternalID(objID, requestData.ExternalId); message.Code = 200; message.Description = "Successfully set external id."; response = JsonConvert.SerializeObject(message); } catch (Exception Ex) { message.Code = 500; message.Description = Ex.Message; message.ResponseObject = null; response = JsonConvert.SerializeObject(message); } return(response); }
/// <summary> /// Replaces an existing file with data from another stream. /// </summary> /// <param name="objectFile">The file to replace.</param> /// <param name="vault">The vault from in which the file exists.</param> /// <param name="objectId">The object to which this file belongs.</param> /// <param name="input">The new content for the file.</param> /// <param name="blockSize">The block size to use.</param> public static void ReplaceFileContent ( this ObjectFile objectFile, Vault vault, ObjID objectId, Stream input, int blockSize = FileTransfers.DefaultBlockSize ) { // Sanity. if (null == objectFile) { throw new ArgumentNullException(nameof(objectFile)); } if (null == vault) { throw new ArgumentNullException(nameof(vault)); } if (null == objectId) { throw new ArgumentNullException(nameof(objectId)); } if (null == input) { throw new ArgumentNullException(nameof(input)); } if (false == input.CanRead) { throw new ArgumentException("The input stream is not readable.", nameof(input)); } // Documentation says block size must be between 1KB and 4MB. if (blockSize < FileTransfers.MinimumUploadBlockSize) { blockSize = FileTransfers.MinimumUploadBlockSize; } if (blockSize > FileTransfers.MaximumUploadBlockSize) { blockSize = FileTransfers.MaximumUploadBlockSize; } // Create the (write-only) upload stream. using (var uploadStream = new FileUploadStream(objectFile.FileVer, objectId, vault)) { // Copy the input stream to the upload stream. input.CopyTo(uploadStream, blockSize); } }
public ObjectVersionAndProperties GetLatestObjectVersionAndProperties(ObjID objID, bool allowCheckedOut, bool updateFromServer = false) { vault.MetricGatherer.MethodCalled(); // TODO: use arguments List <TestObjectVersionAndProperties> thisObj = vault.ovaps.Where(obj => obj.ObjVer.ID == objID.ID && obj.ObjVer.Type == objID.Type).ToList(); if (thisObj.Count == 0) { return(null); } int maxObj = thisObj.Max(obj => obj.ObjVer.Version); ObjectVersionAndProperties ovap = thisObj.Single(obj => obj.ObjVer.Version == maxObj); return(ovap); }