Example #1
0
        private IEnumerator Execute(IEnumerator enumerator, EnumeratorContext context)
        {
            while (true)
            {
                if (context.ExceptionWasRecorded)
                {
                    break;
                }

                try
                {
                    if (!enumerator.MoveNext())
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    context.RecordExceptionWithHint(ex);
                    break;
                }

                if (enumerator.Current is IEnumerator nestedEnumerator)
                {
                    yield return(Execute(nestedEnumerator, context));
                }
                else
                {
                    yield return(enumerator.Current);
                }
            }
        }
        public static void ValidateArticle(int templateCode, Stream inputStream)
        {
            if (!inputStream.CanSeek)
            {
                throw new InvalidOperationException($"Parameter '{nameof(inputStream)}' is not a seekable stream");
            }

            var enumeratorContext = new EnumeratorContext {
                IsGoalReached = false
            };

            try
            {
                ChmFile.Open(inputStream)
                .Enumerate(
                    EnumerateLevel.Normal | EnumerateLevel.Files,
                    ArticleEnumeratorCallback,
                    enumeratorContext);
            }
            catch (InvalidDataException)
            {
                throw new InvalidBinaryException(templateCode, new InvalidArticleError());
            }

            if (!enumeratorContext.IsGoalReached)
            {
                throw new InvalidBinaryException(templateCode, new ArticleMissingIndexError());
            }
        }
        public static void ValidateArticle(int templateCode, Stream inputStream)
        {
            var enumeratorContext = new EnumeratorContext {
                IsGoalReached = false
            };

            try
            {
                using (var memoryStream = new MemoryStream())
                {
                    inputStream.CopyTo(memoryStream);
                    memoryStream.Position = 0;

                    ChmFile.Open(memoryStream)
                    .Enumerate(
                        EnumerateLevel.Normal | EnumerateLevel.Files,
                        ArticleEnumeratorCallback,
                        enumeratorContext);
                }
            }
            catch (InvalidDataException)
            {
                throw new InvalidBinaryException(templateCode, new InvalidArticleError());
            }

            if (!enumeratorContext.IsGoalReached)
            {
                throw new InvalidBinaryException(templateCode, new ArticleMissingIndexError());
            }
        }
Example #4
0
        internal object ExecuteQuery(string members, string predicate, bool isEnumerable, params SqlParameter[] parameters)
        {
            int count     = this.dataTable.Rows.Count;
            var lastIndex = count - 1;
            var command   = this.commandBuilder.SelectCommand(members).FromTable(this.options.Table)
                            .When(predicate, parameters).Build();

            this.adapter.SelectCommand = command;
            this.adapter.Fill(this.dataTable);
            if (isEnumerable)
            {
                var context = new EnumeratorContext(lastIndex, this.dataTable, ElementType, this.options.Propertis);
                return(new EntityEnumerable <TEntity>(context));
            }
            else
            {
                if (this.dataTable.Rows.Count > count)
                {
                    var row = this.dataTable.Rows[lastIndex + 1];
                    return(this.mapper.MapRow(row));
                }
                return(null);
            }
        }
        private static EnumerateStatus ArticleEnumeratorCallback(ChmFile file, ChmUnitInfo unitInfo, EnumeratorContext context)
        {
            if (string.Equals(unitInfo.path.TrimStart('/'), "index.html", StringComparison.OrdinalIgnoreCase))
            {
                context.IsGoalReached = true;
                return(EnumerateStatus.Success);
            }

            return(EnumerateStatus.Continue);
        }
Example #6
0
	public EnumeratorContext enumerator() {
		EnumeratorContext _localctx = new EnumeratorContext(_ctx, State);
		EnterRule(_localctx, 158, RULE_enumerator);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 908; identifier();
			State = 911;
			_la = _input.La(1);
			if (_la==ASSIGN) {
				{
				State = 909; Match(ASSIGN);
				State = 910; constant_expression();
				}
			}

			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.ReportError(this, re);
			_errHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}