Ejemplo n.º 1
0
        private void HandleJobStarted(object sender, JobStartedEventArgs args)
        {
            if (this.ActiveJob != null && this.ActiveJob.Job == args.Job)
            {
                return;
            }

            SyncJob syncJob = args.Job as SyncJob;

            if (syncJob != null)
            {
                this.ActiveJob = new SyncJobViewModel(syncJob, this, false);
            }

            AnalyzeJob analyzeJob = args.Job as AnalyzeJob;

            if (analyzeJob != null)
            {
                this.ActiveJob = new AnalyzeJobViewModel(analyzeJob, this);
            }

            RestoreJob restoreJob = args.Job as RestoreJob;

            if (restoreJob != null)
            {
                this.ActiveJob = new RestoreJobViewModel(restoreJob, this, false);
            }

            this.UpdateStatusDescription();
        }
Ejemplo n.º 2
0
        private async Task RunHelpAsync(bool _isHelp, string commandName)
        {
            if (_isHelp || string.IsNullOrEmpty(commandName))
            {
                var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}");

                await Console.Out.WriteLineAsync($"当前文件夹: {Settings.ContentRootPath}");

                await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}");

                await Console.Out.WriteLineAsync();

                await CliUtils.PrintRowLine();

                await CliUtils.PrintRow("Usage");

                await CliUtils.PrintRowLine();

                BackupJob.PrintUsage();
                RestoreJob.PrintUsage();
                await CliUtils.PrintRowLine();

                await CliUtils.PrintRow("https://www.datory.io/docs/");

                await CliUtils.PrintRowLine();

                Console.ReadLine();
            }
            else
            {
                Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'");
            }
        }
Ejemplo n.º 3
0
        private static async Task RunHelpAsync(bool isHelp, string commandName, Dictionary <string, Func <IJobContext, Task> > pluginJobs)
        {
            if (isHelp || string.IsNullOrEmpty(commandName))
            {
                var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}");

                await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}");

                await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}");

                await Console.Out.WriteLineAsync();

                await CliUtils.PrintRowLine();

                await CliUtils.PrintRow("Usage");

                await CliUtils.PrintRowLine();

                var backupJob  = new BackupJob();
                var installJob = new InstallJob();
                var restoreJob = new RestoreJob();
                var syncJob    = new SyncJob();
                var updateJob  = new UpdateJob();
                var versionJob = new VersionJob();

                backupJob.PrintUsage();
                installJob.PrintUsage();
                restoreJob.PrintUsage();
                syncJob.PrintUsage();
                updateJob.PrintUsage();
                versionJob.PrintUsage();

                if (pluginJobs != null && pluginJobs.Count > 0)
                {
                    Console.WriteLine($"插件命令: {TranslateUtils.ObjectCollectionToString(pluginJobs.Keys)}");
                    Console.WriteLine();
                }

                await CliUtils.PrintRowLine();

                await CliUtils.PrintRow(CloudUtils.Root.DocsCliUrl);

                await CliUtils.PrintRowLine();

                Console.ReadLine();
            }
            else
            {
                Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'");
            }
        }
Ejemplo n.º 4
0
 public void RestoreWork()
 {
     Log.Info("restore thread running");
     while (!stopRequested)
     {
         RestoreJob job = restoreQueue.Dequeue();
         Log.Info("executing restore job " + job);
         job.Restore();
         // wait at least 2 seconds;
         Thread.Sleep(MILLIS_RESTORE_WAIT);
         restoreCompleted = restoreQueue.Size() == 0;
     }
     Log.Info("restore thread terminated");
 }
Ejemplo n.º 5
0
        public async Task Should_call_grain_to_get_restore_status()
        {
            IRestoreJob state = new RestoreJob();

            var grain = A.Fake <IRestoreGrain>();

            A.CallTo(() => grainFactory.GetGrain <IRestoreGrain>(SingleGrain.Id, null))
            .Returns(grain);

            A.CallTo(() => grain.GetStateAsync())
            .Returns(state.AsJ());

            var result = await sut.GetRestoreAsync();

            Assert.Same(state, result);
        }
