internal override LinqExtender.Ast.Expression VisitTypeExpression(LinqExtender.Ast.TypeExpression expression) { // For Report entities the format of the query string is different string format = string.Empty; if (expression.Type.UnderlyingType.BaseType.Name.Equals("ReportQueryBase")) { this.operationType = QueryOperationType.report; // TODO: Uncomment this if the query language is different for report and query // format = "REPORT {0} WITH "; format = " {0} "; } else if (expression.Type.UnderlyingType.Name.Equals("ChangeData")) { this.operationType = QueryOperationType.changedata; } else { this.operationType = QueryOperationType.query; format = " FROM {0} "; } this.queryBuilder.Append("Select "); this.fromBuilder.Append(string.Format(CultureInfo.InvariantCulture, format, expression.Type.Name)); return(expression); }
/// <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); }
///<summary> /// Reading database schema from JSON file ///</summary> ///<param name="objectType">Object type</param> ///<param name="operationType">Operation type</param> ///<returns>Returns instance of schema, defined in JSON file</returns> public static string ObjectStorageSchemaValue(ObjectType objectType, QueryOperationType operationType) { var fileName = objectType.ToString(); var schema = Settings.ReadConfigFile <ObjectStorageSchema>(fileName); try { return(schema[operationType.ToString()]); } catch (NullReferenceException ex) { throw new MutatedException(OperationResultType.ErrorConfigurationReadNotFound, ex.Message); } catch (Exception ex) { throw new MutatedException(OperationResultType.ErrorConfigurationReadBadInput, ex.Message); } }
/// <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); }