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


C# HubConnection.Dispose方法代码示例

本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# HubConnection.Dispose方法的具体用法?C# HubConnection.Dispose怎么用?C# HubConnection.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNet.SignalR.Client.HubConnection的用法示例。


在下文中一共展示了HubConnection.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BenchmarkMessages

		public void BenchmarkMessages()
		{
			var port = new Random().Next(20000, 60000);

			GlobalHost.Configuration.DefaultMessageBufferSize = 2000; // maximum number of messages to buffer
			GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
			GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(15); // auto set keepalive to 5

			var url = "http://localhost:" + port + "/";
			var server = WebApp.Start<Startup>(url);
			var client = new HubConnection(url + "s1");
			var proxy = client.CreateHubProxy("ISumService");
			client.Start().Wait();

			Assert.Equal(ConnectionState.Connected, client.State);

			const int randCnt = 100;
			var rand = new Random(42);
			var randoms = new int[randCnt];
			for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000);

			var sw = new Stopwatch();
			long timeFromClient = 0, timeToClient = 0;
			const int cnt = 1000;
			for (int j = 0; j < cnt; j++)
			{
				sw.Start();
				var sum = proxy.Invoke<int>("Sum", randoms).Result;
				sw.Stop();
				Assert.Equal(randoms.Sum(), sum);
				for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000);
				var times = proxy.Invoke<Tuple<long,long>>("TimeDiff", Stopwatch.GetTimestamp()).Result;
				timeFromClient += times.Item1;
				timeToClient += Stopwatch.GetTimestamp() - times.Item2;
			}

			_testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds);
			_testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10);
			_testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10);

			sw.Reset();
			var tree = new SumServiceTree();
			SumServiceTree.FillTree(tree, rand, 2);
			_testOutputHelper.WriteLine("Starting large message transfer.");
			sw.Start();
			var result = proxy.Invoke<SumServiceTree>("Increment", tree).Result;
			sw.Stop();
			Assert.Equal(tree.Leaf + 1, result.Leaf);
			_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds);

			client.Dispose();
			server.Dispose();
		}
开发者ID:BrannonKing,项目名称:Kts.Remoting,代码行数:53,代码来源:SignalR.cs

示例2: EndToEndHub

		public async Task EndToEndHub ()
		{
			var sessionId = Guid.NewGuid().ToString();
			var clients = 0;

			var pubConn = new HubConnection(ThisAssembly.HubUrl);
			var pubProxy = pubConn.CreateHubProxy("FormsPlayer");

			var subConn = new HubConnection(ThisAssembly.HubUrl);
			var subProxy = subConn.CreateHubProxy("FormsPlayer");

			var xamls = new List<string>();
			var jsons = new List<string>();

			pubProxy.On<int> ("Connected", count => clients = count);

			subProxy.On<string> ("Xaml", xaml => xamls.Add (xaml));
			subProxy.On<string> ("Json", json => jsons.Add (json));

			await pubConn.Start ();
			await subConn.Start ();

			await pubProxy.Invoke ("Join", sessionId);
			await subProxy.Invoke ("Join", sessionId);

			SpinWait.SpinUntil (() => clients == 2, 1000);

			// Count will be 1+ than actual "clients", since the publisher/VS is also a client.
			Assert.Equal (2, clients);

			await pubProxy.Invoke ("Xaml", sessionId, "xaml");
			await pubProxy.Invoke ("Xaml", Guid.NewGuid ().ToString (), "xaml");
			await pubProxy.Invoke ("Json", sessionId, "json");
			await pubProxy.Invoke ("Json", Guid.NewGuid ().ToString (), "json");

			Assert.Equal (1, xamls.Count);
			Assert.Equal (1, jsons.Count);

			Assert.Equal ("xaml", xamls[0]);
			Assert.Equal ("json", jsons[0]);

			subConn.Dispose ();

			SpinWait.SpinUntil (() => clients == 1, 1000);
			Assert.Equal (1, clients);
		}
开发者ID:null-directory,项目名称:FormsPlayer,代码行数:46,代码来源:HubTests.cs

示例3: EnsureProxy

        private async Task<bool> EnsureProxy()
        {
            if (HubProxy != null)
                return true;

            Connection = new HubConnection(ServerUri);
            HubProxy = Connection.CreateHubProxy("CustomerHub");

            // Register callbacks
            HubProxy.On<Customer>("Saved", OnCustomerSaved);
            HubProxy.On<Guid>("Deleted", OnCustomerDeleted);
            try
            {
                await Connection.Start();
                return true;
            }
            catch (HttpRequestException)
            {
                Connection.Dispose();
                Connection = null;
                MessageBox.Show("Unable to connect to server: Start server before connecting clients.");
                return false;
            }
        }
开发者ID:modulexcite,项目名称:CodeFluent-Entities,代码行数:24,代码来源:MainWindow.xaml.cs

示例4: Connect

        internal void Connect()
        {
            IsConnected = false;
            connection = new HubConnection ("http://formsplayer.azurewebsites.net/");
            proxy = connection.CreateHubProxy ("FormsPlayer");

            try {
                connection.Start ().Wait (3000);
                IsConnected = true;
                IdeApp.Workbench.StatusBar.ShowMessage (string.Format("Successfully connected to FormsPlayer. Session ID: {0}", SessionId));
            } catch (Exception e) {
                IdeApp.Workbench.StatusBar.ShowMessage (string.Format("Error connecting to FormsPlayer: {0}", e.Message));
                connection.Dispose ();
                Console.WriteLine (e);
            }
        }
