public Cursor(StatefulFilterTransform <TSrc, TDst, TState> parent, RowCursor <TSrc> input, IEnumerable <DataViewSchema.Column> columnsNeeded)
                : base(parent.Host)
            {
                Ch.AssertValue(input);
                Ch.AssertValue(columnsNeeded);

                _parent = parent;
                _input  = input;

                _src   = new TSrc();
                _dst   = new TDst();
                _state = new TState();

                CursorChannelAttribute.TrySetCursorChannel(_parent.Host, _src, Ch);
                CursorChannelAttribute.TrySetCursorChannel(_parent.Host, _dst, Ch);
                CursorChannelAttribute.TrySetCursorChannel(_parent.Host, _state, Ch);

                parent._initStateAction?.Invoke(_state);

                var appendedDataView = new DataViewConstructionUtils.SingleRowLoopDataView <TDst>(parent.Host, _parent._addedSchema);

                appendedDataView.SetCurrentRowObject(_dst);

                var columnNames = columnsNeeded.Select(c => c.Name);

                _appendedRow = appendedDataView.GetRowCursor(appendedDataView.Schema.Where(c => !c.IsHidden && columnNames.Contains(c.Name)));
            }
            public Cursor(StatefulFilterTransform <TSrc, TDst, TState> parent, IRowCursor <TSrc> input, Func <int, bool> predicate)
                : base(parent.Host)
            {
                Ch.AssertValue(input);
                Ch.AssertValue(predicate);

                _parent = parent;
                _input  = input;

                _src   = new TSrc();
                _dst   = new TDst();
                _state = new TState();

                CursorChannelAttribute.TrySetCursorChannel(_parent.Host, _src, Ch);
                CursorChannelAttribute.TrySetCursorChannel(_parent.Host, _dst, Ch);
                CursorChannelAttribute.TrySetCursorChannel(_parent.Host, _state, Ch);

                if (parent._initStateAction != null)
                {
                    parent._initStateAction(_state);
                }

                var appendedDataView = new DataViewConstructionUtils.SingleRowLoopDataView <TDst>(parent.Host, _parent._addedSchema);

                appendedDataView.SetCurrentRowObject(_dst);

                Func <int, bool> appendedPredicate =
                    col =>
                {
                    col = _parent._bindings.AddedColumnIndices[col];
                    return(predicate(col));
                };

                _appendedRow = appendedDataView.GetRowCursor(appendedPredicate);
            }
Ejemplo n.º 3
0
 public T FindData(T t)
 {
     return(AllDatas.FirstOrDefault((TSrc) =>
     {
         return TSrc.Predicate(t);
     }));
 }
            public Cursor(StatefulCustomMappingFilter <TSrc, TState> parent, DataViewRowCursor input, bool[] active)
                : base(parent.Host, input, input.Schema, active)
            {
                Contracts.AssertValue(parent);

                IRowReadableAs <TSrc> inputRow = parent.TypedSrc.GetRow(input);

                TSrc   src   = new TSrc();
                TState state = new TState();

                parent._stateInitAction(state);
                long   lastServedPosition = -1;
                Action refresh            = () =>
                {
                    if (lastServedPosition != input.Position)
                    {
                        inputRow.FillValues(src);
                        lastServedPosition = input.Position;
                    }
                };

                var predicate = parent._predicate;

                _accept = () =>
                {
                    refresh();
                    return(!predicate(src, state));
                };
            }
            protected ValueGetter <TDst> GetLambdaGetter()
            {
                var  getter = _inputCursor.GetGetter <TSrc>(_view._srcIndex);
                TSrc temp   = default(TSrc);

                return((ref TDst dst) =>
                {
                    getter(ref temp);
                    _view._mapper(in temp, ref dst);
                });
            }
Ejemplo n.º 6
0
        public void Fixture_MapFromString <TSrc, TDest>()
            where TSrc : class, new() where TDest : class, new()
        {
            dynamic src = new TSrc();

            src.Value = 13.ToString();

            dynamic dest = Map <TSrc, TDest>(src);

            Assert.AreEqual(src.Value, dest.Value.ToString());
        }
Ejemplo n.º 7
0
            public void UpdateData(T t)
            {
                var fd = AllDatas.FirstOrDefault((TSrc) =>
                {
                    return(TSrc.Predicate(t));
                });

                if (fd != null)
                {
                    fd.Update(t);
                }
            }
Ejemplo n.º 8
0
            public Row(IRow <TSrc> input, MapTransform <TSrc, TDst> parent, Func <int, bool> active, TSrc src, TDst dst)
            {
                _input  = input;
                _parent = parent;
                _schema = parent.Schema;

                _active = Utils.BuildArray(_schema.ColumnCount, active);
                _src    = src;
                _dst    = dst;

                _lastServedPosition = -1;
                _appendedRow        = _parent.GetAppendedRow(active, _dst);
            }
