private Domain.Configuration ProcessFile(Domain.Configuration configuration, Domain.FileSettings fileSettings) { try { var restClient = new RestClient(configuration); Domain.ConfigurationResponse configurationResponse = null; if (Utilities.FileSystem.IsDirectory(fileSettings.Name)) { var filesNames = Utilities.FileSystem.GetFilesList(fileSettings.Name); var files = filesNames.Select ( fi => new Domain.File { Content = null, Name = fi.FullName, SizeBytes = fi.Length, TimeStampUtc = fi.LastWriteTimeUtc, } ); configurationResponse = restClient.SelectFile(new Domain.SelectFileRequest(configuration, fileSettings, files)); } else { Utilities.Logger.Log(NLog.LogLevel.Trace, Resources.Messages.StartProcessFile, fileSettings.Name, System.Threading.Thread.CurrentThread.ManagedThreadId); System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew(); Processor._filesProcessed++; Domain.File file = Domain.File.Load(configuration, fileSettings); Domain.PostFileRequest postFileRequest = new Domain.PostFileRequest(configuration, file); configurationResponse = restClient.UploadFile(postFileRequest); Processor._filesUploaded++; Utilities.Logger.Log(NLog.LogLevel.Info, Resources.Messages.FileUploaded, fileSettings.Name, Utilities.Logger.GetTimeElapsed(stopWatch)); } configuration.UpdateLocalConfiguration(configurationResponse); return(configuration); } catch (Exception ex) { Utilities.Logger.Log(ex); return(null); } }
internal Domain.ConfigurationResponse UploadFile(Domain.PostFileRequest fileRequest) { string response = string.Empty; try { string content = fileRequest.Serialize(); System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew(); Utilities.Logger.Log(NLog.LogLevel.Trace, Resources.Messages.StartUploadFile, this.Configuration.UrlPostFile, content); response = this.PostRequest(this.Configuration.UrlPostFile, content); Utilities.Logger.Log(NLog.LogLevel.Trace, Resources.Messages.EndOfExecution, "RestClient.UploadFile", Logger.GetTimeElapsed(stopWatch)); Utilities.Logger.Log(NLog.LogLevel.Trace, "RestClient.UploadFile Response: " + response); } catch (Exception ex) { Utilities.Logger.Log(NLog.LogLevel.Error, Resources.Messages.FailurePostingFile, fileRequest.Name); throw ex; } return(this.ParseResponse <Domain.ConfigurationResponse>(response)); }