Example #1
0
        private static void SetConfig(IOutputService outputService, List <string> parameters)
        {
            //  We must have a key and value.
            if (parameters.Count != 2)
            {
                outputService.WriteError(string.Format("Incorrect syntax. Use: srm config <setting> <value>"));
                return;
            }

            //  Get the setting and value.
            var setting = parameters[0];
            var value   = parameters[1];

            //  Get the config.
            var config = SystemConfigurationProvider.Configuration;

            //  Set the setting.
            if (string.Compare("LoggingMode", setting, StringComparison.OrdinalIgnoreCase) == 0)
            {
                //  Try and parse the setting. If we fail, show an error.
                LoggingMode mode;
                if (Enum.TryParse(value, true, out mode) == false)
                {
                    const LoggingMode allFlags = LoggingMode.Disabled | LoggingMode.Debug | LoggingMode.EventLog | LoggingMode.File;
                    outputService.WriteError(string.Format("Invalid value '{0}'. Acceptible values are: {1}", value, allFlags));
                    return;
                }

                //  Set the logging mode.
                config.LoggingMode = mode;

                //  Save back to the registry.
                SystemConfigurationProvider.Save();

                //  Update the user.
                outputService.WriteSuccess(string.Format("Set LoggingMode to {0}", mode));
            }
            else if (string.Compare("LogPath", setting, StringComparison.OrdinalIgnoreCase) == 0)
            {
                //  Set the path.
                config.LogPath = value;

                //  Save back to the registry.
                SystemConfigurationProvider.Save();

                //  Update the user.
                outputService.WriteSuccess(string.Format("Set LogPath to {0}", value));
            }
            else
            {
                //  Show an error.
                outputService.WriteError(string.Format("{0} is not a valid config setting. Valid settings are LoggingMode and LogPath.", value));
            }
        }
        public void EmptyAppData()
        {
            string        appData       = _context.Server.MapPath("~/App_Data");
            DirectoryInfo directoryInfo = new DirectoryInfo(appData);

            foreach (FileInfo file in directoryInfo.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in directoryInfo.GetDirectories())
            {
                dir.Delete(true);
            }
            SystemConfigurationProvider.ClearCache();
            ConfigurationProvider.ClearCache();
        }