Пример #1
0
        public CopyCollections(Window mainWindow, ConnectionInfo sourceConnection, IEnumerable<ConnectionInfo> connections)
        {
            _mainWindow = mainWindow;
            _dialog = new CopyCollectionsDialog();
            _dialog.Owner = _mainWindow;
            _sourceConnection = sourceConnection;

            _targetDatabases = new ObservableCollection<string>();

            _targetConnections = new ObservableCollection<TargetConnection>();
            connections.ToList().ForEach(item => _targetConnections.Add(
                new TargetConnection(
                    string.IsNullOrWhiteSpace(item.Name) ? string.Format("{0}:{1}", item.Host, item.Port) : item.Name,
                    item)));
            _dialog.TargetServer.ItemsSource = _targetConnections;
            _dialog.TargetServer.SelectionChanged += TargetServerSelectionChanged;
            _dialog.TargetServer.SelectedIndex = 0;

            _targetCollections = new ObservableCollection<CopyTargetDefinition>();
            _dialog.TargetCollections.ItemsSource = _targetCollections;

            _dialog.SourceServer.Text = string.Format("{0}:{1}", _sourceConnection.Host, _sourceConnection.Port);

            _dialog.TargetDatabaseLostFocus += TargetDatabaseLostFocus;
            _dialog.CopyButton.Click += CopyButtonClick;
        }
        public DeleteCollectionsAndDatabases(Window mainWindow, ConnectionInfo connection)
        {
            _connection = connection;
            _mainWindow = mainWindow;

            _dialog = new DeleteCollectionsAndDatabasesDialog();
            _dialog.Owner = mainWindow;
        }
Пример #3
0
        public EvaluateJavaScript(ConnectionInfo cnn, string database)
        {
            _cnn = cnn;
            _databaseName = database;

            _control = new EvalJSControl();
            _control.EvaluateClicked += EvaluateClicked;
            _control.PreviewKeyUp += PreviewKeyUp;
        }
        public void CreateIndexes(ConnectionInfo cnn, string database, string collection, IEnumerable<IndexDescriptor> indexes)
        {
            var operation = new OperationStatus
            {
                IsIndeterminate = true,
                Title = Properties.Resources.ManageIndexes_Applying,
                Description = Properties.Resources.ManageIndexes_Dropping
            };
            _mingApp.AddLongRunningOperation(operation);

            var task = new CancelableTask(() => DoCreateIndexes(operation, cnn, database, collection, indexes), null);
            task.Execute();
        }
Пример #5
0
        public ManageIndexes(Window mainWindow, ConnectionInfo connection, string database, string collectionName)
        {
            _mainWindow = mainWindow;
            _connection = connection;
            _database = database;
            _collectionName = collectionName;

            _dialog = new ManageIndexesDialog();
            _dialog.Owner = _mainWindow;

            _properties = new ObservableCollection<string>();
            _dialog.AvailableProperties.ItemsSource = _properties;

            _dialog.SaveButton.Click += SaveButtonClick;
        }
Пример #6
0
        public MongoConsole(string fullPathToexe, ConnectionInfo cnnInfo, string database)
        {
            _control = new EvalJSControl();
            _control.EvaluateClicked += ControlEvaluateClicked;
            _cnn = cnnInfo;

            LoadSettings();

            _control.Output.Text = string.Format("{0}\n", Properties.Resources.Console_AltEnterTip);
            _control.Output.Text += string.Format("{0}\n\n", Properties.Resources.Console_ClearTip);

            try
            {
                var psi = new ProcessStartInfo(fullPathToexe);
                // TODO: Username/password
                psi.Arguments = string.Format("{1}:{2}", fullPathToexe, _cnn.Host, _cnn.Port);
                psi.UseShellExecute = false;
                psi.CreateNoWindow = true;
                psi.RedirectStandardInput = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError = true;

                _process = new Process();
                _process.StartInfo = psi;
                _process.OutputDataReceived += ProcessOutputDataReceived;
                _process.ErrorDataReceived += ProcessOutputDataReceived;
                _process.Exited += ProcessExited;
                _control.PreviewKeyUp += ControlPreviewKeyUp;
                _process.Start();
                _stdInput = _process.StandardInput;
                _process.BeginOutputReadLine();
            }
            catch (Exception ex)
            {
                _control.Output.Text = Properties.Resources.Console_ErrorOpening;
                // TODO: This setting isn't this classes responsibility
                Properties.Settings.Default.MongoExeLocation = string.Empty;
                Properties.Settings.Default.Save();
                Utilities.LogException(ex);
            }

            if (!string.IsNullOrEmpty(database))
            {
                _stdInput.WriteLine(string.Format("use {0}", database));
            }
        }
