1+ using System . IO ;
2+ using Simplify . Web . Modules ;
3+ using Simplify . Web . Postman . Json ;
4+ using Simplify . Web . Postman . Models ;
5+ using Simplify . Web . Postman . Settings ;
6+
7+ namespace Simplify . Web . Postman
8+ {
9+ /// <summary>
10+ /// Provides postman collection to file exporter
11+ /// </summary>
12+ /// <seealso cref="ICollectionExporter" />
13+ public class FileCollectionExporter : ICollectionExporter
14+ {
15+ private readonly CollectionModelSerializer _serializer ;
16+ private readonly IEnvironment _environment ;
17+ private readonly IPostmanGenerationSettings _settings ;
18+
19+ /// <summary>
20+ /// Initializes a new instance of the <see cref="FileCollectionExporter"/> class.
21+ /// </summary>
22+ /// <param name="serializer">The serializer.</param>
23+ /// <param name="environment">The environment.</param>
24+ /// <param name="settings">The settings.</param>
25+ public FileCollectionExporter ( CollectionModelSerializer serializer , IEnvironment environment , IPostmanGenerationSettings settings )
26+ {
27+ _serializer = serializer ;
28+ _environment = environment ;
29+ _settings = settings ;
30+ }
31+
32+ /// <summary>
33+ /// Exports the specified model.
34+ /// </summary>
35+ /// <param name="model">The model.</param>
36+ public void Export ( CollectionModel model )
37+ {
38+ var folderPath = GenerateExportFolderPath ( ) ;
39+
40+ if ( ! Directory . Exists ( folderPath ) )
41+ Directory . CreateDirectory ( folderPath ) ;
42+
43+ File . WriteAllText ( GenerateCollectionFilePath ( folderPath ) , _serializer . Serialize ( model ) ) ;
44+ }
45+
46+ private string GenerateExportFolderPath ( )
47+ {
48+ return Path . Combine ( _environment . SitePhysicalPath , _settings . GenerationFolderPath ) ;
49+ }
50+
51+ private string GenerateCollectionFilePath ( string folderPath )
52+ {
53+ return Path . Combine ( folderPath , _settings . CollectionFileName + _settings . CollectionFileNamePostfix + ".json" ) ;
54+ }
55+ }
56+ }
0 commit comments