Наследование: IConnection
Пример #1
0
 public StatusMonitor()
 {
     _timer = new Timer(UpdateState, null, Timeout.Infinite, Timeout.Infinite);
     _connection = new Connection(Config.SignalRServer);
     _connection.Error += ConnectionOnError;
     _connection.Received += ConnectionOnReceived;
 }
Пример #2
0
        static void Main(string[] args)
        {
            Task.Run(async () =>
            {
                var conHub = new HubConnection("http://localhost:8080/");
                conHub.CreateHubProxy("Shell").On<ShellCommandParams>("cmd", (data) =>
                {
                });

                using (var con = new Connection("http://localhost:8080/api/cmd"))
                {
                    con.Received += (data) =>
                    {
                        Console.WriteLine($"ola, recebi! {data}");
                    };
                    con.StateChanged += (state) =>
                    {
                        if (state.NewState != state.OldState)
                        {
                            Console.WriteLine($"De {state.OldState} para {state.NewState}");
                        }
                    };
                    await con.Start();

                    await con.Send("Hello Mello");
                }
            }).Wait();

        }
Пример #3
0
        public ActivityClient( string ip, int port, IDevice device, bool useCache = true )
        {
            LocalCaching = useCache;

            InitializeEvents();

            Ip = ip;
            Port = port;

            Address = Net.GetUrl( ip, port, "" ).ToString();

            Device = device;

            try
            {
                _eventHandler = new Connection(Address);
                _eventHandler.JsonSerializer.TypeNameHandling = TypeNameHandling.Objects;
                _eventHandler.Received += eventHandler_Received;
                _eventHandler.Start().Wait();
            }
            catch(HttpClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #4
0
 public RootControl()
 {
     InitializeComponent();
     XmlConfigurator.Configure();
     NetworkChange.NetworkAvailabilityChanged += (s, e) =>
     {
         Console.WriteLine(e.IsAvailable);
     };
     this.Loaded += (s, e) =>
     {
         connection = new Connection(AppConfig.Host + "/Connections/PadControl");
         connection.Received += Connection_Received;
         connection.StateChanged += Connection_StateChanged;
         connection.Closed += Connection_Closed;
         connection.ConnectionSlow += Connection_ConnectionSlow;
         connection.Start();
         if (!AppConfig.AutoScale)
         {
             Window window = Window.GetWindow(this);
             window.WindowState = WindowState.Normal;
             Int32Rect displayBounds = AppConfig.DisplayBound;
             window.Left = displayBounds.X;
             window.Top = displayBounds.Y;
             window.Width = displayBounds.Width;
             window.Height = displayBounds.Height;
         }
     };
  
 }
Пример #5
0
        public void AppendCustomQueryStringAppendsConnectionQueryString(string connectionQs, string expected)
        {
            var connection = new Connection("http://foo.com", connectionQs);

            var urlQs = TransportHelper.AppendCustomQueryString(connection, "http://foo.com");

            Assert.Equal(urlQs, expected);
        }
 public void Dispose()
 {
     if (_conn != null)
     {
         _conn.Stop();
         _conn = null;
     }
 }
Пример #7
0
        public void GetReceiveQueryStringAppendsConnectionQueryString(string connectionQs, string expected)
        {
            var connection = new Connection("http://foo.com", connectionQs);
            connection.ConnectionToken = "";

            var urlQs = TransportHelper.GetReceiveQueryString(connection, null, "");

            Assert.True(urlQs.EndsWith(expected));
        }
Пример #8
0
 protected Connection CreateConnection(string url)
 {
     string testName = GetTestName() + "." + Interlocked.Increment(ref _id);
     var query = new Dictionary<string, string>();
     query["test"] = testName;
     var connection = new Connection(url, query);
     connection.TraceWriter = HostedTestFactory.CreateClientTraceWriter(testName);
     return connection;
 }
		public ConnectionService (string connectionUri)
		{
			connection = new Connection (connectionUri);
			connection.TraceLevel = Microsoft.AspNet.SignalR.Client.TraceLevels.All;
			connection.Closed += Connection_Closed;
			connection.Error += Connection_Error;
			connection.Received += Connection_Received;
			connection.Reconnecting += Connection_Reconnecting;
			connection.Reconnected += Connection_Reconnected;
		}
Пример #10
0
        public Cache(string server)
        {
            if (!server.EndsWith("/"))
            {
                server += "/";
            }

            _connection = new Connection(server + "cache");
            _connection.Received += OnCacheEntryReceived;
        }
Пример #11
0
        public void NoReconnectsAfterFallback()
        {
            // There was a regression where the SSE transport would try to reconnect after it times out.
            // This test ensures that no longer happens.
            // #2180
            using (var host = new MemoryHost())
            {
                var myReconnect = new MyReconnect();

                host.Configure(app =>
                {
                    Func<AppFunc, AppFunc> middleware = (next) =>
                    {
                        return env =>
                        {
                            var request = new OwinRequest(env);
                            var response = new OwinResponse(env);

                            if (!request.Path.Value.Contains("negotiate") && !request.QueryString.Value.Contains("longPolling"))
                            {
                                response.Body = new MemoryStream();
                            }

                            return next(env);
                        };
                    };

                    app.Use(middleware);

                    var config = new ConnectionConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    config.Resolver.Register(typeof(MyReconnect), () => myReconnect);

                    app.MapSignalR<MyReconnect>("/echo", config);
                });

                var connection = new Connection("http://foo/echo");

                using (connection)
                {
                    connection.Start(host).Wait();

                    // Give SSE an opportunity to reconnect
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    Assert.Equal(connection.State, ConnectionState.Connected);
                    Assert.Equal(connection.Transport.Name, "longPolling");
                    Assert.Equal(0, myReconnect.Reconnects);
                }
            }
        }
Пример #12
0
        public async Task RunAsync(string url)
        {
            _connection = new Connection(url);
            _connection.TraceWriter = _traceWriter;
            _connection.Received += (data) =>
            {
                _traceWriter.WriteLine("received: " + data);
            };

            await _connection.Start();
            await _connection.Send(new { Type = "sendToMe", Content = "Hello World!" });
        }
Пример #13
0
        public void OnInitializedFiresFromInitializeMessage()
        {
            bool timedOut, disconnected, triggered = false;
            var connection = new Connection("http://foo.com");

            TransportHelper.ProcessResponse(connection, "{\"S\":1, \"M\":[]}", out timedOut, out disconnected, () =>
            {
                triggered = true;
            });

            Assert.True(triggered);
        }
Пример #14
0
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += (s, e) =>
            {
                connection = new Connection(AppConfig.Host + "/Connections/PadControl");
                connection.Received += Connection_Received;
                connection.StateChanged += Connection_StateChanged;
                connection.Closed += Connection_Closed;
                connection.ConnectionSlow += Connection_ConnectionSlow;
                connection.Start();
            };
        }
        public void Setup()
        {
            _signalRReceived = new List<object>();
            _connection = new Connection("http://localhost:8989/signalr/rootfolder");
            _connection.Start(new LongPollingTransport()).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Assert.Fail("SignalrConnection failed. {0}", task.Exception.GetBaseException());
                }
            });

            _connection.Received += _connection_Received;
        }
