示例#1
0
 public ParserValue(string text, ParserLocation loc, int leng, int lineNo)
 {
     Text   = text;
     Loc    = loc;
     Leng   = leng;
     LineNo = lineNo;
 }
示例#2
0
 public ParserValue(ParserValue parserValue)
 {
     Text   = parserValue.Text;
     Leng   = parserValue.Leng;
     Loc    = parserValue.Loc;
     LineNo = parserValue.LineNo;
 }
示例#3
0
 public ParserError(String text, ParserState state, ParserSymbol symbol, int lineNo, ParserLocation loc, Stack <string> expected)
 {
     Text     = text;
     State    = state;
     Symbol   = symbol;
     LineNo   = lineNo;
     Loc      = loc;
     Expected = expected;
 }
示例#4
0
        /// <summary>
        /// Parses the supplied source payload with the supplied ParserLocation.Path and returns the value as a JToken so it can be added to a JObject.
        /// Will use a supplied Jobject instead if one is supplied.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="sourcePayload"></param>
        /// <param name="destinationType"></param>
        /// <param name="jObject"></param>
        /// <returns></returns>
        public static JToken ParsePayloadProperty(ParserLocation location, object sourcePayload, DataType destinationType, JToken jObject = null)
        {
            if (jObject == null)
            {
                jObject = GetJObject(sourcePayload);
            }

            return(destinationType == DataType.String ?
                   ParsePayloadPropertyAsString(location.Path, sourcePayload) :
                   jObject.SelectToken(location.Path));
        }
示例#5
0
        public ParserLocation Clone()
        {
            var parserLocation = new ParserLocation(FirstLine, LastLine, FirstColumn, LastColumn);

            if (Range != null)
            {
                parserLocation.Range = Range.Clone();
            }

            return(parserLocation);
        }
示例#6
0
        static void Main(string[] args)
        {
            ConnectionFactory connecfactory  = new ConnectionFactory();
            ParserLocation    parserLocation = new ParserLocation();
            DataAccesLayer    dataAccesLayer = new DataAccesLayer();


            connecfactory.HostName = "localhost";
            using (var connection = connecfactory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare("hello", durable: false, false, false, null);

                    channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
                    // mesaj 1 tane gelsin doğru işlenirse 1 tane daha gönder
                    // diğer insantaların aldığınıda hesaba katmak için global=true yapılır. ama benim tercihim false yönünde
                    Console.WriteLine("Mesajları bekliyoum");


                    var consumer = new EventingBasicConsumer(channel);

                    channel.BasicConsume("hello", autoAck: false, consumer);// autoAck:false, silinmemesi için false yapmak gerekir.

                    consumer.Received += (model, e) =>
                    {
                        // int time = Convert.ToInt32(GetMessage(args));
                        // int time = 200;
                        //Thread.Sleep(1000);

                        var result = parserLocation.GetParser(e.Body);


                        dataAccesLayer.Add((Location)result);


                        channel.BasicAck(deliveryTag: e.DeliveryTag, multiple: false);
                        // mesaj başarıyla işledim kuyruktan silebilirsin anlamına geliyor.
                    };
                    Console.WriteLine("Çıkmak için tıklayınız");
                    Console.ReadLine();
                }
            }
        }
示例#7
0
 public void Recall(Parser parser, ParserLocation location)
 {
     CurrentComments           = location.Comments;
     parser.Tokenizer.Location = location.TokenizerLocation;
 }
