public async Task IgnoresPasswordIfNotPremium()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));

                NetworkMessenger.Override(messenger);

                var settings = new UserSettings
                {
                    AdministratorPassword = "******",
                    IsPremium             = false
                };

                // We're not in the trial period
                var installationDateFetcher = Substitute.For <IInstallationDateFetcher>();

                installationDateFetcher.GetInstallationDate().Returns(DateTimeOffset.MinValue);
                var clock = Substitute.For <IClock>();

                clock.Now.Returns(DateTimeOffset.MinValue + AppConstants.TrialTime);

                var vm = new ConnectionViewModel(settings, () => "192.168.1.2", installationDateFetcher, clock);

                vm.Activator.Activate();

                await vm.ConnectCommand.ExecuteAsync();

                messenger.Received().ConnectAsync("192.168.1.1", settings.Port, new Guid(), null);
            }
Exemplo n.º 2
0
        public ConnectionData()
        {
            var aNodeViewModel = new NodeViewModel(100, 150, "A")
            {
                CanChange = false
            };
            var bNodeViewModel = new NodeViewModel(300, 150, "B")
            {
                CanChange = false
            };

            points.Add(aNodeViewModel);
            points.Add(bNodeViewModel);
            var connection = new ConnectionViewModel(aNodeViewModel, bNodeViewModel);

            connections.Add(connection);

            using (var values = Values().GetEnumerator())
            {
                Observable.Interval(TimeSpan.FromSeconds(2))
                .ObserveOn(App.Current.Dispatcher)
                .Subscribe(p =>
                {
                    values.MoveNext();

                    aNodeViewModel.Y = (int)(values.Current.x * 10);
                    bNodeViewModel.Y = (int)(values.Current.y * 10);
                });
            }
        }
            public async Task DoesntTryToDiscoverServerWithCustomIpAddressIfSet()
            {
                var settings = new UserSettings {
                    ServerAddress = "192.168.1.3"
                };

                bool discoverServerSubscribed = false;

                var messenger = Substitute.For <INetworkMessenger>();

                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>())
                .Returns(Observable.Defer(() => Observable.Start(() => discoverServerSubscribed = true).Select(_ => string.Empty)));
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                await vm.ConnectCommand.ExecuteAsync();

                Assert.False(discoverServerSubscribed);
            }
            public async Task SmokeTest()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.IsConnected.Returns(false);
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));
                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel();

                vm.Activator.Activate();

                Assert.True(vm.ConnectCommand.CanExecute(null));

                await vm.ConnectCommand.ExecuteAsync();

                messenger.IsConnected.Returns(true);
                messenger.PropertyChanged += Raise.Event <PropertyChangedEventHandler>(messenger, new PropertyChangedEventArgs("IsConnected"));

                Assert.False(vm.ConnectCommand.CanExecute(null));

                messenger.Received(1).ConnectAsync("192.168.1.1", NetworkConstants.DefaultPort, Arg.Any <Guid>(), null);
            }
Exemplo n.º 5
0
        /// <summary>
        /// Searches for loops in a network.
        /// A loop is a connection sequence that starts and ends at the same node.
        /// </summary>
        /// <param name="network">the network to search for loops.</param>
        /// <returns>an enumeration of connections involved in loops</returns>
        public static IEnumerable <ConnectionViewModel> FindLoops(NetworkViewModel network)
        {
            Stack <NodeViewModel> nodesToCheck = new Stack <NodeViewModel>(network.Nodes);
            Dictionary <NodeViewModel, NodeState> nodeStates = new Dictionary <NodeViewModel, NodeState>(nodesToCheck.Count);

            while (nodesToCheck.Count > 0)
            {
                NodeViewModel currentNode = nodesToCheck.Peek();

                NodeState state;
                if (!nodeStates.TryGetValue(currentNode, out state))
                {
                    state = NodeState.Ready;
                }

                if (state == NodeState.Error)
                {
                    nodesToCheck.Pop();
                    continue;
                }

                ConnectionViewModel recursiveConnection = FindLoops(nodeStates, currentNode);
                if (recursiveConnection != null)
                {
                    yield return(recursiveConnection);
                }

                nodesToCheck.Pop();
            }
        }