Ejemplo n.º 6
0
        private static async Task RunHelpAsync(bool isHelp, string commandName)
        {
            if (isHelp || string.IsNullOrEmpty(commandName))
            {
                var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}");

                await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}");

                await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}");

                await Console.Out.WriteLineAsync();

                await CliUtils.PrintRowLine();

                await CliUtils.PrintRow("Usage");

                await CliUtils.PrintRowLine();

                BackupJob.PrintUsage();
                InstallJob.PrintUsage();
                RestoreJob.PrintUsage();
                UpdateJob.PrintUsage();
                VersionJob.PrintUsage();
                await CliUtils.PrintRowLine();

                await CliUtils.PrintRow("https://www.siteserver.cn/docs/cli");

                await CliUtils.PrintRowLine();

                Console.ReadLine();
            }
            else
            {
                Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'");
            }
        }
Ejemplo n.º 7
0
            public bool RestoreGame(String game, String from)
            {
                BackupSet set = GetBackupSetForName(game);

                if (set != null)
                {
                    restoreCompleted = false;
                    restoredGame     = game;
                    RestoreJob job = new RestoreJob(set, from);
                    Log.Warning("restoring game " + game);
                    if (SAVE.configuration.asynchronous)
                    {
                        Log.Info("asynchronous restore from backup set '" + game + "' backup '" + from + "'");
                        restoreQueue.Enqueue(job);
                    }
                    else
                    {
                        Log.Info("synchronous restore from backup set '" + game + "' backup '" + from + "'");
                        // wait for asynchronous restores to complete
                        while (restoreQueue.Size() > 0)
                        {
                            Thread.Sleep(100);
                        }
                        // do restore
                        job.Restore();
                        // done
                        restoreCompleted = true;
                    }
                    return(true);
                }
                else
                {
                    Log.Warning("no backup set '" + game + "' found");
                    return(false);
                }
            }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 public RestoreJobViewModel(RestoreJob job, SyncRelationshipViewModel relationshipViewModel, bool loadFromHistory)
     : base(job, relationshipViewModel)
 {
     this.RestoreJob.ProgressChanged += this.RestoreJobOnProgressChanged;
 }
Ejemplo n.º 11
0
        private static void Main(string[] args)
        {
            try
            {
                Console.OutputEncoding = Encoding.GetEncoding(936);
            }
            catch
            {
                try
                {
                    Console.OutputEncoding = Encoding.UTF8;
                }
                catch
                {
                    // ignored
                }
            }

            if (!CliUtils.ParseArgs(Options, args))
            {
                return;
            }

            var commandNames = new List <string>();
            var commandArgs  = new List <string>();

            if (args.Length >= 1)
            {
                var isCommand = true;
                foreach (var arg in args)
                {
                    if (isCommand && !StringUtils.StartsWith(arg, "-"))
                    {
                        commandNames.Add(StringUtils.Trim(arg));
                    }
                    else
                    {
                        isCommand = false;
                        commandArgs.Add(StringUtils.Trim(arg));
                    }
                }
            }
            CommandName = string.Join(" ", commandNames);
            CommandArgs = commandArgs.ToArray();

            Console.WriteLine("欢迎使用 SiteServer Cli 命令行工具");
            Console.WriteLine();

            var backupJob  = new BackupJob();
            var installJob = new InstallJob();
            var restoreJob = new RestoreJob();
            var syncJob    = new SyncJob();
            var updateJob  = new UpdateJob();
            var versionJob = new VersionJob();
            var testJob    = new TestJob();

            Jobs = new Dictionary <string, Func <IJobContext, Task> >(StringComparer.CurrentCultureIgnoreCase)
            {
                { BackupJob.CommandName, backupJob.Execute },
                { InstallJob.CommandName, installJob.Execute },
                { RestoreJob.CommandName, restoreJob.Execute },
                { SyncJob.CommandName, syncJob.Execute },
                { UpdateJob.CommandName, updateJob.Execute },
                { VersionJob.CommandName, versionJob.Execute },
                { TestJob.CommandName, testJob.Execute }
            };

            PluginManager.LoadPlugins(CliUtils.PhysicalApplicationPath);
            var pluginJobs = PluginJobManager.GetJobs();

            if (pluginJobs != null && pluginJobs.Count > 0)
            {
                foreach (var command in pluginJobs.Keys)
                {
                    if (!Jobs.ContainsKey(command))
                    {
                        Jobs.Add(command, pluginJobs[command]);
                    }
                }
            }

            if (!Jobs.ContainsKey(CommandName))
            {
                RunHelpAsync(IsHelp, CommandName, pluginJobs).GetAwaiter().GetResult();
            }
            else if (!string.IsNullOrEmpty(Repeat))
            {
                RunRepeatAsync(Repeat).GetAwaiter().GetResult();
            }
            else
            {
                RunExecuteAsync(CommandName, CommandArgs, null).GetAwaiter().GetResult();
            }
        }