Exemple #1
0
        private Tuple <bool, string> UploadLocal(string fileName, System.IO.Stream fileStream, Agent agent)
        {
            try
            {
                string uploadPath = PathUtility.EnsureTrailingSlash(ConfigurationManager.AppSettings["ShareName"]);
                uploadPath += PathUtility.EnsureTrailingSlash(agent.Queue.ToString());
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                string fullFilePath = Path.Combine(uploadPath, fileName);

                using (var file = System.IO.File.Create(fullFilePath))
                {
                    fileStream.Seek(0, SeekOrigin.Begin);
                    fileStream.CopyTo(file);
                }

                var recordCount = TotalLines(fileStream);

                LogFile(agent.Id, fileName, UrlUtility.ConvertLocalPathToUri(fullFilePath), FileStatusEnum.UPLOADED, recordCount);
                var logMessage = $"File '{fileName}' was uploaded to '{uploadPath}' for Agent '{agent.Name}' (Id: {agent.Id}).";
                if (LogService != null)
                {
                    LogService.Info(logMessage);
                }

                return(new Tuple <bool, string>(true, logMessage));
            }
            catch (Exception ex)
            {
                var logMessage = $"Error Uploading File '{fileName}' to '{agent.Directory}' for Agent '{agent.Name}'.";
                LogService.Error(logMessage, ex);
                return(new Tuple <bool, string>(false, logMessage));
            }
        }