Пример #7
0
        public LogWatch(ConnectionInfo cnn)
        {
            _cnn = cnn;
            _control = new LogWatchControl();
            _control.LogViewer.ViewSize = _viewSize;
            _logs = new ObservableCollection<string>();
            _control.LogName.ItemsSource = _logs;
            _control.LogName.SelectionChanged += LogNameSelectionChanged;

            _control.PauseButton.Click += PauseButtonClick;

            _timer = new Timer();
            _timer.Interval = 1000;
            _timer.Elapsed += TimerElapsed;

            _entries = new List<LogEntry>();

            LoadAvailableLogs();
            GetLogLevel();
        }
Пример #8
0
        public SystemStatus(ConnectionInfo cnnInfo)
        {
            _cnn = cnnInfo;
            _control = new SystemStatusControl();

            InitLockOptions();
            SetupCharts();

            _intervalMultiplier = 1;

            _timer = new Timer();
            _timer.Interval = 1000;

            LoadSettings();

            _timer.Elapsed += TimerElapsed;
            _timer.Start();

            _control.Interval.ValueChanged += IntervalValueChanged;
            _control.Span.ValueChanged += SpanValueChanged;
        }
        public void CompactCollections(MingTreeViewItem node, ConnectionInfo cnnInfo, string database)
        {
            var confirm = new MessageBox();
            var message = database == null
                ? string.Format(Properties.Resources.CompactCollections_ConfirmAll, cnnInfo.Host, cnnInfo.Port)
                : string.Format(Properties.Resources.CompactCollections_Confirm, database);
            if (!confirm.ShowConfirm(_mingApp.MainWindow, message))
            {
                return;
            }

            var operation = new OperationStatus
            {
                IsIndeterminate = true,
                Title = Properties.Resources.CompactCollections_Title,
                Description = Properties.Resources.CompactCollections_DescCounting
            };
            _mingApp.AddLongRunningOperation(operation);
            var task = new CancelableTask(() => DoCompactCollections(operation, cnnInfo, database), null);
            task.Execute();
        }
Пример #10
0
        public static MongoServer Create(ConnectionInfo cnnInfo)
        {
            if (!string.IsNullOrWhiteSpace(cnnInfo.Username))
            {
                return MongoServer.Create(string.Format("mongodb://{0}:{1}@{2}:{3}/?safe=true;slaveOk=true",
                    cnnInfo.Username,
                    Security.SecureStringToString(cnnInfo.Password),
                    cnnInfo.Host,
                    cnnInfo.Port));

                /*
                var client = new MongoClient(string.Format("mongodb://{0}:{1}@{2}:{3}/?safe=true;slaveOk=true",
                    cnnInfo.Username,
                    Security.SecureStringToString(cnnInfo.Password),
                    cnnInfo.Host,
                    cnnInfo.Port));

                return client.GetServer();*/

            }
            return MongoServer.Create(string.Format("mongodb://{0}:{1}/?safe=true;slaveOk=true", cnnInfo.Host, cnnInfo.Port));
        }