Exemplo n.º 6
0
        public void SetConnectionString_IsSearching()
        {
            var policies = new Subject <EndpointDescription[]>();

            var discovery = Substitute.For <IDiscoveryService>();

            discovery.GetEndpoints("url").Returns(policies);
            var blobCache = BlobCache.InMemory;

            var vm = new ConnectionViewModel(null, TestChannelService.Silent, discovery, blobCache);

            vm.ConnectionString = "url";
            vm.StartDiscover();

            vm.IsSearchingForSecurityPolicies
            .Should().BeTrue();

            policies.OnNext(_testEndpoints1);
            policies.OnCompleted();

            vm.IsSearchingForSecurityPolicies
            .Should().BeFalse();
            vm.AvailableEndpoints
            .Should().BeEquivalentTo(_testEndpoints1);
        }
Exemplo n.º 7
0
        public void TestSetUp()
        {
            if (TestContext.Properties.Contains("WitsmlStoreUrl"))
            {
                _validWitsmlUri = TestContext.Properties["WitsmlStoreUrl"].ToString();
            }

            if (TestContext.Properties.Contains("EtpServerUrl"))
            {
                _validEtpUri = TestContext.Properties["EtpServerUrl"].ToString();
            }

            _bootstrapper = new BootstrapperHarness();
            _runtime      = new TestRuntimeService(_bootstrapper.Container);

            _witsmlConnection = new Connection()
            {
                Name     = "Witsml",
                Uri      = _validWitsmlUri,
                Username = "******"
            };

            _etpConnection = new Connection()
            {
                Name     = "Etp",
                Uri      = _validEtpUri,
                Username = "******"
            };

            _witsmlConnectionVm = new ConnectionViewModel(_runtime, ConnectionTypes.Witsml);
            _etpConnectionVm    = new ConnectionViewModel(_runtime, ConnectionTypes.Etp);

            DeletePersistenceFolder();
        }
        /// <summary>
        /// Called when the user has started to drag out a connector, thus creating a new connection.
        /// </summary>
        public ConnectionViewModel ConnectionDragStarted(ConnectorViewModel draggedOutConnector, Point curDragPoint)
        {
            //
            // Create a new connection to add to the view-model.
            //
            var connection = new ConnectionViewModel();

            if (draggedOutConnector.Type == ConnectorType.Output)
            {
                //
                // The user is dragging out a source connector (an output) and will connect it to a destination connector (an input).
                //
                connection.SourceConnector      = draggedOutConnector;
                connection.DestConnectorHotspot = curDragPoint;
            }
            else
            {
                //
                // The user is dragging out a destination connector (an input) and will connect it to a source connector (an output).
                //
                connection.DestConnector          = draggedOutConnector;
                connection.SourceConnectorHotspot = curDragPoint;
            }

            //
            // Add the new connection to the view-model.
            //
            Network.Connections.Add(connection);

            return(connection);
        }
            public void AppDoeNotDieWhenDeactivatingViewModelBeforeCommandThrows()
            {
                var settings = new UserSettings {
                    ServerAddress = "192.168.1.1"
                };

                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Observable.Never <ConnectionResultContainer>().ToTask());
                messenger.IsConnected.Returns(false);

                NetworkMessenger.Override(messenger);

                new TestScheduler().With(sched =>
                {
                    ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);
                    vm.Activator.Activate();

                    vm.ConnectCommand.Execute(null);

                    vm.Activator.Deactivate();

                    sched.AdvanceByMs(ConnectionViewModel.ConnectCommandTimeout.TotalMilliseconds + 10);
                });
            }
            public async Task ConnectsWithCustomIpAddressIfSet()
            {
                var settings = new UserSettings {
                    ServerAddress = "192.168.1.3"
                };

                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                ConnectionResultContainer result = await vm.ConnectCommand.ExecuteAsync();

                Assert.Equal(ConnectionResult.Successful, result.ConnectionResult);
                Assert.Equal(new Version("99.99.99"), result.ServerVersion);;

                messenger.Received(1).ConnectAsync(settings.ServerAddress, NetworkConstants.DefaultPort,
                                                   settings.UniqueIdentifier, null);
            }
Exemplo n.º 11
0
        // Event raised while the user is dragging a connection.
        private void networkControl_ConnectionDragging(object sender, ConnectionDraggingEventArgs e)
        {
            System.Windows.Point curDragPoint = Mouse.GetPosition(networkControl);
            ConnectionViewModel  connection   = (ConnectionViewModel)e.Connection;

            ViewModel.ConnectionDragging(curDragPoint, connection);
        }
