public async Task <DependencyVersion> GetLatestMetaDataAsync(RegistryDto registry, Dependency dependency)
        {
            RegistryClientConfiguration clientConfig = new RegistryClientConfiguration(new Uri(registry.Endpoint).GetComponents(UriComponents.HostAndPort, UriFormat.SafeUnescaped));

            DependencyVersion version;

            if (!string.IsNullOrWhiteSpace(registry.Username) && !string.IsNullOrWhiteSpace(registry.Password))
            {
                using (IRegistryClient client = clientConfig.CreateClient(new PasswordOAuthAuthenticationProvider(registry.Username, registry.Password)))
                {
                    ListImageTagsResponse imageTags = await client.Tags.ListImageTagsAsync(dependency.Name, new ListImageTagsParameters());

                    version = new DependencyVersion {
                        Dependency = dependency, DependencyId = dependency.Id, Version = imageTags.Tags.Last(), IsLatest = true
                    };
                }
            }
            else
            {
                using (IRegistryClient client = clientConfig.CreateClient())
                {
                    ListImageTagsResponse imageTags = await client.Tags.ListImageTagsAsync(dependency.Name, new ListImageTagsParameters());

                    version = new DependencyVersion {
                        Dependency = dependency, DependencyId = dependency.Id, Version = imageTags.Tags.Last(), IsLatest = true
                    };
                }
            }

            return(version);
        }
        public ManifestDialogViewModel(
            ILifetimeScope scope,
            IRegistryClient registryClient,
            IMessageBoxService messageBoxService,
            IFileDialogService fileDialogService,
            ImageManifest2_2 manifest,
            TagViewModel parent)
        {
            _scope             = scope ?? throw new ArgumentNullException(nameof(scope));
            _registryClient    = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
            _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService));
            _fileDialogService = fileDialogService ?? throw new ArgumentNullException(nameof(fileDialogService));
            _manifest          = manifest ?? throw new ArgumentNullException(nameof(manifest));
            _parent            = parent ?? throw new ArgumentNullException(nameof(parent));

            if (manifest.Layers != null)
            {
                Layers = manifest.Layers
                         .Select(l => scope.Resolve <ManifestLayerViewModel>
                                 (
                                     new TypedParameter(typeof(ManifestLayer), l)
                                 ))
                         .ToArray();
            }

            DownloadCommand = new RelayCommand(Download, CanDownload);
        }
        public RepositoryViewModel(string name, IRegistryClient registryClient, ILifetimeScope lifetimeScope)
        {
            _registryClient = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
            _lifetimeScope  = lifetimeScope ?? throw new ArgumentNullException(nameof(lifetimeScope));
            Name            = name;

            Refresh();
        }
Beispiel #4
0
 public RegistryConnection(IRegistryClient client, string registry, bool isAnonymous, string username, string password)
 {
     Client      = client;
     Registry    = registry;
     IsAnonymous = isAnonymous;
     Username    = username;
     Password    = password;
 }
        public RepositoriesViewModel(IRegistryClient registryClient, ILifetimeScope lifetimeScope, ITextEditService textEditService)
        {
            _registryClient  = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
            _lifetimeScope   = lifetimeScope ?? throw new ArgumentNullException(nameof(lifetimeScope));
            _textEditService = textEditService ?? throw new ArgumentNullException(nameof(textEditService));

            LoadAllRepositoriesCommand = new RelayCommand(LoadAllRepositories);
            LoadRepositoryCommand      = new RelayCommand(LoadRepository);
        }
 public ManifestLayerViewModel(
     IRegistryClient registryClient,
     IMessageBoxService messageBoxService,
     ManifestLayer model)
 {
     _registryClient    = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
     _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService));
     _model             = model ?? throw new ArgumentNullException(nameof(model));
 }
        public RepositoryViewModel(string name, RegistryViewModel parent, IRegistryClient registryClient, ILifetimeScope lifetimeScope)
        {
            _parent         = parent ?? throw new ArgumentNullException(nameof(parent));
            _registryClient = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
            _lifetimeScope  = lifetimeScope ?? throw new ArgumentNullException(nameof(lifetimeScope));
            Name            = name;

            Refresh();

            RefreshCommand = new RelayCommand(Refresh);
        }
        public TagViewModel(
            ILifetimeScope scope,
            IRegistryClient registryClient,
            IMessageBoxService messageBoxService,
            IViewService viewService,
            string repository,
            string tag)
        {
            _scope             = scope ?? throw new ArgumentNullException(nameof(scope));
            _registryClient    = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
            _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService));
            _viewService       = viewService ?? throw new ArgumentNullException(nameof(viewService));
            Repository         = repository;
            Tag = tag;

            GetManifestCommand = new RelayCommand(GetManifest);
        }
