/// <summary>
        /// Adds a TaxCode under the specified realm. The realm must be set in the context.
        /// </summary>
        /// <param name="taxCode">TaxCode to Add.</param>
        /// <returns>Returns an updated version of the entity with updated identifier.</returns>
        public Intuit.Ipp.Data.TaxService AddTaxCode(Intuit.Ipp.Data.TaxService taxCode)
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method AddTaxCode for TaxService.");


            // Validate parameter
            if (!GlobalTaxServiceHelper.IsTypeNull(taxCode))
            {
                IdsException exception = new IdsException(Resources.ParameterNotNullMessage, new ArgumentNullException(Resources.EntityString));
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Error, string.Format(CultureInfo.InvariantCulture, Resources.ExceptionGeneratedMessage, exception.ToString()));
                IdsExceptionManager.HandleException(exception);
            }


            string resourceString = taxCode.GetType().Name.ToLower(CultureInfo.InvariantCulture);


            // Builds resource Uri
            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/{2}/taxcode", CoreConstants.VERSION, this.serviceContext.RealmId, resourceString);

            // Creates request parameters
            RequestParameters parameters;

            if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONJSON);
            }
            else
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONXML);
            }

            // Prepares request
            HttpWebRequest request = this.restHandler.PrepareRequest(parameters, taxCode);

            string response = string.Empty;

            try
            {
                // gets response
                response = this.restHandler.GetResponse(request);
            }
            catch (IdsException ex)
            {
                IdsExceptionManager.HandleException(ex);
            }

            CoreHelper.CheckNullResponseAndThrowException(response);

            // de serialize object
            IntuitResponse restResponse = (IntuitResponse)CoreHelper.GetSerializer(this.serviceContext, false).Deserialize <IntuitResponse>(response);

            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method Add.");
            return((Intuit.Ipp.Data.TaxService)(restResponse.AnyIntuitObject as Intuit.Ipp.Data.TaxService));
        }
示例#2
0
        /// <summary>
        /// This method executes the batch request.
        /// </summary>
        public void Execute()
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Started Executing Method Execute for Batch");

            // Create Intuit Batch Request
            IntuitBatchRequest intuitBatchRequest = new IntuitBatchRequest();

            intuitBatchRequest.BatchItemRequest = this.batchRequests.ToArray <BatchItemRequest>();

            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/batch", Utility.CoreConstants.VERSION, this.serviceContext.RealmId);

            // Creates request parameters
            RequestParameters parameters;

            if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, Utility.CoreConstants.CONTENTTYPE_APPLICATIONJSON);
            }
            else
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML);
            }
            // Prepares request
            HttpWebRequest request = this.restHandler.PrepareRequest(parameters, intuitBatchRequest);

            string response = string.Empty;

            try
            {
                // gets response
                response = this.restHandler.GetResponse(request);
            }
            catch (IdsException ex)
            {
                IdsExceptionManager.HandleException(ex);
            }

            CoreHelper.CheckNullResponseAndThrowException(response);

            // de serialize object
            IntuitResponse restResponse = (IntuitResponse)this.responseSerializer.Deserialize <IntuitResponse>(response);

            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Execute method for batch.");
            foreach (object obj in restResponse.AnyIntuitObjects)
            {
                BatchItemResponse batchItemResponse = obj as BatchItemResponse;
                this.batchResponses.Add(batchItemResponse);

                // process batch item
                this.intuitBatchItemResponses.Add(ProcessBatchItemResponse(batchItemResponse));
            }
        }
