本文整理汇总了C#中Route.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# Route.Connect方法的具体用法?C# Route.Connect怎么用?C# Route.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route.Connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasurePerformance
/// <summary>
/// Measures the performance.
/// </summary>
/// <param name="route">The route.</param>
/// <param name="testTarget">The test target.</param>
/// <param name="tests">The tests.</param>
/// <returns>A performance value or null if performance could not be measured</returns>
public ProxyPerformance MeasurePerformance(Route route, Uri testTarget, int tests = 3)
{
try
{
var ping = TimeSpan.Zero;
var downloadTime = TimeSpan.Zero;
var downloadSize = 0;
var timer = new Stopwatch();
timer.Start();
for (int test = 0; test < tests; test++)
{
var t0 = timer.Elapsed;
using (var stream = route.Connect(testTarget, NameResolver))
{
var t1 = timer.Elapsed;
ping += t1 - t0;
HttpRequest.CreateGet(testTarget).Write(stream);
var t2 = timer.Elapsed;
var httpResponse = HttpResponse.FromStream(stream);
downloadSize += httpResponse.ReadContent(stream).Length;
var t3 = timer.Elapsed;
downloadTime += t3 - t2;
}
}
return new ProxyPerformance(TimeSpan.FromTicks(ping.Ticks / tests), downloadSize / downloadTime.TotalSeconds);
}
catch (ProxyRouteException)
{ }
catch (IOException)
{ }
catch (SocketException)
{ }
return null;
}
示例2: CheckUpdate
/// <summary>
/// Checks if there is an update available.
/// </summary>
/// <param name="route">The route.</param>
private void CheckUpdate(Route route)
{
if (SetupConfiguration.IsClickOnce)
return;
if (_updateChecked)
return;
try
{
using (var stream = route.Connect(_applicationUri, NameResolver))
{
_updateChecked = true;
var request = HttpRequest.CreateGet(_applicationUri);
request.Verb = "HEAD";
request.Write(stream);
var response = HttpResponse.FromStream(stream);
var lastModified = response.Headers["last-modified"].FirstOrDefault();
DateTime lastModifiedDate;
if (lastModified == null || !DateTime.TryParse(lastModified, out lastModifiedDate))
return;
var thisAssemblyPath = GetType().Assembly.Location;
var oldVersions = Directory.GetFiles(Path.GetDirectoryName(thisAssemblyPath), Path.GetFileName(thisAssemblyPath) + ".old.*");
foreach (var oldVersion in oldVersions)
{
try
{
File.Delete(oldVersion);
}
catch (IOException)
{ }
}
var thisAssemblyDate = File.GetLastWriteTime(thisAssemblyPath);
if (thisAssemblyDate < lastModifiedDate)
LoadUpdate(route);
}
}
catch (ProxyRouteException)
{ }
}
示例3: LoadUpdate
/// <summary>
/// Loads the update.
/// </summary>
/// <param name="route">The route.</param>
private void LoadUpdate(Route route)
{
try
{
using (var stream = route.Connect(_applicationUri, NameResolver))
{
HttpRequest.CreateGet(_applicationUri).Write(stream);
var response = HttpResponse.FromStream(stream);
var applicationBytes = response.ReadContent(stream);
var thisAssemblyPath = GetType().Assembly.Location;
var oldPath = thisAssemblyPath + ".old." + Guid.NewGuid();
File.Move(thisAssemblyPath, oldPath);
File.Delete(thisAssemblyPath);
File.WriteAllBytes(thisAssemblyPath, applicationBytes);
Process.Start(thisAssemblyPath, Environment.CommandLine);
Environment.Exit(0);
}
}
catch (IOException)
{ }
}