Answered RXX SelectMany

  • Friday, July 13, 2012 3:40 AM
     
      Has Code

    .NET 4.0 and latest version of RXX (validated the dll was 4.0)

    Took the lab example of this code:

     public void DownloadHtmlPageExperiment()
        {
          Uri address = UserInputUrl(Text.PromptFormat, Instructions.EnterAUrl);
    
          TraceLine(Text.Subscribing);
          TraceLine();
    
          using (var client = new WebClient())
          {
            var htmlTagsWithIds = client
              .DownloadStringObservable(address)
              .SelectMany(response =>
                Regex.Matches(
                  response,
                  @"\< (?<Tag> \w+? ) \s [^\>]*? id= (?<Q> [""']? ) (?<ID> .+? ) \k<Q> .*? \>",
                    RegexOptions.IgnoreCase
                  | RegexOptions.ExplicitCapture
                  | RegexOptions.IgnorePatternWhitespace
                  | RegexOptions.Singleline)
                .Cast<Match>())
              .Select(match => new
              {
                Tag = match.Groups["Tag"].Value,
                Id = match.Groups["ID"].Value
              });
    
            using (htmlTagsWithIds.Subscribe(ConsoleOutput))
            {
              TraceLine(Instructions.PressAnyKeyToCancel);
    
              WaitForKey();
            }
          }
        }
    

    Chopped it up in my code to look like this:

      public void DownloadHtmlPageExperiment()
            {
                Uri address = new Uri("http://www.test.com");
    
                using (var client = new WebClient())
                {
                    var htmlTagsWithIds = client                   
                      .DownloadStringObservable(address)
                     
                      .SelectMany(response =>
                        Regex.Matches(
                          response,
                          @"\< (?<Tag> \w+? ) \s [^\>]*? id= (?<Q> [""']? ) (?<ID> .+? ) \k<Q> .*? \>",
                            RegexOptions.IgnoreCase
                          | RegexOptions.ExplicitCapture
                          | RegexOptions.IgnorePatternWhitespace
                          | RegexOptions.Singleline)
                        .Cast<Match>())
                      .Select(match => new
                      {
                          Tag = match.Groups["Tag"].Value,
                          Id = match.Groups["ID"].Value
                      });
                }
            }

    VS2010 is telling me there's no support of SelectMany<IObservable<string>>....  Can't compile example...


    JP Cowboy Coders Unite!

All Replies

  • Thursday, July 26, 2012 7:33 PM
     
     Answered

    a) Did you make sure that the reactive extensions are properly referenced?

    b) Do you have System.Reactive.Linq in your using statements?


    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)


    Ruminations of J.net


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    • Proposed As Answer by Dave Sexton Tuesday, July 31, 2012 7:28 PM
    • Marked As Answer by Mr. Javaman II Tuesday, July 31, 2012 8:11 PM
    •  
  • Friday, July 27, 2012 12:55 PM
     
     
    Thanks for response, I'll give it a second look once I reopen project... I set it aside after this issue, but now I have to find it... egad!

    JP Cowboy Coders Unite!

  • Tuesday, July 31, 2012 7:28 PM
     
      Has Code

    Hi,

    As DevBiker wrote, you need to add a using directive to the top of your file:

    using System.Reactive.Linq;

    It's probably better to copy the entire lab, not just a portion of it.  Other using statements specified at the top of the lab may also be required.

    - Dave


    http://davesexton.com/blog

    • Edited by Dave Sexton Tuesday, July 31, 2012 7:28 PM
    • Proposed As Answer by Dave Sexton Tuesday, July 31, 2012 7:28 PM
    • Unproposed As Answer by Dave Sexton Tuesday, July 31, 2012 7:28 PM
    • Edited by Dave Sexton Tuesday, July 31, 2012 7:29 PM Formatting; added reference to previous answer
    •