Beispiel #1
0
        private IPackageConfiguration ExtractAndReadConfiguration(FileStorage.IFileStore fileStore,
                                                                  Configuration.IConfigurationSerializer <StringBuilder> serializer,
                                                                  string filename)
        {
            if (!fileStore.Contains(filename))
            {
                return(null);
            }
            var extractedFilename = fileStore.Get(filename).Extract(System.IO.Path.GetTempPath(), true);

            if (!System.IO.File.Exists(extractedFilename))
            {
                return(null);
            }
            try
            {
                var config = serializer.Deserialize(new StringBuilder(System.IO.File.ReadAllText(extractedFilename)));
                return((IPackageConfiguration)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(typeof(PackageConfiguration), config));
            }
            catch
            {
                // swallow any exception; return null
                return(null);
            }
            finally
            {
                FileStorage.FileStorageHelper.DeleteFile(extractedFilename);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Instantiates a new <see cref="PackageProvider"/> .
 /// </summary>
 /// <param name="packagesFileStore">The file store containing the package files.</param>
 /// <param name="configurationFilename">The filename of the configuration file in the packages.</param>
 /// <param name="configurationSerializer">The configuration serializer to use to serialize and deserialize configuration files.</param>
 /// <param name="packageFileStoreProvider">A file store provider which facilitates creating and connecting to packages.</param>
 public PackageProvider(FileStorage.IFileStore packagesFileStore,
                        string configurationFilename,
                        Configuration.IConfigurationSerializer <StringBuilder> configurationSerializer,
                        IPackageFileStoreProvider packageFileStoreProvider)
     : this()
 {
     _AllPackagesFileStore = packagesFileStore ?? throw new ArgumentNullException(nameof(packagesFileStore));
     if (string.IsNullOrWhiteSpace(configurationFilename))
     {
         throw new ArgumentNullException(nameof(configurationFilename));
     }
     _ConfigurationFilename   = configurationFilename;
     _ConfigurationSerializer = configurationSerializer ?? throw new ArgumentNullException(nameof(configurationSerializer));
     PackageFileStoreProvider = packageFileStoreProvider ?? throw new ArgumentNullException(nameof(packageFileStoreProvider));
 }