Beispiel #9
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            Cursor PreviousCursor = this.Cursor;

            Cursor = Cursors.WaitCursor;
            Button   Sender        = sender as Button;
            GroupBox grp           = default;
            ComboBox comboEndpoint = default;
            CheckBox chkAnonymous  = default;
            TextBox  txtUserName   = default;
            TextBox  txtPassword   = default;

            if (Sender == btnBaseLogin)
            {
                grp                 = grpBaseRegistry;
                comboEndpoint       = comboBaseRegistry;
                chkAnonymous        = chkBaseAnonymous;
                txtUserName         = txtBaseUserName;
                txtPassword         = txtBasePassword;
                _baseRegistryClient = null;
            }
            else
            {
                grp                   = grpTargetRegistry;
                comboEndpoint         = comboTargetRegistry;
                chkAnonymous          = chkTargetAnonymous;
                txtUserName           = txtTargetUserName;
                txtPassword           = txtTargetPassword;
                _targetRegistryClient = null;
            }

            if (Sender.Text == "Logout")
            {
                foreach (var control in grp.Controls)
                {
                    if (control.GetType() == typeof(ListBox))
                    {
                        ((ListBox)control).Items.Clear();
                    }

                    if (control.GetType() == typeof(TextBox))
                    {
                        ((TextBox)control).Text = "";
                    }
                    // ...
                }

                _baseRegistryClient = null;
                Sender.Text         = "Login";
                comboEndpoint.Focus();
            }
            else
            {
                var configuration = new RegistryClientConfiguration(comboEndpoint.SelectedItem?.ToString() ?? comboEndpoint.Text);

                AuthenticationProvider authenticationProvider;

                if (chkAnonymous.Checked)
                {
                    authenticationProvider = new AnonymousOAuthAuthenticationProvider();
                }
                else
                {
                    authenticationProvider = new PasswordOAuthAuthenticationProvider(txtUserName.Text, txtPassword.Text);
                }

                var client = configuration.CreateClient(authenticationProvider);

                try
                {
                    await client.System.PingAsync();
                }
                catch (UnauthorizedAccessException ex)
                {
                    // authentication failed
                    MessageBox.Show($"Authentication failed with {ex.Message}", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Cursor = PreviousCursor;
                    return;
                }
                catch (RegistryConnectionException ex)
                {
                    // connection failed
                    MessageBox.Show($"Unable to connect, exception {ex.Message})", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Cursor = PreviousCursor;
                    return;
                }

                Sender.Text = "Logout";
                if (Sender == btnBaseLogin)
                {
                    _baseRegistryClient = client;
                }
                else
                {
                    _targetRegistryClient = client;
                }
            }

            Cursor = PreviousCursor;
        }
Beispiel #10
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            Cursor PreviousCursor = this.Cursor;

            Cursor = Cursors.WaitCursor;

            if ((sender as Button).Text == "Logout")
            {
                Text = $"Not connected";
                foreach (var control in grpControls.Controls)
                {
                    if (control.GetType() == typeof(ListBox))
                    {
                        ((ListBox)control).Items.Clear();
                    }

                    if (control.GetType() == typeof(TextBox))
                    {
                        ((TextBox)control).Text = "";
                    }

                    // ...
                }

                grpControls.Enabled = false;

                _registryClient = null;
                btnLogin.Text   = "Login";
                comboEndpoint.Focus();
            }
            else
            {
                var configuration = new RegistryClientConfiguration(comboEndpoint.SelectedItem?.ToString() ?? comboEndpoint.Text);

                AuthenticationProvider authenticationProvider;

                if (chkAnonymous.Checked)
                {
                    authenticationProvider = new AnonymousOAuthAuthenticationProvider();
                }
                else
                {
                    authenticationProvider = new PasswordOAuthAuthenticationProvider(txtUserName.Text, txtPassword.Text);
                }

                var client = configuration.CreateClient(authenticationProvider);

                try
                {
                    await client.System.PingAsync();
                }
                catch (UnauthorizedAccessException ex)
                {
                    // authentication failed
                    MessageBox.Show("Authentication failed", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Cursor = PreviousCursor;
                    return;
                }
                catch (RegistryConnectionException ex)
                {
                    // connection failed
                    MessageBox.Show("Unable to connect", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Cursor = PreviousCursor;
                    return;
                }

                Text = $"Connected to endpoint {comboEndpoint.SelectedItem.ToString()}";
                grpControls.Enabled = true;
                btnLogin.Text       = "Logout";
                _registryClient     = client;
                btnCatalog.Focus();
            }

            Cursor = PreviousCursor;
        }
Beispiel #11
0
 public RegistryClientTests(Fixtures.RegistryClientFixture fixture)
 {
     _sut = fixture.RegistryClient;
 }
Beispiel #12
0
 public void AddClient(IRegistryClient client)
 {
     _registryClients.Add(client);
 }