internal void Create(MFilesVault vault, MFObject obj) { var mfVault = MFServerUtility.GetVault(vault); try { Create(mfVault, obj); } catch (Exception ex) { throw new Exception(obj.ToString(), ex); } }
internal static void Create(Vault vault, MFObject obj) { // Writelog(string.Format("--11--{0},{1},{2}",obj.Id,obj.Properties.Count,obj)); var objType = MfAlias.GetObjType(vault, obj.ObjDef.TypeAlias); // Writelog("--22--"); var objClass = MfAlias.GetObjectClass(vault, obj.ObjDef.ClassAlias); // Writelog("--33--"); var pvs = new PropertyValues(); var classPV = MFPropertyUtils.Class(objClass); pvs.Add(-1, classPV); // Writelog("--44--"); SetProperties(vault, pvs, obj); var isSingleFile = false; // Writelog("--55--"); SourceObjectFiles files = null; if (obj.Filepaths != null && obj.Filepaths.Count > 0) { files = new SourceObjectFiles(); //todo if (obj.Filepaths.Count == 1) { isSingleFile = true; } // Writelog("--66--"); } var singleFilePV = MFPropertyUtils.SingleFile(isSingleFile); pvs.Add(-1, singleFilePV); // Writelog("--77--"); try { var objVersion = vault.ObjectOperations.CreateNewObject(objType, pvs, files); // Writelog("--88--"); var newObjVersion = vault.ObjectOperations.CheckIn(objVersion.ObjVer); obj.Id = newObjVersion.ObjVer.ID; } catch (Exception ex) { Log.Error(string.Format("CreateNewObject error:{0},{1},{2}", objType, pvs.Count, ex.Message)); } }
public static MFObject GetMfProjectObject(this VaultConfig config, Project proj) { var projObjDef = config.Project; var obj = new MFObject(projObjDef); obj.Properties.Add("PropProjName", proj.Name); obj.Properties.Add("PropProjNum", proj.Number); obj.Properties.Add("PropDescription", proj.Description); obj.Properties.Add("PropDeadLine", proj.EndDateUtc.ToLocalTime()); obj.Properties.Add("PropStartDate", proj.StartDateUtc.ToLocalTime()); obj.Properties.Add("PropProjPhase", proj.StatusId); obj.Properties.Add("PropProprietorUnit", proj.OwnerUnit); obj.Properties.Add("PropDesignUnit", proj.DesignUnit); obj.Properties.Add("PropBuilderUnit", proj.ConstructionUnit); obj.Properties.Add("PropSupervisorUnit", proj.SupervisionUnit); return(obj); }
public static MFObject GetMfProject(this MetadataAliases aliases, Project proj) { var od = GetMfObjDef(aliases, "ObjProject", "ClassProject"); var obj = new MFObject(od) { Id = proj.InternalId }; var projClass = aliases.Objects["ObjProject"].ClassDict["ClassProject"]; //projClass.PropDict[ obj.Properties.Add("PropProjName", proj.Name); obj.Properties.Add("PropDescription", proj.Description); obj.Properties.Add("PropStartDate", proj.StartDateUtc); obj.Properties.Add("MFBuiltInPropertyDefDeadline", proj.EndDateUtc); if (projClass.PropDict.ContainsKey("PropProjNum")) { obj.Properties.Add("PropProjNum", proj.Number); } if (projClass.PropDict.ContainsKey("PropProjPhase")) { obj.Properties.Add("PropProjPhase", proj.StatusId); } if (projClass.PropDict.ContainsKey("PropProprietorUnit")) { obj.Properties.Add("PropProprietorUnit", proj.OwnerUnit); } if (projClass.PropDict.ContainsKey("PropDesignUnit")) { obj.Properties.Add("PropDesignUnit", proj.DesignUnit); } if (projClass.PropDict.ContainsKey("PropBuilderUnit")) { obj.Properties.Add("PropBuilderUnit", proj.ConstructionUnit); } if (projClass.PropDict.ContainsKey("PropSupervisorUnit")) { obj.Properties.Add("PropSupervisorUnit", proj.SupervisionUnit); } //obj.Properties.Add(projClass.PropDict["PropProjName"], proj.Name); return(obj); }
private static void SetProperties(Vault vault, PropertyValues pvs, MFObject obj) { foreach (var key in obj.Properties.Keys) { var value = obj.Properties[key]; try { //if (!obj.ObjDef.Properties.ContainsKey(key)) //{ //} var propId = MfAlias.GetPropDef(vault, obj.ObjDef.Properties[key]); var pv = MFPropertyUtils.Create(vault, propId, value); pvs.Add(-1, pv); } catch (Exception ex) { Log.Error("创建MF对象失败:" + ex.Message, ex); throw; } } }
internal static void Update(Vault vault, MFObject obj) { var objType = MfAlias.GetObjType(vault, obj.ObjDef.TypeAlias); var pvs = new PropertyValues(); SetProperties(vault, pvs, obj); ObjID objID = null; if (obj.Id <= 0) { var objClass = MfAlias.GetObjectClass(vault, obj.ObjDef.ClassAlias); objID = SearchObjectByClass(vault, objType, objClass); //new ObjID(); //objID.SetIDs(objType, obj.Id); } else { objID = SearchObjectByObjId(vault, objType, obj.Id); } var objVersion = vault.ObjectOperations.CheckOut(objID); var newobjVersion = vault.ObjectPropertyOperations.SetProperties(objVersion.ObjVer, pvs); vault.ObjectOperations.CheckIn(newobjVersion.ObjVer); }
internal void Update(MFilesVault vault, MFObject obj) { var mfVault = MFServerUtility.GetVault(vault); Update(mfVault, obj); }
public static MFObject GetMfContact(this MetadataAliases aliases, Vault vault, MfContact contact) { var user = contact.User; var loginAccount = contact.Id; var od = GetMfObjDef(aliases, "ObjContacts", "ClassContacts"); var obj = new MFObject(od) { Id = contact.InternalId }; var contactClass = aliases.Objects["ObjContacts"].ClassDict["ClassContacts"]; if (loginAccount > 0) { obj.Properties.Add(contactClass.PropDict["PropAccount"], loginAccount); } if (!String.IsNullOrEmpty(contact.RoleAlias)) { var roleId = MfAlias.GetUsergroup(vault, contact.RoleAlias); obj.Properties.Add(contactClass.PropDict["PropProjectRole"], roleId); } if (user != null) //contactClass.PropDict[ { var name = String.IsNullOrEmpty(user.FullName) ? user.UserName : user.FullName; obj.Properties.Add("PropLinkmanName", name); obj.Properties.Add("PropTelPhone", user.Phone ?? ""); obj.Properties.Add("PropEmail", user.Email); if (contactClass.PropDict.ContainsKey("PropQQ")) { obj.Properties.Add("PropQQ", user.QQ ?? ""); } if (contactClass.PropDict.ContainsKey("PropUnit")) { var company = String.Empty; if (user.Company != null) { company = user.Company.Name; } obj.Properties.Add("PropUnit", company); } if (contactClass.PropDict.ContainsKey("PropDepartment")) { var department = String.Empty; if (user.Department != null) { department = user.Department.Name; } obj.Properties.Add("PropDepartment", department); } if (contactClass.PropDict.ContainsKey("PropPosition")) { obj.Properties.Add("PropPosition", user.Post ?? ""); } if (contactClass.PropDict.ContainsKey("PropRemarks")) { obj.Properties.Add("PropRemarks", user.Description); } } if (contactClass.PropDict.ContainsKey("PropUserStatus")) { obj.Properties.Add("PropUserStatus", contact.Disabled); } if (contactClass.PropDict.ContainsKey("PropIsProjCreator")) { obj.Properties.Add("PropIsProjCreator", contact.IsCreator); } if (!String.IsNullOrEmpty(contact.PartName)) { var ownerAlias = aliases.Objects["ObjContacts"].Owner; if (ownerAlias != null) { var objTypeId = MfAlias.GetObjType(vault, ownerAlias); var objType = vault.ObjectTypeOperations.GetObjectType(objTypeId); var pwnerPropertyId = objType.OwnerPropertyDef; //所属属性 obj.Properties.Add(pwnerPropertyId.ToString(), GetPartyId(aliases, vault, contact.PartName)); od.Properties.Add(pwnerPropertyId.ToString(), pwnerPropertyId.ToString()); } } return(obj); }