Exemplo n.º 12
0
        public void Construction02()
        {
            var uri  = new Uri("http://microsoft.com");
            var conn = Substitute.For <IConnection>();

            conn.Uri.Returns(uri);
            conn.Name.Returns("name");
            conn.Path.Returns("path");
            conn.RCommandLineArguments.Returns("arg");
            conn.IsRemote.Returns(true);

            var cm = new ConnectionViewModel(conn, Substitute.For <IConnectionManager>(), new TestImageService());

            cm.IsUserCreated.Should().BeFalse();

            conn.IsUserCreated.Returns(true);
            cm = new ConnectionViewModel(conn, Substitute.For <IConnectionManager>(), new TestImageService());

            conn.IsRemote.Should().BeTrue();
            cm.IsUserCreated.Should().BeTrue();
            cm.IsEditing.Should().BeFalse();
            cm.IsTestConnectionSucceeded.Should().BeFalse();
            cm.Name.Should().Be(conn.Name);
            cm.Path.Should().Be(conn.Path);
            cm.RCommandLineArguments.Should().Be(conn.RCommandLineArguments);
        }
Exemplo n.º 13
0
        public void InputFieldTooltips(string name, string path, FieldState expectedNameState, FieldState expectedPathState)
        {
            string nameTooltip = null;
            string pathTooltip = null;

            switch (expectedNameState)
            {
            case FieldState.Missing: nameTooltip = Resources.ConnectionManager_ShouldHaveName; break;

            case FieldState.Invalid: nameTooltip = Resources.ConnectionManager_InvalidName; break;
            }
            switch (expectedPathState)
            {
            case FieldState.Missing: pathTooltip = Resources.ConnectionManager_ShouldHavePath; break;

            case FieldState.Invalid: pathTooltip = Resources.ConnectionManager_InvalidPath; break;
            }
            var saveTooltip = nameTooltip ?? (pathTooltip ?? Resources.ConnectionManager_Save);

            var conn = Substitute.For <IConnection>();

            conn.Name.Returns(name);
            conn.Path.Returns(path);
            var cm = new ConnectionViewModel(conn, Substitute.For <IConnectionManager>(), new TestImageService());

            cm.NameTextBoxTooltip.Should().Be(nameTooltip);
            cm.PathTextBoxTooltip.Should().Be(pathTooltip);
            cm.SaveButtonTooltip.Should().Be(saveTooltip);

            cm.IsNameValid.Should().Be(expectedNameState == 0);
            cm.IsPathValid.Should().Be(expectedPathState == 0);
            cm.IsValid.Should().Be(cm.IsNameValid && cm.IsPathValid);
        }
        public void Render(ConnectionViewModel viewModel)
        {
            this.SuspendLayout();

            if (viewModel == null)
            {
                this.nameValueLabel.Text = "";
                this.parentValueLabel.Text = "";
                this.userNameValueLabel.Text = "";
                this.addressValueLabel.Text = "";
                this.RenderState(null);

                this.tunnelsGridView.DataSource = this.tunnelViewModels = new TunnelViewModel[0];
            }
            else
            {
                var parentName = viewModel.Info.Parent == null
                    ? "-"
                    : viewModel.Info.Parent.Name;

                this.nameValueLabel.Text = viewModel.Info.Name;
                this.parentValueLabel.Text = parentName;
                this.userNameValueLabel.Text = viewModel.Info.UserName;
                this.addressValueLabel.Text = string.Format("{0}:{1}", viewModel.Info.HostName, viewModel.Info.Port);
                this.RenderState(viewModel);

                this.tunnelViewModels = viewModel.Info.Tunnels.Select(t => new TunnelViewModel(t)).ToArray();
                this.tunnelsGridView.DataSource = this.tunnelViewModels;
            }

            this.ResumeLayout(true);
        }
