Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ABNF_ProseVal Parse(System.IO.StringReader reader)
        {
            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            /*
                prose-val      =  "<" *(%x20-3D / %x3F-7E) ">"
                                ; bracketed string of SP and VCHAR
                                ;  without angles
                                ; prose description, to be used as
                                ;  last resort

            */

            if(reader.Peek() != '<'){
                throw new ParseException("Invalid ABNF 'prose-val' value '" + reader.ReadToEnd() + "'.");
            }

            // Eat "<"
            reader.Read();

            // TODO: *c-wsp

            StringBuilder value = new StringBuilder();

            while(true){
                // We reached end of stream, no closing DQUOTE.
                if(reader.Peek() == -1){
                    throw new ParseException("Invalid ABNF 'prose-val' value '" + reader.ReadToEnd() + "'.");
                }
                // We have closing ">".
                else if(reader.Peek() == '>'){
                    reader.Read();
                    break;
                }
                // Allowed char.
                else if((reader.Peek() >= 0x20 && reader.Peek() <= 0x3D) || (reader.Peek() >= 0x3F && reader.Peek() <= 0x7E)){
                    value.Append((char)reader.Read());
                }
                // Invalid value.
                else{
                    throw new ParseException("Invalid ABNF 'prose-val' value '" + reader.ReadToEnd() + "'.");
                }
            }

            return new ABNF_ProseVal(value.ToString());
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ABNF_RuleName Parse(System.IO.StringReader reader)
        {
            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            // RFC 5234 4.
            //  rulename =  ALPHA *(ALPHA / DIGIT / "-")

            if(!char.IsLetter((char)reader.Peek())){
                throw new ParseException("Invalid ABNF 'rulename' value '" + reader.ReadToEnd() + "'.");
            }

            StringBuilder ruleName = new StringBuilder();

            while(true){
                // We reached end of string.
                if(reader.Peek() == -1){
                    break;
                }
                // We have valid rule name char.
                else if(char.IsLetter((char)reader.Peek()) | char.IsDigit((char)reader.Peek()) | (char)reader.Peek() == '-'){
                    ruleName.Append((char)reader.Read());
                }
                // Not rule name char, probably readed name.
                else{
                    break;
                }
            }

            return new ABNF_RuleName(ruleName.ToString());
        }
 public override void Parse(System.IO.TextReader reader, IProcessorContext context)
 {
     lock (_syncRoot)
     {
         context.Output.Write(_compiler.CompileString(reader.ReadToEnd()));
     }
 }
Example #4
0
        public override Expression Parse(System.IO.TextReader reader, TextManager manager)
        {
            var expr = new Expression();
            expr.Parts.Add(new Text { Spelling = reader.ReadToEnd() });

            return expr;
        }
Example #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ABNF_CharVal Parse(System.IO.StringReader reader)
        {
            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            /*
                char-val       =  DQUOTE *(%x20-21 / %x23-7E) DQUOTE
                                ; quoted string of SP and VCHAR
                                ;  without DQUOTE
            */

            if(reader.Peek() != '\"'){
                throw new ParseException("Invalid ABNF 'char-val' value '" + reader.ReadToEnd() + "'.");
            }

            // Eat DQUOTE
            reader.Read();

            // TODO: *c-wsp

            StringBuilder value = new StringBuilder();

            while(true){
                // We reached end of stream, no closing DQUOTE.
                if(reader.Peek() == -1){
                    throw new ParseException("Invalid ABNF 'char-val' value '" + reader.ReadToEnd() + "'.");
                }
                // We have closing DQUOTE.
                else if(reader.Peek() == '\"'){
                    reader.Read();
                    break;
                }
                // Allowed char.
                else if((reader.Peek() >= 0x20 && reader.Peek() <= 0x21) || (reader.Peek() >= 0x23 && reader.Peek() <= 0x7E)){
                    value.Append((char)reader.Read());
                }
                // Invalid value.
                else{
                    throw new ParseException("Invalid ABNF 'char-val' value '" + reader.ReadToEnd() + "'.");
                }
            }

            return new ABNF_CharVal(value.ToString());
        }
Example #6
0
 private static void BaseLine(System.IO.TextReader reader, System.IO.TextWriter writer)
 {
     var x = reader.ReadToEnd();
     var r = new System.Text.RegularExpressions.Regex(@"[^_a-f\s]+");
     for (var k = 0; k < 3; k++)
     {
         var y = new String(x.Reverse().ToArray());
         y = r.Replace(y, "_");
         writer.Write(new string(y.Reverse().ToArray()));
     }
 }
		public static CharStream Get(System.IO.TextReader input)
		{
			var charStream = input as CharStream;
			if (charStream != null)
				return charStream;
			
			// {{Aroush-2.9}} isn't there a better (faster) way to do this?
			var theString = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(input.ReadToEnd()));
			return new CharReader(new System.IO.StreamReader(theString));
			//return input is CharStream?(CharStream) input:new CharReader(input);
		}
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context_name"></param>
 /// <param name="stringCodeReader"></param>
 /// <returns></returns>
 public override object Read(string context_name, System.IO.TextReader stringCodeReader, OutputDelegate WriteLine)
 {
     string res = null;
     int line = 0;
     while (stringCodeReader.Peek() != -1)
     {
         line++;
         res += stringCodeReader.ReadToEnd();
     }
     return res;
 } // method: Read
