コード例 #1
0
 public void Init()
 {
 	dataset = new Dataset();
 	EditableExtensionInfo.Dataset = dataset;
     parser = new ExtensionParser();
     App.InstallingExtension = false;
 }
コード例 #2
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Gets an alphabetical list of extensions from a dataset.
        /// </summary>
        /// <param name="dataset"></param>
        /// <returns></returns>
        public static List<ExtensionInfo> GetExtsInAlphaOrder(Dataset dataset)
        {
            List<ExtensionInfo> extensions = new List<ExtensionInfo>(dataset.Count);
            for (int i = 0; i < dataset.Count; i++)
                extensions.Add(dataset[i]);
            extensions.Sort(CompareNames);
            return extensions;
        }
コード例 #3
0
        public void AddNameTwice()
        {
            Dataset dataset = new Dataset();
            Assert.AreEqual(0, dataset.Count);

            dataset.Add(fooExtension);
            Assert.AreEqual(1, dataset.Count);
            Assert.AreEqual(fooExtension, dataset[0]);
            Assert.AreEqual(fooExtension, dataset[fooExtension.Name]);

            dataset.Add(fooExtension);
        }
コード例 #4
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Loads the plug-ins dataset from a file if the file exists;
        /// otherwise creates an empty dataset and saves it to that file.
        /// </summary>
        public static Dataset LoadOrCreate(string path)
        {
        	if (path == null)
        		throw new ArgumentNullException();
        	if (path.Trim(null) == "")
        		throw new ArgumentException("Path is empty or just whitespace.");

            if (File.Exists(path))
                return new Dataset(path);
            else {
                Dataset dataset = new Dataset();
                dataset.SaveAs(path);
                return dataset;
            }
        }
コード例 #5
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Writes a javascript file with information about the extensions in
        /// a dataset.
        /// </summary>
        public static void WriteJavascriptFile(Dataset dataset)
        {
            string filename = GetJavascriptFilename();
            string path = Path.Combine(Application.Directory, filename);
            using (StreamWriter file = new StreamWriter(path)) {
                file.WriteLine("with (LANDIS)");
                file.WriteLine("{");
                List<ExtensionInfo> extensions = GetExtsInAlphaOrder(dataset);
                foreach (ExtensionInfo extension in extensions) {
                    file.WriteLine("    addPlugIn(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\")",
                                   extension.Name,
                                   extension.Version == null ? "" : extension.Version,
                                   extension.Type,
                                   extension.Description == null ? "" : extension.Description,
                                   extension.UserGuidePath == null ? "" : extension.UserGuidePath);
                }
                file.WriteLine("}");
            }
        }
コード例 #6
0
 //---------------------------------------------------------------------
 private void SavedEventHandler(Dataset dataset)
 {
     eventDataset = dataset;
 }
コード例 #7
0
        public void IDataset_Indexer()
        {
            Dataset dataset = new Dataset();
            dataset.Add(fooExtension);
            dataset.Add(barExtension);

            Landis.PlugIns.IDataset coreDataset = dataset;
            AssertAreEqual(fooExtension.CoreInfo, coreDataset[fooExtension.Name]);
            AssertAreEqual(barExtension.CoreInfo, coreDataset[barExtension.Name]);
        }
コード例 #8
0
        public void Remove()
        {
            Dataset dataset = new Dataset();
            dataset.Add(fooExtension);
            dataset.Add(barExtension);

            ExtensionInfo removedExtension = dataset.Remove(fooExtension.Name);
            AssertAreEqual(fooExtension, removedExtension);
            Assert.AreEqual(1, dataset.Count);
            AssertAreEqual(barExtension, dataset[0]);

            removedExtension = dataset.Remove(barExtension.Name);
            AssertAreEqual(barExtension, removedExtension);
            Assert.AreEqual(0, dataset.Count);
        }
コード例 #9
0
 public void Remove_Null()
 {
     Dataset dataset = new Dataset();
     dataset.Remove(null);
 }
コード例 #10
0
 public void DefaultCtor()
 {
     Dataset dataset = new Dataset();
     Assert.AreEqual(0, dataset.Count);
     Assert.AreEqual(Dataset.DefaultPath, dataset.Path);
 }