Exemplo n.º 15
0
        private void CreateBlockingNode(NetworkViewModel model, NodeViewModel previous_node)
        {
            // Create blocking node and add it to the graph
            BlockingCutNodeViewModel blocking_node = new BlockingCutNodeViewModel(Cut);

            model.Nodes.Edit(x => x.Add(blocking_node));

            // Set the blocking node's position to where this cut node was
            blocking_node.Position = (System.Windows.Point)(Position - new System.Windows.Point(150, 0));

            // Move this cut node forward to not overlap the blocking node
            Position = new System.Windows.Point(Position.X + 450, Position.Y);

            ConnectionViewModel previous_to_blocking = new ConnectionViewModel(
                model,
                blocking_node.Inputs.Items.First(),
                previous_node.Outputs.Items.First());

            ConnectionViewModel blocking_to_current = new ConnectionViewModel(
                model,
                Inputs.Items.First(),
                blocking_node.Outputs.Items.First());

            // Add the connections to the node network.
            model.Connections.Edit(x => x.Add(previous_to_blocking));
            model.Connections.Edit(x => x.Add(blocking_to_current));
        }
Exemplo n.º 16
0
        public void AddProperty()
        {
            PendingConnectionViewModel pending = Parent.PendingConnection;

            if (pending == null || pending.Output == null || !(pending.Output.Parent is SubstanceNodeViewModel))
            {
                return;
            }

            SubstanceNodeViewModel sub_view = pending.Output.Parent as SubstanceNodeViewModel;

            NodeInputViewModel new_prop_input = new NodeInputViewModel();

            new_prop_input.Connections.Connect()
            .Subscribe(change => {
                OnPropertyInputChanged(change);
            });

            Inputs.Edit(x => x.Add(new_prop_input));

            ConnectionViewModel new_prop_connection = new ConnectionViewModel(
                Parent,
                new_prop_input,
                sub_view.Outputs.Items.First());

            Parent.Connections.Edit(x => x.Add(new_prop_connection));
        }
Exemplo n.º 17
0
 public static void FillConnectionsFromButtonsOfChatNode(NodeViewModel node)
 {
     if (node.Network != null)
     {
         foreach (var btn in node.ChatNode.Buttons)
         {
             if (!string.IsNullOrWhiteSpace(btn.NextNodeId))
             {
                 var destNode = node.Network.Nodes.FirstOrDefault(x => x.ChatNode.Id == btn.NextNodeId);
                 if (destNode != null)
                 {
                     var conn = new ConnectionViewModel
                     {
                         SourceConnector = node.OutputConnectors.FirstOrDefault(x => x.Button._id == btn._id),
                         DestConnector   = destNode.InputConnectors.FirstOrDefault()
                     };
                     conn.ConnectionChanged += ConnectionViewModelConnectionChanged;
                     if (conn.SourceConnector == null || conn.DestConnector == null)
                     {
                         continue;
                     }
                     node.Network.Connections.Add(conn);
                 }
             }
         }
     }
 }
