예제 #1
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            LazyInit();

            ValidateRequest(requestId);

            PrepareToGetData();

            var dataProvider = new AQSGetDataFromDatabase(_baseDao, _clearMetadataBeforeRun, _startDate, _endDate, _siteId,
                                                          _countyCode, _commaSeparatedActionCodes, !_includeRawResultsOnly,
                                                          _filterByImportedDate);

            AirQualitySubmissionType data = dataProvider.GetAirQualityData(this);

            data.Version = _aqsSchemaVersionType;

            AppendAuditLogEvent("Generating serialized xml results for query");

            _dataFilePath = AddExchangeDocumentHeader(data, true, _dataRequest.TransactionId);

            PaginatedContentResult result =
                new PaginatedContentResult(_dataRequest.RowIndex, _dataRequest.MaxRowCount, true, CommonContentType.ZIP,
                                           File.ReadAllBytes(_dataFilePath));

            return(result);
        }
예제 #2
0
        protected PaginatedContentResult OnProcessQueryRequest(DataRequest dataRequest)
        {
            if (dataRequest == null)
            {
                throw new ArgumentException(string.Format("Request not found"));
            }
            PaginatedContentResult result = new PaginatedContentResult();

            result.Content = new SimpleContent();
            bool doCompress = DoReturnCompressedResult(dataRequest.Parameters);

            result.Content.Type = doCompress ? CommonContentType.ZIP : CommonContentType.XML;

            int    actualCount;
            bool   isLast;
            string documentName;

            result.Content.Content =
                CreateRandomXMLQueryResult(doCompress, dataRequest.RowIndex, dataRequest.MaxRowCount,
                                           out actualCount, out isLast, out documentName);
            result.Paging        = new PaginationIndicator();
            result.Paging.Start  = dataRequest.RowIndex;
            result.Paging.Count  = actualCount;
            result.Paging.IsLast = isLast;
            return(result);
        }
예제 #3
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            ValidateRequest(requestId);
            _argDate = DateTime.MinValue;
            if (!TryGetParameterByIndex <DateTime>(_dataRequest, 0, ref _argDate))
            {
                throw new ApplicationException("Invalid Change Date argument");
            }

            string requestingUsername = _transactionManager.GetTransactionUsername(_dataRequest.TransactionId);

            ICollection <string> allFlowList           = _flowManager.GetDataFlowNames();
            ICollection <string> protectedFlowList     = _flowManager.GetProtectedFlowNames();
            ICollection <string> userProtectedFlowList = _flowManager.GetProtectedFlowNamesForUser(requestingUsername);

            HEREData            data    = new HEREData(ValidateDBProvider(DataSourceParameterType.SourceDatabaseDataSource.ToString()));
            HEREManifestService service = new HEREManifestService(data);

            PaginatedContentResult result = GetXmlPaginatedContentResult(service.Execute(allFlowList, protectedFlowList, userProtectedFlowList,
                                                                                         _argDate, _serializationHelper, this),
                                                                         _dataRequest.RowIndex, _dataRequest.MaxRowCount,
                                                                         true);

            string xmlString = Encoding.UTF8.GetString(result.Content.Content);

            SaveStringAndAddToTransaction(xmlString, "Manifest.xml", _settingsProvider, _compressionHelper, _documentManager,
                                          _dataRequest.TransactionId);
            return(result);
        }
예제 #4
0
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            GetServiceImplementation(out _requestManager);
            GetServiceImplementation(out _serializationHelper);
            GetServiceImplementation(out _documentManager);
            GetServiceImplementation(out _accountManager);
            GetServiceImplementation(out _flowManager);

            AppendAuditLogEvent("Validating requestId ...");
            DataRequest dataRequest = _requestManager.GetDataRequest(requestId);

            GetAuthorizedUsersResponse response = GetAuthorizedUsersResponseData();

            byte[] content = _serializationHelper.Serialize(response);

            if (response.AuthorizedUserList.Length == 0)
            {
                AppendAuditLogEvent("Did not find authorization information for any users");
            }
            else
            {
                AppendAuditLogEvent("Returning authorization information for {0} users ...", response.AuthorizedUserList.Length);
            }

            string docId =
                _documentManager.AddDocument(dataRequest.TransactionId, CommonTransactionStatusCode.Completed,
                                             null, new Document(null, CommonContentType.XML, content));

            PaginatedContentResult result = new PaginatedContentResult(0, response.AuthorizedUserList.Length, true,
                                                                       CommonContentType.XML, content);

            return(result);
        }