Ejemplo n.º 9
0
            public void DelByUser(string user, T t)
            {
                if (!AllataDict.ContainsKey(user))
                {
                    return;
                }
                var fd = AllDatas.FirstOrDefault((TSrc) =>
                {
                    return(TSrc.Predicate(t));
                });

                if (fd != null)
                {
                    AllDatas.Remove(fd);
                    AllataDict[user].Remove(fd);
                }
            }
Ejemplo n.º 10
0
                public Cursor(RowToRowMapper parent, DataViewRowCursor input, bool[] active)
                    : base(parent.Host, input)
                {
                    Ch.AssertValue(parent);
                    Ch.Assert(active == null || active.Length == parent.OutputSchema.Count);

                    _parent  = parent;
                    _active  = active;
                    _getters = new Delegate[parent._parent.AddedSchema.Columns.Length];

                    var dstRow = new DataViewConstructionUtils.InputRow <TDst>(_parent.Host, _parent._parent.AddedSchema);
                    IRowReadableAs <TSrc> inputRow = _parent._typedSrc.GetRow(input);

                    TSrc   src   = new TSrc();
                    TState state = new TState();
                    TDst   dst   = new TDst();

                    _parent._parent._stateInitAction(state);
                    long   lastServedPosition = -1;
                    Action refresh            = () =>
                    {
                        if (lastServedPosition != input.Position)
                        {
                            inputRow.FillValues(src);
                            _parent._parent._mapAction(src, dst, state);
                            dstRow.ExtractValues(dst);

                            lastServedPosition = input.Position;
                        }
                    };

                    for (int i = 0; i < active.Length; i++)
                    {
                        var iinfo = _parent._bindings.MapColumnIndex(out var isSrc, i);
                        if (isSrc)
                        {
                            continue;
                        }
                        _getters[iinfo] = Utils.MarshalInvoke(_parent.GetDstGetter <int>, _parent._bindings.Schema[i].Type.RawType, dstRow, _parent._bindings.Schema[i].Name, refresh);
                    }
                }
Ejemplo n.º 11
0
            public Delegate[] CreateGetters(IRow input, Func <int, bool> activeOutput, out Action disposer)
            {
                disposer = null;
                // If no outputs are active, we short-circuit to empty array of getters.
                var result = new Delegate[_parent.AddedSchema.Columns.Length];

                if (!Enumerable.Range(0, result.Length).Any(activeOutput))
                {
                    return(result);
                }

                var dstRow = new DataViewConstructionUtils.InputRow <TDst>(_host, _parent.AddedSchema);
                IRowReadableAs <TSrc> inputRow = _typedSrc.GetRow(input);

                TSrc src = new TSrc();
                TDst dst = new TDst();

                long   lastServedPosition = -1;
                Action refresh            = () =>
                {
                    if (lastServedPosition != input.Position)
                    {
                        inputRow.FillValues(src);
                        _parent._mapAction(src, dst);
                        dstRow.ExtractValues(dst);

                        lastServedPosition = input.Position;
                    }
                };

                for (int i = 0; i < result.Length; i++)
                {
                    if (!activeOutput(i))
                    {
                        continue;
                    }
                    result[i] = Utils.MarshalInvoke(GetDstGetter <int>, dstRow.Schema[i].Type.RawType, dstRow, i, refresh);
                }
                return(result);
            }
Ejemplo n.º 12
0
            protected override Delegate[] CreateGetters(DataViewRow input, IEnumerable <DataViewSchema.Column> activeColumns, out Action disp)
            {
                disp = null;
                var getters = new Delegate[_parent.AddedSchema.Columns.Length];

                var dstRow = new DataViewConstructionUtils.InputRow <TDst>(Host, _parent.AddedSchema);
                IRowReadableAs <TSrc> inputRow = _typedSrc.GetRow(input);

                TSrc   src   = new TSrc();
                TState state = new TState();
                TDst   dst   = new TDst();

                _parent._stateInitAction(state);
                long   lastServedPosition = -1;
                Action refresh            = () =>
                {
                    if (lastServedPosition != input.Position)
                    {
                        inputRow.FillValues(src);
                        _parent._mapAction(src, dst, state);
                        dstRow.ExtractValues(dst);

                        lastServedPosition = input.Position;
                    }
                };

                foreach (var col in activeColumns)
                {
                    var iinfo = _bindings.MapColumnIndex(out var isSrc, col.Index);
                    if (isSrc)
                    {
                        continue;
                    }
                    getters[iinfo] = Utils.MarshalInvoke(GetDstGetter <int>, col.Type.RawType, dstRow, col.Name, refresh);
                }

                return(getters);
            }