//--------------------------------------------------------------------- /// <summary> /// Executes the command. /// </summary> public void Execute() { #if ENABLE_OLD_CODE // TODO: This code is from the old AddCommand, so it needs to be // updated eventually. Dataset dataset = Dataset.LoadOrCreate(Dataset.DefaultPath); EditableExtensionInfo.Dataset = dataset; ExtensionParser parser = new ExtensionParser(); ExtensionInfo extension = Data.Load <ExtensionInfo>(extensionInfoPath, parser); List <string> missingLibs = new List <string>(); foreach (string library in extension.ReferencedAssemblies) { if (!dataset.ReferencedByEntries(library)) { missingLibs.Add(library); } } List <string> libsToBeInstalled = new List <string>(); foreach (string libPath in extension.LibraryPaths) { libsToBeInstalled.Add(Path.GetFileNameWithoutExtension(libPath)); } foreach (string libToBeInstalled in libsToBeInstalled) { missingLibs.Remove(libToBeInstalled); } if (missingLibs.Count > 0) { MultiLineText message = new MultiLineText(); message.Add("Error: The extension requires the following libraries which are not"); message.Add(" currently installed and are not listed in the extension info file:"); foreach (string lib in missingLibs) { message.Add(" " + lib); } throw new MultiLineException(message); } Console.WriteLine("Installation directory: {0}", installDir); Console.WriteLine("Copying files to installation directory ..."); CopyFileToInstallDir(extension.AssemblyPath); foreach (string libPath in extension.LibraryPaths) { CopyFileToInstallDir(libPath); } dataset.Add(extension); dataset.Save(); Console.WriteLine("Extension {0} installed", extension.Name); #endif }
//--------------------------------------------------------------------- /// <summary> /// Executes the command. /// </summary> public void Execute() { #if ENABLE_OLD_CODE // TODO: This code is from the old AddCommand, so it needs to be // updated eventually. Dataset dataset = Dataset.LoadOrCreate(Dataset.DefaultPath); EditableExtensionInfo.Dataset = dataset; ExtensionParser parser = new ExtensionParser(); ExtensionInfo extension = Data.Load<ExtensionInfo>(extensionInfoPath, parser); List<string> missingLibs = new List<string>(); foreach (string library in extension.ReferencedAssemblies) { if (! dataset.ReferencedByEntries(library)) missingLibs.Add(library); } List<string> libsToBeInstalled = new List<string>(); foreach (string libPath in extension.LibraryPaths) { libsToBeInstalled.Add(Path.GetFileNameWithoutExtension(libPath)); } foreach (string libToBeInstalled in libsToBeInstalled) { missingLibs.Remove(libToBeInstalled); } if (missingLibs.Count > 0) { MultiLineText message = new MultiLineText(); message.Add("Error: The extension requires the following libraries which are not"); message.Add(" currently installed and are not listed in the extension info file:"); foreach (string lib in missingLibs) message.Add(" " + lib); throw new MultiLineException(message); } Console.WriteLine("Installation directory: {0}", installDir); Console.WriteLine("Copying files to installation directory ..."); CopyFileToInstallDir(extension.AssemblyPath); foreach (string libPath in extension.LibraryPaths) { CopyFileToInstallDir(libPath); } dataset.Add(extension); dataset.Save(); Console.WriteLine("Extension {0} installed", extension.Name); #endif }
public void AddMethod() { MultiLineText text = new MultiLineText(); string[] lines = Gettysburg; foreach (string line in lines) text.Add(line); AssertLinesEqual(lines, text); }
//--------------------------------------------------------------------- /// <summary> /// Read a value from a TextReader. /// </summary> /// <remarks> /// If the wrapped parse method throws an exception, this method /// catches the exception, modifies its Data property, and then /// rethrows it. A new key/value pair is set in the Data property: /// the key is "ParseMethod.Word", and the value is the word that /// was passed as a parameter to the parse method. /// </remarks> public InputValue <T> Read(StringReader reader, out int index) { // Read word from reader. A word is a sequence of 1 or more // non-whitespace characters. TextReader.SkipWhitespace(reader); if (reader.Peek() == -1) { throw new InputValueException(); } index = reader.Index; string word = TextReader.ReadWord(reader); try { return(new InputValue <T>(parseMethod(word), word)); } catch (System.OverflowException) { string format = Type.GetNumericFormat <T>(); if (format.Length > 0) { format = string.Format("{{0:{0}}}", format); } else { format = "{0}"; } string min = string.Format(format, Type.GetMinValue <T>()); string max = string.Format(format, Type.GetMaxValue <T>()); string numericDesc = Type.GetNumericDescription <T>(); numericDesc = String.PrependArticle(numericDesc); string message = string.Format("{0} is outside the range for {1}", word, numericDesc); MultiLineText range = new MultiLineText(); range.Add(string.Format("Range is {0} to {1}", min, max)); throw new InputValueException(word, message, range); } catch (System.Exception exc) { string message = string.Format("\"{0}\" is not a valid {1}", word, Type.GetDescription <T>()); System.FormatException formatExc = exc as System.FormatException; // Add the format message if it's not a system type (assume // derived type is providing more detailed explanation). if (formatExc != null && !typeof(T).Namespace.StartsWith("System")) { throw new InputValueException(word, message, new MultiLineText(formatExc.Message)); } else { throw new InputValueException(word, message); } } }
public void AddMethod() { MultiLineText text = new MultiLineText(); string[] lines = Gettysburg; foreach (string line in lines) { text.Add(line); } AssertLinesEqual(lines, text); }
/// <summary> /// Checks a template for output filenames to ensure that all the /// variables used in the template are known. /// </summary> /// <param name="template"> /// The template for a set of output filenames. /// </param> /// <param name="variables"> /// A dictionary collection of known variables where a key is the /// variable's name and its value indicates whether the variable /// is required or not. /// </param> /// <remarks> /// A variable is used by enclosing its name in curly braces, e.g., /// "{variable-name}". /// </remarks> /// <exception cref="InputValueException"> /// The template is missing a required variable or has unknown /// variable. /// </exception> public static void CheckTemplateVars(string template, IDictionary<string, bool> variables) { IList<string> namesUsed = Macros.GetNames(template); IList<string> unknownVars = new List<string>(); foreach (string name in namesUsed) { if (! variables.ContainsKey(name)) unknownVars.Add(name); } if (unknownVars.Count == 1) { string mesg = string.Format("The template uses an unknown variable: {{{0}}}", unknownVars[0]); throw new InputValueException(template, mesg); } if (unknownVars.Count > 1) { MultiLineText innerMesg = new MultiLineText(); foreach (string name in unknownVars) innerMesg.Add(string.Format("{{{0}}}", name)); throw new InputValueException(template, "The template uses these unknown variables", innerMesg); } // No unknown variables; check if all required variables were used IList<string> missingReqdVars = new List<string>(); foreach (string name in variables.Keys) { if (variables[name]) { // Required if (! namesUsed.Contains(name)) missingReqdVars.Add(name); } } if (missingReqdVars.Count == 1) { MultiLineText mesg = new MultiLineText(); mesg.Add(string.Format("The template must include the variable {{{0}}} to ensure", missingReqdVars[0])); mesg.Add("that the names of all output files are unique."); throw new InputValueException(template, mesg); } if (missingReqdVars.Count > 1) { MultiLineText mesg = new MultiLineText(); mesg.Add("The template must use the following variables to ensure"); mesg.Add("that the names of all output files are unique:"); MultiLineText innerMesg = new MultiLineText(); foreach (string name in missingReqdVars) innerMesg.Add(string.Format("{{{0}}}", name)); throw new InputValueException(template, mesg, innerMesg); } }