public void StrArrayCtor_Implicit()
        {
            string[]      lines = Gettysburg;
            MultiLineText text  = lines;

            AssertLinesEqual(lines, text);
        }
        public void DefaultCtor()
        {
            MultiLineText text = new MultiLineText();

            Assert.AreEqual(0, text.Count);
            Assert.AreEqual("", text.ToString());
        }
 //---------------------------------------------------------------------
 public InputValueException(string        inputValue,
     MultiLineText  message,
     MultiLineText innerMessage)
     : base(message, innerMessage)
 {
     this.val = inputValue;
 }
        public void StrArrayCtor()
        {
            string[]      lines = Gettysburg;
            MultiLineText text  = new MultiLineText(lines);

            AssertLinesEqual(lines, text);
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="plugIn">
 /// Information about the plug-in that the exception relates to.
 /// </param>
 /// <param name="message">
 /// A single-line message describing the exception.
 /// </param>
 /// <param name="innerMessage">
 /// Additional details about the exception.
 /// </param>
 public Exception(IInfo         plugIn,
     string        message,
     MultiLineText innerMessage)
     : base(message, innerMessage)
 {
     this.plugIn = plugIn;
 }
Example #6
0
        //---------------------------------------------------------------------

        public InputValueException(string inputValue,
                                   MultiLineText message,
                                   MultiLineText innerMessage)
            : base(message, innerMessage)
        {
            this.val = inputValue;
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="plugIn">
        /// Information about the plug-in that the exception relates to.
        /// </param>
        /// <param name="message">
        /// A single-line message describing the exception.
        /// </param>
        /// <param name="innerMessage">
        /// Additional details about the exception.
        /// </param>
        public Exception(IInfo plugIn,
                         string message,
                         MultiLineText innerMessage)
            : base(message, innerMessage)
        {
            this.plugIn = plugIn;
        }
        public void OperatorPlus_StrArray()
        {
            MultiLineText text = new MultiLineText();

            string[] lines = Gettysburg;
            text += lines;

            AssertLinesEqual(lines, text);
        }
        public void StringCtor_Implicit()
        {
            string        line = Gettysburg[0];
            MultiLineText text = line;

            Assert.AreEqual(1, text.Count);
            Assert.AreEqual(line, text.ToString());
            Assert.AreEqual(line, text[0]);
        }
        public void AddMethod()
        {
            MultiLineText text = new MultiLineText();
            string[] lines = Gettysburg;
            foreach (string line in lines)
                text.Add(line);

            AssertLinesEqual(lines, text);
        }
        public void CopyCtor()
        {
            string[] lines = Gettysburg;
            MultiLineText text1 = new MultiLineText(lines);
            MultiLineText text2 = new MultiLineText(text1);
            text1 = null;

            AssertLinesEqual(lines, text2);
        }
        public void CopyCtor()
        {
            string[]      lines = Gettysburg;
            MultiLineText text1 = new MultiLineText(lines);
            MultiLineText text2 = new MultiLineText(text1);

            text1 = null;

            AssertLinesEqual(lines, text2);
        }
        //---------------------------------------------------------------------

        private void AssertLinesEqual(string[]      lines,
                                      MultiLineText text)
        {
            Assert.AreEqual(lines.Length, text.Count);
            for (int i = 0; i < lines.Length; ++i)
            {
                Assert.AreEqual(lines[i], text[i]);
            }
            Assert.AreEqual(JoinLines(lines), text.ToString());
        }
Example #14
0
        //---------------------------------------------------------------------

        /// <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);
                }
            }
        }
Example #15
0
        //---------------------------------------------------------------------

        /// <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 OperatorPlus_Str()
        {
            MultiLineText text = new MultiLineText();

            string[] lines = Gettysburg;
            foreach (string line in lines)
            {
                text += line;
            }

            AssertLinesEqual(lines, text);
        }
        public void AddMethod()
        {
            MultiLineText text = new MultiLineText();

            string[] lines = Gettysburg;
            foreach (string line in lines)
            {
                text.Add(line);
            }

            AssertLinesEqual(lines, text);
        }
        public void IEnumeratorCtor()
        {
            List <string> lines = new List <string>();

            foreach (string line in Gettysburg)
            {
                lines.Add(line);
            }

            MultiLineText text = new MultiLineText(lines);

            AssertLinesEqual(lines.ToArray(), text);
        }
 public void EnumeratorMethod()
 {
     string[] lines = Gettysburg;
     MultiLineText text = new MultiLineText(lines);
     Assert.AreEqual(lines.Length, text.Count);
     int i = 0;
     foreach (string line in text) {
         Assert.IsTrue(i < lines.Length);
         Assert.AreEqual(lines[i], line);
         i++;
     }
     Assert.AreEqual(lines.Length, i);
 }
        public void ListStrCtor_Implicit()
        {
            List <string> lines = new List <string>();

            foreach (string line in Gettysburg)
            {
                lines.Add(line);
            }

            MultiLineText text = lines;

            AssertLinesEqual(lines.ToArray(), 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);
            }
        }
 //---------------------------------------------------------------------
 public MultiLineException(MultiLineText    message,
     System.Exception innerException)
     : base(ConvertToString(message), innerException)
 {
     if (innerException == null)
         SetMultiLineMessage(message, null);
     else {
         MultiLineException inner = innerException as MultiLineException;
         if (inner != null)
             SetMultiLineMessage(message, inner.MultiLineMessage);
         else
             SetMultiLineMessage(message, innerException.Message);
     }
 }