Пример #11
0
        public void Show()
        {
            _connectForm.ShowDialog();

            if (_viewModel.ShouldAdd)
            {
                var cnnInfo = new ConnectionInfo(_viewModel.Name, _viewModel.Service.Id, _viewModel.Host, int.Parse(_viewModel.Port), _viewModel.Username, _viewModel.Password);

                try
                {
                    SettingsManager.Instance.AddConnection(cnnInfo);
                }
                catch (ArgumentException)
                {
                    new Forms.MessageBox().ShowMessage(_owner,
                        string.Format(Properties.Resources.Connect_Error_Duplicate,
                            string.Format("{0}:{1}", cnnInfo.Host, cnnInfo.Port),
                            _viewModel.Service.Name),
                        Properties.Resources.Connect_Error_Title);
                }
            }
        }
 public void CopyCollection(MingTreeViewItem node, ConnectionInfo cnnInfo, string database, string collection)
 {
     var ted = new TextEntryDialogController(_mingApp.MainWindow, Properties.Resources.CopyCollection_Title, Properties.Resources.CreateCollection_Prompt);
     ted.Text = collection;
     if (!ted.ShowDialog())
     {
         return;
     }
     var name = ted.Text.Trim();
     if (string.IsNullOrWhiteSpace(name))
     {
         return;
     }
     var operation = new OperationStatus
     {
         IsIndeterminate = true,
         Title = Properties.Resources.CopyCollection_OpTitle,
         Description = Properties.Resources.CopyCollection_Counting
     };
     _mingApp.AddLongRunningOperation(operation);
     var task = new CancelableTask(() => DoCopyCollection(node, operation, cnnInfo, database, collection, name), null);
     task.Execute();
 }
Пример #13
0
        public CollectionView(ConnectionInfo cnn, string database, string collection)
        {
            _control = new CollectionViewControl();
            _control.PropertyExpanderClicked += PropertyExpanderClicked;
            _control.RefreshClicked += RefreshClicked;
            _control.MainListView.SelectionChanged += MainListViewSelectionChanged;
            _control.PreviewKeyUp += PreviewKeyUp;
            _cnn = cnn;
            _collectionName = collection;
            _databaseName = database;

            _pager = new Pager();
            _control.Pager.DataContext = _pager;

            _collectionData = new ObservableCollection<MongoDocumentProperty>();
            _control.MainListView.ItemsSource = _collectionData;

            _sortFields = new ObservableCollection<string>();
            _sortFieldsTemp = new List<string>();
            _sortFieldsInfo = new Dictionary<string, BsonType>();

            _control.SortFields.ItemsSource = _sortFields;
            _control.FilterFields.ItemsSource = _sortFields;

            _sortOn = new ObservableCollection<SortField>();
            _control.SortFieldList.ItemsSource = _sortOn;

            _filterOn = new ObservableCollection<FilterField>();
            _control.FilterFieldList.ItemsSource = _filterOn;

            _control.AddSortClicked += AddSortClicked;
            _control.SortRemoveButtonClicked += SortRemoveButtonClicked;
            _control.AddFilterClicked += AddFilterClicked;
            _control.FilterRemoveButtonClicked += FilterRemoveButtonClicked;

            StartScanCollectionForProperties();
        }
        private void DoCopyCollection(MingTreeViewItem node, OperationStatus operation, ConnectionInfo cnnInfo, string database, string collection, string newCollection)
        {
            try
            {
                if (MongoUtilities.Create(cnnInfo).GetDatabase(database).CollectionExists(newCollection))
                {
                    operation.IsSuccess = false;
                    operation.IsComplete = true;
                    operation.Description = string.Format(Properties.Resources.CopyCollection_Exists, newCollection);
                    return;
                }
                var src = MongoUtilities.Create(cnnInfo).GetDatabase(database).GetCollection(collection);
                var dest = MongoUtilities.Create(cnnInfo).GetDatabase(database).GetCollection(newCollection);
                var count = src.Count();
                operation.IsIndeterminate = false;
                operation.Description = string.Format(Properties.Resources.CopyCollection_Copying, 0);

                var copied = 0;
                var srcCur = src.FindAll().SetSnapshot();
                foreach (var item in srcCur)
                {
                    dest.Insert(item);
                    copied++;
                    operation.Description = string.Format(Properties.Resources.CopyCollection_Copying, copied);
                    operation.PercentComplete = (int)((100.0 / (double)count) * (double)copied);
                }
                operation.IsSuccess = true;
                operation.IsComplete = true;
            }
            catch (Exception ex)
            {
                operation.Description = string.Format(Properties.Resources.CopyCollections_Error, ex.Message);
                operation.IsSuccess = false;
                operation.IsComplete = true;
            }
            _mingApp.RefreshTreeViewItem(node.Parent);
        }
