Rx for .net
-
Upload
dotnetusergroupdnipro -
Category
Documents
-
view
1.070 -
download
0
Transcript of Rx for .net
Reactive Extensions for .NET, Rx
One of the most powerful extensions for .NET Framework
Ievgen Olieniev.Net Senior Developer
Soft Serve
THE FIRST APPEARANCE IN THE WORLD:
July 2009
Silverligh 3 Toolkit
Unit Tests
CURRENT SITUATION:
.NET 4.0Silverligh 4.0
Includes libraries:• System.CoreEx.dll• System.Interactive.dll• System.Observable.dll• System.Reactive.dll• System.Reactive.Testing.dll
THE ITERATOR PATERN
IEnumerable<T>
• IEnumerator<T> GetEnumerator()
IEnumerator<T>
• bool MoveNext()• Reset()• T Current
PULLING DATA FROM A SOURCE
int[] numbers = new int[] { 20, 31, 5, 16, 22 };
IEnumerable<int> numbersSmallerThan20 = numbers.Where(number => number < 20);
5, 16, break
IEnumerable<int> NaturalNumbers(){
int number = 0;while (true){
yield return number;number++;
}}
0,1,2,3,4,5,6…
REACTIVE PROGRAMMING
button.MouseMove += (s, args) => Debug.WriteLine("You moved the mouse to {0}",
args.GetPosition(button));
“You moved the mouse to 20,3”
“You moved the mouse to 33,12”
“You moved the mouse to 44,18”
DownloadFile("http://www.jeffwilcox.com", (byteArray) => Debug.WriteLine("This file is {0} bytes long.",
byteArray.Length);
“This file is 12323 bytes long.”
EVENTS AND CALLBACKS ARE
SEQUENCES OF DATA!
new MouseEventArgs(new Point(20,3)),new MouseEventArgs(new Point(33,12)),
new MouseEventArgs(new Point(44,18))…
new byte[]{23,211,33,23…}, break
A NEW LOOK AT THE OBSERVER PATTERN
IEnumerable<T>
• IEnumerator<T> GetEnumerator()
IEnumerator<T>
• bool MoveNext()• Reset()• T Current
IObservable<T>
• IDisposable<T> Subscribe(IObserber<T>)
IObserver<T>
• void OnNext()• void OnCompleted()• void OnError(Exception ex)
UNIT TESTING SL UI WITH RX
Rating rating = new Rating();
IObservable<Unit> test = ObservableExtensions .DoAsync(() => TestPanel.Children.Add(rating)) // add a control to a panel .WaitFor(TestPanel.GetLayoutUpdated()) // listen to LayoutUpdated event .DoAsync(() => rating.Value = 1.0) // set a property .WaitFor( rating.GetActualValueChanged() // listen to ActualValueChanged event .SkipWhile(actualValueChangedEvent => actualValueChangedEvent.EventArgs.NewValue != rating.Value)) .Assert(() => rating.GetRatingItems().Last().ActualValue == 1.0); // Assert
// run the test and clean up at the endtest.Subscribe(() => TestPanel.Children.Remove(rating));
INFO REFERENCES:
• Introducing Rx (Linq to Events) - http://themechanicalbride.blogspot.com/2009/07/introducing-rx-linq-to-events.html
• A Brief Introduction to the Reactive Extensions for .NET, Rx - http://blogs.msdn.com/b/wesdyer/archive/2009/11/18/a-brief-introduction-to-the-reactive-extensions-for-net-rx.aspx
• First encounters with Reactive Extensions -http://msmvps.com/blogs/jon_skeet/archive/2010/01/16/first-encounters-with-reactive-extensions.aspx
• LINQ to Rx: second impressions - http://msmvps.com/blogs/jon_skeet/archive/2010/01/19/linq-to-rx-second-impressions.aspx
• DevLabs: Reactive Extensions for .NET (Rx) -http://rxwiki.wikidot.com/
DOWNLOAD REFERENCES:
• Rx for Silverlight 4 - http://go.microsoft.com/fwlink/?LinkId=182998
• Rx for .NET Framework 4.0 - http://go.microsoft.com/fwlink/?LinkId=182997
• Rx for JavaScript - http://msdn.microsoft.com/devlabs/ff628422
• Rx for .NET Framework 3.5 SP1 - http://go.microsoft.com/fwlink/?LinkId=182996
Thank You!