public void Init() { dataset = new Dataset(); EditableExtensionInfo.Dataset = dataset; parser = new ExtensionParser(); App.InstallingExtension = false; }
//--------------------------------------------------------------------- /// <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; }
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); }
//--------------------------------------------------------------------- /// <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; } }
//--------------------------------------------------------------------- /// <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("}"); } }
//--------------------------------------------------------------------- private void SavedEventHandler(Dataset dataset) { eventDataset = dataset; }
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]); }
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); }
public void Remove_Null() { Dataset dataset = new Dataset(); dataset.Remove(null); }
public void DefaultCtor() { Dataset dataset = new Dataset(); Assert.AreEqual(0, dataset.Count); Assert.AreEqual(Dataset.DefaultPath, dataset.Path); }
//--------------------------------------------------------------------- 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; } }
//--------------------------------------------------------------------- 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); }
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); }
//--------------------------------------------------------------------- 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); } }
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); }
public void Remove_Whitespace() { Dataset dataset = new Dataset(); dataset.Remove(" "); }
public void Remove_UnknownName() { Dataset dataset = new Dataset(); dataset.Add(fooExtension); dataset.Add(barExtension); Assert.IsNull(dataset.Remove("Unknown Plug-In")); }