示例#8
0
 public void Recall(Parser parser, ParserLocation location)
 {
     CurrentComments = location.Comments;
     parser.Tokenizer.Location = location.TokenizerLocation;
 }
        /*
         * /// <summary>
         * /// Parses the given response stream, only handles whatever is needed for previews.
         * /// The following code is not written for readability, but for speed. So nothing is split up into seperate functions, function calls are slow
         * /// </summary>
         * /// <param name="sResponse">The stream to read from</param>
         * private static URLPreview ParseResponseStream(Stream oResponse)
         * {
         *      bool conditionMetTitle = false;
         *      bool conditionMetImage = false;
         *      bool conditionMetDescription = false;
         *
         *      string title = String.Empty;
         *      string imageUrl = String.Empty;
         *      string description = String.Empty;
         *
         *      using(StreamReader sr = new StreamReader(oResponse))
         *      {
         *              //try
         *              //{
         *                      bool ignoreTag = false;
         *                      ParserState previousState = ParserState.None;
         *                      ParserState currentState = ParserState.None;
         *                      char[] previousChar = {'a', 'a'};
         *                      char currentChar = 'a';
         *                      string currentTag = "";
         *                      string currentTagProperties = "";
         *
         *                      while(!sr.EndOfStream)
         *                      {
         *                              previousChar[1] = previousChar[0];
         *                              previousChar[0] = currentChar;
         *                              currentChar = (char)sr.Read();
         *
         *                              if(currentState == ParserState.Comment)
         *                              {
         *                                      if(currentChar == '>' && previousChar[0] == '-' && previousChar[1] == '-')
         *                                              currentState = previousState;
         *                              }
         *                              else if(currentState == ParserState.String)
         *                              {
         *                                      if(currentChar == '"')
         *                                              currentState = previousState;
         *                              }
         *                              else if(ignoreTag)
         *                              {
         *                                      if(currentChar == '<')
         *                                              ignoreTag = false;
         *                              }
         *
         *                              if(!ignoreTag)
         *                              {
         *                                      switch(currentChar)
         *                                      {
         *                                              case '<':
         *                                                      currentState = ParserState.TagOpen;
         *                                                      currentTag = "";
         *                                                      currentTagProperties = "";
         *                                                      break;
         *                                              case '!':
         *                                                      if(currentState == ParserState.TagOpen)
         *                                                              previousState = currentState;
         *                                                              currentState = ParserState.Comment;
         *                                                      break;
         *                                              case '"':
         *                                                      currentState = ParserState.String;
         *                                                      break;
         *                                              case '/':
         *                                                      if(currentState == ParserState.TagOpen)
         *                                                              ignoreTag = true;
         *                                                      break;
         *                                              case '>':
         *                                                      currentState = ParserState.None;
         *                                                      ignoreTag = !IsWantedTag(currentTag);
         *                                                      if(currentTag.Length == 0)
         *                                                              Console.WriteLine("Empty tag 2");
         *                                                      break;
         *                                              default:
         *                                                      if(currentState == ParserState.TagOpen)
         *                                                      {
         *                                                              if(!Char.IsWhiteSpace(currentChar))
         *                                                                      currentState = ParserState.TagName;
         *                                                      }
         *
         *                                                      if(currentState == ParserState.TagName)
         *                                                      {
         *                                                              if(!Char.IsWhiteSpace(currentChar))
         *                                                              {
         *                                                                      if(currentTag.Length == iLongestSearchTag)
         *                                                                              ignoreTag = true; // We no longer want this tag
         *                                                                      else
         *                                                                              currentTag += currentChar;
         *                                                              }
         *                                                              else
         *                                                              {
         *                                                                      ignoreTag = !IsWantedTag(currentTag);
         *                                                              }
         *                                                      }
         *                                                      break;
         *                                      }
         *                              }
         *                      }
         *              //}
         *              //catch
         *              //{
         *                      // Woopsie daisy, looks like we won't have a preview here either
         *                      // Add appropriate log message
         *              //	return null;
         *              //}
         *      }
         *
         *      return null;
         * }
         */
        #endregion

        /// <summary>
        /// Parses a given string, attempts to extract useful data for a URL Preview
        /// </summary>
        /// <param name="str">The string to extract data from</param>
        /// <returns>A URLPreview or null</returns>
        private static URLPreview ParseResponseString(String str)
        {
            URLPreview preview = new URLPreview();

            bool conditionMetTitle = false;
            bool conditionMetImage = false;

            string title       = String.Empty;
            string imageUrl    = String.Empty;
            string description = String.Empty;

            int strLength = str.Length;
            //try
            //{
            bool           ignoreTag         = false;
            int            tagIndex          = -1;
            ParserState    currentState      = ParserState.None;
            ParserLocation currentLocation   = ParserLocation.HTML;
            char           previousChar      = 'a';
            char           currentChar       = 'a';
            string         currentTag        = "";
            string         currentTagContent = "";

            for (int x = 0; x < strLength; x++)
            {
                previousChar = currentChar;
                currentChar  = (char)str[x];

                // There is a very specific order here
                // 1. Check if we are in a comment (comments are always ignored)
                // 2. Check if we are in a string, if we are check if the string doesn't end here
                //		2.5 Check if we're parsing content, if we are we want this string data
                // 3. Check if we are ignoring a tag, if we are we check if the tag wasn't closed
                // 4. If we aren't ignoring a tag, we handle the rest

                // Check if we are still in a comment or string
                if (currentLocation == ParserLocation.Comment)
                {
                    if (currentChar == '>' && previousChar == '-')
                    {
                        currentLocation = ParserLocation.HTML;
                    }

                    continue;                             // Current character is inside a command or the last character of a comment, do nothing
                }
                else if (currentLocation == ParserLocation.String)
                {
                    // If we're parsing tag content we want the string data
                    if (currentState == ParserState.TagAttributes || currentState == ParserState.Content)
                    {
                        currentTagContent += currentChar;
                    }

                    // Check if the string ends here
                    if (currentChar == '"')
                    {
                        currentLocation = ParserLocation.HTML;
                    }

                    continue;                             // Current character is inside a string or the last character of a string, do nothing
                }
                else if (ignoreTag)
                {
                    if (currentChar != '<')
                    {
                        continue;                                 // We're ignoring this tag until we find a new opening char, do nothing
                    }
                    // New tag, let it flow through and continue with the code
                    ignoreTag = false;
                }

                // If we aren't ignoring this tag we continue whatever we want to continue
                if (!ignoreTag)
                {
                    switch (currentChar)
                    {
                    case '<':
                        if (currentState == ParserState.Content)
                        {
                            ContentParser(preview, currentTag, currentTagContent);
                            //Console.WriteLine("Tag: " + currentTag + ", Content: " + currentTagContent);
                        }

                        currentState      = ParserState.TagOpen;
                        currentTag        = "";
                        currentTagContent = "";
                        break;

                    case '>':
                        if (currentState == ParserState.TagAttributes)
                        {
                            ContentParser(preview, currentTag, currentTagContent);
                            currentState = ParserState.None;
                            //Console.WriteLine("Tag: " + currentTag + ", Attributes: " + currentTagContent);
                        }
                        else
                        {
                            tagIndex = IsWantedTag(currentTag);
                            if (tagIndex == -1)
                            {
                                currentState = ParserState.None;
                                ignoreTag    = true;
                            }
                            else
                            {
                                currentState = searchTags[tagIndex].parseMethod;
                            }
                        }
                        break;

                    case '-':
                        // There are tags like <!DOCTYPE, so we can't just check for !
                        if (previousChar == '!')
                        {
                            if (currentState == ParserState.TagOpen)
                            {
                                currentState    = ParserState.TagName;
                                currentLocation = ParserLocation.Comment;
                            }
                        }
                        break;

                    case '"':
                        currentLocation = ParserLocation.String;

                        if (currentState == ParserState.TagAttributes || currentState == ParserState.Content)
                        {
                            currentTagContent += '"';
                        }
                        break;

                    case '/':
                        if (currentState == ParserState.TagOpen)
                        {
                            ignoreTag = true;
                        }
                        break;

                    default:
                        // If we're parsing tag content we want these characters
                        if (currentState == ParserState.TagAttributes || currentState == ParserState.Content)
                        {
                            currentTagContent += currentChar;
                        }
                        else
                        {
                            // If the parser is at a tag open '<' and the next character is not a whitespace, then we're reading the tag name
                            if (currentState == ParserState.TagOpen)
                            {
                                if (!Char.IsWhiteSpace(currentChar))
                                {
                                    currentState = ParserState.TagName;
                                }
                            }

                            // If we're at the tag name we want to store that in a variable
                            if (currentState == ParserState.TagName)
                            {
                                if (!Char.IsWhiteSpace(currentChar))
                                {
                                    if (currentTag.Length == iLongestSearchTag)
                                    {
                                        ignoreTag = true;                                                         // We no longer want this tag
                                    }
                                    else
                                    {
                                        currentTag += currentChar;
                                    }
                                }
                                else
                                {
                                    tagIndex = IsWantedTag(currentTag);
                                    if (tagIndex == -1)
                                    {
                                        ignoreTag = true;
                                    }
                                    else
                                    {
                                        currentState = searchTags[tagIndex].parseMethod;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }



                if (preview.PreferredTitle && preview.PreferredImageUrl && preview.PreferredDescription)
                {
                    return(preview);
                }
            }

            //}
            //catch
            //{
            // Woopsie daisy, looks like we won't have a preview here either
            // Add appropriate log message
            //	return null;
            //}

            return(preview);
        }