public void List_OnExecute_OrdersConnectionsByHostThenDatabase()
        {
            List <ConnectionModel> connections = new List <ConnectionModel>();

            connections.Add(new ConnectionModel()
            {
                Host = "Z", Database = "A"
            });
            connections.Add(new ConnectionModel()
            {
                Host = "Y", Database = "Z"
            });
            connections.Add(new ConnectionModel()
            {
                Host = "Y", Database = "B"
            });
            connections.Add(new ConnectionModel()
            {
                Host = "Z", Database = "B"
            });
            connections.Add(new ConnectionModel()
            {
                Host = "A", Database = "A"
            });
            connections.Add(new ConnectionModel()
            {
                Host = "A", Database = "B"
            });
            _userStore.Connections.Returns(connections);

            // execute
            ConnectionModule module = new ConnectionModule(_userStore, _connectionValidator, null, _workflowStoreService, _workflowStoreFactory);

            module.Context = new NancyContext();
            var result = module.List();

            // assert
            ConnectionListViewModel model = result.NegotiationContext.DefaultModel as ConnectionListViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual(model.WorkflowStores[0].ConnectionModel.Host, "A");
            Assert.AreEqual(model.WorkflowStores[0].ConnectionModel.Database, "A");
            Assert.AreEqual(model.WorkflowStores[1].ConnectionModel.Host, "A");
            Assert.AreEqual(model.WorkflowStores[1].ConnectionModel.Database, "B");
            Assert.AreEqual(model.WorkflowStores[2].ConnectionModel.Host, "Y");
            Assert.AreEqual(model.WorkflowStores[2].ConnectionModel.Database, "B");
            Assert.AreEqual(model.WorkflowStores[3].ConnectionModel.Host, "Y");
            Assert.AreEqual(model.WorkflowStores[3].ConnectionModel.Database, "Z");
            Assert.AreEqual(model.WorkflowStores[4].ConnectionModel.Host, "Z");
            Assert.AreEqual(model.WorkflowStores[4].ConnectionModel.Database, "A");
            Assert.AreEqual(model.WorkflowStores[5].ConnectionModel.Host, "Z");
            Assert.AreEqual(model.WorkflowStores[5].ConnectionModel.Database, "B");
        }
Ejemplo n.º 2
0
        public dynamic List()
        {
            // load the connections
            var connections = _userStore.Connections;
            ConnectionListViewModel    model = new ConnectionListViewModel();
            List <ConnectionViewModel> connectionViewModels = _mapper.Map <List <ConnectionModel>, List <ConnectionViewModel> >(connections);

            model.Connections.AddRange(connectionViewModels.OrderBy(x => x.Host.ToUpper()).ThenBy(x => x.Database.ToUpper()));

            model.CurrentUserCanDeleteConnection = this.Context.CurrentUser.HasClaim(Claims.ConnectionDelete);
            return(this.View[Views.Connection.List, model]);;
        }
Ejemplo n.º 3
0
        public dynamic List()
        {
            // load the connections
            List <WorkflowStoreModel> workflowStoreModels = new List <WorkflowStoreModel>();

            foreach (ConnectionModel cm in _userStore.Connections)
            {
                workflowStoreModels.Add(new WorkflowStoreModel(cm));
            }

            // process getting all the store info in parallel
            Parallel.ForEach(workflowStoreModels, _workflowStoreService.PopulateWorkflowStoreInfo);

            ConnectionListViewModel model = new ConnectionListViewModel();

            model.WorkflowStores.AddRange(workflowStoreModels.OrderBy(x => x.ConnectionModel.Host).ThenBy(x => x.ConnectionModel.Database));
            model.CurrentUserCanDeleteConnection = this.Context.CurrentUser.HasClaim(Claims.ConnectionDelete);
            return(this.View[Views.Connection.List, model]);;
        }
        public void List_UserHasConnectionDeleteClaim_CurrentUserCannotDeleteConnectionOnModelIsFalse()
        {
            // setup
            List <ConnectionModel> connections = new List <ConnectionModel>();

            _userStore.Connections.Returns(connections);

            ConnectionModule module = new ConnectionModule(_userStore, _connectionValidator, _encryptionProvider, _workflowStoreService, _workflowStoreFactory);

            module.Context             = new NancyContext();
            module.Context.CurrentUser = new UserIdentity()
            {
                Claims = new string[] { }
            };

            // execute
            var result = module.List();

            // assert
            ConnectionListViewModel model = result.NegotiationContext.DefaultModel as ConnectionListViewModel;

            Assert.IsFalse(model.CurrentUserCanDeleteConnection);
        }
 public void GetSetPropertiesTest()
 {
     var tag = new ConnectionListViewModel();
     TestsHelper.TestPublicPropertiesGetSet(tag, x => tag.Model, x => tag.Title);
 }
