示例#1
0
 public static void resetForTesting()
 {
 #if (DEBUG )
     instance = null;
 #else
     throw new InvalidOperationException("This method can only called on testting ");
 #endif
 }
示例#2
0
 public static DackupContext Create(string logFile, string tmpPath)
 {
     if (instance != null)
     {
         throw new InvalidOperationException("DackupContext already created - use BacupContext.Current to get");
     }
     else
     {
         lock (_mutex)
         {
             if (instance == null)
             {
                 instance = new DackupContext(logFile, tmpPath);
             }
         }
     }
     return(instance);
 }
示例#3
0
文件: Program.cs 项目: huobazi/dackup
        public static void Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name        = "dackup",
                Description = "A backup app for your server or database or desktop",
            };

            app.HelpOption(inherited: true);

            app.Command("new", newCmd =>
            {
                newCmd.Description = "Generate a config file";
                var modelName      = newCmd.Argument("model", "Name of the model").IsRequired();

                newCmd.OnExecute(() =>
                {
                    var fileName = Path.Combine(Environment.CurrentDirectory, modelName.Value + ".config");
                    GenerateMockupConfig(fileName);
                });
            });

            app.Command("perform", performCmd =>
            {
                performCmd.Description = "Performing your backup by config";

                var configFile = performCmd.Option("--config-file  <FILE>", "Required. The File name of the config.", CommandOptionType.SingleValue)
                                 .IsRequired()
                                 .Accepts(v => v.ExistingFile());
                var logPathConfig = performCmd.Option("--log-path  <PATH>", "op. The File path of the log.", CommandOptionType.SingleValue);
                var tmpPathConfig = performCmd.Option("--tmp-path  <PATH>", "op. The tmp path.", CommandOptionType.SingleValue);

                performCmd.OnExecute(() =>
                {
                    var logPath        = logPathConfig.Value();
                    var tmpPath        = tmpPathConfig.Value();
                    var configFilePath = configFile.Value();

                    if (string.IsNullOrEmpty(logPath))
                    {
                        logPath = "log";
                    }
                    if (string.IsNullOrEmpty(tmpPath))
                    {
                        tmpPath = "tmp";
                    }

                    DackupContext.Create(Path.Join(logPath, "dackup.log"), tmpPath);

                    var serviceProvider = ServiceProviderFactory.ServiceProvider;

                    var logger = serviceProvider.GetService <ILogger <Program> >();
                    AppDomain.CurrentDomain.UnhandledException += (s, args) => logger.LogError(args.ExceptionObject as Exception, "*** Crash! ***", "UnhandledException");
                    TaskScheduler.UnobservedTaskException      += (s, args) => logger.LogError(args.Exception, "*** Crash! ***", "UnobservedTaskException");

                    var app = serviceProvider.GetService <DackupApplication>();
                    app.Run(configFilePath).Wait();
                });
            });

            app.OnExecute(() =>
            {
                app.ShowHelp();
            });

            app.Execute(args);
        }