Example #9
0
		public static CharStream Get(System.IO.TextReader input)
		{
            if (input is CharStream)
                return (CharStream) input;
            else
            {
                // {{Aroush-2.9}} isn't there a better (faster) way to do this?
                System.IO.MemoryStream theString = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(input.ReadToEnd()));
                return new CharReader(new System.IO.StreamReader(theString));
            }
			//return input is CharStream?(CharStream) input:new CharReader(input);
		}
Example #10
0
        public CodeCompileUnit Parse(System.IO.TextReader codeStream)
        {
            string text = codeStream.ReadToEnd();

            Ruby.Compiler.AST.Scope AST = Ruby.Compiler.Parser.ParseString(null, null, "", new Ruby.String(text), 1);

            CodeCompileUnit CodeDom = ((SOURCEFILE)AST).ToCodeCompileUnit();

            CodeDom.UserData["text"] = text;

            return CodeDom;
        }
Example #11
0
            public int[] ReadInput(System.IO.TextReader inStream)
            {
                var nfi = NumberFormatInfo.InvariantInfo;
                var args = inStream.ReadToEnd().Split(new[] {'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);

                var lenstr = Int32.Parse(args[0], nfi);
                if (lenstr ==0)
                    return new int[0];
                var entries = args[1].Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Take(lenstr).Select(entr => Int32.Parse(entr, nfi)).ToArray();

                return entries;
            }
Example #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ABNF_Option Parse(System.IO.StringReader reader)
        {
            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            // option = "[" *c-wsp alternation *c-wsp "]"

            if(reader.Peek() != '['){
                throw new ParseException("Invalid ABNF 'option' value '" + reader.ReadToEnd() + "'.");
            }

            // Eat "[".
            reader.Read();

            // TODO: *c-wsp

            ABNF_Option retVal = new ABNF_Option();

            // We reached end of stream, no closing "]".
            if(reader.Peek() == -1){
                throw new ParseException("Invalid ABNF 'option' value '" + reader.ReadToEnd() + "'.");
            }
         
            retVal.m_pAlternation = ABNF_Alternation.Parse(reader);

            // We don't have closing ")".
            if(reader.Peek() != ']'){
                throw new ParseException("Invalid ABNF 'option' value '" + reader.ReadToEnd() + "'."); 
            }
            else{
                reader.Read();
            }

            return retVal;
        }
Example #13
0
		/// <summary>
		/// This function will add or remove the given PUA characters from the given
		/// DerivedBidiClass.txt file by either inserting or not inserting them as necessary
		/// as it reads through the file in a single pass from <code>tr</code> to <code>tw</code>.
		/// </summary>
		/// <remarks>
		/// <list type="number">
		/// <listheader><description>Assumptions</description></listheader>
		/// <item><description>The like Bidi values are grouped together</description></item>
		/// </list>
		///
		/// <list type="number">Non Assumptions:
		/// <item><description>That comments add any information to the file.  We don't use comments for parsing.</description></item>
		/// <item><description>That "blank" lines appear only between different bidi value sections.</description></item>
		/// <item><description>That the comments should be in the format:
		///		# field2 [length of range]  Name_of_First_Character..Name_of_Last_Charachter
		///		(If it is not, we'll just ignore.</description></item>
		/// </list>
		/// </remarks>
		/// <param name="tr">A reader with information DerivedBidiData.txt</param>
		/// <param name="tw">A writer with information to write to DerivedBidiData.txt</param>
		/// <param name="puaCharacters">A list of PUACharacters to either add or remove from the file</param>
		/// <param name="add">Whether to add or remove the given characters</param>
		private void ModifyUCDFile(System.IO.TextReader tr, System.IO.TextWriter tw,
			ArrayList ucdCharacters, bool add)
		{
			if(ucdCharacters.Count==0)
			{
				// There is no point in processing this file if we aren't going to do anything to it.
				tw.Write(tr.ReadToEnd());
				// Allows us to know that there will be at least on ucdCharacter that we can access to get some properties
				return;
			}

			//contains our current line
			// not null so that we get into the while loop
			string line = "unused value";
			//Bidi class value from the previous line
			string lastProperty="blank";
			//Bidi class value from the current line
			string currentProperty;

			// the index of the PUACharacter the we are currently trying to insert
			// Note, the initial value will never be used, because there will be no
			//		bidi class value called "blank" in the file, thus it will be initialized before it is every used
			//		but VS requires an initialization value "just in case"
			int codeIndex=-1;
			// If we have read in the line already we want to use this line for the loop, set this to be true.
			bool dontRead = false;

			//Count the number of characters in each range
			int rangeCount = 0;

			//While there is a line to be read in the file

			while(  (dontRead && line!=null) || (line=tr.ReadLine()) != null )
			{
				dontRead = false;
				if( HasBidiData(line) )
				{
					// We found another valid codepoint, increment the count
					IncrementCount(ref rangeCount,line);

					currentProperty=GetProperty(line);

					//If this is a new section of bidi class values
					if(!((UCDCharacter)ucdCharacters[0]).SameRegion(currentProperty,lastProperty))
					{
						lastProperty = currentProperty;
						// Find one of the ucdCharacters in this range in the list of ucdCharacters to add.
						codeIndex = ucdCharacters.BinarySearch(currentProperty,new UCDComparer());
						// if we don't have any characters to put in this section
						if(codeIndex < 0)
						{
							tw.WriteLine(line);
							line = ReadToEndOfSection(tr,tw,lastProperty,rangeCount,(UCDCharacter)ucdCharacters[0]);
							rangeCount = 0;
							dontRead = true;
							continue;
						}

						// Back up to the beginning of the section of ucdCharacters that have the same bidiclass
						while(--codeIndex>=0 &&
							((UCDCharacter)ucdCharacters[codeIndex]).SameRegion(currentProperty));
						codeIndex++;
					}

					if ( codeIndex < 0 || codeIndex>=ucdCharacters.Count )
						throw new System.Exception("There was a conceptual error while parsing the UCD file." +
							"This should never happen.");

					#region insert_the_PUACharacter
					//Grab codepoint
					string code = line.Substring(0,line.IndexOf(';')).Trim();

					//If it's a range of codepoints
					if(code.IndexOf('.')!=-1)
					{
						#region if_range
						//Grabs the end codepoint
						string endCode = code.Substring(code.IndexOf("..")+2).Trim();
						code = code.Substring(0,code.IndexOf("..")).Trim();

						//A dynamic array that contains our range of codepoints and the properties to go with it
						System.Collections.ArrayList codepointsWithinRange = new System.Collections.ArrayList();

						// If the PUACharacter we want to insert is before the range
						while(
							//If this is the last one stop looking for more
							StillInRange(codeIndex,ucdCharacters,currentProperty) &&
							// For every character before the given value
							((PUACharacter)ucdCharacters[codeIndex]).CompareCodePoint(code) < 0
							)
						{
							//Insert characters before the code
							AddUCDLine(tw,(UCDCharacter)ucdCharacters[codeIndex],add);
							codeIndex++;
						}
						while(
							//If this is the last one stop looking for more
							StillInRange(codeIndex,ucdCharacters,currentProperty) &&
							// While our xmlCodepoint satisfies: code <= xmlCodepoint <= endCode
							((PUACharacter)ucdCharacters[codeIndex]).CompareCodePoint(endCode) < 1
							)
						{
							//Adds the puaCharacter to the list of codepoints that are in range
							codepointsWithinRange.Add(ucdCharacters[codeIndex]);
							codeIndex++;
						}
						//If we found any codepoints in the range to insert
						if(codepointsWithinRange.Count>0)
						{
							#region parse_comments
							//Do lots of smart stuff to insert the PUA characters into the block
							string generalCategory="";
							//Contains the beginning and ending range names
							string firstName="";
							string lastName="";

							//If a comment exists on the line in the proper format
							// e.g.   ---  # --- [ --- ] --- ... ---
							if(line.IndexOf('#')!=-1 && line.IndexOf('[')!=-1
								&& (line.IndexOf('#') <= line.IndexOf('[')) )
							{
								//Grabs the general category
								generalCategory = line.Substring(line.IndexOf('#')+1,line.IndexOf('[')-line.IndexOf('#')-1).Trim();
							}
							//find the index of the second ".." in the line
							int indexDotDot = line.Substring(line.IndexOf(']')).IndexOf("..");
							if( indexDotDot != -1 )
								indexDotDot += line.IndexOf(']');

							int cat = line.IndexOf(']') ;

							if(line.IndexOf('#')!=-1 && line.IndexOf('[')!=-1 && line.IndexOf(']')!=-1 && indexDotDot!=-1
								&& ( line.IndexOf('#') < line.IndexOf('[') )
								&& ( line.IndexOf('[') < line.IndexOf(']') )
								&& ( line.IndexOf(']') < indexDotDot )
								)
							{
								//Grab the name of the first character in the range
								firstName = line.Substring(line.IndexOf(']')+1,indexDotDot-line.IndexOf(']')-1).Trim();
								//Grab the name of the last character in the range
								lastName = line.Substring(indexDotDot+2).Trim();
							}
							#endregion
							WriteBidiCodepointBlock(tw,code,endCode,codepointsWithinRange,
								generalCategory,firstName,lastName,add);
						}
						else
						{
							tw.WriteLine(line);
						}
						#endregion
					}
						//if the codepoint in the file is equal to the codepoint that we want to insert
					else
					{
						if(PUACharacter.CompareHex(code,
							((PUACharacter)ucdCharacters[codeIndex]).CodePoint) > 0)
						{
							// Insert the new PuaDefinition before the line (as well as any others that might be)
							while(
								//If this is the last one stop looking for more
								StillInRange(codeIndex,ucdCharacters,currentProperty) &&
								// For every character before the given value
								((PUACharacter)ucdCharacters[codeIndex]).CompareCodePoint(code) < 0
								)
							{
								//Insert characters before the code
								AddUCDLine(tw,(UCDCharacter)ucdCharacters[codeIndex],add);
								codeIndex++;
							}
						}
						//if the codepoint in the file is equal to the codepoint that we want to insert
						if(StillInRange(codeIndex,ucdCharacters,currentProperty) &&
							(code == ((PUACharacter)ucdCharacters[codeIndex]).CodePoint))
						{
							// Replace the line with the new PuaDefinition
							AddUCDLine(tw,(UCDCharacter)ucdCharacters[codeIndex],add);
							// Look for the next PUA codepoint that we wish to insert
							codeIndex++;
						}
							//if it's not a first tag and the codepoints don't match
						else
						{
							tw.WriteLine(line);
						}
					}

					//If we have no more codepoints to insert in this section, then just finish writing this section
					if( ! StillInRange(codeIndex,ucdCharacters,currentProperty) )
					{
						line = ReadToEndOfSection(tr,tw,lastProperty,rangeCount,(UCDCharacter)ucdCharacters[0]);
						rangeCount = 0;
						dontRead = true;
						continue;
					}
					#endregion
				}
					//If it's a comment, simply write it out
				else
				{
					// find the total count comment and replace it with the current count.
					if(line.ToLowerInvariant().IndexOf("total code points")!=-1)
					{
						line = "# Total code points:" + rangeCount;
						rangeCount = 0;
					}
					tw.WriteLine(line);
				}
			}
		}
Example #14
0
        //Format: /s [11, 22, 33, 44, 55, 66, 77, 88]

        public byte[] Resolve(System.IO.StringReader reader)
        {
// ReSharper disable once PossibleNullReferenceException
            string[] bytes = reader.ReadToEnd().Replace(" ", string.Empty).Replace("[", "").Replace("]", "").Split(',');
            return bytes.Select(s => Convert.ToByte(s, 16)).ToArray();
        }
 public EventRequestData GetEventRequestFromVCardStream(System.IO.TextReader stream)
 {
     return CreateResult(stream.ReadToEnd());
 }
 /// <summary>
 /// Parses the given file.
 /// </summary>
 /// <remarks>
 /// This will be invoked by the IDE when the document is changed in the editor
 /// </remarks>
 public override ParsedDocument Parse(bool storeAst, string fileName, System.IO.TextReader content, MonoDevelop.Projects.Project project = null)
 {
     var doc = new GoldParsedDocument ();
     doc.Parse (content.ReadToEnd ());
     return doc;
 }
Example #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ABNF_DecVal Parse(System.IO.StringReader reader)
        {
            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            // dec-val =  "d" 1*DIGIT [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ]

            if(reader.Peek() != 'd'){
                throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
            }

            // Eat 'd'.
            reader.Read();

            if(!char.IsNumber((char)reader.Peek())){
                throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
            }

            ValueType     valueType = ValueType.Single;
            List<int>     values    = new List<int>();
            StringBuilder b         = new StringBuilder();
            while(true){
                // We reached end of string.
                if(reader.Peek() == -1){
                    // - or . without required 1 DIGIT.
                    if(b.Length == 0){
                        throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
                    }
                    break;
                }
                else if(char.IsNumber((char)reader.Peek())){
                    b.Append((char)reader.Read());
                }
                // Concated value.
                else if(reader.Peek() == '.'){
                    // Range and conacted is not allowed to mix.
                    if(valueType == ValueType.Range){
                        throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
                    }
                    if(b.Length == 0){
                        throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
                    }

                    values.Add(Convert.ToInt32(b.ToString()));
                    b = new StringBuilder();
                    valueType = ValueType.Concated;

                    // Eat '.'.
                    reader.Read();
                }
                // Value range.
                else if(reader.Peek() == '-'){
                    // Range and conacted is not allowed to mix. Also multiple ranges not allowed.
                    if(valueType != ValueType.Single){
                        throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
                    }
                    values.Add(Convert.ToInt32(b.ToString()));
                    b = new StringBuilder();
                    valueType = ValueType.Range;

                    // Eat '-'.
                    reader.Read();
                }
                // Not dec-val char, value reading completed.
                else{
                    // - or . without required 1 DIGIT.
                    if(b.Length == 0){
                        throw new ParseException("Invalid ABNF 'dec-val' value '" + reader.ReadToEnd() + "'.");
                    }
                    break;
                }
            }
            values.Add(Convert.ToInt32(b.ToString()));

            //Console.WriteLine(valueType.ToString());
            //foreach(int v in values){
            //    Console.WriteLine(v);
               // }

            if(valueType == ValueType.Single){
                return new ABNF_DecVal(values[0],values[0]);
            }
            else if(valueType == ValueType.Concated){
                return new ABNF_DecVal(values.ToArray());
            }
            else{
                return new ABNF_DecVal(values[0],values[1]);
            }
        }
        private static System.IO.TextReader GetDecodedInterviewAnswers(System.IO.TextReader input, ref string originalAnswers)
        {
            int firstc = input.Peek();
            if (firstc != -1)
            {
                char first = (char)firstc;
                if (first == '[') // looks like answers from stateless interview (HDANS format)
                {
                    // answers probably start with "[HDANS(" etc.
                    string ansPkg = input.ReadToEnd();
                    if (ansPkg.StartsWith("[HDSANS(", StringComparison.OrdinalIgnoreCase))
                    {
                        int end = ansPkg.IndexOf(")]", 8);
                        if (end > 0)
                        {
                            var lens = ansPkg.Substring(8, end - 8).Split(',');
                            if (lens.Length == 2)
                            {
                                int ansLen = int.Parse(lens[0]);
                                int orgLen = int.Parse(lens[1]);
                                if (ansPkg[end + 2 + ansLen] == '|')
                                {
                                    if (orgLen > 0 && originalAnswers != null)
                                        originalAnswers = ansPkg.Substring(end + ansLen + 3, orgLen);

                                    // decode & then return XML
                                    ansPkg = Encoding.UTF8.GetString(Convert.FromBase64String(ansPkg.Substring(end + 2, ansLen)));
                                    if (ansPkg[0] == 0xFEFF)
                                        ansPkg = ansPkg.Substring(1);
                                    return new System.IO.StringReader(ansPkg);
                                }
                            }
                        }
                    }
                    // else
                    throw new ArgumentException("Error parsing interview answers.");
                }
                else if (first == '<') // looks like bare XML answers
                {
                    // answers probably start with "<?xml "
                    return input;
                }
                else // otherwise should be base64 encoded UTF16 XML
                {
                    byte[] buffer = Convert.FromBase64String(input.ReadToEnd());
                    string decoded = Encoding.Unicode.GetString(buffer);//This was "Unicode" (not "UTF8").
                    if (decoded.Length > 0 && decoded[0] == '\xfeff')
                        decoded = decoded.Substring(1);
                    return new System.IO.StringReader(decoded);
                }
            }
            return new System.IO.StringReader("");
        }
Example #19
0
        public CodeCompileUnit ParseMergeable(System.IO.TextReader codeStream, IMergeDestination destination)
        {
            // get a better filename if we can
            string name = "<unknown>";
            StreamReader sw = codeStream as StreamReader;
            if (sw != null) {
                FileStream fs = sw.BaseStream as FileStream;
                if (fs != null) name = fs.Name;
            }
            //!!! it'd be nice to have Parser.FromStream to get proper decodings here
            string codeText = codeStream.ReadToEnd();
            CodeCompileUnit tree = Parse(Parser.FromString(state, new CompilerContext(), codeText), name);

            if (destination != null) CodeMerger.CacheCode(tree, destination);
            else CodeMerger.CacheCode(tree, codeText);

            return tree;
        }
Example #20
0
 public static void Parse(System.IO.StreamReader Stream, QuipCompiler Compiler)
 {
     var file = Stream.ReadToEnd();
     var state = new ParseState { start = 0, end = file.Length, source = file, filename = "" };
     ParseLines(state, Compiler);
 }
        /// <summary>
        /// Assembles a document from the given template, answers and settings.
        /// </summary>
        /// <param name="template">The template to assemble.</param>
        /// <param name="answers">The answers to use during the assembly.</param>
        /// <param name="settings">The settings for the assembly.</param>
        /// <include file="../../Shared/Help.xml" path="Help/string/param[@name='logRef']"/>
        /// <returns>An <c>AssembleDocumentResult</c> that contains the results of the assembly.</returns>
        public AssembleDocumentResult AssembleDocument(Template template, System.IO.TextReader answers, AssembleDocumentSettings settings, string logRef)
        {
            // Validate input parameters, creating defaults as appropriate.
            string logStr = logRef == null ? string.Empty : logRef;

            if (template == null)
                throw new ArgumentNullException("template", string.Format(@"Cloud.Services.AssembleDocument: the ""template"" parameter passed in was null, logRef: {0}", logStr));

            if (settings == null)
                settings = new AssembleDocumentSettings();

            AssembleDocumentResult result = null;
            AssemblyResult asmResult = null;

            using (var client = new SoapClient(_subscriberID, _signingKey, HostAddress, ProxyAddress))
            {
                asmResult = client.AssembleDocument(
                    template,
                    answers == null ? "" : answers.ReadToEnd(),
                    settings,
                    logRef
                );
            }

            if (asmResult != null)
            {
                result = Util.ConvertAssemblyResult(template, asmResult, settings.Format);
            }

            return result;
        }
 public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
 {
     return base.TokenStream(fieldName, new StringReader(reader.ReadToEnd().ToLower()));
 }
Example #23
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static ABNF_Repetition Parse(System.IO.StringReader reader)
        {
            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            /*
                repetition     =  [repeat] element
                repeat         =  1*DIGIT / (*DIGIT "*" *DIGIT)
                element        =  rulename / group / option / char-val / num-val / prose-val
            */

            int min = 0;
            int max = int.MaxValue;

            // --- range ------------------------------------
            if(char.IsDigit((char)reader.Peek())){
                StringBuilder minString = new StringBuilder();
                while(char.IsDigit((char)reader.Peek())){
                    minString.Append((char)reader.Read());
                }
                min = Convert.ToInt32(minString.ToString());
            }
            if(reader.Peek() == '*'){
                reader.Read();
            }
            if(char.IsDigit((char)reader.Peek())){
                StringBuilder maxString = new StringBuilder();
                while(char.IsDigit((char)reader.Peek())){
                    maxString.Append((char)reader.Read());
                }
                max = Convert.ToInt32(maxString.ToString());
            }
            //-----------------------------------------------

            // End of stream reached.
            if(reader.Peek() == -1){
                return null;
            }
            // We have rulename.
            else if(char.IsLetter((char)reader.Peek())){
                return new ABNF_Repetition(min,max,ABNF_RuleName.Parse(reader));
            }
            // We have group.
            else if(reader.Peek() == '('){
                return new ABNF_Repetition(min,max,ABFN_Group.Parse(reader));
            }
            // We have option.
            else if(reader.Peek() == '['){
                return new ABNF_Repetition(min,max,ABNF_Option.Parse(reader));
            }
            // We have char-val.
            else if(reader.Peek() == '\"'){
                return new ABNF_Repetition(min,max,ABNF_CharVal.Parse(reader));
            }
            // We have num-val.
            else if(reader.Peek() == '%'){
                // Eat '%'.
                reader.Read();

                if(reader.Peek() == 'd'){
                    return new ABNF_Repetition(min,max,ABNF_DecVal.Parse(reader));
                }
                else{
                    throw new ParseException("Invalid 'num-val' value '" + reader.ReadToEnd() + "'.");
                }
            }
            // We have prose-val.
            else if(reader.Peek() == '<'){
                return new ABNF_Repetition(min,max,ABNF_ProseVal.Parse(reader));
            }

            return null;
        }
            public TestTokenizer(System.IO.TextReader Reader)
            {
                //Caution: "Reader" is actually of type "ReusableStringReader" and some 
                //methods (for ex. "ReadToEnd", "Peek",  "ReadLine") is not implemented. 

                Assert.AreEqual("ReusableStringReader", Reader.GetType().Name);
                Assert.AreEqual("First Line", Reader.ReadLine(), "\"ReadLine\" method is not implemented");
                Assert.AreEqual("Second Line",Reader.ReadToEnd(),"\"ReadToEnd\" method is not implemented");
            }
Example #25
0
 public TestTokenizer(System.IO.TextReader Reader)
     : base(Reader)
 {
     //Caution: "Reader" is actually of type "ReusableStringReader" and some 
     //methods (for ex. "ReadToEnd", "Peek",  "ReadLine") is not implemented. 
     Assert.AreEqual(TEST_STRING, Reader.ReadToEnd(), "Issue LUCENENET-150: \"ReadToEnd\" method is not implemented");
 }
Example #26
0
 public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
 {
     TokenStream result = new LuceneTokenizer(reader, reader.ReadToEnd());
     result = new LowerCaseFilter(result);
     return result;
 }
Example #27
0
        protected virtual Holodeck.Resource[] ReadResources(System.IO.StreamReader file)
        {
            const string Name = "Name: ";
            const string Func = "Func: ";
            const string Proc = "Proc: ";
            const string Time = "Time: ";
            const string Retv = "Retv: ";
            const string Errc = "Errc: ";
            const string Exce = "Exce: ";

            Holodeck.Resource resource;
            System.Collections.Hashtable resources = new System.Collections.Hashtable (10);
            string stream = file.ReadToEnd ();
            try {
                int begIndex = 0;
                int endIndex = 0;
                while (true) {

                    begIndex = stream.IndexOf (Name, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Name.Length;
                    resource.Name = stream.Substring (begIndex, endIndex - begIndex - 1);

                    begIndex = stream.IndexOf (Func, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Func.Length;
                    resource.LastFunction = stream.Substring (begIndex, endIndex - begIndex - 1);

                    begIndex = stream.IndexOf (Proc, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Proc.Length;
                    resource.processID = Int64.Parse (stream.Substring (begIndex, endIndex - begIndex - 1));

                    begIndex = stream.IndexOf (Time, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Time.Length;
                    resource.TimeStamp = stream.Substring (begIndex, endIndex - begIndex - 1);

                    begIndex = stream.IndexOf (Retv, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Retv.Length;
                    resource.ReturnValue = stream.Substring (begIndex, endIndex - begIndex - 1);

                    begIndex = stream.IndexOf (Errc, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Errc.Length;
                    resource.ErrorCode = stream.Substring (begIndex, endIndex - begIndex - 1);

                    begIndex = stream.IndexOf (Exce, endIndex);
                    endIndex = stream.IndexOf ("\n", begIndex);
                    begIndex += Exce.Length;
            //					resource. = stream.Substring (begIndex, endIndex - begIndex - 1);

                    resource.NumHits = 1;
                    resource.threadID = 0;

                    if (resources.Contains (resource.Name)) {
                        Holodeck.Resource oldResource = (Holodeck.Resource) resources[resource.Name];
                        resource.NumHits += oldResource.NumHits;
                        resources.Remove (resource.Name);
                    }
                    resources.Add (resource.Name, resource);
                }
            } catch (Exception) {
            }

            Holodeck.Resource[] result = new Holodeck.Resource[resources.Count];
            System.Collections.IEnumerator iEnum = resources.Values.GetEnumerator ();
            int i = 0;
            while (iEnum.MoveNext ()) {
                result[i] = (Holodeck.Resource) iEnum.Current;
                i++;
            }

            return result;
        }