Пример #16
0
        static void Connect(Microsoft.AspNet.SignalR.Client.Connection connection)
        {
            Logger.Info("SignalR: Starting connection");

            try
            {
                connection.Start(new LongPollingTransport()).Wait();
            }
            catch (Exception exception)
            {
                Logger.Error(MaybeAggregateException(exception),
                             "SignalR: Could not start connection");
                throw;
            }
        }
 public SignalRMessageBus(SignalRScaleoutConfiguration scaleoutConfiguration, IDependencyResolver dependencyResolver)
     : base(dependencyResolver, scaleoutConfiguration)
 {
     _connection = new Connection(scaleoutConfiguration.ServerUri.ToString());
     _connection.Closed += connectionOnClosed;
     _connection.Received += notificationRecieved;
     _connection.Error += onConnectionOnError;
     var startTask = _connection.Start();
     startTask.ContinueWith(t =>
         {
             if (t.IsFaulted && t.Exception != null)
                 throw t.Exception.GetBaseException();
         }, TaskContinuationOptions.OnlyOnFaulted);
     startTask.ContinueWith(_ => Open(streamIndex), TaskContinuationOptions.OnlyOnRanToCompletion);
 }
Пример #18
0
        public ActionResult Test(string input)
        {
            // Connect to the service
            var connection = new Connection("http://squarepegio.apphb.com/echo");

            // Print the message when it comes in
            connection.Received += data => Console.WriteLine(data);

            // Start the connection
            connection.Start().Wait();

            connection.Send(input).Wait();

            return null;
        }
        //leaving this as a compleately seperate system to event sending for now
        public static void Increment(string key)
        {
            // locking this operation so that it's thread safe
            if (incrementPersistantConnection == null)
            {
                lock (connectionLock)
                {
                    //Console.WriteLine("Creating new persistant connection");
                    incrementPersistantConnection = new Connection(connectionUrl + "events/increment");
                    incrementPersistantConnection.Start().Wait();
                    //Console.WriteLine("Connection created");
                }
            }

            incrementPersistantConnection.Send(key);
        }
Пример #20
0
        static void Main(string[] args)
        {
            var connection = new Connection("http://localhost:3669/sensor/events");

            connection.Start().Wait();

            connection.AsObservable<SensorEvent>()
                .GroupBy(e => e.SensorId)
                .CombineLatest()
                .Select(latest => latest.Where(e => e.Reading > 0.75).ToList())
                .Where(latest => latest.Count() >= 2)
                .Subscribe(latest => Console.WriteLine("Sensors {0} show readings greater than 0.75", string.Join(",", latest.Select(e => e.SensorId))));

            Console.Read();

            connection.Stop();
        }
 public async Task Start()
 {
     if (_conn != null)
     {
         return;
     }
     _conn = new Connection2(Urls.RealTimeMessaging);
     _conn.Headers["ak"]   = App.Apikey;
     _conn.Headers["e"]    = App.Environment.ToString();
     _conn.Received       += OnReceived;
     _conn.Closed         += OnClosed;
     _conn.ConnectionSlow += OnConnectionSlow;
     _conn.Error          += OnError;
     _conn.Reconnected    += OnReconnected;
     _conn.Reconnecting   += OnReconnecting;
     _conn.StateChanged   += OnStatechange;
     await _conn.Start();
 }
Пример #22
0
        static void Main(string[] args)
        {
            // Connect to the service
            var connection = new Connection("http://localhost:6820/echo");

            // Print the message when it comes in
            connection.Received += data => Console.WriteLine(data);

            // Start the connection
            connection.Start().Wait();

            string line = null;
            while ((line = Console.ReadLine()) != null)
            {
                // Send a message to the server
                connection.Send(line).Wait();
            }
        }
Пример #23
0
        public static void Start()
        {
            const string url = "http://*****:*****@ {1}",connection.Url,DateTime.Now));
                                //Just a sample to test the concept
                                Thread.Sleep(2000);
                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                        }
                    }
                }));

            Console.ReadLine();
            //server.Dispose();
        }
 public SignalRMessageBus(SignalRScaleoutConfiguration scaleoutConfiguration, IDependencyResolver dependencyResolver)
     : base(dependencyResolver, scaleoutConfiguration)
 {
     _connection = new Connection(scaleoutConfiguration.ServerUri.ToString());
     _connection.Received += notificationRecieved;
     _connection.Error += e =>
         {
             Debug.WriteLine(e.ToString());
             OnError(0, e);
         };
     startTask = _connection.Start();
     startTask.ContinueWith(t =>
         {
             throw t.Exception.GetBaseException();
         }, TaskContinuationOptions.OnlyOnFaulted);
     startTask.ContinueWith(_ =>
         {
             Open(StreamIndex);
         }, TaskContinuationOptions.OnlyOnRanToCompletion);
 }
Пример #25
0
        static void Main(string[] args)
        {
            try
            {
                var connection = new Connection("http://slabsignalrdemo.azurewebsites.net/semanticLogging");
                

                connection.Received += data =>
                    {
                        Console.WriteLine(data);
                    };

                connection.Start().ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                        Console.WriteLine("There was an error opening the connection:{0}",
                                          task.Exception.GetBaseException());
                    }
                    else
                    {
                        Console.WriteLine("Connected");
                    }

                }).Wait();

                connection.Error += Console.WriteLine;


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Press enter to close");
            Console.ReadLine();

        }
Пример #26
0
        public ActivityClient( string ip, int port, IDevice device )
        {
            Ip = ip;
            Port = port;

            Address = Net.GetUrl( ip, port, "" ).ToString();

            Device = device;

            Initialize();

            try
            {
                _eventHandler = new Connection(Address);
                _eventHandler.Received += eventHandler_Received;
                _eventHandler.Start().Wait();
            }
            catch(HttpClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            var connection = new Connection("http://localhost:52029/echo");

            connection.Received += data =>
            {
                Console.WriteLine(data);
            };

            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);
                    // Do more stuff here
                }
            });
        }
Пример #28
0
 public ConnectionDown(Microsoft.AspNet.SignalR.Client.Connection connection)
 {
     Connection = connection;
 }
 public async Task Start()
 {
     if (_conn != null)
         return;
     _conn = new Connection2(Urls.RealTimeMessaging);
     _conn.Headers["ak"] = App.Apikey;
     _conn.Headers["e"] = App.Environment.ToString();
     _conn.Received += OnReceived;
     _conn.Closed += OnClosed;
     _conn.ConnectionSlow += OnConnectionSlow;
     _conn.Error += OnError;
     _conn.Reconnected += OnReconnected;
     _conn.Reconnecting += OnReconnecting;
     _conn.StateChanged += OnStatechange;
     await _conn.Start();
 }
 public void Stop()
 {
     if (_conn != null)
     {
         _conn.Stop();
         _conn = null;
     }
 }
Пример #31
0
        protected void ConnectSignalR()
        {
            _signalRReceived = new List<SignalRMessage>();
            _signalrConnection = new Connection("http://localhost:8989/signalr");
            _signalrConnection.Start(new LongPollingTransport()).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Assert.Fail("SignalrConnection failed. {0}", task.Exception.GetBaseException());
                }
            });

            var retryCount = 0;

            while (_signalrConnection.State != ConnectionState.Connected)
            {
                if (retryCount > 25)
                {
                    Assert.Fail("Couldn't establish signalr connection. State: {0}", _signalrConnection.State);
                }

                retryCount++;
                Console.WriteLine("Connecting to signalR" + _signalrConnection.State);
                Thread.Sleep(200);
            }

            _signalrConnection.Received += json => _signalRReceived.Add(Json.Deserialize<SignalRMessage>(json)); ;
        }
Пример #32
0
        public void IntegrationTearDown()
        {
            if (_signalrConnection != null)
            {
                switch (_signalrConnection.State)
                {
                    case ConnectionState.Connected:
                    case ConnectionState.Connecting:
                        {
                            _signalrConnection.Stop();
                            break;
                        }
                }

                _signalrConnection = null;
                _signalRReceived = new List<SignalRMessage>();
            }
        }
Пример #33
-1
 public ClientServerMemoryRun(RunData runData)
     : base(runData)
 {
     _connections = new Connection[runData.Connections];
     for (int i = 0; i < runData.Connections; i++)
     {
         _connections[i] = new Connection("http://memoryhost/echo");
     }
 }