Example #1
0
        public Program(IEnvironmentConfigRepository environmentConfigRepository,
		               ILocalApplicationDataRepository localApplicationDataRepository)
        {
            // Remember our dependencies
            _environmentConfigRepository = environmentConfigRepository;
            _localApplicationDataRepository = localApplicationDataRepository;

            // Create a simple tray menu.
            trayMenu = new ContextMenu();

            // create new tray settings file for first run
            var testSettings = _localApplicationDataRepository.Get();
            if (testSettings == null)
                _localApplicationDataRepository.CreateNewSettingsFile();

            // Get our previously defined settings: environment.config location, list of environment and role names, etc.
            _localApplicationData = _localApplicationDataRepository.Get();

            BuildContextMenu();

            // Create a tray icon.
            trayIcon = new NotifyIcon();
            trayIcon.Text = "Application Environment File Configurator";
                // Runtime Exception is thrown when this value is > 63 characters long.
            trayIcon.Icon = new Icon(GetType(), "World.ico");

            // Add menu to tray icon and show it.
            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible = true;
        }
        public void Save(LocalApplicationData settings)
        {
            var localApplicationDataFolderPath =
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ConfigPTFE",
                             "ApplicationEnvironmentFileConfigurator");

            if (!Directory.Exists(localApplicationDataFolderPath))
                Directory.CreateDirectory(localApplicationDataFolderPath);

            var pathToSettingsConfig = Path.Combine(localApplicationDataFolderPath, "settings.config");

            var xmlSerializer = new XmlSerializer(settings.GetType());
            using (var fileStream = File.Open(pathToSettingsConfig, FileMode.Create)) {
                xmlSerializer.Serialize(fileStream, settings);
            }
        }
        public LocalApplicationData Get()
        {
            var settings = new LocalApplicationData();
            var localApplicationDataFolderPath =
                Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    "ConfigPTFE", "ApplicationEnvironmentFileConfigurator"
                    );

            var pathToSettingsConfig = Path.Combine(localApplicationDataFolderPath, "settings.config");

            var xmlSerializer = new XmlSerializer(settings.GetType());
            if (File.Exists(pathToSettingsConfig)) {
                using (var fileStream = File.OpenRead(pathToSettingsConfig)) {
                    settings = (LocalApplicationData) xmlSerializer.Deserialize(fileStream);
                }
            }
            else {
                settings = null;
            }

            return settings;
        }
 public void CreateNewSettingsFile()
 {
     var settings =
         new LocalApplicationData() {
             EnvironmentConfigFileName = "common.environment.config",
             EnvironmentNames =
                 new BindingList<StringWrapper>() {
                     new StringWrapper() {Text = "DEV"},
                     new StringWrapper() {Text = "INTEGRATION"},
                     new StringWrapper() {Text = "TEST"},
                     new StringWrapper() {Text = "REGRESSION"},
                     new StringWrapper() {Text = "PRODUCTION"}
                 },
             EnvironmentRoles =
                 new BindingList<StringWrapper>() {
                     new StringWrapper() {Text = "[none]"},
                     new StringWrapper() {Text = "REPORTS"},
                     new StringWrapper() {Text = "SERVICES"},
                     new StringWrapper() {Text = "WEBSERVER"}
                 },
         };
     Save(settings);
 }
Example #5
0
        private void OnOptionsSelection(object sender, EventArgs e)
        {
            var options = ObjectFactory.GetInstance<OptionsForm>();
            options.ShowDialog(this);

            // Get our previously defined settings: environment.config location, list of environment and role names, etc.
            _localApplicationData = _localApplicationDataRepository.Get();

            BuildContextMenu();
        }