Ejemplo n.º 6
0
        private void ShowConnectionInfomation()
        {
            try
            {
                for (;;)
                {
                    var connectionInformation = _amoebaManager.ConnectionInformation.ToArray();
                    var dic = new Dictionary <int, Information>();

                    foreach (var item in connectionInformation.ToArray())
                    {
                        dic[(int)item["Id"]] = item;
                    }

                    var dic2 = new Dictionary <int, ConnectionListViewModel>();

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        foreach (var item in _listViewModelCollection.ToArray())
                        {
                            dic2[item.Id] = item;
                        }
                    }));

                    var removeList = new List <ConnectionListViewModel>();

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        foreach (var item in _listViewModelCollection.ToArray())
                        {
                            if (!dic.ContainsKey(item.Id))
                            {
                                removeList.Add(item);
                            }
                        }
                    }));

                    var newList   = new List <ConnectionListViewModel>();
                    var updateDic = new Dictionary <ConnectionListViewModel, Information>();

                    bool clearFlag   = false;
                    var  selectItems = new List <ConnectionListViewModel>();

                    if (removeList.Count > 100)
                    {
                        clearFlag = true;
                        removeList.Clear();
                        updateDic.Clear();

                        foreach (var information in connectionInformation)
                        {
                            newList.Add(new ConnectionListViewModel(information));
                        }

                        var hid = new HashSet <int>();

                        this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                        {
                            hid.UnionWith(_listView.SelectedItems.OfType <ConnectionListViewModel>().Select(n => n.Id));
                        }));

                        foreach (var item in newList)
                        {
                            if (hid.Contains(item.Id))
                            {
                                selectItems.Add(item);
                            }
                        }
                    }
                    else
                    {
                        foreach (var information in connectionInformation)
                        {
                            ConnectionListViewModel item = null;

                            if (dic2.ContainsKey((int)information["Id"]))
                            {
                                item = dic2[(int)information["Id"]];
                            }

                            if (item != null)
                            {
                                updateDic[item] = information;
                            }
                            else
                            {
                                newList.Add(new ConnectionListViewModel(information));
                            }
                        }
                    }

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        bool sortFlag = false;

                        if (newList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (removeList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (updateDic.Count != 0)
                        {
                            sortFlag = true;
                        }

                        if (clearFlag)
                        {
                            _listViewModelCollection.Clear();
                        }

                        foreach (var item in newList)
                        {
                            _listViewModelCollection.Add(item);
                        }

                        foreach (var item in removeList)
                        {
                            _listViewModelCollection.Remove(item);
                        }

                        foreach (var item in updateDic)
                        {
                            item.Key.Information = item.Value;
                        }

                        if (clearFlag)
                        {
                            _listView.SelectedItems.Clear();
                            _listView.SetSelectedItems(selectItems);
                        }

                        if (sortFlag)
                        {
                            this.Sort();
                        }
                    }));

                    Thread.Sleep(1000 * 3);
                }
            }
            catch (Exception)
            {
            }
        }
 internal ChannelListViewModel(PeerCast peerCast)
 {
     this.peerCast = peerCast;
     connections   = new ConnectionListViewModel();
     relayTree     = new RelayTreeViewModel(peerCast);
 }