//---------------------------------------------------------------------

        private void AssertAreEqual(PersistentDriverDataset.FormatAccess expected,
                                    PersistentDriverDataset.FormatAccess actual)
        {
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Format, actual.Format);
            Assert.AreEqual(expected.Access, actual.Access);
        }
        //---------------------------------------------------------------------

        private void AssertAreEqual(PersistentDriverDataset expected,
                                    PersistentDriverDataset actual)
        {
            Assert.IsNotNull(actual);
            AssertAreEqual(expected.Drivers, actual.Drivers);
            AssertAreEqual(expected.Formats, actual.Formats);
        }
        public void OneDriver()
        {
            PersistentDriverDataset dataset = new PersistentDriverDataset();

            string fooExt = ".foo";

            PersistentDriverDataset.DriverInfo fooDriver;
            fooDriver = new PersistentDriverDataset.DriverInfo(
                                            "Foo Driver",
                                            "Com.Acme.Foo.Driver,Com.Acme.Foo"
            );
            fooDriver.AddFormat(fooExt, FileAccess.ReadWrite);
            dataset.Drivers.Add(fooDriver);

            PersistentDriverDataset.FormatDrivers fooFormat;
            fooFormat = new PersistentDriverDataset.FormatDrivers(fooExt);
            fooFormat.Drivers.Add(fooDriver.Name);
            dataset.Formats.Add(fooFormat);

            string path = Data.MakeOutputPath("OneDriver.xml");
            dataset.Save(path);

            PersistentDriverDataset dataset2;
            dataset2 = PersistentDriverDataset.Load(path);

            AssertAreEqual(dataset, dataset2);
        }
        //---------------------------------------------------------------------

        private void AssertAreEqual(PersistentDriverDataset.DriverInfo expected,
                                    PersistentDriverDataset.DriverInfo actual)
        {
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.ImplementationName, actual.ImplementationName);
            AssertAreEqual(expected.Formats, actual.Formats);
        }
Exemple #5
0
        //---------------------------------------------------------------------

        public DriverDataset(string path)
        {
            this.path = path;
            PersistentDriverDataset dataset = PersistentDriverDataset.Load(path);

            drivers = new List <DriverInfo>();
            foreach (PersistentDriverDataset.DriverInfo info in dataset.Drivers)
            {
                //  Create a dictionary from list of formats
                Dictionary <string, FileAccess> formats;
                formats = new Dictionary <string, FileAccess>();
                foreach (PersistentDriverDataset.FormatAccess formatAccess in info.Formats)
                {
                    formats[formatAccess.Format] = formatAccess.Access;
                }

                drivers.Add(new DriverInfo(info.Name,
                                           info.ImplementationName,
                                           formats));
            }

            this.formats = new Dictionary <string, List <DriverInfo> >();
            foreach (PersistentDriverDataset.FormatDrivers formatDrivers in dataset.Formats)
            {
                List <DriverInfo> driverList = new List <DriverInfo>();
                foreach (string driverName in formatDrivers.Drivers)
                {
                    DriverInfo driverInfo = null;
                    foreach (DriverInfo info in this.drivers)
                    {
                        if (info.Name == driverName)
                        {
                            driverInfo = info;
                            break;
                        }
                    }
                    if (driverInfo == null)
                    {
                        throw new System.ApplicationException(string.Format("Unknown raster driver: \"{0}\"", driverName));
                    }
                    driverList.Add(driverInfo);
                }
                formats[formatDrivers.Format] = driverList;
            }
        }
        //---------------------------------------------------------------------

        private void AssertAreEqual(PersistentDriverDataset.FormatDrivers expected,
                                    PersistentDriverDataset.FormatDrivers actual)
        {
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Format, actual.Format);
            Assert.AreEqual(expected.Drivers.Count, actual.Drivers.Count);
            for (int i = 0; i < expected.Drivers.Count; i++)
                Assert.AreEqual(expected.Drivers[i], actual.Drivers[i]);
        }