Пример #1
0
        private static void Run(Options options)
        {
            var storage          = new FileSystemStorage();
            var passwordProvider = options.Password != null ? new StaticPasswordProvider(options.Password) : new ConsolePasswordProvider() as IPasswordProvider;
            var databaseManager  = new DatabaseManager(storage, passwordProvider);

            var databasePath = options.DatabasePath;
            var database     = storage.Exists(databasePath) ? databaseManager.LoadDatabase(databasePath) : new Database();

            if (database == null)
            {
                System.Console.WriteLine("Invalid password.");
                Environment.ExitCode = 1;
                return;
            }

            var context = new Context();

            context.Database        = database;
            context.DatabasePath    = databasePath;
            context.DatabaseManager = databaseManager;
            context.CurrentFolder   = database.RootFolder;

            var controller = new Controller(context);

            if (options.ItemPath != null)
            {
                controller.PrintItemValue(options.ItemPath);
            }
            else if (options.Script != null)
            {
                controller.RunScript(options.Script);
            }
            else
            {
                controller.RunInteractive();
            }
        }