Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make sure sql replication tables have distinct names and always has v…

…alue

change Source Document collection to be auto complete box instead of combo box
  • Loading branch information...
commit d0a7093d75cddd0532d1fbd18e58ac4440b1dbeb 1 parent 3d0fb26
@DanielDar DanielDar authored
View
73 Raven.Studio/Commands/SaveSettingsCommand.cs
@@ -90,30 +90,55 @@ public override void Execute(object parameter)
{
if (sqlReplicationSettings.SqlReplicationConfigs.Any(config => config.Name == "Temp_Name") == false && sqlReplicationSettings.SqlReplicationConfigs.Any(config => string.IsNullOrWhiteSpace(config.Name)) == false)
{
- session.Advanced.LoadStartingWithAsync<SqlReplicationConfig>("Raven/SqlReplication/Configuration/")
- .ContinueOnSuccessInTheUIThread(documents =>
- {
- sqlReplicationSettings.UpdateIds();
- if (documents != null)
- {
- foreach (var sqlReplicationConfig in documents)
- {
- if (sqlReplicationSettings.SqlReplicationConfigs.All(config => config.Id != sqlReplicationConfig.Id))
- {
- session.Delete(sqlReplicationConfig);
- }
- }
- }
-
- foreach (var sqlReplicationConfig in sqlReplicationSettings.SqlReplicationConfigs)
- {
- sqlReplicationConfig.Id = "Raven/SqlReplication/Configuration/" + sqlReplicationConfig.Name;
- session.Store(sqlReplicationConfig);
- }
-
- session.SaveChangesAsync().Catch();
- })
- .Catch();
+ var problemWithTable = false;
+ foreach (var sqlReplicationConfigModel in sqlReplicationSettings.SqlReplicationConfigs)
+ {
+ var hashset = new HashSet<string>();
+ foreach (var sqlReplicationTable in sqlReplicationConfigModel.SqlReplicationTables)
+ {
+ var exists = !hashset.Add(sqlReplicationTable.TableName);
+ if (string.IsNullOrWhiteSpace(sqlReplicationTable.DocumentKeyColumn) || string.IsNullOrWhiteSpace(sqlReplicationTable.TableName) || exists)
+ {
+ problemWithTable = true;
+ break;
+ }
+ }
+ if(problemWithTable)
+ break;
+ }
+
+ if (problemWithTable)
+ {
+ ApplicationModel.Current.AddNotification(new Notification("Sql Replicaiton settings were not saved, all tables must distinct names and have document keys", NotificationLevel.Error));
+ }
+ else
+ {
+ session.Advanced.LoadStartingWithAsync<SqlReplicationConfig>("Raven/SqlReplication/Configuration/")
+ .ContinueOnSuccessInTheUIThread(documents =>
+ {
+ sqlReplicationSettings.UpdateIds();
+ if (documents != null)
+ {
+ foreach (var sqlReplicationConfig in documents)
+ {
+ if (sqlReplicationSettings.SqlReplicationConfigs.All(config => config.Id != sqlReplicationConfig.Id))
+ {
+ session.Delete(sqlReplicationConfig);
+ }
+ }
+ }
+
+ foreach (var sqlReplicationConfig in sqlReplicationSettings.SqlReplicationConfigs)
+ {
+ sqlReplicationConfig.Id = "Raven/SqlReplication/Configuration/" + sqlReplicationConfig.Name;
+ session.Store(sqlReplicationConfig.ToSqlReplicationConfig());
+ }
+
+ session.SaveChangesAsync().Catch();
+ })
+ .Catch();
+ }
+
}
else
{
View
21 Raven.Studio/Features/Settings/SqlReplicationsSettingsSectionView.xaml
@@ -189,11 +189,22 @@
MinWidth="250" Margin="5,5,0,5" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="Source Document Collection:" VerticalAlignment="Center"/>
- <ComboBox Grid.Row="4" Grid.Column="1" SelectedIndex="{Binding SelectedCollectionIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
- ItemsSource="{Binding AvailableObjects}"
- Margin="5"
- Height="26"
- Width="350" HorizontalAlignment="Left"/>
+ <controls3:AutoCompleteBox Grid.Row="4"
+ Grid.Column="1"
+ Text="{Binding SelectedReplication.Value.RavenEntityName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+ MinimumPrefixLength="0"
+ IsTextCompletionEnabled="True"
+ VerticalAlignment="Center"
+ Margin="5,5,5,0">
+ <i:Interaction.Behaviors>
+ <Behaviors:BindSuggestionsProvider SuggestionProvider="{Binding}"/>
+ </i:Interaction.Behaviors>
+ <i:Interaction.Triggers>
+ <i:EventTrigger EventName="GotFocus">
+ <Behaviors:ShowAutoCompleteDropDown/>
+ </i:EventTrigger>
+ </i:Interaction.Triggers>
+ </controls3:AutoCompleteBox>
<TextBlock Grid.Row="5" Text="Sql Replication Tables: " VerticalAlignment="Top"/>
<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="1">
View
63 Raven.Studio/Models/SqlReplicationSettingsSectionModel.cs
@@ -1,5 +1,7 @@
-using System.Collections.ObjectModel;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Linq;
+using System.Threading.Tasks;
using System.Windows.Input;
using ActiproSoftware.Text;
using ActiproSoftware.Text.Implementation;
@@ -9,6 +11,7 @@
using Raven.Client.Connection.Async;
using Raven.Database.Bundles.SqlReplication;
using Raven.Json.Linq;
+using Raven.Studio.Behaviors;
using Raven.Studio.Controls.Editors;
using Raven.Studio.Features.Bundles;
using Raven.Studio.Features.Settings;
@@ -16,7 +19,7 @@
namespace Raven.Studio.Models
{
- public class SqlReplicationSettingsSectionModel : SettingsSectionModel
+ public class SqlReplicationSettingsSectionModel : SettingsSectionModel, IAutoCompleteSuggestionProvider
{
private ICommand addReplicationCommand;
private ICommand deleteReplicationCommand;
@@ -85,24 +88,26 @@ private void UpdateAvailableCollections()
});
}
- public ICommand DeleteTable{get{return new ActionCommand(() =>
- {
- SelectedReplication.Value.SqlReplicationTables.Remove(SelectedTable.Value);
- SelectedTable.Value = null;
- });}}
-
- public ICommand AddTable
+ public ICommand DeleteTable
{
get
{
return new ActionCommand(() =>
{
- SelectedReplication.Value.SqlReplicationTables.Add(new SqlReplicationTable());
-
+ SelectedReplication.Value.SqlReplicationTables.Remove(SelectedTable.Value);
+ SelectedTable.Value = null;
});
}
}
+ public ICommand AddTable
+ {
+ get
+ {
+ return new ActionCommand(() => SelectedReplication.Value.SqlReplicationTables.Add(new SqlReplicationTable()));
+ }
+ }
+
private void UpdateParameters()
{
if (SelectedReplication.Value == null)
@@ -120,13 +125,6 @@ private void UpdateParameters()
SelectedConnectionStringIndex = 0;
ScriptData = SelectedReplication.Value.Script;
-
- if (!string.IsNullOrWhiteSpace(SelectedReplication.Value.RavenEntityName))
- {
- SelectedCollectionIndex = AvailableObjects.IndexOf(SelectedReplication.Value.RavenEntityName);
- }
- else
- SelectedCollectionIndex = -1;
}
public ICommand DeleteReplication
@@ -152,7 +150,6 @@ public ICommand AddReplication
public Observable<SqlReplicationConfigModel> SelectedReplication { get; set; }
public Observable<SqlReplicationTable> SelectedTable { get; set; }
IEditorDocument script;
- private int selectedCollectionIndex;
private int selectedConnectionStringIndex;
public IEditorDocument Script
{
@@ -171,30 +168,7 @@ public int SelectedConnectionStringIndex
OnPropertyChanged(() => SelectedConnectionStringIndex);
}
}
- public int SelectedCollectionIndex
- {
- get { return selectedCollectionIndex; }
- set
- {
- selectedCollectionIndex = value;
- if (value >= 0)
- {
- SelectedReplication.Value.RavenEntityName = AvailableObjects[selectedCollectionIndex];
- ApplicationModel.DatabaseCommands.QueryAsync(CollectionsIndex, new IndexQuery
- {
- Query =
- "Tag:" +
- AvailableObjects[selectedCollectionIndex],
- PageSize = 1
- }, null).ContinueOnSuccessInTheUIThread(result =>
- {
- FirstItemOfCollection.Value = result.Results.FirstOrDefault();
- });
- }
- OnPropertyChanged(() => SelectedCollectionIndex);
- }
- }
protected Observable<RavenJObject> FirstItemOfCollection { get; set; }
protected string ScriptData
@@ -248,5 +222,10 @@ public void UpdateIds()
sqlReplicationConfig.Id = "Raven/SqlReplication/Configuration/" + sqlReplicationConfig.Name;
}
}
+
+ public Task<IList<object>> ProvideSuggestions(string enteredText)
+ {
+ return TaskEx.FromResult<IList<object>>(AvailableObjects.Cast<object>().ToList());
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.