コード例 #1
0
            public async Task <SettlementMatter> Handle(DeleteSettlementMatterCommand message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Invalid input.", result.Errors);
                }

                if (!_wCADbContext.ActionstepCredentials.UserHasValidCredentialsForOrg(message.AuthenticatedUser, message.OrgKey))
                {
                    throw new UnauthorizedAccessException("User does not have access to the org for this matter.");
                }

                var orgSettlementMatters = _wCADbContext.SettlementMatters
                                           .Where(s => (s.ActionstepOrgKey == message.OrgKey && s.ActionstepMatterId == message.MatterId))
                                           .OrderBy(s => s.Version);

                _wCADbContext.SettlementMatters.RemoveRange(orgSettlementMatters);
                _wCADbContext.SaveChanges();

                return(await Task.FromResult(orgSettlementMatters.LastOrDefault()));
            }
コード例 #2
0
            public async Task <SettlementMatter> Handle(GetSettlementMatterQuery message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new System.ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Invalid input.", result.Errors);
                }

                SettlementMatter settlementMatter;

                settlementMatter = _wCADbContext.SettlementMatters
                                   .Where(s => (s.ActionstepOrgKey == message.OrgKey && s.ActionstepMatterId == message.MatterId))
                                   .OrderBy(s => s.Version)
                                   .LastOrDefault();

                if (settlementMatter == null)
                {
                    settlementMatter = new SettlementMatter(message.OrgKey, message.MatterId);
                }

                settlementMatter.ActionstepData = await _mediator.Send(new SettlementCalculatorMatterQuery
                {
                    AuthenticatedUser = message.AuthenticatedUser,
                    MatterId          = message.MatterId,
                    OrgKey            = message.OrgKey
                });

                return(settlementMatter);
            }
コード例 #3
0
            protected override async Task Handle(DisconnectFromActionstepOrgCommand message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Unable to disconnect from Actionstep organisaion, the command message was invalid.", result.Errors);
                }

                await _tokenSetRepository.Remove(new TokenSetQuery(message.AuthenticatedUser?.Id, message.ActionstepOrgKey));
            }
コード例 #4
0
            public async Task <ActionstepDocument> Handle(ActionstepSavePDFCommand message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Invalid input.", result.Errors);
                }

                TokenSetQuery tokenSetQuery = new TokenSetQuery(message.AuthenticatedUser?.Id, message.OrgKey);

                var actionResponse = await _actionstepService.Handle <GetActionResponse>(new GetActionRequest(tokenSetQuery, message.MatterId));

                string fileName = $"{message.MatterId}_Settlement Statement_{DateTime.UtcNow.ToString("_yyyy-MM-dd hh-mm", CultureInfo.InvariantCulture)}.pdf";

                UploadFileResponse file = await _actionstepService.UploadFile(tokenSetQuery, fileName, message.FilePath);

                #region Check Documents Folder
                ActionFolder             actionFolder   = new ActionFolder(actionResponse.Action.Id);
                GetActionFolderRequest   folderRequest  = new GetActionFolderRequest(tokenSetQuery, actionFolder);
                ListActionFolderResponse folderResponse = await _actionstepService.Handle <ListActionFolderResponse>(folderRequest);

                var parentFolderId = folderResponse.ActionFolders.Where(af => af.Name == "Documents").Select(af => af.Id).FirstOrDefault();
                #endregion

                ActionDocument            document    = new ActionDocument(actionResponse.Action.Id, fileName, file, parentFolderId);
                SaveActionDocumentRequest saveRequest = new SaveActionDocumentRequest(tokenSetQuery, document);

                var saveResponse = await _actionstepService.Handle <SaveActionDocumentResponse>(saveRequest);

                var fileUrl = new Uri(saveResponse.ActionDocument.SharepointUrl);

                string documentUrl = $"https://{fileUrl.Host}/mym/asfw/workflow/documents/views/action_id/{actionResponse.Action.Id}#mode=browse&view=list&folder={parentFolderId}&drive=DL";

                return(new ActionstepDocument(fileUrl, fileName, new Uri(documentUrl)));
            }
コード例 #5
0
            protected override async Task Handle(AddOrUpdateActionstepCredentialCommand message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validatorCollection.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Unable to save Actionstep credentials, the command message was invalid.", result.Errors);
                }

                if (message.AuthenticatedUser?.Id != message.TokenSet.UserId)
                {
                    throw new InvalidCredentialsForActionstepApiCallException("Unable to save credentials. TokenSet User ID doesn't match authenticated User ID.", message.TokenSet?.OrgKey);
                }

                await _tokenSetRepository.AddOrUpdateTokenSet(message.TokenSet);
            }
