private MongoDocumentProperty UpdateDocument(MongoDocumentProperty doc) { var db = MongoUtilities.Create(_cnn).GetDatabase(_databaseName); var col = db.GetCollection(_collectionName); var query = Query.EQ("_id", doc.DocumentObjectId); try { var document = GetBsonDocumentFromCollection(doc.DocumentObjectId); col.Save(document); } catch { doc.IsInError = true; } return doc; }
public void AddChild(MongoDocumentProperty child) { child.Parent = this; _children.Add(child); }
private void SetChildrensVisibility(MongoDocumentProperty documentProperty, Visibility visibility) { documentProperty.Children.ToList().ForEach(item => { item.Visible = visibility; SetChildrensVisibility(item, visibility); }); }
private void PropertyExpanderClicked(MongoDocumentProperty documentProperty) { var visibility = Visibility.Visible; if (! documentProperty.Expanded) { visibility = Visibility.Collapsed; } SetChildrensVisibility(documentProperty, visibility); }
private BsonValue GetBsonValue(MongoDocumentProperty property) { switch (property.Type) { case BsonType.Array: BsonArray arr = new BsonArray(); property.Children.ToList().ForEach( item => arr.Add(GetBsonValue(item))); return arr; case BsonType.Document: BsonDocument doc = new BsonDocument(); property.Children.ToList().ForEach( item => doc.Add(item.Key, GetBsonValue(item))); return doc; default: BsonValue value; if (MongoUtilities.TryConvertStringToBsonType(property.Type, property.Value, out value)) { return value; } return null; } }
private void DocumentUpdated(MongoDocumentProperty doc) { doc.Updated(); }
private void AddItems(BsonElement[] elements, int level, bool alt, MongoDocumentProperty parent, BsonValue objectId, int? arrayIndex = null) { var orderedElements = elements.OrderBy(element => element.Name); foreach (var item in orderedElements) { var mdp = new MongoDocumentProperty { AlternateRow = alt, ArrayIndex = arrayIndex, Depth = level * 20, DocumentObjectId = objectId, Expanded = true, ExpanderVisibility = Visibility.Hidden, FullPath = parent == null ? item.Name : string.Format("{0}{1}{2}", parent.FullPath, arrayIndex == null ? "." : "", item.Name), Id = _nextItemId++, Key = item.Name, TextBoxVisibility = Visibility.Visible, Type = item.Value.BsonType, Value = null, Visible = Visibility.Visible }; if (level == 0 && item.Name == "_id") { mdp.ReadOnly = true; } if (parent != null) { parent.AddChild(mdp); } switch (item.Value.BsonType) { case BsonType.Document: mdp.ExpanderVisibility = Visibility.Visible; mdp.TextBoxVisibility = Visibility.Hidden; mdp.ReadOnly = true; _collectionData.Add(mdp); AddItems(item.Value.AsBsonDocument.ToArray(), level + 1, alt, mdp, objectId); break; case BsonType.Array: mdp.ExpanderVisibility = Visibility.Visible; mdp.TextBoxVisibility = Visibility.Hidden; mdp.ReadOnly = true; _collectionData.Add(mdp); var idx = 0; foreach (var arrayItem in item.Value.AsBsonArray) { AddItems(new[] { new BsonElement(string.Format("[{0}]", idx), arrayItem) }, level + 1, alt, mdp, objectId, idx); idx++; } break; case BsonType.Binary: mdp.Value = Convert.ToBase64String((byte[]) item.Value); mdp.PropertyChanged += DocumentPropertyChanged; _collectionData.Add(mdp); break; default: mdp.Value = item.Value.ToString(); mdp.PropertyChanged += DocumentPropertyChanged; _collectionData.Add(mdp); break; } } }