/// <summary> /// GetEntitlements Asynchronous call back method /// </summary> /// <param name="sender">Rest handler class</param> /// <param name="eventArgs">callback event arguments</param> private void GetEntitlementsAsyncCompleted(object sender, AsyncCallCompletedEventArgs eventArgs) { EntitlementCallCompletedEventArgs <Intuit.Ipp.Data.EntitlementsResponse> entitlementCallCompletedEventArgs = new EntitlementCallCompletedEventArgs <EntitlementsResponse>(); if (eventArgs.Error == null) { try { IEntitySerializer responseSerializer = CoreHelper.GetSerializer(this.serviceContext, false); EntitlementsResponse restResponse = (EntitlementsResponse)responseSerializer.Deserialize <EntitlementsResponse>(eventArgs.Result); entitlementCallCompletedEventArgs.EntitlementsResponse = restResponse; this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing event GetEntitlementsAsync in AyncService object."); // change Response Serialization Format back to Config value serviceContext.IppConfiguration.Message.Response.SerializationFormat = orginialSerializationFormat; this.OnGetEntilementAsyncCompleted(this, entitlementCallCompletedEventArgs); } catch (SystemException systemException) { IdsException idsException = new IdsException(systemException.Message); this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString()); entitlementCallCompletedEventArgs.Error = idsException; this.OnGetEntilementAsyncCompleted(this, entitlementCallCompletedEventArgs); } } else { entitlementCallCompletedEventArgs.Error = eventArgs.Error; this.OnGetEntilementAsyncCompleted(this, entitlementCallCompletedEventArgs); } }
public EntitlementsResponse EntitlementsGetSync(ServiceContext context, string baseUrl) { EntitlementService service = new EntitlementService(context); EntitlementsResponse entitlements = service.GetEntitlements(baseUrl); return(entitlements); }
public void GetEntitlementsTest() { try { EntitlementsResponse entitlements = entitlementServiceTestCases.GetEntitlements("https://qbo.sbfinance.intuit.com/manage"); Assert.IsNotNull(entitlements); } catch (SystemException ex) { Assert.Fail(ex.ToString()); } }
internal static EntitlementsResponse GetEntitlementAsync(ServiceContext context, string baseUrl) { //Initializing the Dataservice object with ServiceContext EntitlementService service = new EntitlementService(context); IdsException exp = null; Boolean entitlementReturned = false; EntitlementsResponse entitlements = null; // Used to signal the waiting test thread that a async operation have completed. ManualResetEvent manualEvent = new ManualResetEvent(false); // Async callback events are anonomous and are in the same scope as the test code, // and therefore have access to the manualEvent variable. service.OnGetEntilementAsyncCompleted += (sender, e) => { manualEvent.Set(); if (e.Error != null) { exp = e.Error; } if (exp == null) { if (e.EntitlementsResponse != null) { entitlementReturned = true; entitlements = e.EntitlementsResponse; } } }; // Call the service method service.GetEntitlementsAsync(baseUrl); manualEvent.WaitOne(30000, false); Thread.Sleep(10000); if (exp != null) { throw exp; } // Check if we completed the async call if (!entitlementReturned) { //return null } // Set the event to non-signaled before making next async call. manualEvent.Reset(); return(entitlements); }
/// <summary> /// Gets entitlements against a specified realm. The realm must be set in the context. /// </summary> /// <param name="entitlementBaseUrl">Base Url of the Entitlements API for OAuth1 vs OAuth2. Default is set to OAuth2 prod environment.</param> /// <returns>Returns EntitlementsResponse</returns> public EntitlementsResponse GetEntitlements(string entitlementBaseUrl = Utility.CoreConstants.ENTITLEMENT_BASEURL) { this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method GetEntitlements."); string uri = string.Format(CultureInfo.InvariantCulture, "{0}/entitlements/{1}/{2}", entitlementBaseUrl, Utility.CoreConstants.VERSION, serviceContext.RealmId); orginialSerializationFormat = this.serviceContext.IppConfiguration.Message.Response.SerializationFormat; // Only XML format is supported by Entitlements API serviceContext.IppConfiguration.Message.Response.SerializationFormat = Core.Configuration.SerializationFormat.Xml; // Creates request parameters RequestParameters parameters = new RequestParameters(uri, HttpVerbType.GET, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML); // Prepares request HttpWebRequest request = this.restHandler.PrepareRequest(parameters, null, uri); string response = string.Empty; try { // gets response response = this.restHandler.GetResponse(request); } catch (IdsException ex) { IdsExceptionManager.HandleException(ex); } CoreHelper.CheckNullResponseAndThrowException(response); // de serialize object EntitlementsResponse restResponse = (EntitlementsResponse)CoreHelper.GetSerializer(this.serviceContext, false).Deserialize <EntitlementsResponse>(response); this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method GetEntitlements."); // change Response Serialization Format back to Config value serviceContext.IppConfiguration.Message.Response.SerializationFormat = orginialSerializationFormat; return(restResponse); }
/// <summary> /// Extracts the Fault from the Error Response. /// </summary> /// <param name="errorString">The error string.</param> /// <returns>Fault object.</returns> private Fault ExtractFaultFromResponse(string errorString) { Fault fault = null; // If the error string is null return null. if (string.IsNullOrWhiteSpace(errorString)) { return(fault); } try { //// TODO: Remove this code after service returns proper response //// This is put in since the service is not returning proper xml header ////if (!errorString.StartsWith("<?xml")) ////{ //// errorString = errorString.Insert(16, " xmlns=\"http://schema.intuit.com/finance/v3\" "); //// errorString = errorString.Insert(0, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); ////} if (errorString.Contains("EntitlementsResponse")) { EntitlementsResponse entitlements = (EntitlementsResponse)CoreHelper.GetSerializer(this.context, false).Deserialize <EntitlementsResponse>(errorString); } // Deserialize to IntuitResponse using the Serializer of the context. else { IntuitResponse intuitResponse = (IntuitResponse)CoreHelper.GetSerializer(this.context, false).Deserialize <IntuitResponse>(errorString); // Check whether the object is null or note. Also check for Items property since it has the fault. if (intuitResponse != null && intuitResponse.AnyIntuitObject != null) { // TODO: Check whether only the first item will have fault or not. // Cast the Items to Fault. fault = intuitResponse.AnyIntuitObject as Fault; } } // TODO: Uncomment this if exception has to be added for batch requests. // This is executed if the response is BatchItemResponse for batch requests. // else // { // Deserialize to BatchItemResponse using the Serializer of the context. // BatchItemResponse batchItemResponse = (BatchItemResponse)this.context.Serializer.Deserialize<BatchItemResponse>(errorString); // Check whether the object is null or note. Also check for Item property since it has the fault. // if (batchItemResponse != null && batchItemResponse.Item != null) // { // Cast the Item to Fault. // fault = batchItemResponse.Item as Fault; // } // } } catch (System.Exception ex) { //Download might have Uri in body try { if (new System.Uri(errorString) != null) { return(null); } } catch (UriFormatException) { return(null); } throw ex; } // Return the fault. return(fault); }