示例#1
0
 /// <summary>
 /// Saves the object's data to the specified file location.
 /// </summary>
 /// <param name="filePath">The file path to save the object's data to.</param>
 /// <param name="fileFormat">Car file format to save</param>
 /// <param name="carCollection">Saves CurrentCarCollection by default</param>
 /// <param name="overWrite">if set to <c>true</c> over write the file contents, otherwise append will occur.</param>
 public void Save(string filePath, CarFileFormat fileFormat, bool overWrite = false, CarCollection carCollection = null)
 {
     using (var fileStream = File.Open(filePath, overWrite ? FileMode.Create : FileMode.CreateNew))
     {
         Save(fileStream, fileFormat, carCollection);
     }
 }
示例#2
0
 /// <summary>
 /// Converts the object's data from the sourceFilePath to the destFilePath file location.
 /// </summary>
 /// <param name="sourceFilePath">The file path to load the object's data from.</param>
 /// <param name="destFilePath">The file path to save the object's data to.</param>
 /// <param name="destFileFormat">Car file format to convert to</param>
 /// <param name="overWrite">if set to <c>true</c> over write the file contents, otherwise append will occur.</param>
 public void Convert(string sourceFilePath, string destFilePath, CarFileFormat destFileFormat, bool overWrite = false)
 {
     Load(sourceFilePath);
     using (var fileStream = File.Open(destFilePath, overWrite ? FileMode.Create : FileMode.CreateNew))
     {
         Save(fileStream, destFileFormat);
     }
 }
示例#3
0
        /// <summary>Saves the object's data to the specified stream.</summary>
        /// <param name="stream">The stream to save the object's data to.</param>
        /// <param name="fileFormat">Car file format to save</param>
        /// <param name="carCollection">Saves CurrentCarCollection by default</param>
        public void Save(Stream stream, CarFileFormat fileFormat, CarCollection carCollection = null)
        {
            carCollection = carCollection ?? CurrentCarCollection;
            if (!FileFormats.ContainsKey(fileFormat))
            {
                throw new CarCollectionFormatException("Cannot save because the file format is not supported");
            }

            var serializer = FileFormats[fileFormat].Value;

            serializer.Write(stream, carCollection);
        }
示例#4
0
 public static void BeforeTests()
 {
     _jsonFileFormat = CarCollectionSupporter.AddFileFormat <CarCollectionJsonSerializer>();
 }