示例#3
0
        /// <summary>
        /// Executes the Ids Query and returns the response.
        /// </summary>
        /// <param name="idsQuery">The string representation of ids query for getting just the count of records.</param>
        /// <param name="queryOperationType">Query Operation Type. Default value is query.</param>
        /// <returns>Count of records.</returns>
        public long ExecuteIdsQueryForCount(string idsQuery, QueryOperationType queryOperationType = QueryOperationType.query)
        {
            // Validate Parameter
            if (string.IsNullOrWhiteSpace(idsQuery))
            {
                throw new InvalidParameterException(string.Format(CultureInfo.InvariantCulture, "The parameter idsQuery cannot be null or empty."));
            }



            // Buid the service uri
            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/{2}", CoreConstants.VERSION, this.serviceContext.RealmId, queryOperationType);

            // Creates request parameters
            RequestParameters parameters = null;

            parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONTEXT);


            // Prepares request
            HttpWebRequest request  = this.restHandler.PrepareRequest(parameters, idsQuery);
            string         response = string.Empty;

            try
            {
                // Gets response
                response = this.restHandler.GetResponse(request);
            }
            catch (IdsException ex)
            {
                IdsExceptionManager.HandleException(ex);
            }

            // Check whether the response is null or empty and throw communication exception.
            CoreHelper.CheckNullResponseAndThrowException(response);

            // Deserialize object
            IntuitResponse restResponse  = (IntuitResponse)this.responseSerializer.Deserialize <IntuitResponse>(response);
            QueryResponse  queryResponse = restResponse.AnyIntuitObject as QueryResponse;


            int totalCount = queryResponse.totalCount;



            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method ExecuteIdsQuery.");

            return(totalCount);
        }
示例#4
0
        /// <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);
        }
示例#5
0
        /// <summary>
        /// Entity Service supports multiple queries within a request. Use this method to perform multiple entity query operation.
        /// </summary>
        /// <param name="queryOperationValues">The simple query language string collection.</param>
        /// <typeparam name="TSource">Where TSource is IEntity.</typeparam>
        /// <returns>Returns a collection of entities for individual simple query.</returns>
        /// <exception cref="InvalidParameterException">If the parameter is null or empty or exceeds a maximum of five(5) queries.</exception>
        /// <exception cref="ValidationException">If the query syntax is incorrect.</exception>
        /// <exception cref="SerializationException">If there were serialization issues with the response from the service.</exception>
        /// <exception cref="IdsException">When service returned with an error information.</exception>
        /// <example>
        /// Usage:
        /// Use the query service created and invoke the ToIdsQuery method to obtain the simple query as string.
        /// <code>
        /// string customerQueryValue = customerContext.Where(c => c.MetaData.CreateTime > this.dateTime).ToIdsQuery();
        /// string invoiceQueryValue = invoiceContext.Select(i => new { i.Id, i.status }).ToIdsQuery();
        /// </code>
        /// Invoke the ExecuteMultipleEntityQueries method with the read only collection of the queries. This method can throw exception so surround the method with a try catch block.
        /// <code>
        /// <![CDATA[List<string> values = new List<string> { customerQueryValue, invoiceQueryValue };]]>
        /// try
        /// {
        ///     <![CDATA[ReadOnlyCollection<ReadOnlyCollection<IEntity>> results = customerContext.ExecuteMultipleEntityQueries<IEntity>(values.AsReadOnly());]]>
        ///     Iterate through the values obtained:
        ///     foreach (var item in results)
        ///     {
        ///         // Read the values
        ///     }
        /// }
        /// catch(IdsException)
        /// {
        ///     // Perform logic here
        /// }
        /// </code>
        /// </example>
        public System.Collections.ObjectModel.ReadOnlyCollection <System.Collections.ObjectModel.ReadOnlyCollection <TSource> > ExecuteMultipleEntityQueries <TSource>(System.Collections.ObjectModel.ReadOnlyCollection <string> queryOperationValues) where TSource : IEntity
        {
            if (queryOperationValues == null || queryOperationValues.Count == 0)
            {
                throw new InvalidParameterException(string.Format(CultureInfo.InvariantCulture, "The parameter queryOperationValues cannot be null or empty."));
            }

            if (queryOperationValues.Count > 5)
            {
                throw new InvalidParameterException(string.Format(CultureInfo.InvariantCulture, "Query Count exceeded. A maximum of 5 queries can be provided at a time."));
            }

            string idsQuery = string.Empty;

            foreach (var item in queryOperationValues)
            {
                if (!string.IsNullOrWhiteSpace(item))
                {
                    idsQuery += item + ";";
                }
            }

            // Buid the service uri
            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/query", CoreConstants.VERSION, this.serviceContext.RealmId);

            // Creates request parameters
            RequestParameters parameters = null;

            parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONTEXT);


            // Prepares request
            HttpWebRequest request  = this.restHandler.PrepareRequest(parameters, idsQuery);
            string         response = string.Empty;

            try
            {
                // Gets response
                response = this.restHandler.GetResponse(request);
            }
            catch (IdsException ex)
            {
                IdsExceptionManager.HandleException(ex);
            }

            // Check whether the response is null or empty and throw communication exception.
            CoreHelper.CheckNullResponseAndThrowException(response);

            // Deserialize object
            IntuitResponse restResponse = (IntuitResponse)this.responseSerializer.Deserialize <IntuitResponse>(response);

            QueryResponse[] queryResponses = restResponse.AnyIntuitObjects as QueryResponse[];

            List <System.Collections.ObjectModel.ReadOnlyCollection <TSource> > returnValues = new List <System.Collections.ObjectModel.ReadOnlyCollection <TSource> >();

            foreach (var queryResponse in queryResponses)
            {
                Type           type     = queryResponse.GetType();
                List <TSource> entities = new List <TSource>();

                PropertyInfo[] propertyInfoArray = type.GetProperties();

                foreach (PropertyInfo propertyInfo in propertyInfoArray)
                {
                    if (true == propertyInfo.PropertyType.IsArray)
                    {
                        object tempEntities = propertyInfo.GetValue(queryResponse, null);
                        if (tempEntities != null)
                        {
                            object[] tempEntityArray = (object[])tempEntities;

                            if (tempEntityArray.Length > 0)
                            {
                                foreach (object item in tempEntityArray)
                                {
                                    entities.Add((TSource)item);
                                }
                            }
                        }

                        break;
                    }
                }

                returnValues.Add(entities.AsReadOnly());
            }

            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method FindAll.");
            return(returnValues.AsReadOnly());
        }
