Exemple #1
0
 private bool InitApp()
 {
     Application.ThreadException += Application_ThreadException;
     try {
         var serviceURl = ConfigurationManager.AppSettings.Get("serviceUrl");
         _app = new OAuthEntityApp(serviceURl);
         _app.Init();
         // Get IOAuthClientService and hook to it's Redirected event - to get notified when user hits "Allow"
         _service             = _app.GetService <IOAuthClientService>();
         _service.Redirected += OAuthClientService_Redirected;
         //Setup default encryption channel - we store OAuth data encrypted
         var cryptoKey   = ConfigurationManager.AppSettings.Get("CryptoKey");
         var encrService = _app.GetService <Vita.Modules.EncryptedData.IEncryptionService>();
         encrService.AddChannel(HexUtil.HexToByteArray(cryptoKey));
         //Connect to db
         var connString = ConfigurationManager.AppSettings.Get("MsSqlConnectionString");
         if (!CheckConnection(connString))
         {
             return(false);
         }
         var dbSettings = new DbSettings(new MsSqlDbDriver(), MsSqlDbDriver.DefaultMsSqlDbOptions, connString);
         _app.ConnectTo(dbSettings);
         //Start local web server to handle redirects back from OAuth server, after user approves access
         StartWebService(serviceURl);
         // Hook to global error log, to show exception when it happens in Redirect controller
         var errLog = _app.GetService <IErrorLogService>();
         errLog.ErrorLogged += ErrLog_ErrorLogged;
         //Just for ease of debugging this app, update servers definitions in database
         var session = OpenSession();
         Vita.Modules.OAuthClient.OAuthServers.CreateUpdatePopularServers(session);
         session.SaveChanges();
         return(true);
     } catch (Exception ex) {
         Log(ex.ToLogString());
         MessageBox.Show(ex.Message, "Error");
         return(false);
     }
 }
Exemple #2
0
 private bool InitApp() {
   Application.ThreadException += Application_ThreadException;
   try {
     var serviceURl = ConfigurationManager.AppSettings.Get("serviceUrl");
     _app = new OAuthEntityApp(serviceURl);
     _app.Init();
     // Get IOAuthClientService and hook to it's Redirected event - to get notified when user hits "Allow"
     _service = _app.GetService<IOAuthClientService>();
     _service.Redirected += OAuthClientService_Redirected;
     //Setup default encryption channel - we store OAuth data encrypted
     var cryptoKey = ConfigurationManager.AppSettings.Get("CryptoKey");
     var encrService = _app.GetService<Vita.Modules.EncryptedData.IEncryptionService>();
     encrService.AddChannel(HexUtil.HexToByteArray(cryptoKey));
     //Connect to db
     var connString = ConfigurationManager.AppSettings.Get("MsSqlConnectionString");
     if(!CheckConnection(connString))
       return false; 
     var dbSettings = new DbSettings(new MsSqlDbDriver(), MsSqlDbDriver.DefaultMsSqlDbOptions, connString);
     _app.ConnectTo(dbSettings);
     //Start local web server to handle redirects back from OAuth server, after user approves access
     StartWebService(serviceURl);
     // Hook to global error log, to show exception when it happens in Redirect controller
     var errLog = _app.GetService<IErrorLogService>();
     errLog.ErrorLogged += ErrLog_ErrorLogged;
     //Just for ease of debugging this app, update servers definitions in database
     var session = OpenSession();
     Vita.Modules.OAuthClient.OAuthServers.CreateUpdatePopularServers(session);
     session.SaveChanges();
     return true;
   } catch(Exception ex) {
     Log(ex.ToLogString());
     MessageBox.Show(ex.Message, "Error");
     return false; 
   }
 }