Exemplo n.º 1
0
        /// <summary>
        /// Attempts to read from this operator's underlying input stream(s) until the next set of
        /// bindings is found which can be outputted by this operator.
        /// </summary>
        /// <returns>
        ///   <c>true</c> if a next binding set is found available to output; otherwise, <c>false</c>.
        /// </returns>
        internal override bool TryReadNext()
        {
            //
            // first creat the sorted temporary file, if it doesn't already exist

            if (!m_tmpFileCreated)
            {
                CreateTmpFile();
            }

            //
            // one the temporary file is in place, we simply read triples from it in order

            if (m_reader.BaseStream.Position < m_reader.BaseStream.Length)
            {
                m_next = new BindingSet();
                for (int i = 0; i < m_sortOrder.Length; i++)
                {
                    var a = new Atom(m_reader.ReadInt64());
                    m_next.Add(new Binding(m_sortOrder[i], a));
                }

                m_hasNext = true;
                return(true);
            }
            else
            {
                m_hasNext = false;
                return(false);
            }
        }
Exemplo n.º 2
0
        public IEnumerable <BindingSet> GetBindings()
        {
            if (_query.QueryType == SparqlQueryType.Select)
            {
                List <BindingSet> result = new List <BindingSet>();

                foreach (var x in _resultHandler.SparqlResultSet)
                {
                    BindingSet r = new BindingSet();

                    foreach (var y in x)
                    {
                        if (y.Value != null)
                        {
                            r.Add(y.Key, ParseCellValue(y.Value));
                        }
                    }

                    result.Add(r);
                }

                return(result);
            }
            else
            {
                throw new QueryTypeNotSupportedException(_query.QueryType);
            }
        }
        protected override IList NonGenericIListFactory(int count)
        {
            BindingSet <string> collection = new BindingSet <string>();
            int seed = 9600;

            while (collection.Count < count)
            {
                object toAdd = CreateT(seed++);
                collection.Add((string)toAdd);
            }
            return(collection);
        }