开发者ID:prashantvc,项目名称:FormsPlayer,代码行数:16,代码来源:FormsPlayerPresenter.cs

示例5: OnWrite

        void OnWrite(string message)
        {
            if (proxy == null) {
                if (string.IsNullOrEmpty (Parameters))
                    // throw new LoggerException ("No build identifier was specified as a logger parameter.");
                    return;

                buildId = Parameters.Split (';')
                    .Select (x => x.Split ('='))
                    .Where (x => x.Length == 2 && x[0].Equals ("buildId", StringComparison.OrdinalIgnoreCase))
                    .Select (x => x[1])
                    .FirstOrDefault ();

                if (string.IsNullOrEmpty (buildId))
                    throw new LoggerException ("No buildId parameter value was specified as a logger parameter. Use buildId=ID after the logger assembly.");

                hubUrl = Parameters.Split (';')
                    .Select (x => x.Split ('='))
                    .Where (x => x.Length == 2 && x[0].Equals ("hubUrl", StringComparison.OrdinalIgnoreCase))
                    .Select (x => x[1])
                    .FirstOrDefault () ?? defaultHubUrl;

                connection = new HubConnection (hubUrl);
                proxy = connection.CreateHubProxy ("build");
                try {
                    connection.Start ().Wait (3000);
                    proxy.On ("Shutdown", () => shutDown.Set ());
                } catch (Exception e) {
                    Trace.WriteLine ("Failed to connect to " + hubUrl + ": " + e.ToString ());
                    connection.Dispose ();
                    connection = null;
                }
            }

            // If connection failed, the connection will be null.
            if (connection != null) {
                proxy.Invoke ("Message", buildId, message)
                    .ContinueWith (t =>
                        Trace.WriteLine ("Failed to publish message."),
                        CancellationToken.None,
                        TaskContinuationOptions.OnlyOnFaulted,
                        TaskScheduler.Default);
            }
        }
开发者ID:kzu,项目名称:CloudBuilder,代码行数:44,代码来源:Logger.cs

示例6: ConnectToServer

        protected virtual string ConnectToServer(Dev2.Data.ServiceModel.Connection connection)
        {
            // we need to grab the principle and impersonate to properly execute in context of the requesting user ;)
            var principle = Thread.CurrentPrincipal;
            var identity = principle.Identity as WindowsIdentity;
            WindowsImpersonationContext context = null;

            try
            {
                if(identity != null && connection.AuthenticationType == AuthenticationType.Windows)
                {
                    context = identity.Impersonate();
                }

                using(var client = new WebClient())
                {
                    if(connection.AuthenticationType == AuthenticationType.Windows)
                    {
                        client.UseDefaultCredentials = true;
                    }
                    else
                    {
                        client.UseDefaultCredentials = false;

                        //// we to default to the hidden public user name of \, silly know but that is how to get around ntlm auth ;)
                        if(connection.AuthenticationType == AuthenticationType.Public)
                        {
                            connection.UserName = GlobalConstants.PublicUsername;
                            connection.Password = string.Empty;
                        }

                        client.Credentials = new NetworkCredential(connection.UserName, connection.Password);
                    }

                    // Need to do hub connect here to get true permissions ;)
                    HubConnection hub = null;
                    try
                    {
                        // Credentials = client.Credentials 
                        hub = new HubConnection(connection.FetchTestConnectionAddress()) { Credentials = client.Credentials };
                        ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
#pragma warning disable 168
                        var proxy = hub.CreateHubProxy("esb"); // this is the magic line that causes proper validation
#pragma warning restore 168
                        hub.Start().Wait();

                        Dev2Logger.Log.Debug("Hub State : " + hub.State);

                        return "Success";
                    }
                        catch(Exception)
                        {
                            // Credentials = client.Credentials 
                            var hub2 = new HubConnectionWrapperOld(connection.FetchTestConnectionAddress()) { Credentials = client.Credentials };
                            ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
#pragma warning disable 168
                            var proxy = hub2.CreateHubProxy("esb"); // this is the magic line that causes proper validation
#pragma warning restore 168
                            hub2.Start().Wait();

                            Dev2Logger.Log.Debug("Hub State : " + hub2.State);

                            return "Success";
                        }
                    finally
                    {
                        if(hub != null)
                        {
                            hub.Stop();
                            hub.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if(context != null && connection.AuthenticationType == AuthenticationType.Windows)
                {
                    context.Undo();
                }
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:82,代码来源:Connections.cs

示例7: UpdateClients

 private void UpdateClients()
 {
     IHubProxy _hub;
     string url = @"http://www.duser.net/";
     var connection = new HubConnection(url);
     _hub = connection.CreateHubProxy("WeatherHub");
     connection.Start().Wait();
     _hub.Invoke("GetData").Wait();
     connection.Dispose();
 }
开发者ID:HenrikObsen,项目名称:WeatherLogger,代码行数:10,代码来源:WeatherLogger.cs


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