protected XDocument LoadFile(PackagesConfigOptions options) { if (!System.IO.File.Exists(file)) { if (!options.HasFlag(PackagesConfigOptions.LoadOrNew)) { throw new FileNotFoundException(nameof(file)); } return(NewStorage()); } if (!options.HasFlag(PackagesConfigOptions.SilentLoading)) { return(XDocument.Load(file)); } try { return(XDocument.Load(file)); } catch (Exception ex) { FailedLoading = ex; return(NewStorage()); } }
/// <param name="path">The path to the directory where the config is located (or must be located if new).</param> /// <param name="options">Configure initialization using <see cref="PackagesConfigOptions"/>.</param> public PackagesConfig(string path, PackagesConfigOptions options = PackagesConfigOptions.Default) { if (path == null) { throw new ArgumentNullException(nameof(path)); } file = options.HasFlag(PackagesConfigOptions.PathToStorage) ? path : Path.Combine(path, FNAME); if ((options & (PackagesConfigOptions.Load | PackagesConfigOptions.LoadOrNew)) == 0) { throw new NotSupportedException(); } xml = Load(options); }
public void CtorTest1(PackagesConfigOptions silentLoading) { Assert.Throws <ArgumentNullException>(() => new PackagesConfig(null, PackagesConfigOptions.Default | silentLoading)); Assert.Throws <NotSupportedException>(() => new PackagesConfig(TestData.ROOT + @"PackagesConfig\packages.1.txt", PackagesConfigOptions.None | silentLoading) ); Assert.Throws <FileNotFoundException>(() => { string dst = TestData.ROOT + @"PackagesConfig\NotRealFolder"; Assert.False(Directory.Exists(dst)); new PackagesConfig(dst, PackagesConfigOptions.Load | silentLoading); }); Assert.Throws <FileNotFoundException>(() => { string dst = TestData.ROOT + @"PackagesConfig\folder"; Assert.True(Directory.Exists(dst)); new PackagesConfig(dst, PackagesConfigOptions.Load | PackagesConfigOptions.PathToStorage | silentLoading); }); }
protected XDocument Load(PackagesConfigOptions options) { xml = LoadFile(options); root = xml.Element(ROOT); return(xml); }
public TempPackagesConfig(string path, PackagesConfigOptions options) : base(path, options) { }