Example #23
0
        public void JustMessage_MultiLine()
        {
            string[] lines = new string[] { "Roses are red",
                                            "Violets are blue" };
            MultiLineText      message   = new MultiLineText(lines);
            MultiLineException exception = new MultiLineException(message);

            Assert.IsNull(exception.InnerException);
            Assert.AreEqual(message.ToString(), exception.Message);
            Assert.AreEqual(lines.Length, exception.MultiLineMessage.Count);
            for (int i = 0; i < lines.Length; i++)
            {
                Assert.AreEqual(lines[i], exception.MultiLineMessage[i]);
            }
        }
        public void OperatorPlus_ListStr()
        {
            List <string> lines = new List <string>();

            foreach (string line in Gettysburg)
            {
                lines.Add(line);
            }

            MultiLineText text = new MultiLineText();

            text += lines;

            AssertLinesEqual(lines.ToArray(), text);
        }
        public void MultiLineText()
        {
            MultiLineText text = new MultiLineText(array);

            TextLineReader reader = new TextLineReader(text);
            Assert.IsNull(reader.SourceName);

            int expectedLineNum = 0;
            foreach (string line in text) {
                Assert.AreEqual(line, reader.ReadLine());
                expectedLineNum++;
                Assert.AreEqual(expectedLineNum, reader.LineNumber);
            }

            AssertReaderAtEnd(reader);
        }
        public void EnumeratorMethod()
        {
            string[]      lines = Gettysburg;
            MultiLineText text  = new MultiLineText(lines);

            Assert.AreEqual(lines.Length, text.Count);
            int i = 0;

            foreach (string line in text)
            {
                Assert.IsTrue(i < lines.Length);
                Assert.AreEqual(lines[i], line);
                i++;
            }
            Assert.AreEqual(lines.Length, i);
        }
Example #27
0
        MultiLineText GetDataPointLabel(double stackLeft, double widthPerStack, double chartBottom, string label)
        {
            var element = new MultiLineText(stackLeft + widthPerStack / 2, chartBottom, label)
                          .WithTextAnchor(TextAnchor.Middle)
                          .WithFill(_dataPointLabelFill)
                          .WithFontFamily(_dataPointLabelFontFamily)
                          .WithFontSize(_dataPointLabelFontSize)
                          .WithLineHeight(_dataPointLabelHeight);

            if (_dataPointAutoLineSplit)
            {
                element.WithAutoLineSplit(_dataPointLengthPerLine);
            }


            return(element);
        }
        //---------------------------------------------------------------------
        /// <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 MultiLineText()
        {
            MultiLineText text = new MultiLineText(array);

            TextLineReader reader = new TextLineReader(text);

            Assert.IsNull(reader.SourceName);

            int expectedLineNum = 0;

            foreach (string line in text)
            {
                Assert.AreEqual(line, reader.ReadLine());
                expectedLineNum++;
                Assert.AreEqual(expectedLineNum, reader.LineNumber);
            }

            AssertReaderAtEnd(reader);
        }
        //---------------------------------------------------------------------

        private void TryReadPercentage(string input,
                                       string expectedValue,
                                       string expectedError)
        {
            StringReader reader = new StringReader(input);
            int          index;

            try {
                InputValue <Percentage> percentage = PartialThinning.ReadPercentage(reader, out index);
            }
            catch (InputValueException exc) {
                Data.Output.WriteLine();
                Data.Output.WriteLine(exc.Message);
                Assert.AreEqual(expectedValue, exc.Value);
                MultiLineText multiLineMesg = exc.MultiLineMessage;
                string        lastLine      = multiLineMesg[multiLineMesg.Count - 1];
                Assert.AreEqual(expectedError, lastLine.Trim());
                throw exc;
            }
        }
Example #31
0
        BaseElement GetGroupLabel(double drawableLeft, double widthPerGroup, int index, double chartBottom, double stackLabelHeight, string label)
        {
            if (string.IsNullOrEmpty(label))
            {
                return(new NoopElement());
            }

            var element = new MultiLineText(drawableLeft + ((widthPerGroup + _groupGutter) * index) + widthPerGroup / 2, chartBottom + stackLabelHeight + 4, label)
                          .WithTextAnchor(TextAnchor.Middle)
                          .WithFill(_groupLabelFill)
                          .WithFontFamily(_groupLabelFontFamily)
                          .WithFontSize(_groupLabelFontSize)
                          .WithLineHeight(_groupLabelLineHeight);

            if (_groupLabelAutoLineSplit)
            {
                element.WithAutoLineSplit(_groupLabelLengthPerLine);
            }

            return(element);
        }
