private async Task <JObject> MoveFileAsync(string fromSiteId, string fromItemPath, string toSiteId, string toItemPath, string requestId = "") { _logger.LogInformation($"RequestId: {requestId} - MoveFileAsync called."); try { Guard.Against.NullOrEmpty(fromSiteId, nameof(fromSiteId), requestId); Guard.Against.NullOrEmpty(fromItemPath, nameof(fromItemPath), requestId); Guard.Against.NullOrEmpty(toSiteId, nameof(toSiteId), requestId); Guard.Against.NullOrEmpty(toItemPath, nameof(toItemPath), requestId); return(await _graphSharePointAppService.MoveFileAsync(fromSiteId, fromItemPath, toSiteId, toItemPath, requestId)); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - MoveFileAsync Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - MoveFileAsync Service Exception: {ex}"); } }
// Workflow Actions public async Task <Opportunity> MoveTempFileToTeamAsync(Opportunity opportunity, string requestId = "") { try { // Find entries that need to be moved var moveFiles = false; foreach (var itm in opportunity.DocumentAttachments) { if (itm.DocumentUri == "TempFolder") { moveFiles = true; } } if (moveFiles) { var fromSiteId = _appOptions.ProposalManagementRootSiteId; var toSiteId = String.Empty; var fromItemPath = String.Empty; var toItemPath = String.Empty; string pattern = @"[ `~!@#$%^&*()_|+\-=?;:'" + '"' + @",.<>\{\}\[\]\\\/]"; string replacement = ""; Regex regEx = new Regex(pattern); var path = regEx.Replace(opportunity.DisplayName, replacement); //var path = WebUtility.UrlEncode(opportunity.DisplayName); //var path = opportunity.DisplayName.Replace(" ", ""); var siteIdResponse = await _graphSharePointAppService.GetSiteIdAsync(_appOptions.SharePointHostName, path, requestId); dynamic responseDyn = siteIdResponse; toSiteId = responseDyn.id.ToString(); if (!String.IsNullOrEmpty(toSiteId)) { var updatedDocumentAttachments = new List <DocumentAttachment>(); foreach (var itm in opportunity.DocumentAttachments) { var updDoc = DocumentAttachment.Empty; if (itm.DocumentUri == "TempFolder") { fromItemPath = $"TempFolder/{opportunity.DisplayName}/{itm.FileName}"; toItemPath = $"General/{itm.FileName}"; var resp = new JObject(); try { resp = await _graphSharePointAppService.MoveFileAsync(fromSiteId, fromItemPath, toSiteId, toItemPath, requestId); updDoc.Id = new Guid().ToString(); updDoc.DocumentUri = String.Empty; //doc.Id = resp.id; } catch (Exception ex) { _logger.LogWarning($"RequestId: {requestId} - MoveTempFileToTeam: from: {fromItemPath} to: {toItemPath} Service Exception: {ex}"); } } updDoc.FileName = itm.FileName; updDoc.Note = itm.Note ?? String.Empty; updDoc.Tags = itm.Tags ?? String.Empty; updDoc.Category = Category.Empty; updDoc.Category.Id = itm.Category.Id; updDoc.Category.Name = itm.Category.Name; updatedDocumentAttachments.Add(updDoc); } opportunity.DocumentAttachments = updatedDocumentAttachments; // Delete temp files var result = await _graphSharePointAppService.DeleteFileOrFolderAsync(_appOptions.ProposalManagementRootSiteId, $"TempFolder/{opportunity.DisplayName}", requestId); } } return(opportunity); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - MoveTempFileToTeam Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - MoveTempFileToTeam Service Exception: {ex}"); } }