예제 #1
0
        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;
        }
예제 #2
0
 public void AddChild(MongoDocumentProperty child)
 {
     child.Parent = this;
     _children.Add(child);
 }
예제 #3
0
 private void SetChildrensVisibility(MongoDocumentProperty documentProperty, Visibility visibility)
 {
     documentProperty.Children.ToList().ForEach(item => { item.Visible = visibility; SetChildrensVisibility(item, visibility); });
 }
예제 #4
0
 private void PropertyExpanderClicked(MongoDocumentProperty documentProperty)
 {
     var visibility = Visibility.Visible;
     if (! documentProperty.Expanded)
     {
         visibility = Visibility.Collapsed;
     }
     SetChildrensVisibility(documentProperty, visibility);
 }
예제 #5
0
 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;
     }
 }
예제 #6
0
 private void DocumentUpdated(MongoDocumentProperty doc)
 {
     doc.Updated();
 }
예제 #7
0
        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;
                }
            }
        }