private async Task <HttpClient> CreateClient(UnicornConnection connection, string url)
        {
            var httpClient = new HttpClient();

            if (_isStreamed)
            {
                httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
            }

            if (!string.IsNullOrEmpty(connection.Token))
            {
                var challenge = await GetChallenge(connection).ConfigureAwait(false);

                if (string.IsNullOrEmpty(challenge))
                {
                    httpClient.DefaultRequestHeaders.Add("Authenticate", connection.Token);
                }
                else
                {
                    var signatureService = new SignatureService(connection.Token);
                    var signature        = signatureService.CreateSignature(challenge, url, Enumerable.Empty <SignatureFactor>());
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-MC-MAC", signature);
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-MC-Nonce", challenge);
                }
            }
            return(httpClient);
        }
 public UnicornConnectionViewModel(UnicornConnection connection)
 {
     _connection = connection;
     TestConnection = new Command(ExecuteTestConnection, () => !ShowProgressBar);
     Save = new Command(ExecuteSave, () => !ShowProgressBar);
     Install = new Command(ExecuteInstall, () => !ShowProgressBar);
     DownloadPackage = new Command(ExecuteDownloadPackage, () => !ShowProgressBar);
 }
Ejemplo n.º 3
0
 public UnicornConnectionViewModel(UnicornConnection connection)
 {
     _connection     = connection;
     TestConnection  = new Command(ExecuteTestConnection, () => !ShowProgressBar);
     Save            = new Command(ExecuteSave, () => !ShowProgressBar);
     Install         = new Command(ExecuteInstall, () => !ShowProgressBar);
     DownloadPackage = new Command(ExecuteDownloadPackage, () => !ShowProgressBar);
 }
Ejemplo n.º 4
0
        public NewConnection(UnicornConnection data)
        {
            InitializeComponent();
            var unicornConnectionViewModel = new UnicornConnectionViewModel(data ?? new UnicornConnection());

            unicornConnectionViewModel.Close = r =>
            {
                DialogResult = r;
                Close();
            };
            DataContext = unicornConnectionViewModel;
        }
        public NewConnection(UnicornConnection data)
        {
            InitializeComponent();
            var unicornConnectionViewModel = new UnicornConnectionViewModel(data ?? new UnicornConnection());
            unicornConnectionViewModel.Close = r =>
            {
                DialogResult = r;
                Close();
            };
            DataContext = unicornConnectionViewModel;

        }
 public static void SaveConnection(UnicornConnection connectionViewModel)
 {
     var store = GetStore();
     EnsureCollectionExists(UnicornConnectionsRoot);
     var connectionPath = GetConnectionPath(connectionViewModel.Id);
     store.CreateCollection(connectionPath);
     store.SetString(connectionPath, ConnectionIdKey, connectionViewModel.Id);
     store.SetString(connectionPath, ConnectionNameKey, connectionViewModel.Name);
     store.SetString(connectionPath, ConnectionUrlKey, connectionViewModel.ServerUrl);
     if (!string.IsNullOrEmpty(connectionViewModel.Token))
         store.SetString(connectionPath, ConnectionTokenKey, connectionViewModel.Token);
     else
         store.DeleteProperty(connectionPath, ConnectionTokenKey);
 }
        protected virtual string BuildUrl(UnicornConnection connection, string selectedConfiguration = "", string verbOverride = null)
        {
            var endpointUrl = connection.ServerUrl;

            if (!endpointUrl.StartsWith("http"))
            {
                endpointUrl = "http://" + endpointUrl;
            }
            var configuration = GetConfiguration(selectedConfiguration);

            endpointUrl += $"{SettingsHelper.GetSettings().EndPoint}?verb={verbOverride ?? GetVerb(connection)}";
            if (!string.IsNullOrEmpty(configuration))
            {
                endpointUrl += configuration;
            }
            return(endpointUrl);
        }
        public static UnicornConnection GetConnectionInfo(string id)
        {
            EnsureCollectionExists(UnicornConnectionsRoot);
            var store = GetStore();
            var connectionPath = GetConnectionPath(id);
            if (!store.CollectionExists(connectionPath))
                return null;

            var unicornConnection = new UnicornConnection
            {
                Id = store.GetString(connectionPath,ConnectionIdKey, string.Empty),
                Name = store.GetString(connectionPath,ConnectionNameKey, string.Empty),
                ServerUrl = store.GetString(connectionPath,ConnectionUrlKey, string.Empty),
                Token = store.GetString(connectionPath,ConnectionTokenKey, string.Empty),
            };
            return unicornConnection;
        }
        private void ShowConnectionDialog(UnicornConnection info = null)
        {
            var shouldUpdate = SelectedConnection != null;

            info = info ?? new UnicornConnection();
            var newConnection = new NewConnection(info);

            if (newConnection.ShowModal() != true)
            {
                return;
            }

            LoadConnections();
            if (shouldUpdate)
            {
                SelectedConnection = null;
                SelectedConnection = info;
            }
        }
        public static void SaveConnection(UnicornConnection connectionViewModel)
        {
            var store = GetStore();

            EnsureCollectionExists(UnicornConnectionsRoot);
            var connectionPath = GetConnectionPath(connectionViewModel.Id);

            store.CreateCollection(connectionPath);
            store.SetString(connectionPath, ConnectionIdKey, connectionViewModel.Id);
            store.SetString(connectionPath, ConnectionNameKey, connectionViewModel.Name);
            store.SetString(connectionPath, ConnectionUrlKey, connectionViewModel.ServerUrl);
            if (!string.IsNullOrEmpty(connectionViewModel.Token))
            {
                store.SetString(connectionPath, ConnectionTokenKey, connectionViewModel.Token);
            }
            else
            {
                store.DeleteProperty(connectionPath, ConnectionTokenKey);
            }
        }
        public static UnicornConnection GetConnectionInfo(string id)
        {
            EnsureCollectionExists(UnicornConnectionsRoot);
            var store          = GetStore();
            var connectionPath = GetConnectionPath(id);

            if (!store.CollectionExists(connectionPath))
            {
                return(null);
            }

            var unicornConnection = new UnicornConnection
            {
                Id        = store.GetString(connectionPath, ConnectionIdKey, string.Empty),
                Name      = store.GetString(connectionPath, ConnectionNameKey, string.Empty),
                ServerUrl = store.GetString(connectionPath, ConnectionUrlKey, string.Empty),
                Token     = store.GetString(connectionPath, ConnectionTokenKey, string.Empty),
            };

            return(unicornConnection);
        }
        private async Task <string> GetChallenge(UnicornConnection connection)
        {
            using (var client = new HttpClient())
            {
                var endPoint = BuildUrl(connection, verbOverride: "Challenge");

                var challengeResponse = await client.GetAsync(endPoint);

                if (challengeResponse.StatusCode == HttpStatusCode.NotFound ||
                    challengeResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    return(string.Empty);
                }

                if (!challengeResponse.IsSuccessStatusCode)
                {
                    throw new UnauthorizedAccessException();
                }

                return(await challengeResponse.Content.ReadAsStringAsync());
            }
        }
