public async Task <IHttpActionResult> PostAsync([FromBody] IEvent @event) { return(await ActionHelper.TryCatchWithLoggerAsync(async() => { _logger.WriteDebug(new LogMessage(string.Concat("VecompSoftware.DocSuiteWeb.WebAPI.Controllers.ServiceBus.TopicController.PostAsync(", @event != null, ")")), LogCategories); if (@event == null) { _logger.WriteWarning(new LogMessage(string.Concat("Event received is invalid (json deserialization set null value) : ", GetType().ToString())), LogCategories); return BadRequest("Event received is invalid (json deserialization set null value)"); } _logger.WriteInfo(new LogMessage(string.Concat("Event received ", @event.ToString())), LogCategories); if (!_validationService.Validate(@event, _ruleset.INSERT)) { _logger.WriteWarning(new LogMessage(string.Concat("Service Bus validation error: ", GetType().ToString())), LogCategories); return BadRequest("Service Bus validation error."); } ServiceBusMessage message = _mapper.Map(@event, new ServiceBusMessage()); if (string.IsNullOrEmpty(message.ChannelName)) { throw new DSWException(string.Concat("Topic name to event [", @event.ToString(), "] is not mapped"), null, DSWExceptionCode.SC_Mapper); } ServiceBusMessage response = await _service.SendToTopicAsync(message); return Ok(response); }, BadRequest, Content, InternalServerError, _logger, LogCategories)); }
private ServiceBusMessage GenerateMessage(Category category, int environmentType, Func <CategoryFascicle, ICommand> func) { IList <CategoryFascicle> categoryFascicles = category.CategoryFascicles.Where(f => (f.DSWEnvironment == environmentType || f.DSWEnvironment == 0)).ToList(); CategoryFascicle categoryFascicle = categoryFascicles.FirstOrDefault(); if (categoryFascicles != null && categoryFascicles.Count > 1) { categoryFascicle = categoryFascicles.FirstOrDefault(f => f.FascicleType == FascicleType.Period); } IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName); ServiceBusMessage message = null; ICommand command = func(categoryFascicle); message = _cqrsMapper.Map(command, new ServiceBusMessage()); if (string.IsNullOrEmpty(message.ChannelName)) { throw new DSWException($"Queue name to command [{command}] is not mapped", null, DSWExceptionCode.SC_Mapper); } return(message); }
protected override void AfterSave(CategoryFascicle entity) { if (CurrentDeleteActionType.HasValue && CurrentDeleteActionType == DeleteActionType.DeleteCategoryFascicle) { IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName); ICommandDeleteCategoryFascicle command = new CommandDeleteCategoryFascicle(Guid.Empty, _parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identity, entity); ServiceBusMessage message = _cqrsMapper.Map(command, new ServiceBusMessage()); if (message == null || string.IsNullOrEmpty(message.ChannelName)) { throw new DSWException(string.Concat("Queue name to command [", command.ToString(), "] is not mapped"), null, DSWExceptionCode.SC_Mapper); } Task.Run(async() => { await _queueService.SubscribeQueue(message.ChannelName).SendToQueueAsync(message); }).Wait(); } base.AfterSave(entity); }
protected override void AfterSave(Dossier entity) { try { _logger.WriteDebug(new LogMessage($"VecompSoftware.DocSuite.Private.WebAPI.Controllers.Entity.Dossiers.AfterSave with entity UniqueId {entity.UniqueId}"), LogCategories); if (CurrentInsertActionType.HasValue || CurrentUpdateActionType.HasValue) { IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName); Dossier dossier = _unitOfWork.Repository <Dossier>().GetByUniqueId(entity.UniqueId).SingleOrDefault(); ICQRS command = new CommandCreateDossier(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identity, dossier); if (CurrentUpdateActionType.HasValue) { command = new CommandUpdateDossier(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identity, dossier); } foreach (IWorkflowAction workflowAction in WorkflowActions) { workflowAction.IdWorkflowActivity = IdWorkflowActivity; command.WorkflowActions.Add(workflowAction); } ServiceBusMessage message = _cqrsMapper.Map(command, new ServiceBusMessage()); if (message == null || string.IsNullOrEmpty(message.ChannelName)) { throw new DSWException($"Queue name to command [{command}] is not mapped", null, DSWExceptionCode.SC_Mapper); } Task.Run(async() => { await _queueService.SubscribeQueue(message.ChannelName).SendToQueueAsync(message); }).Wait(); } } catch (DSWException ex) { _logger.WriteError(ex, LogCategories); } base.AfterSave(entity); }
protected override void AfterSave(Resolution entity) { try { _logger.WriteDebug(new LogMessage(string.Concat("VecompSoftware.DocSuite.Private.WebAPI.Controllers.Entity.Resolutions.AfterSave with entity UniqueId ", entity.UniqueId)), LogCategories); Resolution resolution = _unitOfWork.Repository <Resolution>().GetFullByUniqueId(entity.UniqueId).SingleOrDefault(); if (resolution != null) { IList <CategoryFascicle> categoryFascicles = resolution.Category.CategoryFascicles.Where(f => (f.DSWEnvironment == (int)DSWEnvironmentType.Resolution || f.DSWEnvironment == 0)).ToList(); CategoryFascicle categoryFascicle = categoryFascicles.FirstOrDefault(); if (categoryFascicles != null && categoryFascicles.Count > 1) { categoryFascicle = categoryFascicles.FirstOrDefault(f => f.FascicleType == FascicleType.Period); } _mapper.FileResolution = _unitOfWork.Repository <FileResolution>().GetByResolution(resolution.EntityId).SingleOrDefault(); _mapper.ResolutionRoles = _unitOfWork.Repository <ResolutionRole>().GetByResolution(resolution.EntityId); IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName); ResolutionModel resolutionModel = _mapper.Map(resolution, new ResolutionModel()); ICommandUpdateResolution commandUpdate = new CommandUpdateResolution(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identity, resolutionModel, categoryFascicle, null); ServiceBusMessage message = _cqrsMapper.Map(commandUpdate, new ServiceBusMessage()); if (string.IsNullOrEmpty(message.ChannelName)) { throw new DSWException(string.Concat("Queue name to command [", commandUpdate.ToString(), "] is not mapped"), null, DSWExceptionCode.SC_Mapper); } Task.Run(async() => { await _queueService.SubscribeQueue(message.ChannelName).SendToQueueAsync(message); }).Wait(); } base.AfterSave(entity); } catch (DSWException ex) { _logger.WriteError(ex, LogCategories); } }
protected override void AfterSave(Message entity) { try { _logger.WriteDebug(new LogMessage($"VecompSoftware.DocSuite.Private.WebAPI.Controllers.Entity.Messages.AfterSave with entity UniqueId {entity.UniqueId}"), LogCategories); Message message = _unitOfWork.Repository <Message>().Find(entity.EntityId); if (message != null) { IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName); ICQRS command = null; if (entity.Status == MessageStatus.Active) { command = new CommandCreateMessage(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identity, message); } if (command != null) { foreach (IWorkflowAction workflowAction in WorkflowActions) { workflowAction.IdWorkflowActivity = IdWorkflowActivity; command.WorkflowActions.Add(workflowAction); } ServiceBusMessage serviceBusMessage = _cqrsMapper.Map(command, new ServiceBusMessage()); if (serviceBusMessage == null || string.IsNullOrEmpty(serviceBusMessage.ChannelName)) { throw new DSWException($"Queue name to command [{command}] is not mapped", null, DSWExceptionCode.SC_Mapper); } Task.Run(async() => { await _queueService.SubscribeQueue(serviceBusMessage.ChannelName).SendToQueueAsync(serviceBusMessage); }).Wait(); } } } catch (DSWException ex) { _logger.WriteError(ex, LogCategories); } base.AfterSave(entity); }
protected override void AfterSave(Protocol entity) { try { _logger.WriteDebug(new LogMessage($"VecompSoftware.DocSuite.Private.WebAPI.Controllers.Entity.Protocols.AfterSave with entity UniqueId {entity.UniqueId}"), LogCategories); Protocol protocol = _unitOfWork.Repository <Protocol>().GetByUniqueIdWithRole(entity.UniqueId).FirstOrDefault(); if (protocol != null) { IList <CategoryFascicle> categoryFascicles = protocol.Category.CategoryFascicles.Where(f => f.DSWEnvironment == (int)DSWEnvironmentType.Protocol || f.DSWEnvironment == 0).ToList(); CategoryFascicle categoryFascicle = categoryFascicles.FirstOrDefault(); if (categoryFascicles != null && categoryFascicles.Count > 1) { categoryFascicle = categoryFascicles.FirstOrDefault(f => f.FascicleType == FascicleType.Period); } IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName); ICQRS command = null; if (CurrentUpdateActionType.HasValue && CurrentUpdateActionType == UpdateActionType.ActivateProtocol) { command = new CommandCreateProtocol(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, protocol.TenantAOO.UniqueId, null, null, null, identity, protocol, categoryFascicle, null); } if (CurrentDeleteActionType.HasValue && CurrentDeleteActionType == DeleteActionType.DeleteProtocol) { command = new CommandUpdateProtocol(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, protocol.TenantAOO.UniqueId, null, null, null, identity, protocol, categoryFascicle, null); } if (HttpContext.Current.Request.HttpMethod == HttpMethod.Put.Method && CurrentUpdateActionType.HasValue && CurrentUpdateActionType != UpdateActionType.ActivateProtocol) { command = new CommandUpdateProtocol(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, protocol.TenantAOO.UniqueId, null, null, null, identity, protocol, categoryFascicle, null); } if (command != null) { WorkflowActionDocumentUnitLinkModel workflowActionDocumentUnitLinkModel; DocumentUnitModel documentUnitModel; foreach (IWorkflowAction workflowAction in WorkflowActions) { workflowAction.IdWorkflowActivity = IdWorkflowActivity; if (workflowAction is IWorkflowActionDocumentUnitLink) { workflowActionDocumentUnitLinkModel = (WorkflowActionDocumentUnitLinkModel)workflowAction; documentUnitModel = workflowActionDocumentUnitLinkModel.GetReferenced(); if (documentUnitModel.UniqueId != protocol.UniqueId) { documentUnitModel = workflowActionDocumentUnitLinkModel.GetDestinationLink(); } documentUnitModel.Year = protocol.Year; documentUnitModel.Number = protocol.Number.ToString(); } command.WorkflowActions.Add(workflowAction); } ServiceBusMessage message = _cqrsMapper.Map(command, new ServiceBusMessage()); if (message == null || string.IsNullOrEmpty(message.ChannelName)) { throw new DSWException($"Queue name to command [{command}] is not mapped", null, DSWExceptionCode.SC_Mapper); } Task.Run(async() => { await _queueService.SubscribeQueue(message.ChannelName).SendToQueueAsync(message); }).Wait(); } } } catch (DSWException ex) { _logger.WriteError(ex, LogCategories); } base.AfterSave(entity); }
public async Task <IHttpActionResult> Post(Guid authenticationId, string documentUnit, short year, int number) { return(await ActionHelper.TryCatchWithLoggerGeneric(async() => { _logger.WriteInfo(new LogMessage($"Token securities receive a request for authenticationId {authenticationId}, documentUnit {documentUnit}, year {year} and number {number}"), LogCategories); if (!DSWAuthorizationServerProvider.ValidAuthenticationList.Any(f => f == authenticationId)) { _logger.WriteWarning(new LogMessage($"AuthenticationId {authenticationId} is not valid"), LogCategories); throw new DSWSecurityException($"AuthenticationId {authenticationId} is not valid", null, DSWExceptionCode.SC_InvalidAccount); } DocumentUnit reference = null; switch (documentUnit) { case "Protocol": { reference = _unitOfWork.Repository <DocumentUnit>().GetByNumbering(year, number, (int)DSWEnvironmentType.Protocol, optimization: true); break; } default: { _logger.WriteWarning(new LogMessage($"AuthenticationId {authenticationId} has no valid documentUnit '{documentUnit}' name"), LogCategories); throw new DSWSecurityException($"AuthenticationId {authenticationId} is not valid", null, DSWExceptionCode.SC_InvalidAccount); } } if (reference == null) { _logger.WriteWarning(new LogMessage($"DocumentUnit {documentUnit} - {year}/{number} not found"), LogCategories); throw new DSWSecurityException($"DocumentUnit {documentUnit} - {year}/{number} not found", null, DSWExceptionCode.SC_InvalidAccount); } Guid currentToken = Guid.NewGuid(); DateTimeOffset creationDate = DateTimeOffset.UtcNow; DateTimeOffset expiryDate = creationDate.AddMilliseconds(30 * 1000); HostIdentify hostIdentify = new HostIdentify(Environment.MachineName, "Public WebAPI"); TokenSecurityModel tokenModel = new TokenSecurityModel() { AuthenticationId = authenticationId, ExpiryDate = expiryDate, Token = currentToken, Host = hostIdentify, DocumentUnitAuhtorized = new DocSuiteWeb.Model.Entities.DocumentUnits.DocumentUnitModel() { Environment = reference.Environment, UniqueId = reference.UniqueId, Year = reference.Year, Number = reference.Number.ToString(), Title = reference.Title } }; string username = "******"; if (WindowsIdentity.GetCurrent() != null) { username = WindowsIdentity.GetCurrent().Name; } IdentityContext identityContext = new IdentityContext(username); EventTokenSecurity eventTokenSecurity = new EventTokenSecurity(Guid.NewGuid(), currentToken, _parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identityContext, tokenModel, null); _logger.WriteDebug(new LogMessage($"Generated token {currentToken} by {username} expiry on {expiryDate}"), LogCategories); string topicName = _messageConfiguration.GetConfigurations()[eventTokenSecurity.EventName].TopicName; string dynamicSubscriptionName = currentToken.ToString(); await _topicService.CreateSubscriptionAsync(topicName, dynamicSubscriptionName, currentToken.ToString(), eventTokenSecurity.EventName); ServiceBusMessage message = _cqrsMapper.Map(eventTokenSecurity, new ServiceBusMessage()); ServiceBusMessage response = await _topicService.SendToTopicAsync(message); return Ok(currentToken); }, _logger, LogCategories)); }