Beispiel #1
0
        public void ParseMetaData()
        {
            _reader = new BinaryReader(Stream, Encoding.ASCII);

            var             parsers = new ParserProvider();
            IList <IRecord> records = new List <IRecord>(1000);

            MetaData = new MetaData();

            RecordType    readRecordType;
            IRecord       record;
            IRecordParser recordParser;

            // Read the header record and validate this file
            try
            {
                readRecordType = _reader.ReadRecordType();
                if (readRecordType != RecordType.HeaderRecord)
                {
                    throw new SpssFileFormatException("No header record is present. A header record is required. Is this a valid SPSS file?");
                }
                recordParser = parsers.GetParser(readRecordType);
                record       = recordParser.ParseRecord(_reader);
                record.RegisterMetadata(MetaData);
                records.Add(record);
            }
            catch (EndOfStreamException)
            {
                throw new SpssFileFormatException("No header record is present. A header record is required. Is your file empty?");
            }

            // Read the rest of the records
            do
            {
                readRecordType = _reader.ReadRecordType();
                recordParser   = parsers.GetParser(readRecordType);
                record         = recordParser.ParseRecord(_reader);
                record.RegisterMetadata(MetaData);
                records.Add(record);
            } while (readRecordType != RecordType.End);


            try
            {
                _dataStartPosition = Stream.Position;
            }
            catch (NotSupportedException)
            {
                // Some stream types don't support the Position property (CryptoStream...)
                _dataStartPosition = 0;
            }

            SetDataRecordStream();
            MetaDataParsed = true;
        }
        public void SetUp()
        {
            _firstParser = Substitute.For <IParser>();
            _firstParser.Type.Returns("firstParserType");

            _secondParser = Substitute.For <IParser>();
            _secondParser.Type.Returns("secondtParserType");

            var parsers = new []
            {
                _firstParser,
                _secondParser
            };

            _sut = new ParserProvider(parsers);
        }
        /// <inheritdoc />
        public bool Process(string resultInput)
        {
            IInputParser inputParser = ParserProvider.GetResultInputParser(resultInput) as IInputParser;
            if (inputParser == null)
            {
                return false;
            }

            inputParser.DoParse(resultInput);
            if (!inputParser.IsSuccess)
            {
                return false;
            }

            ProductData.BettingResult = inputParser;
            return true;
        }
        /// <inheritdoc />
        public bool Process(string betInput)
        {
            IBetInputParser inputParser = ParserProvider.GetBetInputParser(betInput) as IBetInputParser;

            if (inputParser == null)
            {
                return(false);
            }

            inputParser.DoParse(betInput);
            if (!inputParser.IsSuccess)
            {
                return(false);
            }

            IProduct product = ProductData.ProductsHost[inputParser.ProductCode] as IProduct;

            product.AddBetData(inputParser.RunnersList, inputParser.BetAmount);
            return(true);
        }
 public PascalPreprocessor()
 {
     Parser = ParserProvider.GetParser();
 }
Beispiel #6
0
 public ApplicationManager()
 {
     _parser   = new ParserProvider();
     _database = new CRMContext();
     _database.Configuration.LazyLoadingEnabled = false;
 }
Beispiel #7
0
 public ParsingContext()
 {
     m_relatedParserProvider = new ParserProvider(this);
 }
Beispiel #8
0
 public SharpPreprocessor()
 {
     Parser     = ParserProvider.GetParser();
     Properties = new SharpPreprocessorProperties();
 }
Beispiel #9
0
        public async Task <IHttpActionResult> Post(CancellationToken ct)
        {
            /**
             * - TenantFinder:  HttpRequest x HttpRequestContext -> Tenant
             * - CommandParser: Tenant -> HttpRequest -> ParsedCommand x CommandType x Version
             * - Translator:    Tenant -> ParsedCommand x CommandType x Version -> CommandEnvelope
             * - Sender: Tenant -> CommandEnvelope -> HttpResult
             */

            // Get tenantId for current request
            var tenantId = await TenantFinder.FindTenantAsync(Request, RequestContext, ct);

            if (tenantId == null)
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden, "Unknown Tenant".ToModelStateErrors())));
            }

            //var multi = await Request.Content.ReadAsMultipartAsync();

            // Parse incomming request as a command schema
            var parser = await ParserProvider.GetParserAsync(tenantId, ct);

            if (parser == null)
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.InternalServerError, "Can not parse request".ToModelStateErrors())));
            }

            var parsedCommandResult = await parser.ParseAsync(Request, RequestContext, ct);

            if (!parsedCommandResult.Success)
            {
                return(BadRequest(parsedCommandResult.Errors.ToModelStateErrors()));
            }

            // Validate parsed command
            var translator = await TranslatorProvider.GetTranslatorAsync(tenantId, ct);

            if (translator == null)
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.InternalServerError, "Can not recognize command".ToModelStateErrors())));
            }

            var translation = await translator.TranslateAsync(parsedCommandResult, ct);

            if (translation.Success)
            {
                // Now send command through the ICommandSender
                var sender = await CommandSenderProvider.GetSenderAsync(tenantId, ct);

                if (sender == null)
                {
                    return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                                                            "Can not start processing command".ToModelStateErrors())));
                }

                var sendResult = await sender.SendCommandAsync(translation.CommandEnvelope, ct);

                if (sendResult.Success)
                {
                    switch (sendResult.Type)
                    {
                    case SendCommandResultType.Completed:
                        return(Ok());

                    case SendCommandResultType.Accepted:
                        return(StatusCode(HttpStatusCode.Accepted));

                    default:
                        return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                                                                "Invalid response processing command".ToModelStateErrors())));
                    }
                }
                else
                {
                    switch (sendResult.Type)
                    {
                    case SendCommandResultType.ValidationFailed:
                        return(BadRequest(sendResult.Errors.ToModelStateErrors()));

                    case SendCommandResultType.BusinessPreconditionFailed:
                        return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden, sendResult.Errors.ToModelStateErrors())));

                    case SendCommandResultType.ProcessingError:
                        return(InternalServerError(sendResult.Exception));

                    case SendCommandResultType.BusinessPostconditionFailed:
                        return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden, sendResult.Errors.ToModelStateErrors())));

                    case SendCommandResultType.PersistenceFailed:
                        return(InternalServerError(sendResult.Exception));

                    default:
                        return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                                                                "Invalid response processing command".ToModelStateErrors())));
                    }
                }
            }
            else
            {
                switch (translation.Type)
                {
                case TranslationResultType.BadRequest:
                    return(BadRequest(translation.ModelState.ToModelStateErrors()));

                case TranslationResultType.NotFound:
                    return(NotFound());

                case TranslationResultType.Obsolete:
                    return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Gone, translation.ModelState.ToModelStateErrors())));

                default:
                    return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.InternalServerError, "Invalid response translating command".ToModelStateErrors())));
                }
            }
        }