Ejemplo n.º 1
0
        public void AutoRegistration_MainComponentsSetUp()
        {
            var sw = new Stopwatch();

            sw.Start();
            var assembly = GetType().GetTypeInfo().Assembly;
            var res      = new AutoRegistration().GetComponentMap(t => t == typeof(TestDependentObject), assembly, t => true, assembly);

            sw.Stop();

            Assert.Equal(
                typeof(ProjectionQuery <Product, ProductDto>),
                res[typeof(IQuery <object, IEnumerable <ProductDto> >)]);

            Assert.Equal(
                typeof(PagedQuery <Product, ProductDto, int>),
                res[typeof(IQuery <IdPaging <ProductDto>, IPagedEnumerable <ProductDto> >)]);

            Assert.Equal(
                typeof(GetByIdQuery <int, Product, ProductDto>),
                res[typeof(IQuery <int, ProductDto>)]);

            Assert.Equal(
                typeof(CreateOrUpdateEntityHandler <int, ProductDto, Product>),
                res[typeof(IHandler <ProductDto, int>)]);

            Assert.True(sw.ElapsedMilliseconds < 50, $"Elapsed ms: {sw.ElapsedMilliseconds}");
        }
Ejemplo n.º 2
0
        public static ContextRouter InitializeContext()
        {
            ContextRouter contextRouter = new ContextRouter();

            InitializeContext(contextRouter);
            AutoRegistration.AutoRegister <Listener>(contextRouter);

            return(contextRouter);
        }
Ejemplo n.º 3
0
        protected ContextRouter InitializeMyContextRouter()
        {
            // Remember, trigger parameters must be in the order of the parameters in the Execute handler.

            ContextRouter cr = new ContextRouter();

            cr
            .Register <Startup>(this)
            .TriggerOn <DrawContext, OtherContextRouter, CanvasController, StartingListener>();

            AutoRegistration.AutoRegister <Listener>(cr);

            return(cr);
        }
        public void RegisterClassTest()
        {
            ContextRouter cr = new ContextRouter();

            AutoRegistration.AutoRegister <Logger>(cr);

            var listeners = cr.GetAllListeners();

            listeners.Count.Should().Be(1);
            listeners[0].Name.Should().Be(typeof(Logger).Name);

            var contexts = cr.GetTriggerContexts(typeof(Logger), "LogMe");

            contexts.Count.Should().Be(2);
            contexts[0].Should().Be("LogTextBox");
            contexts[1].Should().Be("LogInfo");
        }
Ejemplo n.º 5
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            // scan assemblies for types
            var currentAssembly = typeof(Startup).Assembly;
            var componentMap    = AutoRegistration.GetComponentMap(currentAssembly
                                                                   , x => typeof(IController).IsAssignableFrom(x)
                                                                   , currentAssembly
                                                                   , x => x.IsInterface);

            // init conventions for automapper
            StaticAutoMapperWrapper.Init(cfg =>
            {
                ConventionalProfile.Scan(currentAssembly);
                cfg.AddProfile <ConventionalProfile>();
            });

            // init IOC-container
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            var am = Lifestyle.Singleton.CreateRegistration(() => new StaticAutoMapperWrapper(), container);

            container.AddRegistration(typeof(IProjector), am);
            container.AddRegistration(typeof(IMapper), am);

            // Fake Context
            var reg = Lifestyle.Singleton.CreateRegistration(() => new FakeContext(new[] {
                new Product()
                {
                    Category = new Category()
                    {
                        Rating = 100500
                    },
                    Id    = 1,
                    Name  = "1 Product",
                    Price = 100500,
                }
                , new Product()
                {
                    Category = new Category(),
                    Id       = 2,
                    Name     = "2 Product",
                    Price    = 200500
                }
            }), container);

            container.AddRegistration(typeof(ILinqProvider), reg);
            container.AddRegistration(typeof(IUnitOfWork), reg);

            foreach (var kv in componentMap)
            {
                container.Register(kv.Key, kv.Value, Lifestyle.Scoped);
            }

            // This is an extension method from the integration package.
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Ejemplo n.º 6
0
        private bool LoginSuccess(string login, string pass)
        {
            this.login = login;
            this.pass  = pass;
            try
            {
                txtLogin.Text     = new MailAddress(txtLogin.Text).Address;
                autorizationModel = AutoRegistration.Login(login, pass);
                GlobalConfig.logger.Info($" Login: {login} success autorized. UserID: {autorizationModel.user_id}");
                MessageBox.Show($"userID:{autorizationModel.user_id} \r\n expires:{autorizationModel.expires_in} \r\n token:{autorizationModel.access_token}");
                GlobalConfig.AccessToken = autorizationModel.access_token;
                GlobalConfig.UserID      = autorizationModel.user_id;
                return(true);
            }
            #region Отраработка Ошибок
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception2FAutorization ex)
            {
                GlobalConfig.logger.Info($"На аккаунте установлена двухуровневая система авторизации \n {ex.Message}");
                DoSomeThing();
            }
            catch (ExceptionCapthaAutorization ex)
            {
                GlobalConfig.logger.Info($"Просит ввести капчу \n {ex.Message}");
                DoSomeThing();
            }
            catch (HttpException ex)
            {
                GlobalConfig.logger.Info("Произошла ошибка при работе с HTTP-сервером: {0}", ex.Message);
                switch (ex.Status)
                {
                case HttpExceptionStatus.Other:
                    GlobalConfig.logger.Info("Неизвестная ошибка");
                    break;

                case HttpExceptionStatus.ProtocolError:
                    GlobalConfig.logger.Info("Код состояния: {0}", (int)ex.HttpStatusCode);
                    break;

                case HttpExceptionStatus.ConnectFailure:
                    GlobalConfig.logger.Info("Не удалось соединиться с HTTP-сервером.");
                    break;

                case HttpExceptionStatus.SendFailure:
                    GlobalConfig.logger.Info("Не удалось отправить запрос HTTP-серверу.");
                    break;

                case HttpExceptionStatus.ReceiveFailure:
                    GlobalConfig.logger.Info("Не удалось загрузить ответ от HTTP-сервера.");
                    break;
                }
            }
            catch (Exception ex)
            {
                GlobalConfig.logger.Error($"Непредвиденная ошибка \n {ex.Message} \r\n {ex.StackTrace} \r\n {ex}");
                //MessageBox.Show(ex.Message);
            }
            return(false);

            #endregion
        }
Ejemplo n.º 7
0
 public static void InitializeContext(ContextRouter contextRouter)
 {
     contextRouter.AssociateType <HttpContext, GetPage>();
     AutoRegistration.AutoRegister <Listener>(contextRouter);
 }
Ejemplo n.º 8
0
 public void Setup()
 {
     Initialize();
     _autoRegistration = new AutoRegistration(Driver);
 }
Ejemplo n.º 9
0
        public void AssemblyRegistration_Initialize()
        {
            AutoRegistration.Register(typeof(IBird).Assembly);

            Application.Current.Resolve <IBird>();
        }