Пример #1
0
        internal static ACTIONS_FOLDERS MapToActionFolder(ActionFolder a, bool v)
        {
            ACTIONS_FOLDERS f = new ACTIONS_FOLDERS()
            {
                IDACTION = (double)a.idAction,
                IDFOLDER = a.idFolder
            };

            if (!v)
            {
                f.ID = a.iD;
            }
            return(f);
        }
Пример #2
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)));
            }
Пример #3
0
        public async Task <FTAttachment> Handle(SavePolicyPDFToActionstepCommand request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // Get Actionstep matter info
            var tokenSetQuery = new TokenSetQuery(request.AuthenticatedUser?.Id, request.ActionstepOrg);

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

            UploadFileResponse file = await _actionstepService.UploadFile(tokenSetQuery, request.FileName, request.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, request.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 FTAttachment()
            {
                FileName = request.FileName,
                FileUrl = documentUrl
            });
        }
Пример #4
0
            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);
                            }
                        }
                    }
                }
            }
            public async Task <DocumentRelationship> Handle(CopyDocumentVersionToActionstepCommand request, CancellationToken cancellationToken)
            {
                if (request is null)
                {
                    throw new System.ArgumentNullException(nameof(request));
                }
                _validator.ValidateAndThrow(request);

                var tempFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                DocumentFileInfo globalXDocumentFileInfo;

                var tokenSetQuery = new TokenSetQuery(request.ActionstepUserId, request.ActionstepOrgKey);

                // Check to make sure this matter exists first. This will throw if it's not found.
                var matterInfo = await _actionstepService.Handle <GetActionResponse>(new GetActionRequest(tokenSetQuery, request.ActionstepMatterId));

                if (matterInfo is null)
                {
                    throw new InvalidActionstepMatterException($"Matter '{request.ActionstepMatterId}' was not found in Actionstep.");
                }

                try
                {
                    try
                    {
                        globalXDocumentFileInfo = await _globalXService.DownloadDocument(
                            request.DocumentVersion.DocumentId.Value,
                            request.DocumentVersion.DocumentVersionId.Value,
                            tempFilePath,
                            request.GlobalXUserId);
                    }
                    catch (Exception ex)
                    {
                        throw new FailedToDownloadGlobalXDocumentException(ex);
                    }

                    try
                    {
                        var fileName = !string.IsNullOrEmpty(globalXDocumentFileInfo?.FileName)
                            ? globalXDocumentFileInfo.FileName
                            : request.DocumentVersion.DocumentName;

                        var fileUploadResponse = await _actionstepService.UploadFile(tokenSetQuery, fileName, tempFilePath);

                        if (fileUploadResponse is 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(request.ActionstepMatterId);
                        var getFolderRequest = new GetActionFolderRequest(tokenSetQuery, actionFolder);
                        var folderResponse   = await _actionstepService.Handle <ListActionFolderResponse>(getFolderRequest);

                        /// Will be null if the folder name 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 == ActionstepFolderFirstPreference)?.Id ??
                                             folderResponse?.ActionFolders?.FirstOrDefault(af => af.Name == ActionstepFolderSecondPreference)?.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(request.ActionstepMatterId, fileName, fileUploadResponse, parentFolderId);
                        var saveActionDocumentRequest = new SaveActionDocumentRequest(tokenSetQuery, document);

                        var saveActionDocumentResponse = await _actionstepService.Handle <SaveActionDocumentResponse>(saveActionDocumentRequest);

                        return(new DocumentRelationship(
                                   request.DocumentVersion.DocumentId.Value,
                                   request.DocumentVersion.DocumentVersionId.Value,
                                   fileName,
                                   request.DocumentVersion.MimeType,
                                   request.ActionstepOrgKey,
                                   request.ActionstepMatterId,
                                   saveActionDocumentResponse.ActionDocument.Id,
                                   new Uri(saveActionDocumentResponse.ActionDocument.SharepointUrl)));
                    }
                    catch (InvalidTokenSetException ex)
                    {
                        throw new FailedToUploadGlobalXDocumentToActionstepException(
                                  $"Invalid Actionstep Token, unable to upload document. Token revoked at '{ex.TokenSet?.RevokedAt}', Token ID '{ex.TokenSet?.Id}'.",
                                  ex);
                    }
                    catch (Exception ex)
                    {
                        throw new FailedToUploadGlobalXDocumentToActionstepException(ex.Message, ex);
                    }
                }
                finally
                {
                    if (File.Exists(tempFilePath))
                    {
                        File.Delete(tempFilePath);
                    }
                }
            }
Пример #6
0
        internal static void CreateActionsForFolders(decimal idIn, decimal idOut, decimal idInArch, decimal idOutArch, string nome, string idNome)
        {
            List <ActiveUp.Net.Common.DeltaExt.Action> actions = new List <ActiveUp.Net.Common.DeltaExt.Action>();

            ActiveUp.Net.Common.DeltaExt.Action actionin = new ActiveUp.Net.Common.DeltaExt.Action();
            actionin.IdDestinazione       = decimal.Parse(idNome);
            actionin.IdFolderDestinazione = (int)idIn;
            actionin.NomeAzione           = "SPOSTA IN " + nome;
            actionin.TipoAzione           = "SP";
            actions.Add(actionin);
            ActiveUp.Net.Common.DeltaExt.Action actionout = new ActiveUp.Net.Common.DeltaExt.Action();
            actionout.IdDestinazione       = decimal.Parse(idNome);
            actionout.IdFolderDestinazione = (int)idOut;
            actionout.NomeAzione           = "SPOSTA IN " + nome;
            actionout.TipoAzione           = "SP";
            actions.Add(actionout);
            // archivio
            ActiveUp.Net.Common.DeltaExt.Action actioninArch = new ActiveUp.Net.Common.DeltaExt.Action();
            actioninArch.IdDestinazione       = decimal.Parse(idNome);
            actioninArch.IdFolderDestinazione = (int)idInArch;
            actioninArch.NomeAzione           = "SPOSTA IN " + nome;
            actioninArch.TipoAzione           = "SP";
            actions.Add(actioninArch);
            ActiveUp.Net.Common.DeltaExt.Action actionoutArch = new ActiveUp.Net.Common.DeltaExt.Action();
            actionoutArch.IdDestinazione       = decimal.Parse(idNome);
            actionoutArch.IdFolderDestinazione = (int)idOutArch;
            actionoutArch.NomeAzione           = "SPOSTA IN " + nome;
            actionoutArch.TipoAzione           = "SP";
            actions.Add(actionoutArch);
            ActionsService actService = new ActionsService();

            try
            {
                actService.Insert(actions);
                List <ActionFolder> actionsFolders = new List <ActionFolder>();
                // inserimento azioni e collegamento con folders
                ActionFolder afInbox = new ActionFolder();
                afInbox.idAction = actionin.Id;
                afInbox.idFolder = 1;
                actionsFolders.Add(afInbox);
                ActionFolder afNewFolder = new ActionFolder();
                afNewFolder.idAction = 4;
                afNewFolder.idFolder = idIn;
                actionsFolders.Add(afNewFolder);
                ActionFolder afOutBox = new ActionFolder();
                afOutBox.idAction = actionout.Id;
                afOutBox.idFolder = 2;
                actionsFolders.Add(afOutBox);
                ActionFolder afNewFolderOut = new ActionFolder();
                afNewFolderOut.idAction = 6;
                afNewFolderOut.idFolder = idOut;
                actionsFolders.Add(afNewFolderOut);
                // ARCHIVI
                ActionFolder afInboxArch = new ActionFolder();
                afInboxArch.idAction = actioninArch.Id;
                afInboxArch.idFolder = 5;
                actionsFolders.Add(afInboxArch);
                ActionFolder afNewFolderArch = new ActionFolder();
                afNewFolderArch.idAction = 4;
                afNewFolderArch.idFolder = idInArch;
                actionsFolders.Add(afNewFolderArch);
                ActionFolder afOutBoxArch = new ActionFolder();
                afOutBoxArch.idAction = actionoutArch.Id;
                afOutBoxArch.idFolder = 7;
                actionsFolders.Add(afOutBoxArch);
                ActionFolder afNewFolderOutArch = new ActionFolder();
                afNewFolderOutArch.idAction = 6;
                afNewFolderOutArch.idFolder = idOutArch;
                actionsFolders.Add(afNewFolderOutArch);
                ActionsFoldersService service = new ActionsFoldersService();
                service.Insert(actionsFolders);
            }
            catch (Exception ex)
            {
                ManagedException mEx = new ManagedException(ex.Message, "FOL_APP001", string.Empty, string.Empty, ex);
                ErrorLogInfo     er  = new ErrorLogInfo(mEx);
                log.Error(er);
                throw mEx;
            }
        }
Пример #7
0
 public GetActionFolderRequest(TokenSetQuery tokenSetQuery, ActionFolder actionFolder)
 {
     TokenSetQuery = tokenSetQuery;
     ActionFolder  = actionFolder;
 }
Пример #8
0
 public void Update(ActionFolder entity)
 {
     throw new NotImplementedException();
 }
Пример #9
0
 public void Insert(ActionFolder entity)
 {
     throw new NotImplementedException();
 }