Inheritance: IEnvironmentConnection
コード例 #1
0
        /// <summary>
        /// Saves the specified connection - method provided for testing.
        /// </summary>
        /// <param name="jsonObj"></param>
        /// <param name="defaultEnvironment">The environment where the connection will be saved - must ALWAYS be .</param>
        /// <exception cref="System.ArgumentNullException">connectionID</exception>
        public void Save(dynamic jsonObj, IEnvironmentModel defaultEnvironment)
        {
            if(jsonObj == null)
            {
                throw new ArgumentNullException();
            }
            Connection newConnection = JsonConvert.DeserializeObject<Connection>(jsonObj.ToString());

            var resourceId = newConnection.ResourceID;
            ServerProxy connection;
            if(newConnection.AuthenticationType == AuthenticationType.Windows || newConnection.AuthenticationType == AuthenticationType.Anonymous)
            {
                connection = new ServerProxy(new Uri(newConnection.WebAddress));
            }
            else
            {
                //
                // NOTE: Public needs to drop through to User for the rest of the framework to pick up properly behind the scenes ;)
                //
                connection = new ServerProxy(newConnection.WebAddress, newConnection.UserName, newConnection.Password);
            }
            var environmentModel = CurrentEnvironmentRepository.Get(resourceId);
            if(environmentModel == null)
            {
                var newEnvironment = new EnvironmentModel(resourceId, connection) { Name = newConnection.ResourceName, Category = newConnection.ResourcePath };
                CurrentEnvironmentRepository.Save(newEnvironment);
            }
            else
            {
                environmentModel.Connection = connection;
                environmentModel.Name = newConnection.ResourceName;
                environmentModel.Category = newConnection.ResourcePath;
            }
        }
コード例 #2
0
ファイル: TestHelper.cs プロジェクト: ndubul/Chillas
 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);
            

        }
コード例 #4
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);
           
        }
コード例 #6
0
 static IEnvironmentModel CreateEnvironmentModel(Guid id, Uri applicationServerUri, string alias)
 {
     var acutalWebServerUri = new Uri(applicationServerUri.ToString().Replace("localhost", Environment.MachineName));
     var environmentConnection = new ServerProxy(acutalWebServerUri);
     return new EnvironmentModel(id, environmentConnection) { Name = alias };
 }
コード例 #7
0
        static IEnvironmentModel CreateEnvironmentModel(Connection connection)
        {
            var resourceId = connection.ResourceID;
            ServerProxy connectionProxy;
            if (connection.AuthenticationType == AuthenticationType.Windows || connection.AuthenticationType == AuthenticationType.Anonymous)
            {
                connectionProxy = new ServerProxy(new Uri(connection.WebAddress));
            }
            else
            {
                var userName = connection.UserName;
                var password = connection.Password;
                if (connection.AuthenticationType == AuthenticationType.Public)
                {
                    userName = "******";
                    password = "";
                }

                connectionProxy = new ServerProxy(connection.WebAddress, userName, password);
            }
            return new EnvironmentModel(resourceId, connectionProxy) { Name = connection.ResourceName };
        }
コード例 #8
0
 static IEnvironmentModel CreateEnvironmentModel(Guid id, Uri applicationServerUri, AuthenticationType authenticationType, string userName, string password, string name)
 {
     ServerProxy connectionProxy;
     if (authenticationType == AuthenticationType.Windows || authenticationType == AuthenticationType.Anonymous)
     {
         connectionProxy = new ServerProxy(applicationServerUri);
     }
     else
     {
         if (authenticationType == AuthenticationType.Public)
         {
             userName = "******";
             password = "";
         }
         connectionProxy = new ServerProxy(applicationServerUri.ToString(), userName, password);
     }
     return new EnvironmentModel(id, connectionProxy) { Name = name };
 }
コード例 #9
0
 static IEnvironmentConnection SetupEnvironmentConnection()
 {
     IEnvironmentConnection connection = new ServerProxy(new Uri(ServerSettings.DsfAddress));
     return connection;
 }