/// <summary> /// Add some intial data to DB /// </summary> public static void AddInitialDatatoDB() { OAuthTokensRealmLastUpdateddto dbSettings = new OAuthTokensRealmLastUpdateddto(); //Get connectionString for WebHooksDB string connectionString = dbSettings.ConnectionString; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { sqlConnection.Open(); DateTime currDate = DateTime.Now; //Add a sandbox realm and oauth keys for testing webhooks string s1 = "insert into OAuthTokens values('123145693359857','2016-05-06','qyprdFBgt5mkWX6nrsqtKPgKgzeB3rqTGwqANpV8YOnCWUK9','XaZCEi6T6J1s689RfEEsDDtQe5ASfk5LbaNqFILQ','QBO' )"; using (SqlCommand myCommand = new SqlCommand(s1, sqlConnection)) { myCommand.CommandType = CommandType.Text; myCommand.ExecuteNonQuery(); } //Add a prod realmid and oauth keys for testing webhooks string s2 = "insert into OAuthTokens values('1269959970','2016-05-06','qyprdIyga7rdFS9Oe9IyXWZqqs6cYhfXUmR4iQD6XqX3iIrU','PYly9uD6DB8togTDfiqrOytMxafp2udvA5ds1qFV','QBO' )"; using (SqlCommand myCommand = new SqlCommand(s2, sqlConnection)) { myCommand.CommandType = CommandType.Text; myCommand.ExecuteNonQuery(); } sqlConnection.Close(); } }
/// <summary> /// Call CDC for each realm for the configured entitites in app. /// Update the realmlastupdated col in OauthTokens DB /// </summary> public static void UpdateLastUpdatedDateDB(string realmId) { OAuthTokensRealmLastUpdateddto dbSettings = new OAuthTokensRealmLastUpdateddto(); //Get connectionString for WebHooksDB string connectionString = dbSettings.ConnectionString; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { //Get OAuth tokens for making CDC call for the realm string query1 = "select * from OAuthTokens where realmid='" + realmId + "'"; using (SqlCommand myCommand1 = new SqlCommand(query1, sqlConnection)) { sqlConnection.Open(); using (SqlDataReader rd = myCommand1.ExecuteReader()) { while (rd.Read()) { OAuthTokensRealmLastUpdateddto oauthRealmLastUpdateddto = new OAuthTokensRealmLastUpdateddto(); oauthRealmLastUpdateddto.OAuthTokens = new OAuthTokens(); oauthRealmLastUpdateddto.OAuthTokens.realmid = rd["realmid"].ToString(); //Check if this is required or not //string testAccessToken = DBUtility.Decrypt(currentIndex.access_token, OAuthTokens_RealmLastUpdated.SecurityKey); //string testAccessTokenSecret = DBUtility.Decrypt(currentIndex.access_secret, OAuthTokens_RealmLastUpdated.SecurityKey); oauthRealmLastUpdateddto.OAuthTokens.access_token = rd["access_token"].ToString(); oauthRealmLastUpdateddto.OAuthTokens.access_secret = rd["access_secret"].ToString(); //OAuthTokensRealmLastUpdateddto.ConsumerKey = ; //OAuthTokensRealmLastUpdateddto.ConsumerSecret = ; oauthRealmLastUpdateddto.OAuthTokens.datasource = rd["datasource"].ToString(); oauthRealmLastUpdateddto.OAuthTokens.realmlastupdated = (DateTime)rd["realmlastupdated"]; //Get CDC details for configured entities for the app for the time in the OAuthToken tables' realmlastupdated column var cdcResponse = CDCSyncService.GetCDCDetails(oauthRealmLastUpdateddto); } rd.Close(); } } //Update realmlastupdatedtime in OAuthTokens table DateTime cdcLastRunTime = DateTime.Now; string query2 = "UPDATE OAuthTokens SET realmlastupdated=@cdcLastRunTime WHERE realmid=@realmId"; using (SqlCommand myCommand2 = new SqlCommand(query2, sqlConnection)) { myCommand2.Parameters.AddWithValue("@cdcLastRunTime", cdcLastRunTime); myCommand2.Parameters.AddWithValue("@realmId", realmId); myCommand2.ExecuteNonQuery(); } sqlConnection.Close(); } }
/// <summary> /// Allocate memory for service context objects /// </summary> public DataServiceFactory(OAuthTokensRealmLastUpdateddto oAuthorization) { try { oAuthRequestValidator = new OAuthRequestValidator( oAuthorization.OAuthTokens.access_token, oAuthorization.OAuthTokens.access_secret, oAuthorization.ConsumerKey, oAuthorization.ConsumerSecret); intuitServicesType = oAuthorization.OAuthTokens.datasource == "QBO" ? IntuitServicesType.QBO : IntuitServicesType.None; serviceContext = new ServiceContext(oAuthorization.OAuthTokens.realmid.ToString(), intuitServicesType, oAuthRequestValidator); serviceContext.IppConfiguration.BaseUrl.Qbo = ConfigurationManager.AppSettings["ServiceContext.BaseUrl.Qbo"]; //serviceContext.IppConfiguration.Logger.RequestLog.EnableRequestResponseLogging = true; //serviceContext.IppConfiguration.Logger.RequestLog.ServiceRequestLoggingLocation = ConfigurationManager.AppSettings["ServiceRequestLoggingLocation"]; getServiceContext = serviceContext; dataService = new DataService(serviceContext); } catch (Intuit.Ipp.Exception.FaultException ex) { throw ex; } }
/// <summary> /// Get CDC details /// </summary> /// <returns></returns> internal static IntuitCDCResponse GetCDCDetails(OAuthTokensRealmLastUpdateddto OAuthTokensRealmLastUpdateddto) { List <IEntity> entityList = new List <IEntity>(); string getEntitiesForCDC = ConfigurationManager.AppSettings["WebhooksEntities"].ToString(); //Get all configured entities for Webhooks to make cdc call //Break config values and then add to list of entities to fecth with CDC operation string[] entities = getEntitiesForCDC.Trim().Split(','); foreach (string entity in entities) { switch (entity.ToLower()) { case "customer": entityList.Add(new Customer()); break; case "invoice": entityList.Add(new Invoice()); break; case "salesreceipt": entityList.Add(new SalesReceipt()); break; case "estimate": entityList.Add(new Estimate()); break; case "vendor": entityList.Add(new Vendor()); break; case "account": entityList.Add(new Account()); break; case "payment": entityList.Add(new Payment()); break; case "class": entityList.Add(new Class()); break; case "Item": entityList.Add(new Item()); break; case "billpayment": entityList.Add(new BillPayment()); break; case "employee": entityList.Add(new Employee()); break; case "purchase": entityList.Add(new Purchase()); break; default: break; } } //Create a CDCSyncService object CDCSyncService sync = new CDCSyncService(OAuthTokensRealmLastUpdateddto);//check for consumer key n secret //Get Dataservice object for calling CDC DataService qboService = new DataService(sync.dataserviceFactory.getServiceContext); //Make CDC call IntuitCDCResponse CDCResponse = qboService.CDC(entityList, OAuthTokensRealmLastUpdateddto.OAuthTokens.realmlastupdated); return(CDCResponse); }
//CDCSyncdto syncObjects = null; /// <summary> /// Fire up the service context in the constructor. /// </summary> /// <param name="oAuthorization"></param> public CDCSyncService(OAuthTokensRealmLastUpdateddto oAuthorization) { dataserviceFactory = new DataServiceFactory(oAuthorization); dataService = dataserviceFactory.getDataService(); //syncObjects = new CDCSyncdto(); }