private void StartEngine()
 {
     Task.Run(() =>
     {
         try
         {
             this.starting = true;
             Application.Current.Dispatcher.Invoke(CommandManager.InvalidateRequerySuggested);
             ConfigClient c = App.GetDefaultConfigClient();
             c.GetEngineState();
             c.InvokeThenClose(x => x.StartAll());
         }
         catch (EndpointNotFoundException ex)
         {
             Trace.WriteLine(ex.ToString());
             MessageBox.Show($"Could not contact the AutoSync service", "AutoSync service unavailable", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex);
             MessageBox.Show($"Error starting the management agents\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         finally
         {
             this.starting = false;
         }
     }).ContinueWith(x => Application.Current.Dispatcher.Invoke(CommandManager.InvalidateRequerySuggested));
 }
 private void Start()
 {
     Task.Run(() =>
     {
         try
         {
             ConfigClient c = App.GetDefaultConfigClient();
             c.InvokeThenClose(x => x.Start(this.ManagementAgentID));
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex);
             MessageBox.Show($"Could not start the management agent\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     });
 }
예제 #3
0
        private void AskToRestartService()
        {
            try
            {
                ConfigClient c = App.GetDefaultConfigClient();
                List <Guid>  pendingRestartGuids = c.GetManagementAgentsPendingRestart()?.ToList();

                if (pendingRestartGuids != null && pendingRestartGuids.Count > 0)
                {
                    IDictionary <Guid, string> mapping = c.GetManagementAgentNameIDs();

                    IEnumerable <string> pendingRestartItems = mapping.Where(t => pendingRestartGuids.Contains(t.Key)).Select(t => t.Value);

                    string pendingRestartItemList = string.Join("\r\n", pendingRestartItems);

                    if (MessageBox.Show($"The configuration for the following management agents have changed\r\n\r\n{pendingRestartItemList}\r\n\r\nDo you want to restart them now?", "Restart management agents", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        try
                        {
                            c.InvokeThenClose(t => t.RestartChangedControllers());
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine("Error restarting controllers");
                            Trace.WriteLine(ex.ToString());
                            MessageBox.Show($"Could not restart the management agents\n\n{ex.Message}", "Restart management agents", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            }
            catch (EndpointNotFoundException ex)
            {
                Trace.WriteLine(ex.ToString());
                MessageBox.Show($"Could not contact the AutoSync service", "AutoSync service unavailable", MessageBoxButton.OK, MessageBoxImage.Error);
                this.ConfigFile = null;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error determining controllers to restart");
                Trace.WriteLine(ex.ToString());
                MessageBox.Show($"Could not determine if any management agents required a restart\n\n{ex.Message}", "Restart management agents", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #4
0
        internal void ResetConfigViewModel()
        {
            try
            {
                this.Cursor = Cursors.Wait;

                ConfigFile file = null;


                ConfigClient c = App.GetDefaultConfigClient();
                c.InvokeThenClose(x => file = x.GetConfig());

                if (file == null)
                {
                    this.ConfigFile = null;
                }
                else
                {
                    this.ConfigFile = new ConfigFileViewModel(file);
                    this.ConfigFile.ManagementAgents.IsExpanded = true;
                }

                this.IsDirty = false;
            }
            catch (EndpointNotFoundException ex)
            {
                Trace.WriteLine(ex.ToString());
                MessageBox.Show($"Could not contact the AutoSync service", "AutoSync service unavailable", MessageBoxButton.OK, MessageBoxImage.Error);
                this.ConfigFile = null;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception refreshing view");
                Trace.WriteLine(ex.ToString());
                MessageBox.Show($"Could not reload the configuration from the server\n\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                this.ConfigFile = null;
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
예제 #5
0
 private void CommitConfig()
 {
     try
     {
         ConfigClient c = App.GetDefaultConfigClient();
         c.InvokeThenClose(t => t.PutConfig(this.ConfigFile.Model));
         this.Commit();
     }
     catch (EndpointNotFoundException ex)
     {
         Trace.WriteLine(ex.ToString());
         MessageBox.Show($"Could not contact the AutoSync service. The save operation could not be completed", "AutoSync service unavailable", MessageBoxButton.OK, MessageBoxImage.Error);
         this.ConfigFile = null;
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
         MessageBox.Show($"Could not commit the configuration\n\n{ex.Message}", "Save operation", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #6
0
        private void SetupExecutionMonitors()
        {
            IDictionary <Guid, string> maNames = new Dictionary <Guid, string>();

            try
            {
                ConfigClient c = App.GetDefaultConfigClient();
                Debug.WriteLine("Getting management agent names");
                c.InvokeThenClose(x => maNames = x.GetManagementAgentNameIDs());
                Debug.WriteLine("Got management agent names");
                this.ExecutionMonitor = new ExecutionMonitorsViewModel(maNames.Cast <object>().ToList());
            }
            catch (EndpointNotFoundException ex)
            {
                Trace.WriteLine(ex.ToString());
                MessageBox.Show($"Could not contact the AutoSync service. The execution monitor could not be set up.", "AutoSync service unavailable", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Could not setup execution monitors");
                Trace.WriteLine(ex.ToString());
                MessageBox.Show($"Could not setup the execution monitor\n\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void PopulateMenuItems()
        {
            this.MenuItems = new ObservableCollection <MenuItemViewModelBase>();

            this.MenuItems.Add(new MenuItemViewModel()
            {
                Header  = "Start",
                Icon    = App.GetImageResource("Run.ico"),
                Command = new DelegateCommand(t => this.Start(), t => this.CanStart()),
            });

            this.MenuItems.Add(new MenuItemViewModel()
            {
                Header  = "Stop",
                Icon    = App.GetImageResource("Stop.ico"),
                Command = new DelegateCommand(t => this.Stop(false), t => this.CanStop()),
            });

            this.MenuItems.Add(new MenuItemViewModel()
            {
                Header  = "Stop and cancel run",
                Icon    = App.GetImageResource("Stop.ico"),
                Command = new DelegateCommand(t => this.Stop(true), t => this.CanStop() && this.CanCancelRun()),
            });

            this.MenuItems.Add(new MenuItemViewModel()
            {
                Header  = "Cancel run",
                Icon    = App.GetImageResource("Cancel.ico"),
                Command = new DelegateCommand(t => this.CancelRun(), t => this.CanCancelRun()),
            });

            try
            {
                MenuItemViewModel addrp = new MenuItemViewModel()
                {
                    Header  = "Add run profile to execution queue",
                    Command = new DelegateCommand(t => { }, t => this.CanAddToExecutionQueue())
                };

                ConfigClient c = App.GetDefaultConfigClient();
                c.InvokeThenClose(u =>
                {
                    foreach (string rp in c.GetManagementAgentRunProfileNames(this.ManagementAgentID, true).OrderBy(t => t))
                    {
                        addrp.MenuItems.Add(new MenuItemViewModel()
                        {
                            Header  = rp,
                            Command = new DelegateCommand(t => this.AddToExecutionQueue(rp)),
                        });
                    }
                });

                if (addrp.MenuItems.Count > 0)
                {
                    this.MenuItems.Add(new SeparatorViewModel());
                    this.MenuItems.Add(addrp);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error getting the run profile list");
                Trace.WriteLine(ex.ToString());
            }
        }
예제 #8
0
        private void Import()
        {
            this.UpdateFocusedBindings();

            if (!this.ContinueOnUnsavedChanges())
            {
                return;
            }

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt      = ".xml";
            dialog.Filter          = "Configuration Files (.xml)|*.xml|All Files|*.*";
            dialog.CheckFileExists = true;

            bool?result = dialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            if (!System.IO.File.Exists(dialog.FileName))
            {
                return;
            }

            ConfigFile f;

            try
            {
                f = Serializer.Read <ConfigFile>(dialog.FileName);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                MessageBox.Show($"Could not open the file\n\n{ex.Message}", "File Open", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                this.Cursor = Cursors.Wait;
                ConfigClient c = App.GetDefaultConfigClient();
                f = c.ValidateConfig(f);
                c.InvokeThenClose(x => x.PutConfig(f));
                this.AskToRestartService();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                MessageBox.Show($"Could not import the file\n\n{ex.Message}", "File import operation", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }

            this.IsDirty = false;

            this.ResetConfigViewModel();
        }