Ejemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Register<DisplayToolbarMessage>(this, (action)=>HandleToolbarMessage(action));
            Messenger.Default.Register<ShowWindowMessage>(this, HandleShowWindowMessage);
            Messenger.Default.Register<ShowDialogMessage>(this, "MainWindow", HandleShowDialogMessage);
            Messenger.Default.Register<SelectTabMessage>(this, HandleSelectTabMessage);
            Messenger.Default.Register<AppExitMessage>(this, HandleAppExitMessage);
            Messenger.Default.Register<CloseTabMessage>(this, HandleCloseTabMessage);
            Messenger.Default.Register<ShowFileDialogMessage>(this, HandleShowFileDialogMessage);
            Messenger.Default.Register<AuthenticationRequiredMessage>(this, HandleAuthenticationRequiredMessage);

            if ((this.DataContext as MainViewModel).StoreSources.Count == 0)
            {
                var msg = new ShowDialogMessage(
                    Strings.NoConnectionsTitle,
                    Strings.NoConnectionsMessage,
                    MessageBoxImage.Information,
                    MessageBoxButton.YesNo,
                    (result) =>
                        {
                            if (result == MessageBoxResult.Yes)
                            {
                                var showWindowMessage = new ShowWindowMessage {Name = "NewConnection"};
                                Messenger.Default.Send(showWindowMessage);
                            }
                        });
                Messenger.Default.Send(msg, "MainWindow");
            }
        }
Ejemplo n.º 2
0
 public void ServerEdit(Connection serverConnection)
 {
     var msg = new ShowWindowMessage {Name = "EditConnection", ViewModel = serverConnection};
     Messenger.Default.Send(msg);
 }
Ejemplo n.º 3
0
 private void PrefixSettings()
 {
     var msg = new ShowWindowMessage { Name = "PrefixesDialog", ViewModel = Configuration};
     Messenger.Default.Send(msg);
 }
Ejemplo n.º 4
0
 public void ServerCreateStore(Connection serverConnection)
 {
     var msg = new ShowWindowMessage {Name = "CreateStore", ViewModel = serverConnection, Continuation = ContinueCreateStore};
     Messenger.Default.Send(msg);
 }
Ejemplo n.º 5
0
 public void NewConnection()
 {
     var msg = new ShowWindowMessage {Name = "NewConnection", ViewModel = this};
     Messenger.Default.Send(msg);
 }
Ejemplo n.º 6
0
 public void About()
 {
     var msg = new ShowWindowMessage
                   {
                       Name = "AboutDialog",
                       ViewModel = new AboutViewModel()
                   };
     Messenger.Default.Send(msg);
 }
Ejemplo n.º 7
0
 private void HandleShowWindowMessage(ShowWindowMessage msg)
 {
     switch (msg.Name)
     {
         case "NewConnection":
             {
                 var connectionModel = new Connection();
                 var newConnectionDialog = new ConnectionPropertiesDialog {DataContext = connectionModel};
                 var dlgResult = newConnectionDialog.ShowDialog();
                 if (dlgResult.HasValue && dlgResult.Value)
                 {
                     var model = DataContext as MainViewModel;
                     if (model != null)
                     {
                         model.StoreSources.Add(connectionModel);
                         model.AddConnectionConfiguration(connectionModel.Name,
                                                          connectionModel.ConnectionString,
                                                          connectionModel.RequiresAuthentication);
                     }
                 }
                 break;
             }
         case "EditConnection":
             {
                 var connectionModel = msg.ViewModel as Connection;
                 if (connectionModel != null)
                 {
                     var editModel = connectionModel.Clone();
                     var dlg = new ConnectionPropertiesDialog {DataContext = editModel};
                     var dlgResult = dlg.ShowDialog();
                     if (dlgResult.HasValue && dlgResult.Value)
                     {
                         var oldName = connectionModel.Name;
                         connectionModel.CopyFrom(editModel);
                         var mvm = DataContext as MainViewModel;
                         if (mvm != null)
                         {
                             mvm.ServerRefresh(connectionModel);
                         }
                         // Update configuration
                         var model = DataContext as MainViewModel;
                         if (model != null)
                         {
                             model.UpdateConnectionConfiguration(oldName, connectionModel.Name, connectionModel.ConnectionString, connectionModel.RequiresAuthentication);
                         }
                     }
                 }
                 break;
             }
         case "PrefixesDialog":
             {
                 var configuration = msg.ViewModel as PolarisConfigurationModel;
                 if (configuration != null)
                 {
                     var oldPrefixes = new List<PrefixConfiguration>(configuration.Prefixes);
                     var dlg = new PrefixesDialog { DataContext = configuration };
                     var dlgResult = dlg.ShowDialog();
                     if (dlgResult.HasValue && dlgResult.Value)
                     {
                         configuration.Save();
                     } else
                     {
                         configuration.Prefixes = oldPrefixes;
                     }
                 }
                 break;
             }
         case "CreateStore":
             {
                 var connection = msg.ViewModel as Connection;
                 if (connection != null)
                 {
                     var storeModel = new Store(connection, Guid.NewGuid().ToString());
                     var storePropertiesDialog = new StorePropertiesDialog
                                                     {DataContext = storeModel, Title = "New Store Properties"};
                     var dlgResult = storePropertiesDialog.ShowDialog();
                     if (dlgResult.HasValue && dlgResult.Value && msg.Continuation != null)
                     {
                         msg.Continuation(storePropertiesDialog.DataContext);
                     }
                 }
                 break;
             }
         case "AboutDialog":
             {
                 var dlg = new AboutDialog {DataContext = msg.ViewModel};
                 dlg.ShowDialog();
                 break;
             }
     }
 }