Exemple #1
0
        protected override async Task <bool> OnIsSuperUserAsync(int processId, string userId, CancellationToken cancellationToken, IDictionary <object, object> context)
        {
            try
            {
                var policy = _connectionFactory.PolicySelector(_logger);

                var result = await policy.ExecuteAsync(async() =>
                {
                    using (var connection = _connectionFactory.Create("raa"))
                    {
                        string query = $"SELECT dbo.FN_IS_PROCESS_SUPER_USER(@processId, @userId)";

                        var parameters = new DynamicParameters();
                        parameters.AddDynamicParams(new { processId, userId });

                        int temp = await connection.ExecuteScalarAsync <int>(query, parameters);

                        return(temp == 1);
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to check if the user with id {userId} is a super user. Reason: {ex}");
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// Asynchronously retrieves a count of <see cref="Process"/>.
        /// </summary>
        /// <param name="processIds">The list of process identification numbers that we are going to retrieve.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <param name="context">The optional execution context that applies to this operation.</param>
        /// <returns>A <see cref="Task{TResult}"/> </returns>
        private async Task <int> GetProcessCountAsync(IList <int> processIds, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null)
        {
            try
            {
                var policy = _connectionFactory.PolicySelector(_logger);

                var result = await policy.ExecuteAsync(async() =>
                {
                    using (var connection = _connectionFactory.Create("raa"))
                    {
                        string sqlStmnt = @"
SELECT COUNT(P.[PROCESS_ID]) AS ProcessCount
FROM RAA.dbo.PROCESS P
WHERE P.PROCESS_ID in @Ids";
                        var parameters  = new DynamicParameters();
                        parameters.AddDynamicParams(new { Ids = processIds });

                        int count = 0;

                        count = await connection.ExecuteScalarAsync <int>(sqlStmnt, parameters);

                        //IPagedResult<int, Process> returnResult = new PagedResult<Dictionary<int, Process>>(offset, limit, 0, processList);
                        return(count);
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to retrieve process list. Reason: {ex}");
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Asynchronously retrieves a list of <see cref="Activity"/>.
        /// </summary>
        /// <param name="activityIds">The list of activity identification numbers that we are going to retrieve.</param>
        /// <param name="limit">Maximun number of items that we are going to return per page.</param>
        /// <param name="offset">Number of pages that will be skipped.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <param name="context">The optional execution context that applies to this operation.</param>
        /// <returns>A <see cref="Task{TResult}"/> </returns>
        protected override async Task <PagedResult <Activity> > OnGetAsync(IList <int> activityIds, int offset, int limit, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null)
        {
            try
            {
                //int count = await GetActivityCountAsync(activityIds);
                int count = activityIds.Count;

                List <int> subList = activityIds.Skip(offset).Take(limit).ToList <int>();


                var policy = _connectionFactory.PolicySelector(_logger);

                var result = await policy.ExecuteAsync(async() =>
                {
                    using (var connection = _connectionFactory.Create("raa"))
                    {
                        IDictionary <int, Activity> activityList = await GetActivityList(subList, connection);

                        activityList = PopulateActivitiesNotFound(subList, activityList);

                        return(new PagedResult <Activity>(offset, limit, count, activityList.Values.ToList()));
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to retrieve activity list. Reason: {ex}");
                throw;
            }
        }
        /// <summary>
        /// Asynchronously retrieves a <see cref="PersonIdentification"/>.
        /// </summary>
        /// <param name="employeeId">The list of process identification numbers that we are going to retrieve.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <param name="context">The optional execution context that applies to this operation.</param>
        /// <returns>A <see cref="Task{TResult}"/> </returns>
        protected override async Task <PersonIdentification> OnGetByEmployeeIdAsync(string employeeId, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null)
        {
            try
            {
                var policy = _connectionFactory.PolicySelector(_logger);

                var result = await policy.ExecuteAsync(async() =>
                {
                    using (var connection = _connectionFactory.Create("raa"))
                    {
                        string sqlStmnt = @"
SELECT EMPLID AS EmployeeId
	, HANFORD_ID AS HanfordId
	, NETWORK_DOMAIN AS Domain
	, NETWORK_ID AS NetworkId
	, CASE WHEN ACTIVE_SW = 'Y' THEN
		1
		ELSE
		0
	END as IsActive
FROM [opwhse].[dbo].[VW_PUB_PERSON]
WHERE EMPLID =  @employeeId";
                        var parameters  = new DynamicParameters();
                        parameters.AddDynamicParams(new { employeeId = employeeId });


                        var personIdentification = await connection.QuerySingleAsync <PersonIdentification>(sqlStmnt, parameters);

                        if (personIdentification == null)
                        {
                            throw new RowNotInTableException();
                        }

                        return(personIdentification);
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to retrieve requested item. Reason: {ex}");
                throw;
            }
        }
Exemple #5
0
        protected override async Task <PagedResult <ProcessNode> > OnGetByIdsAsync(IList <int> processIds, int offset, int limit, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null)
        {
            int count = 0;

            string query = @"SELECT PROCESS_ID AS ProcessId
                                , NODE_NAME AS NodeName
                                , NODE_LABEL AS NodeLabel
                                , NODE_DATATYPE AS NodeDataType
                                , NODE_VALUE AS NodeValue
                             FROM XML_NODE
                             WHERE PROCESS_ID IN @Ids";

            try
            {
                DynamicParameters parameters = new DynamicParameters();
                parameters.AddDynamicParams(new { Ids = processIds });

                var policy = _connectionFactory.PolicySelector(_logger);

                var result = await policy.ExecuteAsync(async() =>
                {
                    using (var connection = _connectionFactory.Create("raa"))
                    {
                        IEnumerable <ProcessNode> processNodes;
                        IDictionary <int, ProcessNodeResult> processNodeResults = new Dictionary <int, ProcessNodeResult>();

                        using (SqlMapper.GridReader multi = await cn.QueryMultipleAsync(query, parameters, commandType: CommandType.Text))
                        {
                            processNodes = await multi.ReadAsync <ProcessNode>();
                        }

                        if (processNodes != null)
                        {
                            count = processNodes.Count();

                            // Group the nodes together by processId.
                            foreach (var processNode in processNodes)
                            {
                                int processId = processNode.ProcessId;

                                if (!processNodeResults.ContainsKey(processId))
                                {
                                    processNodeResults.Add(processId, new ProcessNodeResult()
                                    {
                                        ProcessId = processId,
                                        Nodes     = new List <Node>()
                                    });
                                }

                                processNodeResults[processId].Nodes.Add(new Node()
                                {
                                    NodeName     = processNode.NodeName,
                                    NodeLabel    = processNode.NodeLabel,
                                    NodeValue    = processNode.NodeValue,
                                    NodeDataType = processNode.NodeDataType
                                });
                            }
                        }

                        var result = processNodeResults
                                     .Values
                                     .ToList()
                                     .Skip(offset *limit)
                                     .Take(limit);

                        return(new PagedResult <ProcessNodeResult>(offset, limit, count, result));
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to retrieve process nodes list. Reason: {ex}");
                throw ex;
            }
        }