예제 #5
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            string dataFilePath = GetDataFile(requestId, false);

            byte[]            data;
            CommonContentType?contentType = CommonContentType.XML;

            if (string.IsNullOrEmpty(dataFilePath))
            {
                data = new byte[0];
            }
            else
            {
                data        = File.ReadAllBytes(dataFilePath);
                contentType = CommonContentAndFormatProvider.GetFileTypeFromContent(data);
                if (!contentType.HasValue)
                {
                    contentType = CommonContentType.OTHER;
                }
            }

            PaginatedContentResult result = new PaginatedContentResult(_dataRequest.RowIndex, 0, true,
                                                                       contentType.Value, data);

            return(result);
        }
        public override PaginatedContentResult ProcessQuery(string requestId)
        {
            PaginatedContentResult result = base.ProcessQuery(requestId);

            CheckToSubmitData(_dataFilePath);

            return(result);
        }
예제 #7
0
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            string filePath = DoRequest(requestId);

            byte[] content = File.ReadAllBytes(filePath);
            PaginatedContentResult result = new PaginatedContentResult(_dataRequest.RowIndex, _dataRequest.MaxRowCount,
                                                                       true, CommonContentType.XML, content);

            return(result);
        }
예제 #8
0
        public string AddDocument(string transactionId, CommonTransactionStatusCode status,
                                  string statusDetail, PaginatedContentResult result)
        {
            string docName =
                Path.ChangeExtension(Guid.NewGuid().ToString(),
                                     CommonContentAndFormatProvider.GetFileExtension(result.Content.Type));
            Document doc = new Document(docName, result.Content.Type, result.Content.Content);

            return(AddDocument(transactionId, status, statusDetail, doc));
        }
예제 #9
0
        /// <summary>
        /// ProcessQuery
        /// </summary>
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            ProcessInit(requestId);

            string filePath = GetServiceDataAndAddToTransaction();

            PaginatedContentResult result = new PaginatedContentResult(filePath);

            return(result);
        }
예제 #10
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            Init(requestId);

            string zipFilePath = GetDataAndAddToTransaction();

            PaginatedContentResult result =
                new PaginatedContentResult(0, 1, true, CommonContentType.ZIP, File.ReadAllBytes(zipFilePath));

            return(result);
        }
예제 #11
0
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            AppendAuditLogEvent("NCT ProcessQuery() enter");

            LazyInit();

            PaginatedContentResult result = OnProcessQueryRequest(_requestManager.GetDataRequest(requestId));

            AppendAuditLogEvent("NCT ProcessQuery() exit");
            return(result);
        }
예제 #12
0
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            int  rowCount;
            bool isLast;

            byte[] data = DoFacilityDetailsQuery(requestId, out rowCount, out isLast);

            PaginatedContentResult result = new PaginatedContentResult(_dataRequest.RowIndex, rowCount, isLast,
                                                                       CommonContentType.XML, data);

            return(result);
        }
예제 #13
0
        public PaginatedContentResult QueryEx(FormattedPaginatedContentRequest request,
                                              NamedOrAuthEndpointVisit visit)
        {
            SecurityService.ValidateVisitIsAuthenticated(visit);

            PaginatedContentResult result = Query(request, visit);

            result = TransformQueryResult(request, result);

            ValidateQueryResult(result, request, visit);

            return(result);
        }
예제 #14
0
 protected virtual void ValidateQueryResult(PaginatedContentResult result, FormattedPaginatedContentRequest request, NamedOrAuthEndpointVisit visit)
 {
     if ((result != null) && result.HasContent)
     {
         if (MaxRestQueryResponseKilobytes > 0)
         {
             if (result.Content.Content.Length > (MaxRestQueryResponseKilobytes * 1024L))
             {
                 throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_QueryReturnSetTooBig,
                                              "The requested data result set is too large.  Please modify the query parameters so that a smaller data result set is returned.");
             }
         }
     }
 }