Пример #15
0
        public static IEnumerable<MongoReplicaSetMemberInfo> GetReplicaSetInfo(ConnectionInfo initialNode)
        {
            try
            {
                var cnn = Create(initialNode);
                BsonDocument rsState = null;

                try
                {
                    rsState = cnn.GetDatabase("local").Eval(EvalFlags.NoLock, "db._adminCommand({ replSetGetStatus: 1 })").AsBsonDocument;
                }
                catch { }
                if (rsState == null)
                {
                    return null;
                }
                var members = rsState["members"].AsBsonArray.ToList();
                var memberObjects = new List<MongoReplicaSetMemberInfo>();
                members.ForEach(member =>
                    {
                        var bson = member.AsBsonDocument;
                        var obj = new MongoReplicaSetMemberInfo();
                        var addr = bson["name"].AsString;
                        obj.Host = addr.Substring(0, addr.IndexOf(':'));
                        obj.Port = int.Parse(addr.Substring(addr.IndexOf(':') + 1));
                        obj.IsPrimary = bson["state"].AsInt32 == 1;
                        obj.IsArbiter = bson["state"].AsInt32 == 7;
                        memberObjects.Add(obj);
                    });
                return memberObjects.OrderByDescending(member => member.IsPrimary).ThenBy(member => member.Host);
            }
            catch
            {
                return null;
            }
        }
 private void DoCompactCollections(OperationStatus operation, ConnectionInfo cnnInfo, string database)
 {
     try
     {
         var databases = new List<string>();
         var cnn = MongoUtilities.Create(cnnInfo);
         if (database != null)
         {
             databases.Add(database);
         }
         else
         {
             cnn.GetDatabaseNames().ToList().ForEach(item => databases.Add(item));
         }
         var collections = new List<Tuple<string, string>>();
         databases.ForEach(db => cnn.GetDatabase(db).GetCollectionNames().ToList().ForEach(col => collections.Add(new Tuple<string, string>(db, col))));
         var done = 0;
         operation.IsIndeterminate = false;
         foreach (var col in collections)
         {
             operation.Description = string.Format(Properties.Resources.CompactCollections_DescCompacting, col.Item1, col.Item2);
             operation.PercentComplete = (int)((100.0 / (double)collections.Count) * (double)done);
             cnn.GetDatabase(col.Item1).Eval(string.Format("db.runCommand({{ compact: \"{0}\", force: true }})", col.Item2));
             done++;
         }
         operation.Description = Properties.Resources.CompactCollections_DescComplete;
         operation.IsSuccess = true;
         operation.IsComplete = true;
     }
     catch (Exception ex)
     {
         operation.Description = string.Format(Properties.Resources.CompactCollections_Error, ex.Message);
         operation.IsSuccess = false;
         operation.IsComplete = true;
     }
 }
Пример #17
0
        public void TestConnection()
        {
            var plugin = PluginManager.Instance.GetPluginInstance(_service.Id);

            var cnn = new ConnectionInfo(_name, _service.Id, _host, int.Parse(_port), _username, _password);

            _testTask = new CancelableTask<bool>(() => plugin.Test(cnn), TestFinished).Execute();

            TestStarted(this, null);
        }
