Ejemplo n.º 1
0
        private OpmVerificationResult Verify(EanEicCode code)
        {
            CheckResult codeValid = EanEicCheckerHttpClient.Post(code);

            if (codeValid.ResultCode != CheckResultCode.EanOk && codeValid.ResultCode != CheckResultCode.EicOk)
            {
                throw new EanEicCodeInvalidException();
            }

            //OK, code is valid, try to find the record in the OpmRepository
            Opm opmForCode;

            if (OpmRepository.TryGetOpm(code, out opmForCode))
            {
                return(new OpmVerificationResult(true));
            }
            return(new OpmVerificationResult(false));
        }
Ejemplo n.º 2
0
        private OpmVerificationResult Verify(EanEicCode code)
        {
            CheckResult codeValid = EanEicCheckerHttpClient.Post(code);

            if (codeValid.ResultCode != CheckResultCode.EanOk && codeValid.ResultCode != CheckResultCode.EicOk)
            {
                //TODO SP: what to do now - maybe better to just return 'false'
                throw new ArgumentException("The supplied code is not valid." + "\n" + codeValid.Description);
            }

            //OK, code is valid, try to find it in the OpmRepository
            Opm opmForCode;

            if (OpmRepository.TryGetOpm(code, out opmForCode))
            {
                return(new OpmVerificationResult(true));
            }
            return(new OpmVerificationResult(false));
        }
Ejemplo n.º 3
0
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();

            #region IoC
            var container = new UnityContainer();
            container.RegisterType<IOpmVerificator, OpmVerificator>(new HierarchicalLifetimeManager());

            string idmUrl = System.Configuration.ConfigurationManager.AppSettings["IdmUrl"];
            IIdentityManagement idm = new IdentityManagement(idmUrl);
            container.RegisterInstance(idm);

            string eanEicCheckerUrl = System.Configuration.ConfigurationManager.AppSettings["EanEicCheckerUrl"];
            IEanEicCheckerHttpClient eanEicCheckerHttpClient = new EanEicCheckerHttpClient(eanEicCheckerUrl);
            container.RegisterInstance(eanEicCheckerHttpClient);

            IOpmRepository opmInMemoryRepository = new OpmInMemoryRepository();
            OpmRepoFiller.Fill(opmInMemoryRepository);
            container.RegisterInstance(opmInMemoryRepository);

            config.DependencyResolver = new UnityResolver(container);
            #endregion IoC
        }