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); }
internal static MfContact GetContactByUserId(Vault mfVault, MetadataAliases aliases, int userId) { var objAlias = aliases.Objects["ObjContacts"]; var classAlias = objAlias.ClassDict["ClassContacts"]; var typeId = MfAlias.GetObjType(mfVault, objAlias.Alias); var classId = MfAlias.GetObjectClass(mfVault, classAlias.Alias); var scs = new SearchConditions(); MFSearchConditionUtils.AddBaseConditions(scs, typeId, classId); var userPropId = MfAlias.GetPropDef(mfVault, classAlias.PropDict["PropAccount"]); scs.Add(-1, MFSearchConditionUtils.Property(MFConditionType.MFConditionTypeEqual, userPropId, MFDataType.MFDatatypeLookup, userId)); var res = mfVault.ObjectSearchOperations.SearchForObjectsByConditions(scs, MFSearchFlags.MFSearchFlagNone, false); if (res.Count != 1) { return(null); } var obj = res[1]; var contact = new MfContact { UserId = userId, InternalId = obj.ObjVer.ID, RoleAlias = classAlias.PropDict["PropProjectRole"] }; var roleId = MfAlias.GetPropDef(mfVault, contact.RoleAlias);//mfVault.UserGroupOperations.GetUserGroupIDByAlias(contact.RoleAlias); contact.RoleName = mfVault.ObjectPropertyOperations.GetProperty(obj.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(obj.ObjVer, partOwnerPropId).Value; contact.PartName = partyTV.DisplayValue; } return(contact); }
public Result Create(Project proj, User creator, VaultTemplate template, MFilesVault vault, MFSqlDatabase sqlDb, string userName, string password, ProjectParty party) { var app = MFServerUtility.ConnectToMfApp(vault); //1. 判断库是否已存在 var hasVault = MFVaultService.HasVault(app, vault); if (hasVault) { return(new Result { Message = "已存在同名的库!" }); } //2.创建库 Vault mVault = null; try { mVault = MFVaultService.Create(app, vault, template.StructurePath, userName, password, sqlDb, null, false); } catch (Exception ex) { Log.Error("创建文档库失败:" + ex.Message, ex); return(new Result { Message = ex.Message, Exception = ex }); } if (mVault == null) { mVault = app.LogInToVault(vault.Guid); } //3.创建MF用户及库用户 int mfUserId = -1; try { mfUserId = MFUserService.CreateVaultUser(mVault, creator); } catch (Exception ex) { var err = "创建或启用库账户失败:" + ex.Message; Log.Error(err, ex); return(new Result { Message = err, Exception = ex }); } if (mfUserId == -1) { return(new Result { Message = "创建或启用库账户失败" }); } var aliases = JsonConvert.DeserializeObject <MetadataAliases>(template.MetadataJson); //4.创建联系人对象 string partyName = null; if (party != null) { partyName = party.Name; } var contact = new MfContact { User = creator, Id = mfUserId, IsCreator = true, RoleAlias = aliases.UserGroups["UGroupPM"] }; if (partyName != null) { contact.PartName = partyName; } try { MFObjectService.Create(mVault, aliases, contact); } catch (Exception ex) { var err = "创建库的联系人失败:" + ex.Message; Log.Error(err, ex); return(new Result { Message = err, Exception = ex }); } //5.创建项目对象 try { ToLocalTimeProj(proj); MFObjectService.Create(mVault, aliases, proj); ToUtcTimeProj(proj); } catch (Exception ex) { var err = "创建库中项目对象失败:" + ex.Message; Log.Error(err, ex); return(new Result { Message = err, Exception = ex }); } //install vaultapp //try //{ // var tmpfile = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~"), "vault.mfappx"); // mVault.CustomApplicationManagementOperations.InstallCustomApplication(tmpfile); //} //catch (Exception ex) //{ // var err = "创建库中vaultapp error:" + ex.Message; // Log.Error(err, ex); // return new Result { Message = err, Exception = ex }; //} return(new Result { Success = true, Contact = contact }); }
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); }