Пример #1
0
        // ToDo: public method - it should be protected, web parser user should not know starting unit - it has to be registered & only mehod startparcing should be available
        public void ExecuteUnit <TIn, TOut>(TIn handlerInputModel)
        {
            try
            {
                if (!workUnits.ContainsKey(Key <TIn, TOut>()))
                {
                    throw new ArgumentException($"Handler for input model '{typeof(TIn).Name}' and output model '{typeof(TOut).Name}' is not registered");
                }

                var workUnitObject = workUnits[Key <TIn, TOut>()];

                var workUnit = workUnitObject as IUnit <TIn>;

                if (workUnit == null)
                {
                    throw new Exception("Unexpected type");
                }

                var workUnitName = workUnit.GetType().Name;

                if (ExecutionPath.AlreadyExecuted(workUnitName))
                {
                    throw new Exception("Cycle found during execution");
                }

                ExecutionPath.Add(workUnitName);

                workUnit.ParseAndSelectNext(handlerInputModel);
            }
            catch (Exception ex)
            {
                Exception = ex;
            }
        }
Пример #2
0
 public WebParser()
 {
     workUnits     = new Dictionary <Tuple <Type, Type>, object>();
     Result        = new TResult();
     ExecutionPath = new ExecutionPath();
 }