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)); }
private Task RequestFileHandler(FileContentRequest request) { var command = new SendRequestedFileCommand(request.Id, request.FileId, request.TargetMethod); return(_bus.Send(command)); }
/***************************************************/ /**** Methods *****/ /***************************************************/ public override bool SetupPullRequest(object request, out IRequest pullRequest) { pullRequest = request as IRequest; // If there is no input request, but a target filepath was specified through the Adapter constructor, use that. if (!string.IsNullOrWhiteSpace(m_defaultFilePath) && (request == null || request is Type)) { if (request is Type) { pullRequest = new FileContentRequest() { File = m_defaultFilePath, Types = new List <Type>() { request as Type } }; BH.Engine.Base.Compute.RecordNote($"Type interpreted as new {nameof(FileContentRequest)} targeting the Adapter targetLocation: `{m_defaultFilePath}` and filtering per type `{(request as Type).Name}`."); } else if (request is IEnumerable <Type> ) { pullRequest = new FileContentRequest() { File = m_defaultFilePath, Types = (request as IEnumerable <Type>).ToList() }; BH.Engine.Base.Compute.RecordNote($"Type interpreted as new {nameof(FileContentRequest)} targeting the Adapter targetLocation: `{m_defaultFilePath}` and filtering per types: {String.Join(", ",(request as IEnumerable<Type>).Select(t => t.Name))}."); } else { pullRequest = new FileContentRequest() { File = m_defaultFilePath }; BH.Engine.Base.Compute.RecordNote($"Pulling file contents from the Adapter targetLocation: `{m_defaultFilePath}`."); } return(true); } if (request == null && string.IsNullOrWhiteSpace(m_defaultFilePath)) { BH.Engine.Base.Compute.RecordError($"Please specify a valid Request, or create the {nameof(FileAdapter)} with the constructor that takes inputs to specify a target Location."); return(false); } if ((request as IRequest) != null && !string.IsNullOrWhiteSpace(m_defaultFilePath)) { BH.Engine.Base.Compute.RecordWarning($"Both request and targetLocation have been specified. Requests take precedence. Pulling as specified by the input `{request.GetType().Name}`."); return(true); } return(base.SetupPullRequest(request, out pullRequest)); }
public async Task <FileContentResponse> Request(FileContentRequest request, string teacherConnectionId) { var source = new TaskCompletionSource <FileContentResponse>(); _pendingTasks[request.Id] = source; await _hubContext .Clients .Client(teacherConnectionId) .RequestFile(request); return(await source.Task); }
public async Task UpdateFile( string userAgent, string authorizationToken, string repositoryName, string branchName, string fileName, string content) { HttpClient httpClient = new HttpClient { BaseAddress = new Uri(ApiBaseUri) }; this.SetRequestHeaders(httpClient.DefaultRequestHeaders, userAgent, authorizationToken, null); // get file to update var requestUri = string.Format(@"repos/{0}/{1}/contents/{2}?ref={3}", userAgent, repositoryName, fileName, branchName); HttpResponseMessage response = await httpClient.GetAsync(requestUri).ConfigureAwait(false); response.EnsureSuccessStatusCode(); var fileToUpdate = await response.Content.ReadAsJsonAsync <FileContentResponse>().ConfigureAwait(false); byte[] data = Convert.FromBase64String(fileToUpdate.Content); string decodedData = Encoding.UTF8.GetString(data); // update file content decodedData += content; // update file requestUri = string.Format(@"repos/{0}/{1}/contents/{2}", userAgent, repositoryName, fileName); var newFile = new FileContentRequest { Message = "add comment", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(decodedData)), Sha = fileToUpdate.Sha, Branch = branchName, }; response = await httpClient.PutAsJsonAsync(requestUri, newFile).ConfigureAwait(false); response.EnsureSuccessStatusCode(); }
public async Task <FileContentResponse> GetFileContent(int fileId, string classroomName) { Logger.LogDebug("Solicitando archivo {File} {Classroom}", fileId, classroomName); try { if (!ClassroomRepository.TryGetClassroom(classroomName, out var classroom)) { throw new HubException("Sala no encontrada"); } var request = new FileContentRequest(fileId, nameof(FileContentRequestCallback)); var result = await _fileContentRequestClient .Request(request, classroom.TeacherConnectionId) .TimeoutAfter(TimeSpan.FromSeconds(10)); return(result); } catch (TimeoutException) { Logger.LogWarning( "La solicitud de contenido de archivo caducó {File} {Classroom}", fileId, classroomName); throw new HubException("Solicitud de contenido de archivo caducó"); } catch (Exception ex) when(ex is not HubException) { Logger.LogError(ex, "No fue posible tratar una solicitud de archivo" + " {FileId} {Classroom} ", fileId, classroomName); throw; } }