Exemplo n.º 18
0
        public void SetConnectionString_OneFalling()
        {
            var discovery = Substitute.For <IDiscoveryService>();

            discovery.GetEndpoints("url1").Returns(Observable.Return(_testEndpoints1));
            discovery.GetEndpoints("badurl").Returns(Observable.Throw <EndpointDescription[]>(new ServiceResultException(StatusCodes.BadArgumentsMissing)));
            discovery.GetEndpoints("url2").Returns(Observable.Return(_testEndpoints2));
            var blobCache = BlobCache.InMemory;

            var vm = new ConnectionViewModel(null, TestChannelService.Silent, discovery, blobCache);

            vm.ConnectionString = "url1";
            vm.StartDiscover();

            vm.AvailableEndpoints
            .Should().BeEquivalentTo(_testEndpoints1);

            vm.ConnectionString = "badurl";
            vm.StartDiscover();

            vm.AvailableEndpoints
            .Should().BeNullOrEmpty();
            vm.ExecutionError
            .Should().NotBeNullOrEmpty();

            vm.ConnectionString = "url2";
            vm.StartDiscover();

            vm.AvailableEndpoints
            .Should().BeEquivalentTo(_testEndpoints2);
            vm.ExecutionError
            .Should().BeNullOrEmpty();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Called when the user has finished dragging out the new connection.
        /// </summary>
        public void ConnectionDragCompleted(ConnectionViewModel newConnection, ConnectorViewModel connectorDraggedOut, ConnectorViewModel connectorDraggedOver)
        {
            if (connectorDraggedOver == null)
            {
                //
                // The connection was unsuccessful.
                // Maybe the user dragged it out and dropped it in empty space.
                //
                this.Network.Connections.Remove(newConnection);
                return;
            }

            //
            // The user has dragged the connection on top of another valid connector.
            //

            var existingConnection = connectorDraggedOver.AttachedConnection;

            if (existingConnection != null)
            {
                //
                // There is already a connection attached to the connector that was dragged over.
                // Remove the existing connection from the view-model.
                //
                this.Network.Connections.Remove(existingConnection);
            }

            //
            // Finalize the connection by attaching it to the connector
            // that the user dropped the connection on.
            //
            newConnection.DestConnector = connectorDraggedOver;
        }
        public ValidationResult Validate(ConnectionViewModel model)
        {
            ValidationResult result = new ValidationResult();

            if (String.IsNullOrWhiteSpace(model.Host))
            {
                result.Messages.Add("Host cannot be empty");
            }
            if (!model.Port.HasValue || model.Port.Value <= 0)
            {
                result.Messages.Add("Port must have a numeric value");
            }
            if (String.IsNullOrWhiteSpace(model.Database))
            {
                result.Messages.Add("Database cannot be empty");
            }
            if (String.IsNullOrWhiteSpace(model.ActiveCollection))
            {
                result.Messages.Add("Active collection cannot be empty");
            }
            if (String.IsNullOrWhiteSpace(model.CompletedCollection))
            {
                result.Messages.Add("Completed collection cannot be empty");
            }
            if (model.Password != model.PasswordConfirm)
            {
                result.Messages.Add("Password and confirmation password do not match");
            }

            return(result);
        }
Exemplo n.º 21
0
        /// <summary>
        /// A function to conveniently populate the view-model with test data.
        /// </summary>
        private void PopulateWithTestData()
        {
            //
            // Create a network, the root of the view-model.
            //
            this.Network = new NetworkViewModel();

            //
            // Create some nodes and add them to the view-model.
            //
            var node1 = CreateNode("Node1", new Point(10, 10));
            var node2 = CreateNode("Node2", new Point(200, 10));


            //
            // Create a connection between the nodes.
            //
            var connection = new ConnectionViewModel();

            connection.SourceConnector = node1.Connectors[1];
            connection.DestConnector   = node2.Connectors[3];

            //
            // Add the connection to the view-model.
            //
            this.Network.Connections.Add(connection);
        }
Exemplo n.º 22
0
        public ActionResult AddEditProjectConnection(int projectId, int connectionId = 0)
        {
            ConnectionViewModel model = new ConnectionViewModel();

            model.ProjectId = projectId;

            ProjectMappingModel projectMapping;
            bool isAssigned = new ProjectBL().IsProjectAssignedToUser(projectId, CurrentUser.Pfid, out projectMapping);

            if (!isAssigned)
            {
                TempData["ErrorMessage"] = "Project not found";
                return(RedirectToAction("Dashboard", "Project"));
            }

            model.ProjectDetails = GetProjectDetailsViewModel(projectMapping);

            if (connectionId > 0)
            {
                ConnectionModel connectionModel = new ConnectionBL().GetConnectionById(connectionId);
                if (connectionModel != null)
                {
                    model.Id                 = connectionModel.Id;
                    model.ConnectionName     = connectionModel.ConnectionName;
                    model.ProjectId          = connectionModel.ProjectId;
                    model.SID                = connectionModel.SID;
                    model.IpAddress          = connectionModel.IpAddress;
                    model.PortNumber         = connectionModel.PortNumber;
                    model.ConnectionUsername = connectionModel.ConnectionUsername;
                }
            }

            return(View(model));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Called when the user has started to drag out a connector, thus creating a new connection.
        /// </summary>
        public ConnectionViewModel ConnectionDragStarted(ConnectorViewModel draggedOutConnector, Point curDragPoint)
        {
            if (draggedOutConnector.AttachedConnection != null)
            {
                //
                // There is an existing connection attached to the connector that has been dragged out.
                // Remove the existing connection from the view-model.
                //
                this.Network.Connections.Remove(draggedOutConnector.AttachedConnection);
            }

            //
            // Create a new connection to add to the view-model.
            //
            var connection = new ConnectionViewModel();

            //
            // Link the source connector to the connector that was dragged out.
            //
            connection.SourceConnector = draggedOutConnector;

            //
            // Set the position of destination connector to the current position of the mouse cursor.
            //
            connection.DestConnectorHotspot = curDragPoint;

            //
            // Add the new connection to the view-model.
            //
            this.Network.Connections.Add(connection);

            return(connection);
        }
            public async Task IsFalseWhileConnectCommandExecutesWithPassword()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(x =>
                {
                    messenger.IsConnected.Returns(true);
                    messenger.PropertyChanged += Raise.Event <PropertyChangedEventHandler>(messenger, new PropertyChangedEventArgs("IsConnected"));
                    return(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99")).ToTaskResult());
                });
                messenger.IsConnected.Returns(false);
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));

                NetworkMessenger.Override(messenger);

                var settings = new UserSettings {
                    AdministratorPassword = "******"
                };

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                var coll = messenger.WhenAnyValue(x => x.IsConnected).CreateCollection();

                await vm.ConnectCommand.ExecuteAsync();

                Assert.Equal(new[] { false, true }, coll);
            }
