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);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public PaginatedContentResult Query(PaginatedContentRequest request, NamedEndpointVisit visit)
        {
            Activity activity      = null;
            string   transactionId = null;

            try
            {
                NodeVisit nodeVisit;
                MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Query,
                                     out nodeVisit, out activity);
                if (request == null)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                 "Empty input request");
                }
                if (string.IsNullOrEmpty(request.OperationName))
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                 "Input request is null");
                }
                if (string.IsNullOrEmpty(request.FlowName))
                {
                    bool   moreThanOneFlowFound;
                    string flowNameByServiceName =
                        FlowManager.GetDataFlowNameByServiceName(request.OperationName, out moreThanOneFlowFound);
                    if (string.IsNullOrEmpty(flowNameByServiceName))
                    {
                        if (moreThanOneFlowFound)
                        {
                            throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                         string.Format("More than one flow was found for the service \"{0}\"",
                                                                       request.OperationName));
                        }
                        else
                        {
                            throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                         string.Format("Could not find a flow for the service \"{0}\"",
                                                                       request.OperationName));
                        }
                    }
                    request.FlowName = flowNameByServiceName;
                }
                bool   isFlowProtected;
                string flowId = FlowManager.GetDataFlowIdByName(request.FlowName, out isFlowProtected);
                if (flowId == null)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow,
                                                 "Flow \"{0}\" was not found", request.FlowName);
                }
                activity.FlowName  = request.FlowName;
                activity.Operation = request.OperationName;

                if (request.Paging == null)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                 "Input paging is null");
                }
                if (request.Paging.Count == -1)
                {
                    if (request.Paging.Start != 0)
                    {
                        throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                     "Start row is not valid: \"{0}\"", request.Paging.Start);
                    }
                }
                else if (request.Paging.Count > 0)
                {
                }
                else
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                 "Max row count is not valid: \"{0}\"", request.Paging.Count);
                }

                DataService queryService = FlowManager.GetQueryServiceForFlow(flowId, request.OperationName);
                if ((queryService == null) || !queryService.IsActive)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable,
                                                 "A valid Query service was not found for the flow \"{0}\" and request \"{1}\"",
                                                 request.FlowName, request.OperationName);
                }

                if (isFlowProtected)
                {
                    ValidateUserPermissions(nodeVisit, request.FlowName, request.OperationName, NodeMethod.Query,
                                            activity);
                }

                activity.AppendFormat("Query request from {0} by {1}. ", visit.IP, nodeVisit.Account.NaasAccount);
                activity.AppendFormat("Service:{0} Parameters:{1} Row:{2} Rows:{3}. ",
                                      request.OperationName, ParsingHelper.ToQualifiedString(request.Parameters),
                                      request.Paging.Start.ToString(), request.Paging.Count.ToString());

                // Load the service plugin
                IQueryProcessor plugin;
                IPluginDisposer disposer;
                try
                {
                    string flowName = FlowManager.GetDataFlowNameById(queryService.FlowId);
                    disposer = PluginLoader.LoadQueryProcessor(queryService, out plugin);
                }
                catch (Exception)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable,
                                                 "Failed to load the Query service for the flow \"{0}\" and request \"{1}\"",
                                                 request.FlowName, request.OperationName);
                }
                PaginatedContentResult result;
                using (disposer)
                {
                    transactionId =
                        TransactionManager.CreateTransaction(NodeMethod.Query, visit.Version, flowId, request.OperationName,
                                                             nodeVisit.Account.Id, CommonTransactionStatusCode.Pending,
                                                             null, null, null, false);
                    activity.TransactionId = transactionId;

                    string requestId =
                        RequestManager.CreateDataRequest(transactionId, queryService.Id, request.Paging.Start,
                                                         request.Paging.Count, RequestType.Query, nodeVisit.Account.Id,
                                                         request.Parameters);

                    try
                    {
                        result = plugin.ProcessQuery(requestId);
                    }
                    finally
                    {
                        activity.Append(plugin.GetAuditLogEvents());
                    }
                }

                TransactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Processed,
                                                        null, false);

                NotificationManager.DoQueryNotifications(flowId, transactionId, request.FlowName, nodeVisit.Account.NaasAccount,
                                                         request.OperationName, request.Paging.Start,
                                                         request.Paging.Count, request.Parameters);
                return(result);
            }
            catch (Exception ex)
            {
                if (transactionId != null)
                {
                    TransactionManager.SetTransactionStatusNoThrow(transactionId,
                                                                   CommonTransactionStatusCode.Failed,
                                                                   ex.Message, false);
                }
                if (activity != null)
                {
                    activity.Append(ExceptionUtils.ToShortString(ex));
                    activity.Type = ActivityType.Error;
                }
                if (ex is SoapException)
                {
                    throw;      // Throw directly since already SoapException
                }
                else
                {
                    throw FaultProvider.GetFault(visit.Version, ex);
                }
            }
            finally
            {
                if (activity != null)
                {
                    ActivityManager.Log(activity);
                }
            }
        }