예제 #1
0
        public ICollection <string> GetUsersInGroup(MFilesVault vault, int groupId)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var users  = GetUsersFromGroup(ovault, groupId);

            return(users.Select(uid => ovault.UserOperations.GetUserAccount(uid)).Select(la => MfUserUtils.GetUserNameWithoutDomain(la.LoginName)).ToList());
        }
예제 #2
0
        public ICollection <string> GetUsersInGroup(MFilesVault vault, string groupName)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var group  = GetGroupByName(ovault, groupName, vault.Id);

            return(GetUsersInGroup(ovault, group.GroupId));
        }
예제 #3
0
        public ICollection <string> GetUsersInGroupByAlias(MFilesVault vault, string groupAlias)
        {
            var ovault  = MFServerUtility.GetVault(vault);
            var groupId = MfAlias.GetUsergroup(ovault, groupAlias);

            return(GetUsersInGroup(ovault, groupId));
        }
예제 #4
0
        public void RenameGroupName(MFilesVault vault, int groupId, string newName)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var uga    = ovault.UserGroupOperations.GetUserGroupAdmin(groupId);

            uga.UserGroup.Name = newName;
            ovault.UserGroupOperations.UpdateUserGroupAdmin(uga);
        }
예제 #5
0
        public void AddUserToGroup(MFilesVault vault, string userName, string groupName)
        {
            var ovault  = MFServerUtility.GetVault(vault);
            var groupId = GetGroupId(ovault, groupName);
            var userId  = GetUserId(ovault, userName);

            AddUserToGroup(ovault, userId, groupId);
        }
예제 #6
0
        public void AddUserToGroup(MFilesVault vault, string userName, params int[] groupIds)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var userId = GetUserId(ovault, userName);

            foreach (var groupId in groupIds)
            {
                AddUserToGroup(ovault, userId, groupId);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        public bool UninstallApps(MFilesVault vault)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var apps   = ovault.CustomApplicationManagementOperations.GetCustomApplications();

            foreach (CustomApplication ca in apps)
            {
                ovault.CustomApplicationManagementOperations.UninstallCustomApplication(ca.ID);
            }
            return(true);
        }
예제 #9
0
        public void DisableVaultUser(string userName, MFilesVault vault)
        {
            var mVault = MFServerUtility.GetVault(vault);

            if (!HasVaultUser(userName, vault))
            {
                Log.Error(string.Format("用户({0})不存在于vault({1}),vaultname={2},中!", userName, vault.Guid, mVault.Name));
                return;
            }
            MfUserUtils.DisableVaultUser(mVault, userName);
        }
예제 #10
0
        public ICollection <MFilesUserGroup> GetUserGroupsContainsString(MFilesVault vault, string groupStr)
        {
            var mfVault = MFServerUtility.GetVault(vault);
            var groups  = mfVault.UserGroupOperations.GetUserGroupsAdmin();
            var list    = (from UserGroupAdmin uga in groups
                           where !uga.UserGroup.Predefined && uga.UserGroup.Name.Contains(groupStr) && uga.UserGroup.Name != groupStr
                           select ConvertTo(uga, vault.Id)).ToList();

            list.Sort();
            return(list);
        }
예제 #11
0
        public ICollection <MFilesUserGroup> GetUserGroups(MFilesVault vault, bool includeInternalGroup = false)
        {
            var mfVault = MFServerUtility.GetVault(vault);
            var groups  = mfVault.UserGroupOperations.GetUserGroupsAdmin();

            if (includeInternalGroup)
            {
                return((from UserGroupAdmin uga in groups select ConvertTo(uga, vault.Id)).ToList());
            }
            return((from UserGroupAdmin uga in groups where !uga.UserGroup.Predefined select ConvertTo(uga, vault.Id)).ToList());
        }
