public XmlFormatSerializationData(IFormatProcessor formatProcessor)
 {
     Debug.Assert(formatProcessor != null, $"Can't init {nameof(XmlFormatSerializationData)} with null");
     XmlFormatSerializationDataItems = new List <XmlFormatSerializationDataItem>();
     foreach (var dataItem in formatProcessor.Data)
     {
         XmlFormatSerializationDataItems.Add(new XmlFormatSerializationDataItem(dataItem));
     }
 }
 public BinaryFormatSerializationData(IFormatProcessor formatProcessor)
 {
     Debug.Assert(formatProcessor != null, $"Can't init {nameof(BinaryFormatSerializationData)} with null");
     RecordsCount = formatProcessor.DataItemsCount;
     DataItems    = new List <BinaryFormatSerializationDataItem>();
     foreach (var dataitem in formatProcessor.Data)
     {
         DataItems.Add(new BinaryFormatSerializationDataItem(dataitem));
     }
 }
예제 #3
0
        /// <summary>
        /// Tries to convert data from provided format processor
        /// </summary>
        /// <param name="inputFormatProcessor"></param>
        /// <param name="outputFilePath"></param>
        /// <param name="outputFormat"></param>
        /// <returns>If conversion was successful</returns>
        public bool ConvertProcessor(IFormatProcessor inputFormatProcessor, string outputFilePath, ConvertedFormat outputFormat)
        {
            if (inputFormatProcessor == null)
            {
                throw new ArgumentNullException("Can't convert data from null-valued input format processor");
            }
            if (string.IsNullOrEmpty(outputFilePath))
            {
                throw new ArgumentException("Can't save data at null or empty file path");
            }
            bool result = false;

            using (var outputProcessor = CreateFormatProcessor(outputFormat))
            {
                outputProcessor.SetData(inputFormatProcessor.Data.AsEnumerable(), true);
                result = outputProcessor.SaveToFile(outputFilePath);
            }
            return(result);
        }