Exemplo n.º 25
0
 /// <summary>
 /// Called as the user continues to drag the connection.
 /// </summary>
 public void ConnectionDragging(ConnectionViewModel connection, Point curDragPoint)
 {
     //
     // Update the destination connection hotspot while the user is dragging the connection.
     //
     connection.DestConnectorHotspot = curDragPoint;
 }
Exemplo n.º 26
0
 public async Task <JsonResult> GetConnectionSingleByMID(string ID)
 {
     try {
         var data    = ConnectionServices.GetByMemberSingleID(ID);
         var vmModel = new List <ConnectionViewModel>();
         foreach (var model in data)
         {
             var temp = new ConnectionViewModel()
             {
                 ID        = model.ID.ToString(),
                 GroupName = model.ConnectionName
             };
             foreach (var member in model.Members)
             {
                 //assign userinformationmodel
                 var vm = new UserInformationViewModel()
                 {
                     User = member.UserID.ToString()
                 };
                 temp.PushMembers(member, vm);
             }
             vmModel.Add(temp);
         }
         return(Json(new { success = true, data = vmModel }, JsonRequestBehavior.AllowGet));
     } catch (Exception e) {
         Console.Write(e);
         return(Json(new { success = false, message = MessageUtility.ServerError() }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 27
0
        public JsonResult TestConnection(ConnectionViewModel connectionViewModel)
        {
            if (ModelState.IsValid)
            {
                ConnectionModel connection = new ConnectionModel
                {
                    IpAddress          = connectionViewModel.IpAddress,
                    PortNumber         = connectionViewModel.PortNumber,
                    SID                = connectionViewModel.SID,
                    ConnectionUsername = connectionViewModel.ConnectionUsername,
                    ConnectionPassword = connectionViewModel.ConnectionPassword,
                };

                try
                {
                    int result = new ConnectionBL().TestConnection(connection);
                    return(Json(new { Success = true, Message = "Database connection tested successfully." }));
                }
                catch (Exception)
                {
                    return(Json(new { Success = false, Message = "Unable to connect to database." }));
                }
            }
            return(Json(new { Success = false, Message = "There are validation errors on page." }));
        }
Exemplo n.º 28
0
        private void OnGraphControlConnectionDragging(object sender, ConnectionDraggingEventArgs e)
        {
            Point currentDragPoint         = Mouse.GetPosition(GraphControl);
            ConnectionViewModel connection = (ConnectionViewModel)e.Connection;

            ViewModel.OnConnectionDragging(currentDragPoint, connection);
        }
Exemplo n.º 29
0
        public ActionResult AddEditConnection(int connectionId = 0)
        {
            ConnectionViewModel model = new ConnectionViewModel();

            if (connectionId > 0)
            {
                ConnectionModel connectionModel = new ConnectionBL().GetConnectionById(connectionId);
                if (connectionModel != null)
                {
                    model.Id                 = connectionModel.Id;
                    model.ConnectionName     = connectionModel.ConnectionName;
                    model.ProjectId          = connectionModel.ProjectId;
                    model.SID                = connectionModel.SID;
                    model.IpAddress          = connectionModel.IpAddress;
                    model.PortNumber         = connectionModel.PortNumber;
                    model.ConnectionUsername = connectionModel.ConnectionUsername;
                }
            }

            var projects = new ProjectBL().GetProjectList().Where(p => p.IsActive == 1).ToList();
            List <SelectListItem> selectListItems = new List <SelectListItem>();

            foreach (var project in projects)
            {
                selectListItems.Add(new SelectListItem
                {
                    Text     = project.ProjectName,
                    Value    = project.Id.ToString(),
                    Selected = model.ProjectId > 0 ? (project.Id == model.ProjectId) : false
                });
            }
            model.ProjectList = new SelectList(selectListItems, "Value", "Text");

            return(View(model));
        }
Exemplo n.º 30
0
        /// <summary>
        /// A function to conveniently populate the view-model with test data.
        /// </summary>
        private void PopulateWithTestData()
        {
            //
            // Create a network, the root of the view-model.
            //
            Network = new NetworkViewModel();

            //
            // Create some nodes and add them to the view-model.
            //
            var node1 = CreateNode("Node1", new Point(100, 60), false);
            var node2 = CreateNode("Node2", new Point(350, 80), false);

            //
            // Create a connection between the nodes.
            //
            var connection = new ConnectionViewModel();

            connection.SourceConnector = node1.OutputConnectors[0];
            connection.DestConnector   = node2.InputConnectors[0];

            //
            // Add the connection to the view-model.
            //
            Network.Connections.Add(connection);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Creates the type graph.
        /// </summary>
        /// <returns>The graph view model.</returns>
        public AGraphViewModel CreateTypeGraph()
        {
            GraphViewModel lGraph = new GraphViewModel();
            NodeViewModel  lNode0 = new TypeNodeViewModel(typeof(SampleClass));

            lGraph.AddNode(lNode0);

            NodeViewModel lNode1 = new TypeNodeViewModel(typeof(SampleClass1VeryTooMuchLong));

            lGraph.AddNode(lNode1);

            NodeViewModel lNode2 = new NodeViewModel();

            lNode2.DisplayString = "Empty node";
            lGraph.AddNode(lNode2);

            int i = 0;

            foreach (NodeViewModel lNode in lGraph.Nodes)
            {
                lNode.X = 300 * i;
                lNode.Y = 100 * i;
                i++;
            }

            ConnectionViewModel lConnectionViewModel = new ConnectionViewModel();

            lConnectionViewModel.Output = lGraph.Nodes.ElementAt(0).Ports.FirstOrDefault(pPort => pPort.Direction == PortDirection.Output);
            lConnectionViewModel.Input  = lGraph.Nodes.ElementAt(1).Ports.FirstOrDefault(pPort => pPort.Direction == PortDirection.Input);
            lGraph.AddConnection(lConnectionViewModel);

            return(lGraph);
        }
        public void Execute(object parameter)
        {
            var shell = IoC.Get<IShell>();

            var context = IoC.Get<EnvironmentExplorerViewModel>().GetCurrentContext();
            var viewModel = default(ConnectionViewModel);

            if (context.Service is AzureService || context.Service is AzureRMService)
                viewModel = new ConnectionViewModel(new ConnectionModelProxy(new Vendor.Azure.Connection(), context));
            else
                viewModel = new ConnectionViewModel(new ConnectionModelProxy(new SMA.Connection(), context));

            shell.OpenDocument(viewModel);
        }
Exemplo n.º 33
0
        public void PropertiesTests()
        {
            var modelMock = Mock.Create<ExpressionConnection>();
            var sourceMock = Mock.Create<IConnectableItemViewModel>();
            var destinationMock = Mock.Create<IConnectableItemViewModel>();
            var diagramMock = Mock.Create<IDiagramViewModel>();
            var vm = new ConnectionViewModel<ExpressionConnection>(modelMock, sourceMock,
                destinationMock, diagramMock);
            
            TestsHelper.TestPublicDeclaredPropertiesGetSet(vm, true, x=>x.X1, x=>x.Y1, x=>x.X2, x=>x.Y2);

            Assert.AreSame(vm.Model, modelMock);
            Assert.AreSame(vm.Connection, modelMock);

            vm.Source = null;
            vm.Source = sourceMock;
            Assert.AreSame(sourceMock, vm.Source);

            vm.Destination = null;
            vm.Destination = destinationMock;
            Assert.AreSame(destinationMock, vm.Destination);
            Assert.AreSame(modelMock, vm.Connection);
            Assert.AreSame(modelMock, vm.Item);

            Assert.IsTrue(vm.IsValid);
            Assert.IsFalse(vm.CanConnectTo(null, null).CanConnect);
            Assert.IsNull(vm.CreateConnectionTo(null));
            Assert.IsTrue(string.IsNullOrWhiteSpace(vm.ValidationMessage));
            Assert.IsFalse(vm.IsConnectedTo(Mock.Create<IDiagramItemViewModel>()));
            Assert.IsNotNull(vm.GetConnectors());
        }       
Exemplo n.º 34
0
 public ConnectionCommand(ConnectionViewModel ViewModel)
 {
     _ViewModel = ViewModel;
 }
Exemplo n.º 35
0
        public void ArcRadius_Is0_ByDefault()
        {
            var modelMock = Mock.Create<ExpressionConnection>();
            var sourceMock = Mock.Create<IConnectableItemViewModel>();
            var destinationMock = Mock.Create<IConnectableItemViewModel>();
            var diagramMock = Mock.Create<IDiagramViewModel>();
            var vm = new ConnectionViewModel<ExpressionConnection>(modelMock, sourceMock,
                destinationMock, diagramMock);
            
            vm.ConnectorType = ConnectorTypes.Default;

            //Assert
            Assert.AreEqual(0, vm.Y2);

            vm.ConnectorType = ConnectorTypes.DecisionOut;

            //Assert
            Assert.AreEqual(0, vm.ArcRadius);

        }
Exemplo n.º 36
0
        public void ItemPropertyChanged_WhenRaised_RaisePropertyChanged()
        {
            var modelMock = Mock.Create<ExpressionConnection>();
            var sourceMock = Mock.Create<IConnectableItemViewModel>();
            var sourceItem = Mock.Create<IDiagramItem>();
            Mock.Arrange(() => sourceMock.Item).Returns(sourceItem);
            var destinationMock = Mock.Create<IConnectableItemViewModel>();
            var diagramMock = Mock.Create<IDiagramViewModel>();
            var vm = new ConnectionViewModel<ExpressionConnection>(modelMock, sourceMock,
                destinationMock, diagramMock);

            var propertyChanged = false;
            vm.PropertyChanged += (o, args) => { propertyChanged = true; };
            Mock.Raise(() => sourceItem.PropertyChanged += null, new PropertyChangedEventArgs(string.Empty));

            Assert.IsTrue(propertyChanged);

        }
 public void RenderState(ConnectionViewModel viewModel)
 {
     if (viewModel == null)
     {
         this.stateValueLabel.Text = "";
         this.stateValueLabel.ForeColor = Color.Black;
     }
     else
     {
         this.stateValueLabel.Text = viewModel.State.ToString();
         this.stateValueLabel.ForeColor = viewModel.StateColor;
     }
 }
Exemplo n.º 38
0
        private void btnConnectClick(object sender, RoutedEventArgs e)
        {
            var conDialog = new wpf_testing.ConnectionDialog();//Application.ActiveWorkbook, _conn.ConnectionString, _xlHelper);
            var vm = new ConnectionViewModel(_conn, "No Workbook Selected");
            conDialog.DataContext = vm;
            var dialogRes = conDialog.ShowDialog();
            if (!(conDialog.DialogResult.HasValue && conDialog.DialogResult.Value)) return;

                    RegistryHelper.SaveServerListToRegistry(vm.DataSource,vm.RecentServers);
                    _conn = vm.Connection;
            _conn.ShowHiddenObjects = true;
            RefreshDatabaseList();
        }
Exemplo n.º 39
0
 public void Select(ConnectionViewModel connection)
 {
     var bindingSource = (BindingSource)this.connectionsGridView.DataSource;
     var index = bindingSource.IndexOf(connection);
     bindingSource.Position = index;
     bindingSource.ResetItem(index);
 }
Exemplo n.º 40
0
 public MainViewModel(ConnectionViewModel connectionViewModel, SettingsViewModel settingsViewModel)
 {
     SettingsViewModel = settingsViewModel;
     ConnectionViewModel = connectionViewModel;
 }
Exemplo n.º 41
0
 private void OnDisconnected()
 {
     Content = new ConnectionViewModel(_cacheClient, OnConnected);
 }
Exemplo n.º 42
0
 public MainViewModel(ICacheClient cacheClient)
 {
     _cacheClient = cacheClient;
     _content = new ConnectionViewModel(_cacheClient, OnConnected);
 }
Exemplo n.º 43
0
 public Fullstack()
 {
     InitializeComponent();
     DataContext = new ConnectionViewModel("TEST");
 }