public void SwitchTo(EnvironmentConfig config)
        {
            _logger.WriteLine("Executing batch to delete config files");
            deleteFiles();

            _logger.WriteLine("Copying ttmd.cfg file");
            config.FileInfo.CopyTo(_ttmConfig.FullName, true);
        }
        private static EnvironmentConfig getConfigFromFile(FileInfo fileInfo)
        {
            EnvironmentConfig cfg = new EnvironmentConfig();
            cfg.FileInfo = fileInfo;
            cfg.IsGuardServerAllowed = !System.Text.RegularExpressions.Regex.IsMatch(fileInfo.Name, "NoGS", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            cfg.Name = System.Text.RegularExpressions.Regex.Replace(fileInfo.Name, @"\.ttmd\.cfg", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            cfg.Name = System.Text.RegularExpressions.Regex.Replace(cfg.Name, @"\.NoGS", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            using (var reader = fileInfo.OpenRead())
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(reader);

                var xpathNavi = doc.CreateNavigator();
                var multicastNode = xpathNavi.SelectSingleNode("/ttmconfiguration[1]/multicastgroups[1]");
                if (multicastNode != null && !String.IsNullOrEmpty(multicastNode.Value))
                {
                    cfg.Multicast = multicastNode.Value.Replace("> =", String.Empty).Trim();
                }

                var daemonNode = xpathNavi.SelectSingleNode("/ttmconfiguration[1]/proxy[1]/daemon1[1]");
                if (daemonNode != null && !String.IsNullOrEmpty(daemonNode.Value))
                {
                    var regex = new System.Text.RegularExpressions.Regex(@"\d+\.\d+\.\d+\.\d+", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
                    var match = regex.Match(daemonNode.Value);

                    if (match.Success)
                    {
                        cfg.RemoteDaemon = match.Value;
                        cfg.Multicast = null;
                    }
                }
            }
            return cfg;
        }
Example #3
0
        private void switchConfigurations(EnvironmentConfig config)
        {
            var w = new NetEnvSwitcher.AreYouSureWindow(config.Name);
            w.Owner = this;
            w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;

            if (w.ShowDialog() == true)
            {
                ConfigurationsPanel.IsEnabled = false;

                LogParagraph.Inlines.Add(new LineBreak());

                var rect = new Rectangle();
                rect.Fill = Brushes.Gray;
                rect.Width = 600;
                rect.Height = 1;
                rect.Margin = new Thickness(0, 10, 0, 10);
                LogParagraph.Inlines.Add(rect);
                LogParagraph.Inlines.Add(new LineBreak());

                var t = new System.Threading.Tasks.Task(() =>
                    {
                        try
                        {
                            WriteLine("======== Switching to " + config.Name);

                            var bannedProcessesRunning = _bannedProcManager.GetBannedProcessesRunning();
                            if (bannedProcessesRunning.Count == 0)
                            {

                                _serviceManager.StopServices();

                                _envManager.SwitchTo(config);

                                _envManager.ResetAConfigRevisionCount();

                                WriteLine("Sleeping 3 seconds for good measure...");
                                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));

                                _serviceManager.StartServices(config.IsGuardServerAllowed);

                                WriteLine("Launching GuardianMFC");
                                _envManager.LaunchGuardianMFC();

                                WriteLine("======== Switched to " + config.Name);
                                addMissionAccomplishedImage();
                            }
                            else
                            {
                                WriteLine("PROBLEM: You need to stop apps before switching!");
                                foreach (var p in bannedProcessesRunning)
                                {
                                    WriteLine(" -> " + p.ProcessName);
                                }

                                Dispatcher.BeginInvoke(new Action(() =>
                                    {
                                        var window = new NetEnvSwitcher.RunningAppsWindow(bannedProcessesRunning);
                                        window.Owner = this;
                                        window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                                        window.ShowDialog();
                                    }));
                            }

                            refreshGuiAfterOperation();
                        }
                        catch (Exception ex)
                        {
                            WriteLine("!!!!!!!! Problem switching to " + config.Name);

                            while (ex != null)
                            {
                                WriteLine(ex.ToString());
                                ex = ex.InnerException;
                            }

                            refreshGuiAfterOperation();
                        }
                    });
                t.Start();
            }
        }