Example #1
0
 public CsvProcessor(CsvMemento csvMemento)
 {
     if (csvMemento == null)
     {
         throw new NullReferenceException();
     }
     _arrayStr = csvMemento.Data;
 }
Example #2
0
        private CsvMemento ReadFile(string filepath)
        {
            CsvMemento memento = null;

            try
            {
                using (Stream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                {
                    IFormatter formatter = new BinaryFormatter();
                    memento = (CsvMemento)formatter.Deserialize(fs);
                }
            }

            catch (Exception ex)
            {
                return(null);
            }

            return(memento);
        }
Example #3
0
        public MappingTableDTO GetMappingTableDTO(int requestId, string path, string extension)
        {
            var request = RequestService.GetByID(requestId);

            if (request == null)
            {
                return(null);
            }

            CsvMemento memento = ReadFile(path + request.RealFileName + extension);

            if (memento == null)
            {
                return(null);
            }

            var processor = new CsvProcessor(memento);

            var mappingTableDTO = new MappingTableDTO()
            {
                DisplayFileName = request.UploadedFileName,
                Headers         = processor.Headers.ToList(),
                RequestId       = request.Id,
                HeadersErrors   = processor.GetHeaderErrors()
            };

            for (int i = 0; i < processor.ColumnLenght; i++)
            {
                mappingTableDTO.TableItemsDTO.Add(new MappingTableItemDTO()
                {
                    Name          = processor.Headers[i],
                    ValueExamples = processor.GetValueExamples(i)
                });
            }

            return(mappingTableDTO);
        }
Example #4
0
        public int SaveFile(Stream stream, string path, string extension, string uploadedFileName, int temporaryFileStorageTime)
        {
            CsvMemento memento = null;
            Guid       newFileName;

            try
            {
                memento = new CsvMemento(stream);
                if (memento == null)
                {
                    throw new NullReferenceException();
                }
                newFileName = Guid.NewGuid();
                using (Stream fs = new FileStream(path + newFileName + extension, FileMode.Create, FileAccess.Write))
                {
                    IFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(fs, memento);
                }
            }

            catch (Exception ex)
            {
                return(0);
            }

            int id = RequestService.Create(new Request()
            {
                DateCreated      = DateTime.Now,
                RealFileName     = newFileName,
                UploadedFileName = uploadedFileName
            }, path, extension);

            HangFireService.CreateDeletionJobForFile(id, path, extension, temporaryFileStorageTime);

            return(id);
        }