예제 #15
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            LazyInit();

            ValidateRequest(requestId);

            CommonContentType contentType;
            var dataFilePath = DoProcessQuerySolicit(out contentType);

            PaginatedContentResult result =
                new PaginatedContentResult(_dataRequest.RowIndex, _dataRequest.MaxRowCount, true, contentType,
                                           File.ReadAllBytes(dataFilePath));

            return(result);
        }
예제 #16
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            ProcessRequestInit(requestId);

            int rowCount;
            CommonContentType contentType;

            byte[] content = GetServices(_returnServiceTypes, out rowCount, out contentType);

            PaginatedContentResult result = new PaginatedContentResult();

            result.Paging  = new PaginationIndicator(0, rowCount, true);
            result.Content = new SimpleContent(contentType, content);

            return(result);
        }
예제 #17
0
        public void ProcessSolicit(string requestId)
        {
            AppendAuditLogEvent("NCT ProcessSolicit() enter");

            LazyInit();

            DataRequest            dataRequest = _requestManager.GetDataRequest(requestId);
            PaginatedContentResult result      = OnProcessQueryRequest(dataRequest);

            _documentManager.AddDocument(dataRequest.TransactionId, CommonTransactionStatusCode.Processed,
                                         string.Empty, new Document(string.Empty, string.Empty,
                                                                    result.Content.Type,
                                                                    result.Content.Content));
            AddReportDocumentToTransaction(dataRequest.TransactionId, true);
            AppendAuditLogEvent("NCT ProcessSolicit() exit");
        }
예제 #18
0
        /// <summary>
        /// ProcessQuery
        /// </summary>
        /// <param name="requestId"></param>
        /// <returns></returns>
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            LOG.DebugEnter(MethodBase.GetCurrentMethod(), requestId);

            LazyInit();

            ValidateRequest(requestId);

            string xmlFilePath = GetXmlDocument();

            string zipFilePath = AddExchangeDocumentHeader(xmlFilePath, true, _request.TransactionId);

            DebugAndAudit("Creating paginated content result");
            PaginatedContentResult result =
                new PaginatedContentResult(_request.RowIndex, _request.MaxRowCount, true, CommonContentType.ZIP,
                                           File.ReadAllBytes(zipFilePath));

            return(result);
        }
예제 #19
0
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            LazyInit();

            ValidateRequest(requestId);

            var parameters = new Dictionary <string, string>();

            parameters[WQXPluginBase.PARAM_ORGANIZATION_IDENTIFIER_KEY] = _organizationIdentifier;
            string executionInfo, transactionId, errorDetails;

            AppendAuditLogEvent("Executing schedule \"{0}\" for WQX organization \"{1}\"", _scheduleName, _organizationIdentifier);

            var scheduledItem = _scheduleManager.ExecuteSchedule(_scheduleName, parameters, out transactionId, out executionInfo, out errorDetails);

            AppendAuditLogEvent("Successfully executed schedule \"{0}\" for WQX organization \"{1}\"", _scheduleName, _organizationIdentifier);

            var resultData = new WQXExecuteScheduleResult();

            resultData.LocalTransactionId = transactionId;
            CommonTransactionStatusCode status;
            EndpointVersionType         endpointVersion;
            string endpointUrl;

            resultData.NetworkTransactionId =
                _transactionManager.GetNetworkTransactionStatus(transactionId, out status, out endpointVersion, out endpointUrl);
            resultData.NodeEndpointUrl     = endpointUrl;
            resultData.NodeEndpointVersion = endpointVersion;
            resultData.ActivityDetails     = executionInfo;
            resultData.ErrorDetails        = errorDetails;
            if (string.Equals(resultData.NetworkTransactionId, resultData.LocalTransactionId))
            {
                resultData.NetworkTransactionId = null;
            }

            var bytes = _serializationHelper.Serialize(resultData);

            //File.WriteAllBytes(@"D:\Temp\Exec.xml", bytes);
            PaginatedContentResult result = new PaginatedContentResult(0, 1, true, CommonContentType.XML, bytes);

            return(result);
        }
