static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Format is: BasicScriptMigration.exe sitecollectionurl username password");
                return;
            }
            string webUrl        = args[0];
            string username      = args[1];
            string password      = args[2];
            var    baseFolder    = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            var    scriptsSource = System.IO.Path.Combine(baseFolder, "Migrations");

            var config = new MigratorConfiguration();

            config.Log     = new ConsoleUpgradeLog(true); // Alternatively use ColoreConsoleTraceListener from Essential.Diagnostics
            config.Journal = new NullJournal();           // Use NullJournal to run the migrations every time
            config.MigrationProviders.Add(new ScriptMigrationProvider(scriptsSource));
            config.ContextManager = new BasicContextManager(webUrl, username, password);

            var migrator = new Migrator(config);
            var result   = migrator.PerformMigration();

            Console.WriteLine(result.Successful ? "Done" : "Failed");
        }
예제 #2
0
        private static MigratorConfiguration Run(string[] args)
        {
            var tokenizer    = new Tokenizer();
            var tokens       = tokenizer.Tokenize(args);
            var tokenManager = new TokenManager(tokens);

            IEnumerable <ICommand> commands = GetAllCommands();

            var configuration = new MigratorConfiguration();

            while (tokenManager.HasToken())
            {
                var currentToken = tokenManager.GetToken();
                tokenManager.Consume();

                if (currentToken.Type != TokenType.Switch)
                {
                    throw new ArgumentException($"Invalid switch {currentToken.RawValue}");
                }

                var command = commands.FirstOrDefault(i => string.Equals(i.ShortOption, (string)currentToken.Value, i.CaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase));
                if (command == null)
                {
                    command = commands.FirstOrDefault(i => string.Equals(i.Option, (string)currentToken.Value, i.CaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase));
                }

                if (command == null)
                {
                    throw new ArgumentException($"Unkown switch {currentToken.RawValue}");
                }

                command.Execute(configuration, tokenManager);
            }
            return(configuration);
        }
예제 #3
0
 public void Execute(MigratorConfiguration migratorConfiguration, TokenManager tokenManager)
 {
     foreach (var command in this.commands)
     {
         Console.Write($"-{command.ShortOption}|--{command.Option}".PadRight(50, ' '));
         Console.WriteLine(command.Help);
     }
 }
예제 #4
0
        private static void ApplyMigrations(string webUrl, string username, string password)
        {
            Console.WriteLine();
            Console.WriteLine("= Apply Migrations =");

            var config = new MigratorConfiguration();

            config.Journal = new WebPropertyBagJournal("Test_Migrations/");

            var baseFolder     = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            var scriptsSource  = System.IO.Path.Combine(baseFolder, "Migrations");
            var scriptProvider = new ScriptMigrationProvider(scriptsSource);

            scriptProvider.Variables.Add("Other", Guid.NewGuid());
            config.MigrationProviders.Add(scriptProvider);

            // Use NullJournal to run the migrations every time
            //config.Journal = new NullJournal();

            // Although basic context can accept plain text password, setting only securePassword prevents it being passed through to $SPPassword
            var securePassword = BasicContextManager.GetSecureStringFromString(password);

            config.ContextManager = new BasicContextManager(webUrl, username, securePassword);
            var migrator = new Migrator(config);
            var result   = migrator.PerformMigration();

            // Alternative using ExistingContextManager
            //MigrationResult result;
            //var securePassword = BasicContextManager.GetSecureStringFromString(password);
            //var credentials = new SharePointOnlineCredentials(username, securePassword);
            //using (var clientContext = new ClientContext(webUrl))
            //{
            //    clientContext.Credentials = credentials;
            //    // If username + password aren't passed, then $SPContext is available, but not $SPCredentials
            //    config.ContextManager = new ExistingContextManager(clientContext, username, securePassword);
            //    var migrator = new Migrator(config);
            //    result = migrator.PerformMigration();
            //}

            Console.WriteLine(result.Successful ? "Done" : "Failed");
        }
예제 #5
0
        public void Execute(MigratorConfiguration migratorConfiguration, TokenManager tokenManager)
        {
            if (tokenManager.HasToken())
            {
                var token = tokenManager.GetToken();

                if (token.Type == TokenType.Boolean)
                {
                    migratorConfiguration.ShowVerbose = (bool)token.Value;
                    tokenManager.Consume();
                }
                else
                {
                    migratorConfiguration.ShowVerbose = true;
                }
            }
            else
            {
                migratorConfiguration.ShowVerbose = true;
            }
        }
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Format is: BasicCodeMigration.exe sitecollectionurl username password");
                return;
            }
            string webUrl   = args[0];
            string username = args[1];
            string password = args[2];

            var config = new MigratorConfiguration();

            config.Log     = new ConsoleUpgradeLog(true); // Alternatively use ColoreConsoleTraceListener from Essential.Diagnostics
            config.Journal = new NullJournal();           // Use NullJournal to run the migrations every time
            config.MigrationProviders.Add(new AssemblyMigrationProvider(Assembly.GetExecutingAssembly()));
            config.ContextManager = new BasicContextManager(webUrl, username, password);

            var migrator = new Migrator(config);
            var result   = migrator.PerformMigration();

            Console.WriteLine(result.Successful ? "Done" : "Failed");
        }
예제 #7
0
        public void Execute(MigratorConfiguration migratorConfiguration, TokenManager tokenManager)
        {
            if (!tokenManager.HasToken())
            {
                throw new ArgumentException("No value provided for -d|--directory");
            }
            var token = tokenManager.GetToken();

            tokenManager.Consume();

            if (token.Type != TokenType.String)
            {
                throw new ArgumentException("No valid value provided for -d|--directory");
            }

            var dir = token.Value.ToString();

            if (!Directory.Exists(dir))
            {
                throw new DirectoryNotFoundException($"Directory '{dir}' does not exist.");
            }

            migratorConfiguration.Directory = dir;
        }
예제 #8
0
        public void Execute(MigratorConfiguration migratorConfiguration, TokenManager tokenManager)
        {
            if (!tokenManager.HasToken())
            {
                throw new ArgumentException("No value provided for -a|--assembly");
            }
            var token = tokenManager.GetToken();

            tokenManager.Consume();

            if (token.Type != TokenType.String)
            {
                throw new ArgumentException("No valid value provided for -a|--assembly");
            }

            var path = token.Value.ToString();

            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"File '{path}' does not exist.");
            }

            migratorConfiguration.AssemblyPath = path;
        }