internal static void CreateForAllBackup(MFilesServerApplication app, MFilesVault vault, string templateRootPath, string impersonationUserName, string impersonationPassword, MFSqlDatabase sqlDb, string vaultIndexRootPath = null) { var vp = new VaultProperties { DisplayName = vault.Name, ExtendedMetadataDrivenPermissions = true, FileDataStorageType = MFFileDataStorage.MFFileDataStorageDisk, MainDataFolder = Path.Combine(@"C:\Program Files\M-Files\Server Vaults", vault.Name), VaultGUID = Guid.NewGuid().ToString() }; if (vp.SeparateLocationForFileData == null) { vp.SeparateLocationForFileData = new AdditionalFolders(); } var af = new AdditionalFolder { Folder = Path.Combine(vault.ServerPath, vault.Name), }; if (!String.IsNullOrEmpty(impersonationUserName) && !String.IsNullOrEmpty(impersonationPassword)) { af.Impersonation = new Impersonation { Account = impersonationUserName, Password = impersonationPassword, ImpersonationType = MFImpersonationType.MFImpersonationTypeSpecificAccount }; } vp.SeparateLocationForFileData.Add(-1, af); var version = app.GetServerVersion().Major; if (sqlDb != null) { var admin = new Impersonation { Account = sqlDb.AdminUserName, Password = sqlDb.AdminPassword, ImpersonationType = sqlDb.SqlserverUser ? MFImpersonationType.MFImpersonationTypeExtAccount : MFImpersonationType.MFImpersonationTypeSpecificAccount }; var mfsqldb = new SQLDatabase { Server = sqlDb.Server, Name = sqlDb.Catelog, Engine = MFDBEngine.MFDBEngineMSSQLServer }; mfsqldb.AdminUser = admin; //2015 vp.SQLDatabase = mfsqldb; } vp.FullTextSearchLanguage = version < 11 ? "other" : "chs"; var rj = new RestoreJob { BackupFileFull = templateRootPath, VaultProperties = vp, OverwriteExistingFiles = true }; app.VaultManagementOperations.RestoreVault(rj); vault.Guid = vp.VaultGUID; //return app.LogInToVault(vp.VaultGUID); }
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); }
internal static Vault Create(MFilesServerApplication app, MFilesVault vault, string templateRootPath, string impersonationUserName, string impersonationPassword, MFSqlDatabase sqlDb, string vaultIndexRootPath = null, bool fullBackupOrStructure = false) { var vp = new VaultProperties { DisplayName = vault.Name, ExtendedMetadataDrivenPermissions = true, FileDataStorageType = MFFileDataStorage.MFFileDataStorageDisk, MainDataFolder = Path.Combine(@"C:\Program Files\M-Files\Server Vaults", vault.Name), VaultGUID = Guid.NewGuid().ToString() }; if (vp.SeparateLocationForFileData == null) { vp.SeparateLocationForFileData = new AdditionalFolders(); } var af = new AdditionalFolder { Folder = Path.Combine(vault.ServerPath, vault.Name), }; if (!String.IsNullOrEmpty(impersonationUserName) && !String.IsNullOrEmpty(impersonationPassword)) { af.Impersonation = new Impersonation { Account = impersonationUserName, Password = impersonationPassword, ImpersonationType = MFImpersonationType.MFImpersonationTypeSpecificAccount }; } vp.SeparateLocationForFileData.Add(-1, af); var version = app.GetServerVersion().Major; if (sqlDb != null) { var admin = new Impersonation { Account = sqlDb.AdminUserName, Password = sqlDb.AdminPassword, ImpersonationType = sqlDb.SqlserverUser ? MFImpersonationType.MFImpersonationTypeExtAccount : MFImpersonationType.MFImpersonationTypeSpecificAccount }; var mfsqldb = new SQLDatabase { Server = sqlDb.Server, Name = sqlDb.Catelog, Engine = MFDBEngine.MFDBEngineMSSQLServer }; mfsqldb.AdminUser = admin; //2015 vp.SQLDatabase = mfsqldb; } vp.FullTextSearchLanguage = version < 11 ? "other" : "chs"; if (fullBackupOrStructure) { var rj = new RestoreJob { BackupFileFull = templateRootPath, VaultProperties = vp, OverwriteExistingFiles = true }; app.VaultManagementOperations.RestoreVault(rj); vault.Guid = vp.VaultGUID; return(null); } var guid = app.VaultManagementOperations.CreateNewVault(vp); vault.Guid = guid; var import = new ImportContentJob { ActivateAutomaticPermissionsForNewOrChangedDefinitions = true, DisableImportedExternalObjectTypeConnections = true, DisableImportedExternalUserGroups = true, DisableImportedVaultEventHandlers = false, Flags = MFImportContentFlag.MFImportContentFlagNone, IgnoreAutomaticPermissionsDefinedByObjects = false, SourceLocation = Path.Combine(templateRootPath, "Index") }; if (!String.IsNullOrEmpty(impersonationUserName) && !String.IsNullOrEmpty(impersonationPassword)) { import.Impersonation = new Impersonation { Account = impersonationUserName, Password = impersonationPassword, ImpersonationType = MFImpersonationType.MFImpersonationTypeSpecificAccount }; } var newvault = app.LogInToVault(guid); //todo,会有数据超限的问题, 2015貌似没有问题,但更新模板数据时可能会有这个问题 try { newvault.ManagementOperations.ImportContent(import); } catch (Exception ex) { Log.Error("导入模版元数据出错:" + ex.Message, ex); } return(newvault); }
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); }
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 }); }