Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
Help migrating code from earliar version of Rx to new

Respondido Help migrating code from earliar version of Rx to new

  • quarta-feira, 11 de abril de 2012 12:10
     
     

    Dear friends,

    I am a novice with Rx and I found this code from a silverlightpluscrm book and I tried to use it but its built on the earliar version of Rx with CoreEx assemblies and Observer dll.

     Observable.FromEvent<LoadCompletedEventArgs>(collection, "LoadCompleted").Subscribe(loadcompleted =>
                    {
                        observer.OnNext(loadcompleted.EventArgs);
                    });

    I tried to migrate it using this code and it didn't show errors and compiles but doesn't work.

     Observable.FromEvent<EventHandler<LoadCompletedEventArgs>, LoadCompletedEventArgs>(c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c).Subscribe(loadcompleted =>
                    {
                        observer.OnNext(loadcompleted);
                    });

    I don't know how I could collect the EventArgs as before. I am sorry if my question is silly.

    ys,

    Sebastian

Todas as Respostas

  • quarta-feira, 11 de abril de 2012 16:50
     
      Contém Código

    Hi Sebastian,

    Try Observable.FromEventPattern instead:

    Observable.FromEventPattern<LoadCompletedEventArgs>(
    	c => collection.LoadCompleted += c, 
    	c => collection.LoadCompleted -= c)
    	.Subscribe(observer.OnNext);

    - Dave


    http://davesexton.com/blog

  • quarta-feira, 11 de abril de 2012 16:53
     
     

    Hi Sebastian,

    Though I suspect that something else may be wrong if your solution doesn't work.  If my solution doesn't work either then try placing a breakpoint in Subscribe to make sure that observer.OnNext is being called.

    - Dave


    http://davesexton.com/blog

  • sexta-feira, 13 de abril de 2012 07:24
     
     

    Hi Dave,

    Thanks a lot for your warm and quick response ... I tried to use the code yesterday and tried to play around ... but it is displaying this error. I am very new to Rx. I am not sure how all this works and am presently just blindly playing around.

    argument: can be converted from "Method group" in "System.IObserver < System.Reactive.EventPattern < System.Data.Services.Client.LoadCompletedEventArgs >

    the best match for the overloaded System.IObservable < System.Reactive.EventPattern < System.Data.Services.Client.LoadCompletedEventArgs > >.Subscribe (System.IObserver < System.Reactive.EventPattern < System.Data.Services.Client.LoadCompletedEventArgs > >) method has some invalid arguments.

    as translated from bingtranslator from German.

    ys,

    Sebastian

  • sexta-feira, 13 de abril de 2012 07:51
     
     

    Hi Sebastian,

    Please post your code that calls Subscribe so that we can see what the compiler is complaining about.

    - Dave


    http://davesexton.com/blog

    • Editado Dave Sexton sexta-feira, 13 de abril de 2012 07:52 Correction: Subscribe
    •  
  • sexta-feira, 13 de abril de 2012 07:54
     
     

    Hi Sebastian,

    The problem is probably that the method you're passing to Subscribe doesn't accept the correct parameter type.  As I mentioned previously, please post some code so that we can see what you're doing.

    - Dave


    http://davesexton.com/blog

  • sexta-feira, 13 de abril de 2012 08:58
     
      Contém Código
     public static IObservable<LoadCompletedEventArgs> RxRunQuery<CollectionType>(this DataServiceCollection<CollectionType> collection, IQueryable<CollectionType> query)
            {
                return Observable.Create<LoadCompletedEventArgs>(observer =>
                {
    
                    //Observable.FromEventPattern<LoadCompletedEventArgs>(c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c).Subscribe(observer.OnNext);
                    Observable.FromEvent<EventHandler<LoadCompletedEventArgs>, LoadCompletedEventArgs>(c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c).Subscribe(loadcompleted =>
                    {
                        observer.OnNext(loadcompleted);
                    });
    
                    collection.LoadAsync(query);
    
                    return () => { };
                });
    
            }
    
            public static iobservable<bool> loadallpages<collectiontype>(this dataservicecollection<collectiontype> collection, iqueryable<collectiontype> query)
            {
                return observable.create<bool>(observer =>
                {
                    observable.fromevent<loadcompletedeventargs>(collection, "loadcompleted").subscribe(loadcompleted =>
                    {
                        if (collection.continuation != null)
                            collection.loadnextpartialsetasync();
                        else
                            observer.onnext(true);
    
                    });
    
                    collection.loadasync(query);
    
                    return () => { };
                });
    
            }

  • sexta-feira, 13 de abril de 2012 20:23
     
     Respondido Contém Código

    Hi Sebastian,

    I think the problem is with the call to Subscribe.  I used the short-hand syntax in my example but I didn't realize that the type of the data changed.  You'll have to change this:

    .Subscribe(observer.OnNext)

    to this:

    .Subscribe(e => observer.OnNext(e.EventArgs))

    - Dave


    http://davesexton.com/blog

  • segunda-feira, 7 de maio de 2012 14:20
     
     

    There are no errors now.

    Thanks a lot Dave for you support. I am ashamed for this delayed reply. I am very grateful for you support. I wish you all the best. I will contribute to this forum once I become capable.