コード例 #6
0
            public void ShouldBeDirtyOnceValidated()
            {
                // Arrange
                string value = "Hello";

                var collection = new ValidatorCollection
                {
                    new AlphaValidator {
                        Key = "AlphaOnly"
                    },
                    new RequiredValidator {
                        Key = "Required"
                    },
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.IsDirty.ShouldBe(true);
            }
コード例 #7
0
            public void ShouldBeInvalidIfInvalidValue()
            {
                // Arrange
                string value = string.Empty;

                var collection = new ValidatorCollection
                {
                    new AlphaValidator {
                        Key = "AlphaOnly"
                    },
                    new RequiredValidator {
                        Key = "Required"
                    },
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.IsInvalid.ShouldBe(true);
            }
コード例 #8
0
            public void ShouldBeValidIfValidValue()
            {
                // Arrange
                string value = "Hello";

                var collection = new ValidatorCollection
                {
                    new AlphaValidator {
                        Key = "AlphaOnly"
                    },
                    new RequiredValidator {
                        Key = "Required"
                    },
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.IsInvalid.ShouldBe(false);
            }
コード例 #9
0
            public async Task <TokenSet> Handle(RefreshActionstepCredentialsCommand message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Invalid input.", result.Errors);
                }

                var tokenToRefresh = await _tokenSetRepository.GetTokenSetById(message.ActionstepCredentialIdToRefresh.ToString(CultureInfo.InvariantCulture));

                if (tokenToRefresh == null)
                {
                    throw new InvalidOperationException($"No Actionstep credentials found with the id {message.ActionstepCredentialIdToRefresh}. No credentials to be refreshed.");
                }

                return(await _actionstepService.RefreshAccessTokenIfExpired(tokenToRefresh, forceRefresh : true));
            }
コード例 #10
0
ファイル: SaveResources.cs プロジェクト: vhurryharry/Konekta
            protected override async Task Handle(SaveResourcesCommand message, CancellationToken token)
            {
                if (message is null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Unable to save Property Resources, the command message was invalid.", result.Errors);
                }

                using (var request = new HttpRequestMessage(HttpMethod.Get, message.ResourceURL))
                {
                    var byteArray = Encoding.ASCII.GetBytes($"{message.InfoTrackCredentials.Username}:{message.InfoTrackCredentials.Password}");
                    request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

                    using (var infoTrackFileDownloadResponse = await _infoTrackService.Client.SendAsync(request))
                    {
                        infoTrackFileDownloadResponse.EnsureSuccessStatusCode();

                        using (var infoTrackFileStream = await infoTrackFileDownloadResponse.Content.ReadAsStreamAsync())
                        {
                            if (infoTrackFileStream.Length <= 0)
                            {
                                throw new HttpRequestException($"Unable to download the resource from InfoTrack.");
                            }
                            else
                            {
                                var tokenSetQuery = new TokenSetQuery(message.AuthenticatedUser?.Id, message.ActionstepOrgKey);

                                var fileNameWithExtension = DetermineBestFileNameWithExtension(message, infoTrackFileDownloadResponse);

                                var fileUploadResponse = await _actionstepService.UploadFile(tokenSetQuery, fileNameWithExtension, infoTrackFileStream);

                                if (fileUploadResponse == null)
                                {
                                    throw new Exception("Unknown error uploading document to Actionstep.");
                                }

                                // Get all folders for matter and check to see if the specified folder exists. If it does, we need its ID.
                                var actionFolder     = new ActionFolder(message.MatterId);
                                var getFolderRequest = new GetActionFolderRequest(tokenSetQuery, actionFolder);
                                var folderResponse   = await _actionstepService.Handle <ListActionFolderResponse>(getFolderRequest);

                                /// Will be null if <see cref="SaveResourcesCommand.FolderName"/> wasn't found. In which case the document will be saved at the root of the matter.
                                var parentFolderId = folderResponse.ActionFolders.FirstOrDefault(af => af.Name == message.FolderName)?.Id;

                                /// <see cref="ActionstepDocument"/> represents the object in "Matter Documents", as opposed to the file content from above (which is just in a big bucket).
                                var document = new ActionDocument(message.MatterId, fileNameWithExtension, fileUploadResponse, parentFolderId);

                                var saveRequest = new SaveActionDocumentRequest(tokenSetQuery, document);

                                await _actionstepService.Handle <SaveActionDocumentResponse>(saveRequest);
                            }
                        }
                    }
                }
            }