Last active
August 29, 2015 14:22
-
-
Save biochimia/fea40facb64b2f3efb20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<App xmlns:b="Fuse.BasicTheme" ux:Class="Example.Network.MainView"> | |
<b:BasicTheme /> | |
<DockPanel> | |
<StatusBarBackground DockPanel.Dock="Top" /> | |
<Button DockPanel.Dock="Top" Text="Send Requests" Clicked="SendRequests" /> | |
<StackPanel DockPanel.Dock="Bottom"> | |
<StackPanel Orientation="Horizontal" Alignment="Center"> | |
<Button Text="Sent: 0" ux:Name="RequestsSent" /> | |
<Button Text="Successful: 0" ux:Name="RequestsSuccessful" /> | |
</StackPanel> | |
<StackPanel Orientation="Horizontal" Alignment="Center"> | |
<Button Text="Errors: 0" ux:Name="RequestErrors" /> | |
<Button Text="Aborted: 0" ux:Name="RequestsAborted" /> | |
<Button Text="Timed out: 0" ux:Name="RequestsTimedOut" /> | |
</StackPanel> | |
</StackPanel> | |
<Panel> | |
<ScrollViewer> | |
<StackPanel ux:Name="Log" /> | |
</ScrollViewer> | |
</Panel> | |
</DockPanel> | |
</App> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Uno; | |
using Uno.Net.Http; | |
namespace Example.Network | |
{ | |
public partial class MainView | |
{ | |
int iteration = 0; | |
int requestsSent = 0; | |
int requestsSuccessful = 0; | |
int requestsAborted = 0; | |
int requestsTimedOut = 0; | |
int requestsErrored = 0; | |
void GetAsync(HttpMessageHandler messageHandler, string url) | |
{ | |
var request = messageHandler.CreateRequest("GET", url); | |
request.Aborted += OnRequestAborted; | |
request.Done += OnRequestDone; | |
request.Error += OnRequestError; | |
request.Timeout += OnRequestTimeout; | |
request.SetTimeout(2000); | |
request.SetResponseType(HttpResponseType.String); | |
request.SendAsync(); | |
RequestsSent.Text = "Sent: " + ++requestsSent; | |
} | |
void SendRequests(object sender, EventArgs args) | |
{ | |
int currentIteration = iteration++; | |
AppendToLog("Sending requests for iteration: " + currentIteration); | |
var messageHandler = new HttpMessageHandler(); | |
GetAsync(messageHandler, "http://www.example.org/?data=" + currentIteration); | |
GetAsync(messageHandler, "https://jigsaw.w3.org/HTTP/cc.html?data=" + currentIteration); | |
GetAsync(messageHandler, "http://en.wikipedia.org/wiki/Special:Random"); | |
// Should error | |
GetAsync(messageHandler, "http://i.do.not.exist"); | |
// Should timeout :-) | |
GetAsync(messageHandler, "http://www.google.com:81"); | |
} | |
void OnRequestTimeout(HttpMessageHandlerRequest request) | |
{ | |
RequestsTimedOut.Text = "Timeout: " + ++requestsTimedOut; | |
AppendToLog(request, "Request timed out"); | |
} | |
void OnRequestAborted(HttpMessageHandlerRequest request) | |
{ | |
RequestsAborted.Text = "Aborted: " + ++requestsAborted; | |
AppendToLog(request, "ABORTED!"); | |
} | |
void OnRequestDone(HttpMessageHandlerRequest request) | |
{ | |
RequestsSuccessful.Text = "Done: " + ++requestsSuccessful; | |
AppendToLog(request, "Done! :-)"); | |
} | |
void OnRequestError(HttpMessageHandlerRequest request, string error) | |
{ | |
RequestErrors.Text = "Errors: " + ++requestsErrored; | |
AppendToLog(request, "ERROR: " + error); | |
} | |
void AppendToLog(HttpMessageHandlerRequest request, string event_) | |
{ | |
AppendToLog(request.Url + " - " + event_); | |
} | |
void AppendToLog(string message) | |
{ | |
debug_log message; | |
var logEntry = new Fuse.Controls.Text(); | |
logEntry.TextWrapping = Fuse.Elements.TextWrapping.Wrap; | |
logEntry.Content = message; | |
Log.Children.Add(logEntry); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<References> | |
<PackageReference Name="Uno.Net.Http" /> | |
<PackageReference Name="FuseCore" /> | |
<PackageReference Name="Fuse.BasicTheme" /> | |
<PackageReference Name="Fuse.Controls" /> | |
<PackageReference Name="Fuse.Elements" /> | |
</References> | |
<Files> | |
<UXFile Name="MainView.ux" /> | |
<SourceFile Name="MainView.ux.uno" /> | |
</Files> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment