Connect() публичный Метод

public Connect ( System.Guid id ) : void
id System.Guid
Результат void
Пример #1
0
 public static string ExecuteServiceOnLocalhostUsingProxy(string serviceName, Dictionary<string,string> payloadArguments)
 {
     CommunicationControllerFactory fact = new CommunicationControllerFactory();
     var comm = fact.CreateController(serviceName);
     var prx = new ServerProxy("http://localhost:3142", CredentialCache.DefaultNetworkCredentials, new TestAsyncWorker());
     prx.Connect(Guid.NewGuid());
     foreach (var payloadArgument in payloadArguments)
     {
         comm.AddPayloadArgument(payloadArgument.Key, payloadArgument.Value);
     }
     if(comm != null)
     {
         var messageToExecute = comm.ExecuteCommand<ExecuteMessage>(prx, Guid.Empty);
         if(messageToExecute != null)
         {
             var responseMessage = messageToExecute.Message;
             if(responseMessage != null)
             {
                 var actual = responseMessage.ToString();
                 return actual;
             }
             return "Error: response message empty!";
         }
         return "Error: message to send to localhost server could not be generated.";
     }
     return "Error: localhost server controller could not be created.";
 }
        public void ServerProxy_FallbackOnConnect()
        {
            //------------Setup for test--------------------------
            var serverProxy = new ServerProxy(new Uri("http://bob"));
            var serverGuid = Guid.NewGuid();
            PrivateObject p = new PrivateObject(serverProxy);
            var wrapped = new Mock<IEnvironmentConnection>();
            wrapped.Setup(a => a.DisplayName).Returns("moo");
            wrapped.Setup(a => a.Connect(It.IsAny<Guid>())).Throws(new FallbackException());
            wrapped.Setup(a => a.WebServerUri).Returns( new Uri("http://bob"));
            p.SetField("_wrappedConnection", wrapped.Object);
   
            try
            {
                serverProxy.Connect(serverGuid);

            }
            // ReSharper disable EmptyGeneralCatchClause
            catch(Exception err)
            {

               Assert.IsNotNull(err);
            }
            var con = p.GetField("_wrappedConnection") as IEnvironmentConnection;
            Assert.IsNotNull(con);
            Assert.AreNotEqual(con,wrapped.Object);
            Assert.AreEqual("moo",con.DisplayName);
            

        }
Пример #3
0
        static void Main(string[] args)
        {
            string uri = "http://*****:*****@"C:\temp\networkSpeedTo{0}.csv", uri.Replace(':', '-').Replace('/', '_')); 

            // header
            timings.Add(string.Format("URI:, '{0}'", uri));
            timings.Add(string.Format("Max message size:, {0}, Initial block size:, {1}, Incrementing factor:, {2}, Rounds per packet size:, {3}", maxMessageSize, numberOfGuidsPerChunk, incrementingFactor, roundsPerPacketStep));

            using (var serverProxy = new ServerProxy(new Uri(uri)))
            {
                serverProxy.Connect(Guid.NewGuid());
                CommunicationControllerFactory cf = new CommunicationControllerFactory();
                while (sb.Length < maxMessageSize)
                {
                    timingsPerRound.Clear();
                    for (int i = 0; i < roundsPerPacketStep; i++)
                    {
                        var controller = cf.CreateController("TestNetworkService");
                        controller.AddPayloadArgument("payload", sb);
                        DateTime start = DateTime.Now;
                        // send very large message
                        var svc = controller.ExecuteCommand<ExecuteMessage>(serverProxy, Guid.NewGuid());

                        TimeSpan elapsed = DateTime.Now - start;
                        timingsPerRound.Add(elapsed.TotalMilliseconds);

                        // give the server time to clear it's queue 
                        Thread.Sleep((int)Math.Round(elapsed.TotalMilliseconds) * 2);
                    }
                    string toAdd = string.Format("{0}, {1}", sb.Length, timingsPerRound.Sum() / roundsPerPacketStep);
                    Console.WriteLine(toAdd);
                    timings.Add(toAdd);
                    // build new packet that is incrementingFactor bigger than previous
                    StringBuilder tmpSb = new StringBuilder();
                    tmpSb.Append(sb);
                    Enumerable.Range(1, (int)Math.Ceiling(incrementingFactor)).ToList().ForEach(x =>
                    tmpSb.Append(tmpSb.ToString()));
                    sb.Append(tmpSb.ToString().Substring(0,
                        (int)((tmpSb.Length - sb.Length) * (incrementingFactor - 1))));
                }
            }
            File.WriteAllLines(outFileName, timings.ToArray());
            //Console.ReadKey();
        }
        public void ServerProxy_FallbackOnConnectWithError()
        {
            //------------Setup for test--------------------------
            var serverProxy = new ServerProxy(new Uri("http://bob"));
            var serverGuid = Guid.NewGuid();
            PrivateObject p = new PrivateObject(serverProxy);
            var wrapped = new Mock<IEnvironmentConnection>();
            var fallback = new Mock<IEnvironmentConnection>();
            wrapped.Setup(a => a.Connect(It.IsAny<Guid>())).Throws(new FallbackException());
            p.SetField("_wrappedConnection",wrapped.Object);
            try
            {
                serverProxy.Connect(serverGuid);
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {

            }
            var con = p.GetField("_wrappedConnection");
            Assert.IsNotNull(con);
           
        }