Example #32
0
        BaseElement GetStackLabel(double stackLeft, double widthPerStack, double chartBottom, double dataPointLabelHeight, string label)
        {
            if (string.IsNullOrEmpty(label))
            {
                return(new NoopElement());
            }

            var element = new MultiLineText(stackLeft + widthPerStack / 2, chartBottom + dataPointLabelHeight + 4, label)
                          .WithTextAnchor(TextAnchor.Middle)
                          .WithFill(_stackLabelFill)
                          .WithFontFamily(_stackLabelFontFamily)
                          .WithFontSize(_stackLabelFontSize)
                          .WithLineHeight(_stackLabelLineHeight);


            if (_stackLabelAutoLineSplit)
            {
                element.WithAutoLineSplit(_stackLabelLengthPerLine);
            }

            return(element);
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance from text with multiple lines.
 /// </summary>
 public TextLineReader(string        sourceName,
     MultiLineText text)
 {
     this.sourceName = sourceName;
     this.text = text;
 }
Example #34
0
        //---------------------------------------------------------------------

        private static Exception LoadException(IInfo plugIn,
                                               MultiLineText message)
        {
            return(new Exception(plugIn, "Error while loading the plug-in",
                                 message));
        }
 //---------------------------------------------------------------------
 public MultiLineException(MultiLineText message,
     MultiLineText innerMessage)
     : base(ConvertToString(message))
 {
     SetMultiLineMessage(message, innerMessage);
 }
        public void OperatorPlus_ListStr()
        {
            List<string> lines = new List<string>();
            foreach (string line in Gettysburg)
                lines.Add(line);

            MultiLineText text = new MultiLineText();
            text += lines;

            AssertLinesEqual(lines.ToArray(), text);
        }
 //---------------------------------------------------------------------
 private static string ConvertToString(MultiLineText message)
 {
     if (message == null)
         throw new System.ArgumentNullException();
     return message.ToString();
 }
 //---------------------------------------------------------------------
 private void SetMultiLineMessage(MultiLineText message,
     MultiLineText innerMessage)
 {
     if (message.Count == 1 && innerMessage != null)
         multiLineMessage = new MultiLineText(message.ToString() + ":");
     else
         multiLineMessage = new MultiLineText(message);
     if (innerMessage != null) {
         foreach (string line in innerMessage)
             multiLineMessage.Add(Indent + line);
     }
 }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance from text with multiple lines.
        /// </summary>
        public TextLineReader(MultiLineText text)
        {
            this.sourceName = null;
            this.text       = text;
        }
 public void StringCtor()
 {
     string line = Gettysburg[0];
     MultiLineText text = new MultiLineText(line);
     Assert.AreEqual(1, text.Count);
     Assert.AreEqual(line, text.ToString());
     Assert.AreEqual(line, text[0]);
 }
        public void OperatorPlus_StrArray()
        {
            MultiLineText text = new MultiLineText();
            string[] lines = Gettysburg;
            text += lines;

            AssertLinesEqual(lines, text);
        }
        public void OperatorPlus_Str()
        {
            MultiLineText text = new MultiLineText();
            string[] lines = Gettysburg;
            foreach (string line in lines)
                text += line;

            AssertLinesEqual(lines, text);
        }
        public void IEnumeratorCtor()
        {
            List<string> lines = new List<string>();
            foreach (string line in Gettysburg)
                lines.Add(line);

            MultiLineText text = new MultiLineText(lines);
            AssertLinesEqual(lines.ToArray(), text);
        }
 public void StrArrayCtor()
 {
     string[] lines = Gettysburg;
     MultiLineText text = new MultiLineText(lines);
     AssertLinesEqual(lines, text);
 }
 public void DefaultCtor()
 {
     MultiLineText text = new MultiLineText();
     Assert.AreEqual(0, text.Count);
     Assert.AreEqual("", text.ToString());
 }
        public void JustMessage_MultiLine()
        {
            string[] lines = new string[]{ "Roses are red",
                                           "Violets are blue" };
            MultiLineText message = new MultiLineText(lines);
            MultiLineException exception = new MultiLineException(message);

            Assert.IsNull(exception.InnerException);
            Assert.AreEqual(message.ToString(), exception.Message);
            Assert.AreEqual(lines.Length, exception.MultiLineMessage.Count);
            for (int i = 0; i < lines.Length; i++)
                Assert.AreEqual(lines[i], exception.MultiLineMessage[i]);
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance from text with multiple lines.
        /// </summary>
        public TextLineReader(string sourceName,
                              MultiLineText text)
        {
            this.sourceName = sourceName;
            this.text       = text;
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance from text with multiple lines.
 /// </summary>
 public TextLineReader(MultiLineText text)
 {
     this.sourceName = null;
     this.text = text;
 }
 //---------------------------------------------------------------------
 private void AssertLinesEqual(string[]      lines,
     MultiLineText text)
 {
     Assert.AreEqual(lines.Length, text.Count);
     for (int i = 0; i < lines.Length; ++i)
         Assert.AreEqual(lines[i], text[i]);
     Assert.AreEqual(JoinLines(lines), text.ToString());
 }