Example #1
0
        private static IConnection Authenticate()
        {
            if (string.IsNullOrWhiteSpace(Properties.Settings.Default.Host))
            {
                Properties.Settings.Default.Host = Interaction.GetText("Youtrack Host");
            }

            if (string.IsNullOrWhiteSpace(Properties.Settings.Default.Username))
            {
                Properties.Settings.Default.Username = Interaction.GetText("Username");
            }

            if (string.IsNullOrWhiteSpace(Properties.Settings.Default.Password))
            {
                System.Console.WriteLine("Make sure nobody is watching!");
                Properties.Settings.Default.Password = Interaction.GetText("Password");;
            }

            var connection = YouTrackManager.GetConnection(Properties.Settings.Default.Host,
                                                           Properties.Settings.Default.Username, Properties.Settings.Default.Password);

            if (connection.IsAuthenticated)
            {
                Properties.Settings.Default.Save();
            }
            return(connection);
        }
Example #2
0
        static App()
        {
            var catalog = new AssemblyCatalog(typeof(App).Assembly);
            var builder = new ContainerBuilder();

            builder.RegisterComposablePartCatalog(catalog);

            builder
            .Register(_ => App.Current)
            .As <Application>()
            .ExternallyOwned()
            .InstancePerLifetimeScope();

            builder
            .Register(b => new MainViewModel())
            .OnActivating(e =>
            {
                e.Instance.StartCommand  = e.Context.Resolve <StartCommand>();
                e.Instance.StopCommand   = e.Context.Resolve <StopCommand>();
                e.Instance.SearchCommand = e.Context.Resolve <SearchCommand>();
            })
            .AsSelf()
            .InstancePerLifetimeScope();

            builder
            .Register(b => YouTrackManager.GetConnection("youtrack.neveling.net", "testuser", "testuser"))
            .As <IConnection>()
            .InstancePerLifetimeScope();

            builder
            .Register(b => new IssueManagement(b.Resolve <IConnection>()))
            .AsSelf()
            .InstancePerLifetimeScope();

            builder
            .RegisterType(typeof(YouTrackRepository))
            .As(typeof(IRepository <string, IRepositoryPayload>))
            .InstancePerLifetimeScope();

            builder
            .RegisterType <YouTrackPayload>()
            .OnActivated(e => e.Instance.Repository = e.Context.Resolve <IRepository <string, IRepositoryPayload> >())
            .As <IRepositoryPayload>()
            .InstancePerDependency();

            builder
            .RegisterType <StartCommand>()
            .OnActivated(e =>
            {
                e.Instance.MainViewModel     = e.Context.Resolve <MainViewModel>();
                e.Instance.StartEventFactory =
                    () => new TrakkrEventViewModel
                {
                    Type      = EventType.Start,
                    Timestamp = DateTime.Now,
                    Payload   = Container.Resolve <IRepositoryPayload>()
                };
            })
            .AsSelf()
            .InstancePerLifetimeScope();

            builder
            .RegisterType <StopCommand>()
            .OnActivated(e =>
            {
                e.Instance.MainViewModel    = e.Context.Resolve <MainViewModel>();
                e.Instance.StopEventFactory =
                    () => new TrakkrEventViewModel
                {
                    Type      = EventType.Stop,
                    Timestamp = DateTime.Now,
                    Payload   = Container.Resolve <IRepositoryPayload>()
                };
            })
            .AsSelf()
            .InstancePerLifetimeScope();

            builder
            .RegisterType <SearchCommand>()
            .OnActivated(e =>
            {
                e.Instance.MainViewModel = e.Context.Resolve <MainViewModel>();
                e.Instance.Repositroy    = e.Context.Resolve <IRepository <string, IRepositoryPayload> >();
            })
            .AsSelf()
            .InstancePerLifetimeScope();

            Container = builder.Build();
        }