예제 #12
0
        public void EnableVaultUser(string userName, MFilesVault vault)
        {
            var mVault = MFServerUtility.GetVault(vault);

            if (!HasVaultUser(userName, vault))
            {
                var err = string.Format("用户{0}不存在于vault{1},vaultname={2},中!", userName, vault.Guid, mVault.Name);
                Log.Error(err);
                throw new Exception(err);
            }
            MfUserUtils.EnableVaultUser(mVault, userName);
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
        public MfContact GetContact(MFilesVault vault, MetadataAliases aliases, string userName)
        {
            var mfVault = MFServerUtility.GetVault(vault);
            var userId  = MfUserUtils.GetUserAccount(mfVault, userName);

            if (userId == null)
            {
                return(null);
            }
            var uid = userId.Value; //userid

            return(GetContactByUserId(mfVault, aliases, uid));
        }
예제 #15
0
        public bool ImportApp(string zipPath, MFilesVault vault)
        {
            var zipDirectory = new DirectoryInfo(zipPath);
            var ovault       = MFServerUtility.GetVault(vault);

            foreach (var di in zipDirectory.GetDirectories())
            {
                var targetPath = Path.Combine(Path.GetTempPath(), di.Name + ".zip");
                var zip        = new ZipFile();
                zip.AddSelectedFiles("name!=*.zip and name!=*.pdb and name!=*.log", di.FullName, di.Name, true);
                zip.Save(targetPath);
                ImportApp(targetPath, ovault);
            }
            return(true);
        }
예제 #16
0
 public MFObject GetMFObject <T>(MFilesVault vault, MetadataAliases aliases, T entity) where T : InternalEntity
 {
     if (entity is Project)
     {
         //var config = VaultConfig.GetConfigFromString(vault.Template.MetadataJson);
         var projObj = aliases.GetMfProject(entity as Project);// config.GetMfProjectObject(entity as Project);
         return(projObj);
     }
     if (entity is MfContact)
     {
         var mfVault    = MFServerUtility.GetVault(vault);
         var contactObj = aliases.GetMfContact(mfVault, entity as MfContact);
         return(contactObj);
     }
     return(null);
 }
예제 #17
0
        public bool Backup(MFilesVault vault)
        {
            var path   = Path.Combine(Path.GetTempPath(), vault.Guid + ".mfb");
            var ovault = MFServerUtility.GetVault(vault);
            var backup = new BackupJob
            {
                BackupType             = MFBackupType.MFBackupTypeFull,
                TargetFile             = path,
                VaultGUID              = ovault.GetGUID(),
                OverwriteExistingFiles = true
            };

            var app = MFServerUtility.ConnectToMfApp(vault);

            app.VaultManagementOperations.BackupVault(backup);
            return(true);
        }
예제 #18
0
        public ICollection <MFilesUserGroup> GetGroupsByUser(MFilesVault vault, string userName)
        {
            var ret        = new List <MFilesUserGroup>();
            var ovault     = MFServerUtility.GetVault(vault);
            var userid     = GetUserId(ovault, userName);
            var usergroups = ovault.UserGroupOperations.GetUserGroupsAdmin();

            foreach (UserGroupAdmin uga in usergroups)
            {
                foreach (int id in uga.UserGroup.Members)
                {
                    if (id < 0)
                    {
                        ret.AddRange(GetUserGroupsOfUserEx(userid, -id, uga, ovault));
                    }
                    else
                    {
                        if (id == userid && !uga.UserGroup.Predefined)
                        {
                            ret.Add(ConvertTo(uga, vault.Id));
                        }
                    }
                }
            }
            var newret = new List <MFilesUserGroup>();

            foreach (var a in ret)
            {
                var found = false;
                foreach (var b in newret)
                {
                    if (b.Id == a.Id)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    newret.Add(a);
                }
            }
            return(newret);
        }
예제 #19
0
        public void AddUserGroupToVault(MFilesVault vault, MFilesUserGroup userGroup)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var newuga = new UserGroupAdmin
            {
                UserGroup = new UserGroup {
                    Name = userGroup.Name
                }
            };

            if (!String.IsNullOrEmpty(userGroup.Alias))
            {
                newuga.SemanticAliases = new SemanticAliases {
                    Value = userGroup.Alias
                };
            }
            var ug = ovault.UserGroupOperations.AddUserGroupAdmin(newuga);

            userGroup.Id = ug.UserGroup.ID;
        }
예제 #20
0
        public void RemoveUserFromGroup(MFilesVault vault, string userName, params int[] groupIds)
        {
            var ovault = MFServerUtility.GetVault(vault);
            var userid = -1;
            var users  = ovault.UserOperations.GetUserAccounts();
            var un     = MfUserUtils.GetUserNameWithoutDomain(userName).ToUpper();

            foreach (UserAccount ua in users)
            {
                var un0 = MfUserUtils.GetUserNameWithoutDomain(ua.LoginName);
                if (un0.ToUpper() == un)
                {
                    userid = ua.ID;
                    break;
                }
            }
            foreach (var groupId in groupIds)
            {
                RemoveUserFromGroupById(ovault, userid, groupId);
            }
        }
예제 #21
0
        public MFDownloadFile DownloadFile(MFilesVault vault, int objType, int objId, int fileId)
        {
            var mfVault = MFServerUtility.GetVault(vault);
            var objID   = new ObjID();

            objID.SetIDs(objType, objId);
            var objVer     = mfVault.ObjectOperations.GetLatestObjVer(objID, false, false);
            var objVersion = mfVault.ObjectOperations.GetObjectInfo(objVer, true, false);

            if (objVersion.FilesCount == 0)
            {
                return(null);
            }
            if (fileId > 0)
            {
                ObjectFile fv = null;
                foreach (ObjectFile file in objVersion.Files)
                {
                    if (file.FileVer.ID == fileId)
                    {
                        fv = file;
                        break;
                    }
                }
                if (fv == null)
                {
                    fv = objVersion.Files[1];
                }
                var session = mfVault.ObjectFileOperations.DownloadFileInBlocks_Begin(fv.FileVer.ID, fv.FileVer.Version);
                var content = mfVault.ObjectFileOperations.DownloadFileInBlocks_ReadBlock(session.DownloadID, session.FileSize32, 0);
                return(new MFDownloadFile
                {
                    Content = content,
                    Name = fv.Title,
                    Extension = fv.Extension,
                    Version = objVer.Version
                });
            }
            return(null);
        }
