예제 #1
0
        public void CreateForAllBackup(MFilesVault vault, string templateRootPath,
                                       string impersonationUserName, string impersonationPassword, MFSqlDatabase sqlDb = null, string vaultIndexRootPath = null)
        {
            var app = MFServerUtility.ConnectToMfApp(vault);

            CreateForAllBackup(app, vault, templateRootPath, impersonationUserName, impersonationPassword, sqlDb,
                               vaultIndexRootPath);
        }
예제 #2
0
        public void Create(MFilesVault vault, string templateRootPath,
                           string impersonationUserName, string impersonationPassword, MFSqlDatabase sqlDb = null, string vaultIndexRootPath = null, bool fullBackupOrStructure = false)
        {
            var app = MFServerUtility.ConnectToMfApp(vault);

            Create(app, vault, templateRootPath, impersonationUserName, impersonationPassword, sqlDb,
                   vaultIndexRootPath, fullBackupOrStructure);
        }
예제 #3
0
        public void ChangeVaultName(MFilesVault vault)
        {
            var app   = MFServerUtility.ConnectToMfApp(vault);
            var props = app.VaultManagementOperations.GetVaultProperties(vault.Guid);

            props.DisplayName = vault.Name;
            var mfVault = app.LogInToVault(vault.Guid);

            mfVault.ManagementOperations.UpdateVaultProperties(props);
        }
예제 #4
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);
        }
예제 #5
0
        public void CreateDefaultVault(MFilesVault vault)
        {
            if (HasVault(vault))
            {
                throw new Exception(string.Format("与{0}同名的vault已存在或guid={1}重复!", vault.Name, vault.Guid));
            }
            var app = MFServerUtility.ConnectToMfApp(vault);
            var vp  = new VaultProperties
            {
                DisplayName = vault.Name,
                ExtendedMetadataDrivenPermissions = true,
                FileDataStorageType = MFFileDataStorage.MFFileDataStorageDefault,
                MainDataFolder      = Path.Combine(vault.ServerPath, vault.Name),
                VaultGUID           = Guid.NewGuid().ToString()
            };

            var version = app.GetServerVersion().Major;

            vp.FullTextSearchLanguage = version < 11 ? "other" : "chs";

            var guid = app.VaultManagementOperations.CreateNewVault(vp);

            vault.Guid = guid;
        }
예제 #6
0
        public bool HasVault(MFilesVault vault)
        {
            var app = MFServerUtility.ConnectToMfApp(vault);

            return(HasVault(app, vault));
        }
예제 #7
0
        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
            });
        }