コード例 #1
0
ファイル: BSONSelector.cs プロジェクト: jburman/ZeroG
        public BSONSelector(BSONWalkingEvents events, string[] paths, BSONSelectorOptions options)
        {
            if (null == events)
            {
                throw new ArgumentNullException("events");
            }

            _events                 = events;
            paths                   = paths ?? new string[0];

            if (options.IgnoreArrays())
            {
                // Filter out paths containing array specifiers
                _paths              = paths.Where(p => -1 == p.IndexOf(ArraySpecifier))
                                        .ToDictionary<string, string>(p => p);
            }
            else
            {
                _paths              = paths.ToDictionary<string, string>(p => p);
            }

            _selectedValues         = new List<SelectedValue>();
            _options                = options;

            _documentPathStack      = new Stack<string>();
            _docTypeStack           = new Stack<BSONTypes>();
            _docPath                = string.Empty;
            _memberPath             = string.Empty;

            _arrayIndex             = -1;
            _arrayIndexStack        = new Stack<int>();

            _events.DocumentStart   += new BSONEventHandler(_events_DocumentStart);
            _events.DocumentEnd     += new BSONEventHandler(_events_DocumentEnd);
            _events.Element         += new BSONElementEventHandler(_events_Element);

            _events.ArrayStart      += new BSONEventHandler(_events_ArrayStart);
            _events.ArrayEnd        += new BSONEventHandler(_events_ArrayEnd);

            _events.String          += new BSONValueEventHandler<string>(_events_String);
            _events.Int32           += new BSONValueEventHandler<Int32>(_events_Int32);
            _events.Int64           += new BSONValueEventHandler<Int64>(_events_Int64);
            _events.Double          += new BSONValueEventHandler<double>(_events_Double);
            _events.DateTime        += new BSONValueEventHandler<DateTime>(_events_DateTime);
            _events.Value           += new BSONValueEventHandler(_events_Value);
            _events.Null            += new BSONEventHandler(_events_Null);
            _events.Boolean         += new BSONValueEventHandler<bool>(_events_Boolean);
        }
コード例 #2
0
ファイル: BSONSelector.cs プロジェクト: jburman/ZeroG
        public static SelectedValue[] SelectValues(BinaryReader bson, string[] selectors, BSONSelectorOptions options)
        {
            if (null == bson)
            {
                return new SelectedValue[0];
            }

            // Create tokenizer for the BSON document - this is fed to a Tree Walking Validator
            BSONTokenizer tokenizer = new BSONTokenizer(bson);

            // Create an events object for the Tree Walker - events are fired as the walker
            // traverses nodes in the tree.
            BSONWalkingEvents events = new BSONWalkingEvents();

            // The selector subscribes to the Walker Events and selects the appropriate values from the
            // BSON tree.
            BSONSelector selector = new BSONSelector(events, selectors);

            // A BSON Tree Walker that validates the structure of the BSON and also fires events
            // while traversing the document.
            BSONWalkingValidator walker = new BSONWalkingValidator();
            walker.Walk(tokenizer.GetEnumerator(), events);

            // Retrieve the values selected from the BSON.
            return selector.SelectedValues;
        }
コード例 #3
0
ファイル: BSONSelector.cs プロジェクト: jburman/ZeroG
 private static bool IsOptionSet(this BSONSelectorOptions options, BSONSelectorOptions flagToCheck)
 {
     return (flagToCheck == (flagToCheck & options));
 }
コード例 #4
0
ファイル: BSONSelector.cs プロジェクト: jburman/ZeroG
        public static SelectedValue[] SelectValues(byte[] bson, string[] selectors, BSONSelectorOptions options)
        {
            if (null == bson)
            {
                return new SelectedValue[0];
            }

            return SelectValues(new BinaryReader(new MemoryStream(bson)), selectors, options);
        }