예제 #22
0
        public int?GetUserId(string userName, MFilesVault vault)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            return(MfUserUtils.GetUserAccount(mfVault, userName));
        }
예제 #23
0
        public void RemoveUserGroupById(MFilesVault vault, int groupId)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            mfVault.UserGroupOperations.RemoveUserGroupAdmin(groupId);
        }
예제 #24
0
        public MFProjectParty GetParty(MFilesVault vault, string partyName, MetadataAliases aliases, int?currentUserId = null)
        {
            var mfVault    = MFServerUtility.GetVault(vault);
            var partyObj   = aliases.Objects["ObjParticipant"];
            var partyClass = partyObj.ClassDict["ClassParticipant"];
            var typeId     = MfAlias.GetObjType(mfVault, partyObj.Alias);
            var classId    = MfAlias.GetObjectClass(mfVault, partyClass.Alias);

            var scs = new SearchConditions();

            MFSearchConditionUtils.AddBaseConditions(scs, typeId, classId);

            var namePropId = MfAlias.GetPropDef(mfVault, partyClass.PropDict["PropParticipantName"]);
            var nameSC     = MFSearchConditionUtils.Property(MFConditionType.MFConditionTypeEqual, namePropId,
                                                             MFDataType.MFDatatypeText, partyName);

            scs.Add(-1, nameSC);

            var res = mfVault.ObjectSearchOperations.SearchForObjectsByConditions(scs, MFSearchFlags.MFSearchFlagNone,
                                                                                  false);

            if (res.Count != 1)
            {
                return(null);
            }

            var party = new MFProjectParty {
                Name = partyName
            };
            var obj = res[1];

            party.InternalId = obj.ObjVer.ID;
            var managerPropId = MfAlias.GetPropDef(mfVault, partyClass.PropDict["PropProjPM"]);
            var managerTV     = mfVault.ObjectPropertyOperations.GetProperty(obj.ObjVer, managerPropId).Value;

            if (!managerTV.IsNULL() && !managerTV.IsUninitialized())
            {
                party.ManagerCount = 1;
                var contactId = managerTV.GetLookupID();
                var userId    = GetContactAccount(mfVault, aliases, contactId);
                if (currentUserId != null && userId == currentUserId.Value)
                {
                    party.IsCurrentManager = true;
                }
            }
            var vmPropId = MfAlias.GetPropDef(mfVault, partyClass.PropDict["PropProjVicePMs"]);
            var vmTV     = mfVault.ObjectPropertyOperations.GetProperty(obj.ObjVer, vmPropId).Value;

            if (!vmTV.IsNULL() && !vmTV.IsUninitialized())
            {
                var lkps = vmTV.GetValueAsLookups();
                party.ViceManagerCount = lkps.Count;
                if (currentUserId != null && !party.IsCurrentManager)
                {
                    for (var i = 1; i <= lkps.Count; i++)
                    {
                        var contactId = lkps[i].Item;
                        var userId    = GetContactAccount(mfVault, aliases, contactId);
                        if (userId == currentUserId.Value)
                        {
                            party.IsCurrentViceManager = true;
                            break;
                        }
                    }
                }
            }
            var mmPropId = MfAlias.GetPropDef(mfVault, partyClass.PropDict["PropMembers"]);
            var mmTV     = mfVault.ObjectPropertyOperations.GetProperty(obj.ObjVer, mmPropId).Value;

            if (!mmTV.IsNULL() && !mmTV.IsUninitialized())
            {
                var lkps = mmTV.GetValueAsLookups();
                party.MemberCount = lkps.Count;
                if (currentUserId != null && !party.IsCurrentViceManager && !party.IsCurrentManager)
                {
                    for (var i = 1; i <= lkps.Count; i++)
                    {
                        var contactId = lkps[i].Item;
                        var userId    = GetContactAccount(mfVault, aliases, contactId);
                        if (userId == currentUserId.Value)
                        {
                            party.IsCurrentMember = true;
                            break;
                        }
                    }
                }
            }

            return(party);
        }
예제 #25
0
        public MFilesUserGroup GetUserGroupById(MFilesVault vault, int groupId)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            return(GetGroupById(mfVault, groupId, vault.Id));
        }
예제 #26
0
        public void Delete(MFilesVault vault, int objType, int objId)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            Delete(mfVault, objType, objId);
        }
예제 #27
0
        public string GetAccountName(int userId, MFilesVault vault)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            return(MfUserUtils.GetUserNameWithoutDomain(mfVault, userId));
        }
예제 #28
0
        public MFilesUserGroup GetUserGroupByName(MFilesVault vault, string groupName)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            return(GetGroupByName(mfVault, groupName, vault.Id));
        }
예제 #29
0
        public MfContact GetContactByContactId(MFilesVault vault, MetadataAliases aliases, int contactId)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            return(GetContactById(mfVault, aliases, contactId));
        }
예제 #30
0
        internal void Update(MFilesVault vault, MFObject obj)
        {
            var mfVault = MFServerUtility.GetVault(vault);

            Update(mfVault, obj);
        }