Ejemplo n.º 1
0
        public async Task<IEnumerable<CisDto>> GetPendingCdaAnalysisAsync(OperationType opType, OperationStatus pendingStatus, string sqlWhereConditions)
        {
            return await WithConnectionPool(async connection =>
            {
                var response = new List<CisDto>();
                var getPendingCdaAnalysisSql = string.Format(@"SELECT   Id
                                                                        ,IdCis                                                                        
                                                                        ,CASE WHEN [Transformations].exist('/TRANSFORMATIONS/TRANSFORMATION[@NAME=""{1}""]/CIS') = 1 then ([Transformations].query('/TRANSFORMATIONS/TRANSFORMATION[@NAME=""{1}""]/CIS')) else NULL end as Transformations
                                                                        ,CdaAnalysisList
                                                                FROM [dbo].[{0}] with (NOLOCK)
                                                                WHERE CdaAnalysisStatus = @pending
                                                                {2}", opType.ReferenceTable, CisTransformationName, sqlWhereConditions);

                var reader = connection.Query<dynamic>(getPendingCdaAnalysisSql, new { pending = pendingStatus.Id }, buffered: false);

                foreach (var item in reader)
                {
                    response.Add(new CisDto()
                    {
                        Id = item.Id,
                        IdCis = item.IdCis,
                        Transformations = string.IsNullOrEmpty(item.Transformations) ? null : TryParseToXNode(item.Transformations, "Transformations"),
                        CdaAnalysisList = string.IsNullOrEmpty(item.CdaAnalysisList) ? null : TryParseXmlString(item.CdaAnalysisList, "CdaAnalysisList"),
                    });
                }

                ObjectPoolPutConnection(connection);

                return await Task.FromResult(response);
            });
        }
Ejemplo n.º 2
0
 public async Task<IEnumerable<OperationGroupDto>> GetPendingOperationsAsync(OperationStatus pendingStatus)
 {
     return await WithConnection(async connection =>
     {
         string getPendingOperationsSql = [email protected]"SELECT * FROM [dbo].[{CdaManagerOperationsTableName}] with (NOLOCK) WHERE Active = @active AND Status = @pending";
         return await connection.QueryAsync<OperationGroupDto>(getPendingOperationsSql, new { active = TrueString, pending = pendingStatus });
     });
 }
Ejemplo n.º 3
0
        private void InitializeHandlers()
        {
            _analyzedOperationsListChangedHandler = Observable.FromEventPattern<NotifyCollectionChangedEventArgs>(
                AnalyzedOperationsList, "CollectionChanged")
                .Where(e =>
                {
                    var completeStatus = new OperationStatus { Id = 3 };

                    bool opCountCheck = GetOperationsCount() == ((ObservableConcurrentDictionary<Guid, byte>)e.Sender).Skip(0).Count();
                    bool groupStatusCheck = Status.Id != completeStatus.Id;

                    return e.EventArgs.Action == NotifyCollectionChangedAction.Add && opCountCheck && groupStatusCheck;
                })
                .Take(1)
                .Subscribe(
                    e =>
                    {
                        var completeStatus = new OperationStatus { Id = 3 };

                        _analyzedOperationsListChangedHandler?.Dispose();
                        //TODO SET TO COMPLETE
                        var time = DateTime.UtcNow;
                        LastStatusChangedTime = time;
                        CompleteTime = time;
                        Status = completeStatus;

                        var notificationCompleted = new AnalysisCompleted
                        {
                            OperationGroup = this
                        };

                        _mediator?.Publish(notificationCompleted);
                    },
                    ex => { Console.WriteLine("OnError: {0}", ex); },
                    () => Console.WriteLine("OnCompleted"));
        }
Ejemplo n.º 4
0
        public async Task<int> SetCompleteCdaAnalysisAsync(IOperationsGroup operationGroup, ICollection<int> idCisList, OperationType opType, OperationStatus completeStatus)
        {
            //TODO [ActivityLog] [ErrorsLog] [FailureCounter]

            var tbl = new DynamicModel(DbConnectionName, tableName: CdaManagerOperationsTableName);

            return await tbl.UpdateAsync(new
            {
                Status = completeStatus.Id,
                operationGroup.LastStatusChangedTime,
                operationGroup.CompleteTime,
                ErrorsLog = operationGroup.ErrorLog.Root
            }, $"Id = {operationGroup.SourceOperationGroupId}");
        }
Ejemplo n.º 5
0
        public async Task<int> SetInProgressCdaAnalysisAsync(IOperationsGroup operationGroup, ICollection<int> idCisList, OperationType opType, OperationStatus inProgressStatus)
        {
            //TODO [ActivityLog] [ErrorsLog] [FailureCounter]

            return await WithConnectionPool(async connection =>
            {
                int groupId = operationGroup.SourceOperationGroupId;

                var sb = new StringBuilder();
                if (CheckConcurrencyCdaAnalysis)
                {
                    sb.AppendFormat(@"UPDATE [dbo].[{0}] SET CdaAnalysisStatus = @inProgress WHERE IdCis IN @idCisList", opType.ReferenceTable).AppendLine();
                }
                sb.AppendFormat(@"UPDATE [dbo].[{0}] SET Status = @inProgress, LastStatusChangedTime = @changedTime WHERE Id = @operationGroupId", CdaManagerOperationsTableName);
                var updateCommand = sb.ToString();

                var response = await connection.ExecuteAsync(updateCommand, 
                    new {
                        inProgress = inProgressStatus.Id,
                        idCisList = idCisList.ToArray(),
                        operationGroupId = groupId,
                        changedTime = operationGroup.LastStatusChangedTime
                    });

                ObjectPoolPutConnection(connection);
                return response;
            });
        }