当前位置: 首页>>代码示例>>C#>>正文


C# Route.Connect方法代码示例

本文整理汇总了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;
 }
开发者ID:systemmetaphor,项目名称:BlueDwarf,代码行数:41,代码来源:ProxyAnalyzer.cs

示例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)
            { }
        }
开发者ID:systemmetaphor,项目名称:BlueDwarf,代码行数:48,代码来源:BlueDwarfApplication.xaml.cs

示例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)
     { }
 }
开发者ID:systemmetaphor,项目名称:BlueDwarf,代码行数:25,代码来源:BlueDwarfApplication.xaml.cs


注:本文中的Route.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。