Beispiel #1
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            ProductInfo  = new ProductInfo(this, CurrentLine.OfType <BaseOffer>());
            OrderWarning = new InlineEditWarning(UiScheduler, Manager);

            //если это отправленный заказ редактор не должен работать
            var currentOrderLine = new NotifyValue <OrderLine>();

            if (IsCurrentOrder)
            {
                currentOrderLine = CurrentLine.Select(v => (OrderLine)v).ToValue();
                currentOrderLine.Subscribe(v => CurrentLine.Value = v);
            }
            editor             = new Editor(OrderWarning, Manager, currentOrderLine, Lines.Cast <IList>().ToValue());
            OnlyWarningVisible = new NotifyValue <bool>(User.IsPreprocessOrders && IsCurrentOrder);
            CurrentLine.OfType <BaseOffer>()
            .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler)
            .Select(x => RxQuery(s => BaseOfferViewModel.LoadOrderHistory(s, Cache, Settings.Value, x, Address)))
            .Switch()
            .Subscribe(HistoryOrders, CloseCancellation.Token);

            FilterItems.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler)
            .Select(_ => Filter())
            .Subscribe(Lines, CloseCancellation.Token);
        }
Beispiel #2
0
        /// <summary>
        /// Initialize the serializer for reading
        /// </summary>
        private void InitialiseRead()
        {
            Initialise();
            _readBuffer = new Queue <string>(SkipFooterRows);
            if (_inputStream == null && _fileName == null)
            {
                throw new InvalidOperationException("Expected input stream or file name");
            }

            if (_inputStream == null && _fileName != null)
            {
                _inputStream = new FileStream(_fileName, FileMode.Open);
            }

            _readStream = new StreamReader(_inputStream);
            LineNo      = 0;

            if (_readStream.BaseStream.CanSeek)
            {
                _readStream.BaseStream.Position = 0;
            }

            for (int i = 0; i < SkipHeaderRows; i++)
            {
                if (_readStream.EndOfStream)
                {
                    throw new ArgumentException($"SkipRows ({SkipHeaderRows}) contains more rows than there are lines in the file");
                }
                _readStream.ReadLine();
                LineNo++;
            }

            if (FirstRowHeader)
            {
                LineNo++;
                var headerRow = _readStream.ReadLine();
                if (string.IsNullOrWhiteSpace(headerRow))
                {
                    throw new InvalidOperationException($"No header row found but one was expected");
                }

                MetaData = SplitLine(headerRow)
                           .Select((a, i) => new ColumnMetaData <T>()
                {
                    ColumnHeader = a.Trim(), Ordinal = i
                })
                           .ToArray();
            }

            if (_readStream.EndOfStream)
            {
                return; // file is empty, nothing to do
            }
            ReadNext();

            if (!FirstRowHeader)
            {
                MetaData = CurrentLine
                           .Select((a, i) => new ColumnMetaData <T>()
                {
                    ColumnHeader = null, Ordinal = i
                })
                           .ToArray();
            }

            foreach (var mapping in MappingAttributes)
            {
                var matchedMeta = MetaData.Where(a => a.IsMatch(mapping.Mapping));
                if (!matchedMeta.Any())
                {
                    throw new ArgumentException($"For mapping attribute on column {(mapping.Mapping.InternalColumnOrdinal.HasValue ? mapping.Mapping.ColumnOrdinal.ToString() : $"\"{mapping.Mapping.ColumnName}\"")}, no match was found in the file");