Пример #18
0
        private IEnumerable<MingTreeViewItem> LoadCollectionIndexes(CollectionIndexesNode parent, ConnectionInfo cnnInfo)
        {
            GetIndexesResult indexes;
            try
            {
                indexes = MongoUtilities.Create(cnnInfo).GetDatabase(parent.DatabaseName).GetCollection(parent.CollectionName).GetIndexes();
            }
            catch
            {
                return ReturnConnectionFailure();
            }

            if (indexes.Count() == 0)
            {
                return new List<MingTreeViewItem>
                    { new MingTreeViewItem(Utilities.BitmapImageFromBitmap(Properties.Resources.warning), Properties.Resources.TreeView_NoIndexes, new CollectionIndexesEmptyNode(), false) };
            }

            var nodes = new List<MingTreeViewItem>();
            indexes.ToList().ForEach(idx =>
                nodes.Add(new MingTreeViewItem(Utilities.BitmapImageFromBitmap(Properties.Resources.index), idx.Name,
                    new CollectionIndexNode(parent.DatabaseName, parent.CollectionName, idx.Name), false)));

            return nodes;
        }
Пример #19
0
        public IEnumerable<MingTreeViewItem> NodeExpanded(MingTreeViewItem node, ConnectionInfo cnnInfo)
        {
            var nodeData = node.Data;

            if (nodeData is TreeViewRootNodeData)
            {
                return LoadReplicaSet(cnnInfo);
            }
            if (nodeData is ReplicaSetMemberNode)
            {
                return LoadDatabases(cnnInfo);
            }
            if (nodeData is DatabaseNode)
            {
                return GetDatabaseObjectNodes(nodeData as DatabaseNode);
            }
            if (nodeData is CollectionsNode)
            {
                return LoadCollections(nodeData as CollectionsNode, cnnInfo);
            }
            if (nodeData is CollectionNode)
            {
                return GetCollectionObjectNodes(nodeData as CollectionNode);
            }
            if (nodeData is CollectionIndexesNode)
            {
                return LoadCollectionIndexes(nodeData as CollectionIndexesNode, cnnInfo);
            }
            if (nodeData is CollectionPropertiesNode)
            {
                return LoadCollectionProperties(nodeData as CollectionPropertiesNode, cnnInfo);
            }
            if (nodeData is CollectionPropertyNode)
            {
                return LoadPropertyProperties(nodeData as CollectionPropertyNode, cnnInfo);
            }

            return null;
        }
Пример #20
0
 public void MenuItemHandler(ConnectionInfo cnnInfo, MingTreeViewItem node, string menuKey)
 {
     throw new NotImplementedException();
 }
Пример #21
0
 public bool Test(ConnectionInfo cnn)
 {
     System.Threading.Thread.Sleep(1000);
     return false;
 }
Пример #22
0
 private void RemoveConnections(ConnectionInfo cnnInfo)
 {
     List<MingTreeViewItem> toRemove = new List<MingTreeViewItem>();
     foreach (var item in _treeView.Items)
     {
         var mtvi = item as MingTreeViewItem;
         if (mtvi != null)
         {
             var root = mtvi.Data as TreeViewRootNodeData;
             if (root != null)
             {
                 var cnnItem = root.ConnectionInfo;
                 if (cnnItem.Host == cnnInfo.Host &&
                     cnnItem.Port == cnnInfo.Port &&
                     cnnItem.ServiceId == cnnInfo.ServiceId)
                 {
                     toRemove.Add(mtvi);
                 }
             }
         }
     }
     toRemove.ForEach(item => _treeView.Items.Remove(item));
 }
Пример #23
0
 public TargetConnection(string description, ConnectionInfo cnnInfo)
 {
     _description = description;
     _cnnInfo = cnnInfo;
 }