예제 #20
0
        public virtual HttpResponseMessage Get([FromUri] QueryParameters parameters)
        {
            NamedOrAuthEndpointVisit visit = GetNamedOrAuthEndpointVisit(parameters);

            FormattedPaginatedContentRequest request = new FormattedPaginatedContentRequest();

            request.FlowName      = parameters.Dataflow;
            request.OperationName = parameters.Request;
            request.Paging        = new PaginationIndicator();
            request.Paging.Start  = parameters.RowId.HasValue ? parameters.RowId.Value : 0;
            request.Paging.Count  = parameters.MaxRows.HasValue ? parameters.MaxRows.Value : -1;
            request.Parameters    = parameters.ParseParams();
            request.ZipResults    = parameters.ZipResults;

            PaginatedContentResult resultSet = ServiceProvider.TransactionService.QueryEx(request, visit);

            if ((resultSet == null) || !resultSet.HasContent)
            {
                return(this.Request.CreateBadRequestResponse("No data was returned from the query."));
            }

            HttpResponseMessage responseMessage = new HttpResponseMessage();

            switch (resultSet.Content.Type)
            {
            case CommonContentType.XML:
            case CommonContentType.Flat:
            case CommonContentType.HTML:
                responseMessage.Content = new StringContent(resultSet.ConvertContentBytesToString());
                break;

            default:
                responseMessage.Content = new ByteArrayContent(resultSet.Content.Content);
                break;
            }

            responseMessage.Content.Headers.ContentType =
                new MediaTypeHeaderValue(CommonContentAndFormatProvider.ConvertToMimeType(resultSet.Content.Type));

            return(responseMessage);
        }
예제 #21
0
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            LOG.DebugEnter(MethodBase.GetCurrentMethod(), requestId);

            LazyInit();

            DataRequest request = _requestManager.GetDataRequest(requestId);

            object returnData = GetObjectFromRequest(request);

            LOG.Debug("Creating PaginatedContentResult");
            PaginatedContentResult result = new PaginatedContentResult();

            result.Paging = new PaginationIndicator(request.RowIndex, request.MaxRowCount, true);

            LOG.Debug("Serializing data");
            result.Content = new SimpleContent(CommonContentType.XML, _serializationHelper.Serialize(returnData));

            LOG.Debug("OK");
            return(result);
        }
        public PaginatedContentResult ProcessQuery(string requestId)
        {
            LazyInit();

            ValidateRequest(requestId);

            int rowCount;

            byte[] content = GetSubmittedDocumentList(out rowCount);

            PaginatedContentResult result = new PaginatedContentResult();

            result.Paging  = new PaginationIndicator(0, rowCount, true);
            result.Content = new SimpleContent(CommonContentType.XML, content);

            string docId =
                _documentManager.AddDocument(_dataRequest.TransactionId, CommonTransactionStatusCode.Completed,
                                             null, new Document(null, CommonContentType.XML, content));

            return(result);
        }
예제 #23
0
        /// <summary>
        /// ProcessSolicit
        /// </summary>
        /// <param name="requestId"></param>
        public virtual PaginatedContentResult ProcessQuery(string requestId)
        {
            ProcessQuerySolicitInit(requestId, false);
            _useSubmissionHistoryTable = false;

            string submitFile = null;

            try
            {
                object data = GetInsertUpdateData();

                submitFile = GenerateSubmissionFileAndAddToTransaction(Submission_Type.UpdateInsert, data);

                byte[] bytes = File.ReadAllBytes(submitFile);
                PaginatedContentResult result = new PaginatedContentResult(0, 1, true, CommonContentType.ZIP, bytes);
                return(result);
            }
            finally
            {
                FileUtils.SafeDeleteFile(submitFile);
            }
        }
        public SimpleContent GetMetaData(string category, NamedEndpointVisit visit)
        {
            PaginatedContentRequest request = new PaginatedContentRequest();

            request.FlowName      = "ENDS_v20";
            request.OperationName = "GetServices";
            request.Paging        = new PaginationIndicator();
            request.Paging.Start  = 0;
            request.Paging.Count  = -1;
            if (visit.Version == EndpointVersionType.EN20)
            {
                request.Parameters = new ByIndexOrNameDictionary <string>(true);
                request.Parameters.Add("ServiceCategory", category);
            }
            else
            {
                request.Parameters = new ByIndexOrNameDictionary <string>(false);
                request.Parameters.Add(category);
            }

            PaginatedContentResult result = _transactionService.Query(request, visit);

            return(result.Content);
        }
