static int Main(string[] args) { Console.ResetColor(); XmlConfigurator.Configure(); //Initialize log4net Log.Debug("Sherpa application started"); try { ProgramOptions = OptionsParser.ParseArguments(args); UrlToSite = new Uri(ProgramOptions.UrlToSite); UnattendedInstall = !string.IsNullOrEmpty(ProgramOptions.Operations); Log.DebugFormat("Sherpa started with the following options - URL: {0}, userName: {1}, configPath: {2}, spo: {3}, unattended: {4}, avoidthrottling: {5}", ProgramOptions.UrlToSite, ProgramOptions.UserName, ProgramOptions.RootPath, ProgramOptions.SharePointOnline, UnattendedInstall, ProgramOptions.AvoidThrottling ); } catch (Exception) { Log.Fatal("Invalid parameters, application cannot continue"); Environment.Exit(1); } if (!UnattendedInstall) { PrintLogo(); } else { Log.Info("Sherpa initialized in unattended mode"); } if (!IsCorrectSharePointAssemblyVersionLoaded()) { Log.Fatal("Old version of SharePoint assemblies loaded. Application cannot be run on a machine with SharePoint 2010 or older installed. Content type installation only works with SharePoint 2013 SP1 and later."); Environment.Exit(1); } try { var authManager = new AuthenticationHandler(); Credentials = authManager.GetSessionAuthCredentials(ProgramOptions.SharePointOnline, ProgramOptions.UserName, UrlToSite); RunApplication(); Log.Debug("Application exiting"); } catch (Exception exception) { Log.Fatal("An exception occured: " + exception.Message); Log.Debug(exception.StackTrace); if (UnattendedInstall) { return(1); } RunApplication(); } return(0); }
static void Main(string[] args) { PrintLogo(); try { if (!IsCorrectSharePointAssemblyVersionLoaded()) { Console.WriteLine("Old version of SharePoint assemblies loaded. Application cannot be run on a machine with SharePoint 2010 or older installed. "); Environment.Exit(1); } ProgramOptions = OptionsParser.ParseArguments(args); UrlToSite = new Uri(ProgramOptions.UrlToSite); } catch (Exception) { Console.WriteLine("Invalid parameters, application cannot continue"); Environment.Exit(1); } PrintLogo(); if (ProgramOptions.SharePointOnline) { Console.WriteLine("Login with your password to {0}", ProgramOptions.UrlToSite); var authenticationHandler = new AuthenticationHandler(); Credentials = authenticationHandler.GetCredentialsForSharePointOnline(ProgramOptions.UserName, UrlToSite); } else { Credentials = CredentialCache.DefaultCredentials; using (new ClientContext(ProgramOptions.UrlToSite) { Credentials = Credentials }) { Console.WriteLine("Authenticated with default credentials"); } } RunApplication(); }