private FileObjectCollection SerializeCsv <T>(FileObject fileObject) where T : IRecord { Log.Debug("enter"); FileObjectCollection collection = new FileObjectCollection() { fileObject }; int counter = 0; string sourceFile = fileObject.FileUri.ToLower().TrimEnd(CsvExtension.ToCharArray()); fileObject.FileUri = $"{sourceFile}{CsvExtension}"; List <byte> csvSerializedBytes = new List <byte>(); string relativeUri = fileObject.RelativeUri.TrimEnd(CsvExtension.ToCharArray()) + CsvExtension; foreach (T record in fileObject.Stream.Read <T>()) { record.RelativeUri = relativeUri; byte[] recordBytes = Encoding.UTF8.GetBytes(record.ToString()); if (csvSerializedBytes.Count + recordBytes.Length > MaxCsvTransmitBytes) { record.RelativeUri = relativeUri.TrimEnd(CsvExtension.ToCharArray()) + $".{counter}{CsvExtension}"; recordBytes = Encoding.UTF8.GetBytes(record.ToString()); fileObject.Stream.Set(csvSerializedBytes.ToArray()); csvSerializedBytes.Clear(); fileObject = new FileObject(record.RelativeUri, fileObject.BaseUri); Log.Debug($"csv serialized size: {csvSerializedBytes.Count} file: {fileObject.FileUri}"); collection.Add(fileObject); } csvSerializedBytes.AddRange(recordBytes); counter++; } fileObject.Stream.Set(csvSerializedBytes.ToArray()); Log.Debug($"csv serialized size: {csvSerializedBytes.Count} file: {fileObject.FileUri}"); return(collection); }
private bool Compare(string self, string comparable) { if (string.IsNullOrEmpty(self) | string.IsNullOrEmpty(comparable)) { return(false); } self = self.ToLower().TrimEnd(ZipExtension.ToCharArray()).TrimEnd(CsvExtension.ToCharArray()); comparable = comparable.ToLower().TrimEnd(ZipExtension.ToCharArray()).TrimEnd(CsvExtension.ToCharArray()); if (self.EndsWith(comparable) | comparable.EndsWith(self)) { Log.Debug("full match", comparable); return(true); } if (self.EndsWith(Path.GetFileName(comparable)) | comparable.EndsWith(Path.GetFileName(self))) { Log.Debug("partial (file name) match", comparable); return(true); } return(false); }