Пример #24
0
        public void DoCreateIndexes(OperationStatus operation, ConnectionInfo cnn, string database, string collection, IEnumerable<IndexDescriptor> indexes)
        {
            var col = MongoUtilities.Create(cnn).GetDatabase(database).GetCollection(collection);

            try
            {
                col.DropAllIndexes();
            }
            catch (Exception ex)
            {
                Utilities.LogException(ex);
            }

            var count = 0;
            var errors = new List<string>();
            foreach (var index in indexes)
            {
                operation.PercentComplete = (int) ((100.0 / (double)indexes.Count()) * (double) count);
                operation.Description = string.Format(Properties.Resources.ManageIndexes_Creating, ++count);

                try
                {
                    var keys = new IndexKeysBuilder();

                    foreach (var property in index.IndexedProperties)
                    {
                        switch (property.IndexType)
                        {
                            case IndexType.Descending:
                                keys.Descending(property.PropertyName);
                                break;
                            case IndexType.Geospatial:
                                keys.GeoSpatial(property.PropertyName);
                                break;
                            default:
                                keys.Ascending(property.PropertyName);
                                break;
                        }
                    }

                    var options = new IndexOptionsBuilder();
                    options.SetSparse(index.IsSparse);
                    options.SetUnique(index.IsUnique);

                    col.CreateIndex(keys, options);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("2d has to be first"))
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_GeospatialNotFirst, count));
                    }
                    else if (ex.Message.Contains("geo field") || ex.Message.Contains("location object expected"))
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_InvalidGeospatial, count));
                    }
                    else if (ex.Message.Contains("duplicate key"))
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_InvalidUnique, count));
                    }
                    else
                    {
                        errors.Add(string.Format(Properties.Resources.ManageIndexes_UnknownError, count, ex.Message));
                        Utilities.LogException(ex);
                    }
                }
            }

            operation.IsComplete = true;
            if (errors.Count == 0)
            {
                operation.IsSuccess = true;
                operation.Description = string.Format(Properties.Resources.ManageIndexes_Success, indexes.Count());
            }
            else
            {
                operation.IsSuccess = false;
                var errorString = new StringBuilder();
                errors.ToList().ForEach(
                    error =>
                    {
                        errorString.Append("\n");
                        errorString.Append(error);
                    });
                operation.Description = string.Format(Properties.Resources.ManageIndexes_Fail, errors.Count, errorString);
            }
        }
Пример #25
0
 private void DisplayConnection(ConnectionInfo cnnInfo)
 {
     var img = Utilities.BitmapImageFromBitmap(PluginManager.Instance.GetPluginInstance(cnnInfo.ServiceId).TreeViewIcon);
     MingTreeViewItem cnnObj;
     if (!string.IsNullOrWhiteSpace(cnnInfo.Name))
     {
         cnnObj = new MingTreeViewItem(img, cnnInfo.Name, new TreeViewRootNodeData(cnnInfo), true);
     }
     else
     {
         if (!string.IsNullOrWhiteSpace(cnnInfo.Username))
         {
             cnnObj = new MingTreeViewItem(img, string.Format("{0}@{1}:{2}", cnnInfo.Username, cnnInfo.Host, cnnInfo.Port), new TreeViewRootNodeData(cnnInfo), true);
         }
         else
         {
             cnnObj = new MingTreeViewItem(img, string.Format("{0}:{1}", cnnInfo.Host, cnnInfo.Port), new TreeViewRootNodeData(cnnInfo), true);
         }
     }
     _treeView.Items.Add(cnnObj);
 }