コード例 #11
0
 //---------------------------------------------------------------------
 private void TryOpenDataset(string filename)
 {
     string path;
     string pathDisplay;
     if (string.IsNullOrEmpty(filename)) {
         path = filename;
         if (filename == null)
             pathDisplay = "(null)";
         else
             pathDisplay = "";
     }
     else {
         path = Data.MakeInputPath(filename);
         pathDisplay = path.Replace(Data.Directory,
                                    Data.DirPlaceholder);
     }
     try {
         Data.Output.WriteLine();
         Data.Output.WriteLine("Reading the plug-in database \"{0}\" ...", pathDisplay);
         Dataset dataset = new Dataset(path);
     }
     catch (System.Exception exc) {
         Data.Output.WriteLine("Error: {0}",
                               exc.Message.Replace(Data.Directory,
                                                   Data.DirPlaceholder));
         throw;
     }
 }
コード例 #12
0
        //---------------------------------------------------------------------
        private void ValidateTwoPlugIns(Dataset dataset)
        {
            Assert.IsNotNull(dataset);
            Assert.AreEqual(2, dataset.Count);
            Assert.AreEqual(twoPlugInDatasetPath, dataset.Path);

            ExtensionInfo info = dataset["Foo"];
            Assert.IsNotNull(info);
            Assert.AreEqual("Foo", info.Name);
            Assert.AreEqual("disturbance:foo", info.Type);
            Assert.AreEqual("Com.Foo.PlugIn", info.ClassName);
            Assert.AreEqual("Com.Foo", info.AssemblyName);

            info = dataset["Bar Extension"];
            Assert.IsNotNull(info);
            Assert.AreEqual("Bar Extension", info.Name);
            Assert.AreEqual("output", info.Type);
            Assert.AreEqual("Org.Bar.PlugIn", info.ClassName);
            Assert.AreEqual("Org.Bar", info.AssemblyName);
        }
コード例 #13
0
        public void LoadOrCreate_Create()
        {
            string path = Data.MakeOutputPath("LoadOrCreate_Create.xml");
            if (File.Exists(path))
                File.Delete(path);
            Assert.IsFalse(File.Exists(path));

            Dataset dataset = Dataset.LoadOrCreate(path);
            Assert.IsNotNull(dataset);
            Assert.AreEqual(0, dataset.Count);
            Assert.AreEqual(path, dataset.Path);
            Assert.IsTrue(File.Exists(path));

            //  Confirm that the new file can be loaded separately
            Dataset loadedDataset = new Dataset(path);
            Assert.IsNotNull(loadedDataset);
            Assert.AreEqual(0, loadedDataset.Count);
            Assert.AreEqual(path, loadedDataset.Path);
        }
コード例 #14
0
 //---------------------------------------------------------------------
 private void AssertAreEqual(Dataset expected,
     Dataset actual)
 {
     Assert.AreEqual(expected.Count, actual.Count);
     for (int i = 0; i < expected.Count; i++) {
         ExtensionInfo expectedInfo = expected[i];
         ExtensionInfo actualInfo = actual[expectedInfo.Name];
         AssertAreEqual(expectedInfo, actualInfo);
     }
 }
コード例 #15
0
        public void SaveAs()
        {
            Dataset dataset = new Dataset();
            dataset.Add(fooExtension);
            dataset.Add(barExtension);

            eventDataset = null;
            string path = Data.MakeOutputPath("SaveAs_Test.xml");
            dataset.SaveAs(path);
            Assert.AreEqual(path, dataset.Path);
            Assert.AreSame(dataset, eventDataset);

            Dataset loadedDataset = new Dataset(path);
            Assert.IsNotNull(loadedDataset);
            AssertAreEqual(dataset, loadedDataset);
        }
コード例 #16
0
 public void Remove_Whitespace()
 {
     Dataset dataset = new Dataset();
     dataset.Remove(" ");
 }
コード例 #17
0
        public void Remove_UnknownName()
        {
            Dataset dataset = new Dataset();
            dataset.Add(fooExtension);
            dataset.Add(barExtension);

            Assert.IsNull(dataset.Remove("Unknown Plug-In"));
        }