Exemplo n.º 4
0
        internal CompositeItemBindingBuilder(
            [NotNull] SourceItemBinding <TSourceItem, TSourceItemValue> sourceItemBinding,
            [NotNull] TargetItemBinding <TTargetItem, TTargetItemValue> targetItemBinding,
            [NotNull] BindingSet <TSourceItem> bindingSet)
        {
            _compositeItemBinding = new CompositeItemBinding <TSourceItem, TSourceItemValue, TTargetItem, TTargetItemValue>(
                sourceItemBinding,
                targetItemBinding,
                BindingMode.TwoWay,
                new CompositeItemBindingValueConverter <DefaultValueConverter>());

            bindingSet.Add(_compositeItemBinding);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads a single binding set from the given binary input stream.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <returns>
        /// A binding set.
        /// </returns>
        public static BindingSet Read(BinaryReader input)
        {
            var count  = input.ReadInt32();
            var values = new BindingSet();

            for (int i = 0; i < count; i++)
            {
                var v = new Variable(input.ReadInt64());
                var a = new Atom(input.ReadInt64());
                values.Add(new Binding(v, a));
            }
            return(values);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Merges the two specified binding sets together, returning a new binding set which
        /// contains bindings from the two given sets.
        /// </summary>
        /// <param name="left">The left binding set.</param>
        /// <param name="right">The right binding set.</param>
        /// <returns>
        /// A new binding set merging the two given sets.
        /// </returns>
        private BindingSet Merge(BindingSet left, BindingSet right)
        {
#if DEBUG
            m_planOperator.StartCPUWork();
#endif
            var b = new BindingSet();

            //
            // binding sets internally disregard (v : a) if they already have some (v : a')

            foreach (var item in left.Bindings)
            {
                b.Add(item);
            }
            foreach (var item in right.Bindings)
            {
                b.Add(item);
            }
#if DEBUG
            m_planOperator.StopCPUWork();
#endif
            return(b);
        }
        internal CompositeItemCommandBindingBuilder(
            [NotNull] SourceItemCommandBinding <TSourceItem, TSourceItemValue> sourceItemBinding,
            [NotNull] TargetItemBinding <TTargetItem, TTargetItemValue> targetItemBinding,
            [NotNull] BindingSet <TSourceItem> bindingSet)
        {
            _compositeItemBinding = new CompositeItemCommandBinding <TSourceItem, TSourceItemValue, TTargetItem, TTargetItemValue>(
                sourceItemBinding,
                targetItemBinding,
                BindingMode.OneWayToSource,
                new CompositeItemBindingValueConverter <TSourceItem>(typeof(DefaultValueConverter)));

            _bindingSet = bindingSet;
            _bindingSet.Add(_compositeItemBinding);
        }
        internal CompositeItemCommandBindingBuilder(
            [NotNull] SourceItemCommandBinding <TSourceItem, TSourceItemValue> sourceItemBinding,
            [NotNull] TargetItemBinding <TTargetItem, TTargetItemValue> targetItemBinding,
            [NotNull] BindingSet <TSourceItem> bindingSet,
            [NotNull] ICompositeItemBinding <TSourceItem> oldCompositeItemBinding)
        {
            _compositeItemBinding = new CompositeItemCommandBinding <TSourceItem, TSourceItemValue, TTargetItem, TTargetItemValue>(
                sourceItemBinding,
                targetItemBinding,
                oldCompositeItemBinding.RequestedBindingMode,
                oldCompositeItemBinding.ValueConverter);

            _bindingSet = bindingSet;
            _bindingSet.Remove(oldCompositeItemBinding);
            _bindingSet.Add(_compositeItemBinding);
        }
Exemplo n.º 9
0
        public InputBinder(InputConfig config)
        {
            On <InputEvent>(OnInput);
            On <LoadMapEvent>(e => _mapId = e.MapId);

            foreach (var rawMode in config.Bindings)
            {
                if (!_bindings.ContainsKey(rawMode.Key))
                {
                    _bindings.Add(rawMode.Key, new Dictionary <KeyBinding, string>());
                }

                var mode = _bindings[rawMode.Key];
                foreach (var rawBinding in rawMode.Value)
                {
                    var parts     = rawBinding.Key.Split('+').Select(x => x.Trim().ToLower()).ToArray();
                    Key key       = Key.LastKey;
                    var modifiers = ModifierKeys.None;
                    for (int i = 0; i < parts.Length; i++)
                    {
                        if (i == parts.Length - 1)
                        {
                            if (int.TryParse(parts[i], out var numeric))
                            {
                                key = Key.Number0 + numeric;
                            }
                            else
                            {
                                key = Enum.Parse <Key>(parts[i], true);
                            }
                        }
                        else
                        {
                            modifiers |= Enum.Parse <ModifierKeys>(parts[i], true);
                        }
                    }

                    if (key != Key.LastKey)
                    {
                        mode[new KeyBinding(key, modifiers)] = rawBinding.Value;
                    }
                }
            }
        }
Exemplo n.º 10
0
        public IEnumerable <BindingSet> GetBindings()
        {
            List <BindingSet> result = new List <BindingSet>();

            if (_query.QueryType == SparqlQueryType.Select)
            {
                foreach (var x in _resultSet)
                {
                    BindingSet r = new BindingSet();
                    foreach (var y in x)
                    {
                        if (y.Value != null)
                        {
                            r.Add(y.Key, ParseCellValue(y.Value));
                        }
                    }
                    result.Add(r);
                }
            }

            return(result);
        }
Exemplo n.º 11
0
        public IEnumerable <BindingSet> GetBindings()
        {
            if (_query.QueryType == SparqlQueryType.Select)
            {
                foreach (SparqlResult result in _queryResults)
                {
                    BindingSet b = new BindingSet();

                    foreach (var r in result)
                    {
                        if (r.Value != null)
                        {
                            b.Add(r.Key, ParseCellValue(r.Value));
                        }
                    }

                    yield return(b);
                }
            }
            else
            {
                throw new ArgumentException("Cannot return bindings for queries of type " + _query.QueryType.ToString());
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Attempts to read from this operator's underlying input stream(s) until the next set of
        /// bindings is found which can be outputted by this operator.
        /// </summary>
        /// <returns>
        ///   <c>true</c> if a next binding set is found available to output; otherwise, <c>false</c>.
        /// </returns>
        internal override bool TryReadNext()
        {
            while (m_cursor.HasNext && (!m_isMiniBucket || m_count > 0))
            {
#if DEBUG
                m_planOperator.StartIOWork();
#endif
                var next = m_cursor.Next();
#if DEBUG
                m_planOperator.StopIOWork();
                m_planOperator.StartCPUWork();
#endif

                if (m_isMiniBucket)
                {
                    m_count--;
                }

                if (IsMatch(next))
                {
                    //
                    // if a triple has been found which matches the given SAP, prepare a binding
                    // set and add the atoms in positions where the SAP has a variable to the set

                    m_next = new BindingSet();

                    if (!m_patternAtoms.HasFlag(TriplePosition.S))
                    {
                        var b = new Binding(m_pattern.S as Variable, next.S);
                        m_next.Add(b);
                    }

                    if (!m_patternAtoms.HasFlag(TriplePosition.P))
                    {
                        var b = new Binding(m_pattern.P as Variable, next.P);
                        m_next.Add(b);
                    }

                    if (!m_patternAtoms.HasFlag(TriplePosition.O))
                    {
                        var b = new Binding(m_pattern.O as Variable, next.O);
                        m_next.Add(b);
                    }

                    m_hasNext = true;
#if DEBUG
                    m_planOperator.StopCPUWork();
                    m_planOperator.AddResult();
#endif
                    return(true);
                }
                else if (!PossibleMatchesAfter(next))
                {
                    //
                    // if the current triple does not match the SAP, see if it is possible that
                    // there are still matches some time after this triple. if there are no more
                    // matches possible, we are done here.
#if DEBUG
                    m_planOperator.StopCPUWork();
#endif
                    break;
                }
#if DEBUG
                m_planOperator.StopCPUWork();
#endif
            }

            m_hasNext = false;
            return(false);
        }