Ejemplo n.º 13
0
 public SynchronizeCommand(UnicornConnection connection, string selectedConfigs, CancellationToken token, Action <StatusReport> reportHandler)
     : base(connection, selectedConfigs, token, reportHandler)
 {
 }
Ejemplo n.º 14
0
 public IsLegacyCommand(UnicornConnection connection) : base(connection)
 {
 }
Ejemplo n.º 15
0
 public IsLegacyCommand(UnicornConnection connection, CancellationToken token)
     : base(connection, token)
 {
 }
 protected override string GetVerb(UnicornConnection connection)
 {
     return("Version");
 }
Ejemplo n.º 17
0
 protected override string GetVerb(UnicornConnection connection)
 {
     return "ConfigurationHealth";
 }
Ejemplo n.º 18
0
 protected BaseUnicornCommand(UnicornConnection connection, string selectedConfigs, CancellationToken token)
 {
     Connection             = connection;
     SelectedConfigurations = selectedConfigs;
     CancellationToken      = token;
 }
 protected override string GetVerb(UnicornConnection connection)
 {
     return connection.IsLegacy ? "Sync" : "VSSync";
 }
 protected override string GetVerb(UnicornConnection connection)
 {
     return connection.IsLegacy ? "Reserialize" : "VSReserialize";
 }
Ejemplo n.º 21
0
 protected override string GetVerb(UnicornConnection connection)
 {
     return(connection.IsLegacy ? "Reserialize" : "VSReserialize");
 }
Ejemplo n.º 22
0
 protected override string GetVerb(UnicornConnection connection)
 {
     return(connection.IsLegacy ? "Sync" : "VSSync");
 }
 public CheckConfigurationHealthCommand(UnicornConnection connection, string configurations, CancellationToken token)
     : base(connection, configurations, token)
 {
 }
 public ConfigurationsCommand(UnicornConnection connection) : base(connection)
 {
 }
Ejemplo n.º 25
0
 protected BaseUnicornCommand(UnicornConnection connection)
     : this(connection, string.Empty, CancellationToken.None)
 {
 }
Ejemplo n.º 26
0
 protected BaseUnicornCommand(UnicornConnection connection, string selectedConfigs)
     : this(connection, selectedConfigs, CancellationToken.None)
 {
 }
 protected override string GetVerb(UnicornConnection connection)
 {
     return(connection.IsLegacy ? "Config" : "Configurations");
 }
 public HandshakeCommand(UnicornConnection connection, CancellationToken token)
     : base(connection, token)
 {
 }
 public CheckConfigurationHealthCommand(UnicornConnection connection, string configurations) : base(connection, configurations)
 {
 }
Ejemplo n.º 30
0
 protected override string GetVerb(UnicornConnection connection)
 {
     return(connection.IsLegacy ? "Handshake" : "Version");
 }
 public SynchronizeCommand(UnicornConnection connection, string selectedConfigs, CancellationToken token, Action<StatusReport> reportHandler) 
     : base(connection, selectedConfigs, token, reportHandler)
 {
 }
 protected abstract string GetVerb(UnicornConnection connection);
 public ConfigurationsCommand(UnicornConnection connection, CancellationToken token)
     : base(connection, token)
 {
 }
 protected BaseReportableCommand(UnicornConnection connection, string selectedConfigs, CancellationToken token, Action <StatusReport> reportHandler)
     : base(connection, selectedConfigs, token)
 {
     ReportHandler = reportHandler;
 }