Skip to content

Commit

Permalink
fixing issue #101. (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible authored May 24, 2023
1 parent 339c71f commit a6f2bb3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/CosmosDbExplorer.Core/Models/CosmosConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ public CosmosConnection(Guid id)
{
Id = id;
EnableEndpointDiscovery = true;
LimitToEndpoint = false;
}

[JsonConstructor]
public CosmosConnection(Guid? id, string? label, Uri? endpoint, string? secret, ConnectionType connectionType, bool enableEndpointDiscovery, Color? accentColor)
public CosmosConnection(Guid? id, string? label, Uri? endpoint, string? secret, ConnectionType connectionType, bool enableEndpointDiscovery, bool limitToEndpoint, Color? accentColor)
{
Id = id ?? Guid.NewGuid();
Label = label;
DatabaseUri = endpoint;
AuthenticationKey = secret;
ConnectionType = connectionType;
EnableEndpointDiscovery = enableEndpointDiscovery;
LimitToEndpoint = limitToEndpoint;
AccentColor = accentColor;
}

Expand All @@ -43,6 +45,9 @@ public CosmosConnection(Guid? id, string? label, Uri? endpoint, string? secret,
[JsonProperty]
public bool EnableEndpointDiscovery { get; protected set; }

[JsonProperty]
public bool LimitToEndpoint { get; protected set; }

[JsonProperty]
public Color? AccentColor { get; protected set; }

Expand Down
3 changes: 2 additions & 1 deletion src/CosmosDbExplorer.Core/Services/CosmosClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ private CosmosClient CreateClient(CosmosConnection connection)
var options = new CosmosClientOptions
{
ConnectionMode = connection.ConnectionType == ConnectionType.Gateway ? ConnectionMode.Gateway : ConnectionMode.Direct,
EnableTcpConnectionEndpointRediscovery = connection.EnableEndpointDiscovery
EnableTcpConnectionEndpointRediscovery = connection.EnableEndpointDiscovery,
LimitToEndpoint = connection.LimitToEndpoint
};

return new CosmosClient(accountEndpoint: connection.DatabaseUri?.ToString(), authKeyOrResourceToken: connection.AuthenticationKey, options);
Expand Down
5 changes: 4 additions & 1 deletion src/CosmosDbExplorer/ViewModels/AccountSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public AccountSettingsViewModel(IPersistAndRestoreService persistAndRestoreServi

public bool EnableEndpointDiscovery { get; set; }

public bool LimitToEndpoint { get; set; }

public Color? AccentColor { get; set; }

public Action<bool?>? SetResult { get; set; }
Expand Down Expand Up @@ -93,7 +95,7 @@ public void SaveCommandExecute()
? System.Drawing.Color.Transparent
: System.Drawing.Color.FromArgb(AccentColor.Value.A, AccentColor.Value.R, AccentColor.Value.G, AccentColor.Value.B);

var connection = new CosmosConnection(_connection.Id, Label, new Uri(AccountEndpoint), AccountSecret, ConnectionType, EnableEndpointDiscovery, accentColor);
var connection = new CosmosConnection(_connection.Id, Label, new Uri(AccountEndpoint), AccountSecret, ConnectionType, EnableEndpointDiscovery, LimitToEndpoint, accentColor);

_persistAndRestoreService.PersistConnection(connection);
Messenger.Send(new ConnectionSettingSavedMessage(connection));
Expand Down Expand Up @@ -130,6 +132,7 @@ private void SetConnection(CosmosConnection connection)
}

EnableEndpointDiscovery = _connection.EnableEndpointDiscovery;
LimitToEndpoint = _connection.LimitToEndpoint;
}

private void OnClose()
Expand Down
14 changes: 12 additions & 2 deletions src/CosmosDbExplorer/Views/AccountSettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
xmlns:viewmodels="clr-namespace:CosmosDbExplorer.ViewModels"
Title="{Binding Title}"
Width="850"
Height="350"
Height="400"
d:DataContext="{d:DesignInstance Type=viewmodels:AccountSettingsViewModel}"
d:DesignHeight="350"
d:DesignHeight="400"
d:DesignWidth="850"
Style="{DynamicResource MahApps.Styles.Page}"
mc:Ignorable="d">
Expand Down Expand Up @@ -141,6 +141,16 @@
Grid.Column="1"
IsChecked="{Binding EnableEndpointDiscovery, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
<Grid Margin="{StaticResource XSmallTopMargin}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200px" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<TextBlock Style="{StaticResource BodyTextStyle}" Grid.Row="6" Grid.Column="0" Text="Limit to Endpoint" />
<CheckBox Grid.Row="6" Grid.Column="1"
IsChecked="{Binding LimitToEndpoint, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
</StackPanel>

<mah:ToggleSwitch
Expand Down

0 comments on commit a6f2bb3

Please sign in to comment.