Beispiel #1
0
        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());
            }
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        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);
            });
        }
Beispiel #4
0
 protected XDocument Load(PackagesConfigOptions options)
 {
     xml  = LoadFile(options);
     root = xml.Element(ROOT);
     return(xml);
 }
Beispiel #5
0
 public TempPackagesConfig(string path, PackagesConfigOptions options)
     : base(path, options)
 {
 }