示例#6
0
        /// <summary>
        /// Executes the Ids Query and returns the response.
        /// </summary>
        /// <param name="idsQuery">The string representation of ids query.</param>
        /// <param name="queryOperationType">Query Operation Type. Default value is query.</param>
        /// <returns>ReadOnly Collection fo items of type T.</returns>
        public System.Collections.ObjectModel.ReadOnlyCollection <T> ExecuteIdsQuery(string idsQuery, QueryOperationType queryOperationType = QueryOperationType.query)
        {
            // Validate Parameter
            if (string.IsNullOrWhiteSpace(idsQuery))
            {
                throw new InvalidParameterException(string.Format(CultureInfo.InvariantCulture, "The parameter idsQuery cannot be null or empty."));
            }

            // Buid the service uri
            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/{2}", CoreConstants.VERSION, this.serviceContext.RealmId, queryOperationType);

            // Creates request parameters
            RequestParameters parameters = null;

            parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONTEXT);


            // Prepares request
            HttpWebRequest request  = this.restHandler.PrepareRequest(parameters, idsQuery);
            string         response = string.Empty;

            try
            {
                // Gets response
                response = this.restHandler.GetResponse(request);
            }
            catch (IdsException ex)
            {
                IdsExceptionManager.HandleException(ex);
            }

            // Check whether the response is null or empty and throw communication exception.
            CoreHelper.CheckNullResponseAndThrowException(response);

            // Deserialize object
            IntuitResponse restResponse  = (IntuitResponse)this.responseSerializer.Deserialize <IntuitResponse>(response);
            QueryResponse  queryResponse = restResponse.AnyIntuitObject as QueryResponse;

            if (idsQuery.ToLower().Contains("count(*)"))
            {
                int      totalCount           = queryResponse.totalCount;
                List <T> dummyCountCollection = new List <T>();
                for (int i = 0; i < totalCount; i++)
                {
                    dummyCountCollection.Add((T)Activator.CreateInstance(typeof(T)));
                }

                System.Collections.ObjectModel.ReadOnlyCollection <T> countCollection = new System.Collections.ObjectModel.ReadOnlyCollection <T>(dummyCountCollection);
                return(countCollection);
            }

            List <T> entities = new List <T>();

            if (queryResponse.maxResults > 0)

            {
                object tempEntities = queryResponse.AnyIntuitObjects;
                if (tempEntities != null)
                {
                    object[] tempEntityArray = (object[])tempEntities;

                    if (tempEntityArray.Length > 0)
                    {
                        foreach (object item in tempEntityArray)
                        {
                            entities.Add((T)item);
                        }
                    }
                }
            }

            /* Type type = queryResponse.GetType();
             * List<T> entities = new List<T>();
             *
             * PropertyInfo[] propertyInfoArray = type.GetProperties();
             *
             * foreach (PropertyInfo propertyInfo in propertyInfoArray)
             * {
             *   if (true == propertyInfo.PropertyType.)
             *   {
             *       object tempEntities = propertyInfo.GetValue(queryResponse, null);
             *       if (tempEntities != null)
             *       {
             *           object[] tempEntityArray = (object[])tempEntities;
             *
             *           if (tempEntityArray.Length > 0)
             *           {
             *               foreach (object item in tempEntityArray)
             *               {
             *                   entities.Add((T)item);
             *               }
             *           }
             *       }
             *
             *       break;
             *   }
             * }*/

            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method FindAll.");
            System.Collections.ObjectModel.ReadOnlyCollection <T> readOnlyCollection = new System.Collections.ObjectModel.ReadOnlyCollection <T>(entities);
            return(readOnlyCollection);
        }
        /// <summary>
        /// Executes a report against a specified realm. The realm must be set in the context.
        /// </summary>
        /// <param name="reportName">Name of Report to Run.</param>
        /// <returns>Returns an updated version of the entity with updated identifier and sync token.</returns>
        public Report ExecuteReport(string reportName)
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method ExecuteReport.");

            // Validate parameter
            if (string.IsNullOrEmpty(reportName))
            {
                IdsException exception = new IdsException(Resources.ParameterNotNullMessage, new ArgumentNullException(Resources.StringParameterNullOrEmpty));
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Error, string.Format(CultureInfo.InvariantCulture, Resources.ExceptionGeneratedMessage, exception.ToString()));
                IdsExceptionManager.HandleException(exception);
            }

            string resourceString = reportName;

            //Build Query Parameters

            // Builds resource Uri
            string uri = "";
            string reportsQueryParameters = GetReportQueryParameters();

            if (reportsQueryParameters.Length > 0)
            {
                uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/reports/{2}?{3}", Utility.CoreConstants.VERSION, this.serviceContext.RealmId, resourceString, reportsQueryParameters);
            }
            else
            {
                uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/reports/{2}", Utility.CoreConstants.VERSION, this.serviceContext.RealmId, resourceString);
            }

            // Creates request parameters
            RequestParameters parameters;

            if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
            {
                parameters = new RequestParameters(uri, HttpVerbType.GET, Utility.CoreConstants.CONTENTTYPE_APPLICATIONJSON);
            }
            else
            {
                parameters = new RequestParameters(uri, HttpVerbType.GET, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML);
            }

            // Prepares request
            HttpWebRequest request = this.restHandler.PrepareRequest(parameters, null);

            string response = string.Empty;

            try
            {
                // gets response
                response = this.restHandler.GetResponse(request);
            }
            catch (IdsException ex)
            {
                IdsExceptionManager.HandleException(ex);
            }

            CoreHelper.CheckNullResponseAndThrowException(response);

            // de serialize object
            IntuitResponse restResponse = (IntuitResponse)CoreHelper.GetSerializer(this.serviceContext, false).Deserialize <IntuitResponse>(response);

            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method ExecuteReport.");
            return((Report)(restResponse.AnyIntuitObject as Report));
        }