public IEnumerable <object> Read(FileContentRequest fcr, PullConfig pullConfig) { List <object> output = new List <object>(); string fileFullPath = fcr.File.IFullPath(); oM.Adapters.File.FSFile readFile = ReadFile(fileFullPath, true, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles); if (readFile == null) { return(output); } output = readFile.Content ?? new List <object>(); if (!output.Any()) { BH.Engine.Base.Compute.RecordWarning($"No content could be pulled for {fileFullPath}. Make sure it's not protected or empty."); } return(output .Where(o => fcr.Types.Count > 0 ? fcr.Types.Any(t => t == o.GetType()) : true) .Where(o => fcr.FragmentTypes.Count > 0 ? (o as BHoMObject)?.Fragments.Select(f => f.GetType()).Intersect(fcr.FragmentTypes).Any() ?? false : true) .Where(o => fcr.CustomDataKeys.Count > 0 ? (o as BHoMObject)?.CustomData.Keys.Intersect(fcr.CustomDataKeys).Any() ?? false : true)); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public IEnumerable <object> Read(FileDirRequest fdr, PullConfig pullConfig) { // Copy for immutability in UI FileDirRequest fdrCopy = BH.Engine.Base.Query.ShallowClone(fdr); // Recursively walk the directories to retrieve File and Directory Info. List <IFSInfo> output = new List <IFSInfo>(); List <FSFile> files = new List <FSFile>(); List <FSDirectory> dirs = new List <FSDirectory>(); WildcardPattern wildcardPattern = null; if (!Modify.ProcessFileDirRequest(fdrCopy, out wildcardPattern)) { return(null); } int retrievedFiles = 0, retrievedDirs = 0; WalkDirectories(files, dirs, fdrCopy, ref retrievedFiles, ref retrievedDirs, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles, wildcardPattern); output.AddRange(dirs); output.AddRange(files); // If a sort order is applied, sort separately files and dirs, // then return the maxItems of each of those. if (fdrCopy.SortOrder != SortOrder.Default) { output = Query.SortOrder(output, fdrCopy.SortOrder); files = output.OfType <FSFile>().Take(fdrCopy.MaxFiles == -1 ? output.Count : fdrCopy.MaxFiles).ToList(); dirs = output.OfType <FSDirectory>().Take(fdrCopy.MaxDirectories == -1 ? output.Count : fdrCopy.MaxDirectories).ToList(); } if (fdrCopy.IncludeFileContents) { files.ForEach(f => ReadAndAddContent(f)); } output = new List <IFSInfo>(); if (fdrCopy.SortOrder != SortOrder.Default && fdrCopy.SortOrder != SortOrder.ByName) { output.AddRange(files); output.AddRange(dirs); } else { output.AddRange(dirs); output.AddRange(files); } return(output); }
public override IEnumerable <object> Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null) { PullConfig pullConfig = actionConfig as PullConfig ?? new PullConfig(); RevisionRequest rr = request as RevisionRequest; if (rr != null) { return(GetRevisions(rr).OfType <object>()); } IssueRequest ir = request as IssueRequest; if (ir != null) { return(GetIssues(ir, pullConfig).OfType <object>()); } AuditRequest ar = request as AuditRequest; if (ar != null) { if (ar.Audit == null) { BH.Engine.Reflection.Compute.RecordWarning("Please specify the Audit whose Issues you want to pull from 3DRepo in the request."); return(null); } ir = new IssueRequest() { ModelId = ar.ModelId, RevisionId = ar.RevisionId, TeamSpace = ar.TeamSpace, UserAPIKey = ar.UserAPIKey }; Audit audit = ar.Audit.DeepClone(); // The conversion between 3DRepo issues and BHoM Issues // will need to be passed any Pulled media file Name, if they were pulled with the Issues. Dictionary <oM.Adapters.TDRepo.Issue, List <string> > mediaFilenames_perIssue = new Dictionary <oM.Adapters.TDRepo.Issue, List <string> >(); List <oM.Inspection.Issue> pulledIssues = GetIssues(ir, pullConfig, true, mediaFilenames_perIssue); // Return the Audit with the Pulled issues from 3DRepo. return(new List <object>() { audit }); } BH.Engine.Reflection.Compute.RecordWarning($"The specified request is not compatible with {this.GetType().Name}."); return(new List <object>()); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static oM.Adapters.File.FSFile ReadFile(FileRequest fr, PullConfig pc) { string fullPath = fr.Location.IFullPath(); return(ReadFile(fullPath, fr.IncludeFileContents, pc.IncludeHiddenFiles, pc.IncludeSystemFiles)); }
/***************************************************/ public IEnumerable <object> Read(FileRequest fr, PullConfig pullConfig) { // Convert to the most generic type of Request. return(Read((FileDirRequest)fr, pullConfig)); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public List <oM.Inspection.Issue> GetIssues(IssueRequest ir, PullConfig pullConfig, bool enableMessages = true, Dictionary <Issue, List <string> > mediaFileNames = null) { List <Issue> allIssues = new List <Issue>(); List <oM.Inspection.Issue> allBHoMIssues = new List <oM.Inspection.Issue>(); string modelId = ir?.ModelId ?? m_modelId; string teamsSpace = ir?.TeamSpace ?? m_teamspace; string userAPIkey = ""; if (!string.IsNullOrWhiteSpace(ir.UserAPIKey)) { userAPIkey = ir.UserAPIKey; } else if (!string.IsNullOrWhiteSpace(m_userAPIKey)) { userAPIkey += m_userAPIKey; } bool singleIssue = !string.IsNullOrWhiteSpace(ir.IssueId); if (singleIssue) { // Get the Issue corresponding to the specified IssueId. if (enableMessages) { BH.Engine.Reflection.Compute.RecordNote($"Getting {nameof(Issue)} with id {ir.IssueId} \nfrom the 3DRepo Model `{modelId}` in the Teamspace `{teamsSpace}`."); } Issue issue = GetIssue(ir.IssueId, teamsSpace, modelId, userAPIkey); allIssues.Add(issue); } else { // If no IssueId is specified, get *all the issues* attached to a specific Revision. // (In 3DRepo, the issues are attached to a specific Model's Revision.) // If no RevisionId is specified in the Request, consider the latest revision (First()). string revisionId = ir.RevisionId ?? GetRevisions(new RevisionRequest(), false).First().Id; if (enableMessages) { BH.Engine.Reflection.Compute.RecordNote($"Getting all of the {nameof(Issue)}s attached to RevisionId {revisionId} \nfrom the 3DRepo Model `{modelId}` in the Teamspace `{teamsSpace}`."); } allIssues = GetAllIssues(teamsSpace, modelId, revisionId, userAPIkey); } if (pullConfig.DownloadResources) { // Attempt the pull of the resources. foreach (Issue issue in allIssues) { // Dictionary whose Key is filename (fullPath), Value is the base64 string representation. Dictionary <string, string> base64resources = new Dictionary <string, string>(); // Get all resources files. https://3drepo.github.io/3drepo.io/#api-Resources-getResource foreach (var resource in issue.Resources) { string endpoint = $"https://api1.www.3drepo.io/api/{teamsSpace}/{modelId}/resources/{resource._id}?key={userAPIkey}"; // GET request HttpResponseMessage respMessage; byte[] fullResponse = null; using (var httpClient = new HttpClient()) { respMessage = httpClient.GetAsync(endpoint).Result; // Process response fullResponse = respMessage.Content.ReadAsByteArrayAsync().Result; string base64 = System.Convert.ToBase64String(fullResponse); base64resources.Add(Path.Combine(pullConfig.ResourceDownloadDirectory, resource.name), base64); } } // Get resources (image) attached in the Comments, if any. (TODO) foreach (var comment in issue?.Comments) { var screenshot = comment.viewpoint?.Screenshot; if (screenshot != null) { base64resources.Add(Path.Combine(pullConfig.ResourceDownloadDirectory, comment.comment), screenshot); } // TODO: Apparently, the actual image is not pulled (`Comments` property is empty) when using the GET Issue endpoint. // There is another endpoint/way to pull the image that was posted in the Comments: // `getViewpoint` endpoint is to be used to get image from the Viewpoint. https://3drepo.github.io/3drepo.io/#api-Viewpoints-findViewpoint } // Save the pulled resource to file. If the base64 string is missing, it will simply create an empty file. base64resources.ToList().ForEach(kv => Compute.WriteToByteArray(kv.Value, kv.Key, false)); // Store the pulled images Filenames in the resources. // This allows to pass this information to the Convert method, see the Pull. if (mediaFileNames != null) { mediaFileNames[issue] = issue.Comments.Select(c => c.comment).ToList(); } } } foreach (Issue issue in allIssues) { List <string> fileNames = new List <string>(); if (issue.Resources != null) { fileNames = issue.Resources.Select(x => x.name).ToList(); } oM.Inspection.Issue bhomIssue = issue.FromTDRepo(fileNames); allBHoMIssues.Add(bhomIssue); } return(allBHoMIssues); }