예제 #25
0
        protected virtual PaginatedContentResult TransformQueryResult(FormattedPaginatedContentRequest request, PaginatedContentResult result)
        {
            CheckToCompressContent(request, result);

            return(result);
        }
예제 #26
0
        protected virtual string GetFileNameForRequestContent(FormattedPaginatedContentRequest request, PaginatedContentResult result)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(request.FlowName))
            {
                if (sb.Length > 0)
                {
                    sb.Append("_");
                }
                sb.Append(request.FlowName);
            }
            if (!string.IsNullOrEmpty(request.OperationName))
            {
                if (sb.Length > 0)
                {
                    sb.Append("_");
                }
                sb.Append(request.OperationName);
            }
            if (sb.Length > 0)
            {
                sb.Append("_");
            }
            sb.Append("Results");
            sb.Append(CommonContentAndFormatProvider.GetFileExtension(result.Content.Type));
            return(FileUtils.ReplaceInvalidFilenameChars(sb.ToString(), '_'));
        }
예제 #27
0
 protected virtual bool CheckToCompressContent(FormattedPaginatedContentRequest request, PaginatedContentResult result)
 {
     if ((result == null) || !result.HasContent)
     {
         return(false);
     }
     if (request.ZipResults.HasValue && request.ZipResults.Value)
     {
         byte[] content = result.Content.Content;
         if (!CompressionHelper.IsCompressed(content))
         {
             string fileName = GetFileNameForRequestContent(request, result);
             result.Content.Content = CompressionHelper.Compress(fileName, content);
             result.Content.Type    = CommonContentType.ZIP;
             return(true);
         }
     }
     return(false);
 }
예제 #28
0
        /// <summary>
        /// Query
        /// </summary>
        /// <param name="securityToken"></param>
        /// <param name="request"></param>
        /// <param name="rowId"></param>
        /// <param name="maxRows"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        string INetworkNodeBinding.Query(string securityToken, string request, string rowId, string maxRows, string[] parameters)
        {
            Init();
            LOG.Debug("Query");

            #region Validate

            if (string.IsNullOrEmpty(securityToken))
            {
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL SecurityToken argument");
            }

            if (string.IsNullOrEmpty(request))
            {
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL Request argument");
            }

            int rowIdValue;
            if (!int.TryParse(rowId, out rowIdValue) || (rowIdValue < 0))
            {
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Invalid RowId argument");
            }

            int maxRowsValue;
            if (!int.TryParse(maxRows, out maxRowsValue) || !((maxRowsValue == -1) || (maxRowsValue > 0)))
            {
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Invalid MaxRows argument");
            }

            #endregion Validate

            try
            {
                LOG.Debug("Getting visit");
                NamedEndpointVisit visit =
                    _service11Provider.VisitProvider.GetVisit(securityToken);

                PaginatedContentRequest pagRequest = new PaginatedContentRequest();
                pagRequest.FlowName      = null; //TODO: use the name to derive it.
                pagRequest.OperationName = request;
                pagRequest.Paging        = new PaginationIndicator();
                pagRequest.Paging.Start  = rowIdValue;
                pagRequest.Paging.Count  = maxRowsValue;

                pagRequest.Parameters = CreateParameters(parameters);

                LOG.Debug("Querying: " + pagRequest);

                PaginatedContentResult resultSet =
                    _service11Provider.TransactionService.Query(pagRequest, visit);

                LOG.Debug("ResultSet: " + resultSet);

                if (resultSet == null || resultSet.Content == null || resultSet.Content.Content == null)
                {
                    throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_Unknown, "NULL Content");
                }


                return(ConvertBytesToString(resultSet.Content.Content));
            }
            catch (Exception ex)
            {
                LOG.Error("Error while querying", ex);
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex);
            }
        }