Пример #26
0
        private IEnumerable<MingTreeViewItem> LoadCollections(CollectionsNode parent, ConnectionInfo cnnInfo)
        {
            IEnumerable<string> collections;
            try
            {
                collections = MongoUtilities.Create(cnnInfo).GetDatabase(parent.DatabaseName).GetCollectionNames();
            }
            catch
            {
                return ReturnConnectionFailure();
            }

            if (collections.Count() == 0)
            {
                return new List<MingTreeViewItem>
                    { new MingTreeViewItem(Utilities.BitmapImageFromBitmap(Properties.Resources.warning), Properties.Resources.TreeView_NoCollections, new CollectionsEmptyNode(), false) };
            }

            var nodes = new List<MingTreeViewItem>();
            collections.Where(col => ! col.StartsWith(SystemCollectionPrefix)).ToList().ForEach(col =>
                nodes.Add(new MingTreeViewItem(Utilities.BitmapImageFromBitmap(Properties.Resources.collection), col,
                    new CollectionNode(parent.DatabaseName, col), true)));

            return nodes;
        }
Пример #27
0
 public CollectionDefinition(ConnectionInfo connection, string database, string collection)
 {
     _connection = connection;
     _database = database;
     _collection = collection;
 }
Пример #28
0
        private IEnumerable<MingTreeViewItem> LoadDatabases(ConnectionInfo cnnInfo)
        {
            IEnumerable<string> databases;
            try
            {
                databases = MongoUtilities.Create(cnnInfo).GetDatabaseNames();
            }
            catch
            {
                return ReturnConnectionFailure();
            }

            if (databases.Count() == 0)
            {
                return new List<MingTreeViewItem>
                    { new MingTreeViewItem(Utilities.BitmapImageFromBitmap(Properties.Resources.warning), Properties.Resources.TreeView_NoDatabases, new DatabasesEmptyNode(), false) };
            }

            var nodes = new List<MingTreeViewItem>();
            databases.ToList().ForEach(db =>
                nodes.Add(new MingTreeViewItem(Utilities.BitmapImageFromBitmap(Properties.Resources.database), db, new DatabaseNode(db), true)));

            return nodes;
        }
Пример #29
0
        private IEnumerable<MingTreeViewItem> LoadPropertyProperties(CollectionPropertyNode parent, ConnectionInfo cnnInfo)
        {
            IEnumerable<CollectionProperty> properties;
            try
            {
                var analyser = new CollectionPropertyAnalyser(MongoUtilities.Create(cnnInfo), parent.DatabaseName, parent.CollectionName);

                var parents = new List<string>();

                properties = analyser.GetProperties(parent.FullPath);
            }
            catch
            {
                return ReturnConnectionFailure();
            }

            var nodes = new List<MingTreeViewItem>();
            properties.ToList().ForEach(property =>
            {
                var hasChildren = property.Type == BsonType.Document || property.Type == BsonType.Array;
                nodes.Add(new MingTreeViewItem(Utilities.BitmapImageFromBitmap(hasChildren ? Properties.Resources.documents : Properties.Resources.document),
                    property.Name,
                    string.Format("({0})", property.Type.ToString().ToLower()),
                    new CollectionPropertyNode(parent.DatabaseName, parent.CollectionName, property.Name, string.Format("{0}.{1}", parent.FullPath, property.Name)), hasChildren));
            });
            return nodes;
        }
Пример #30
0
        private IEnumerable<MingTreeViewItem> LoadReplicaSet(ConnectionInfo cnnInfo)
        {
            try
            {
                var rsState = MongoUtilities.GetReplicaSetInfo(cnnInfo);
                if (rsState == null)
                {
                    return LoadDatabases(cnnInfo);
                }

                var items = new List<MingTreeViewItem>();

                rsState.ToList().ForEach(member =>
                    {
                        var dynamicChildren = !member.IsArbiter;
                        var image = member.IsPrimary ? Properties.Resources.primary : member.IsArbiter ? Properties.Resources.arbiter : Properties.Resources.secondary;
                        items.Add(
                            new MingTreeViewItem(
                                Utilities.BitmapImageFromBitmap(image),
                                    string.Format("{0}:{1}", member.Host, member.Port),
                                    new ReplicaSetMemberNode(member.Host, member.Port, member.IsPrimary),
                                    dynamicChildren));
                    });

                return items;
            }
            catch
            {
                return ReturnConnectionFailure();
            }
        }