Beispiel #1
0
 /// <summary>
 /// 判断服务端是否已连接
 /// </summary>
 /// <returns></returns>
 private bool ServerAppConnected()
 {
     if (_serverApp == null)
     {
         return(false);
     }
     try
     {
         _serverApp.GetServerVersion();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }