예제 #1
0
        /// <summary>
        /// Save user configuration
        /// </summary>
        public override void SaveUserConfiguration(string userId, OpenIZConfiguration config)
        {
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }
            else if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            // Try-catch for save
            try
            {
                var userPrefDir = this.Configuration.GetSection <ApplicationConfigurationSection>().UserPrefDir;
                if (!Directory.Exists(userPrefDir))
                {
                    Directory.CreateDirectory(userPrefDir);
                }

                // Now we want to load
                String configFile = Path.ChangeExtension(Path.Combine(userPrefDir, userId), "userpref");
                using (var fs = File.Create(configFile))
                    config.Save(fs);
            }
            catch (Exception ex)
            {
                this.m_tracer.TraceError("Error saving user configuration data {0}: {1}", userId, ex);
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Save the specified configuration
        /// </summary>
        /// <param name="config">Config.</param>
        public void Save(OpenIZConfiguration config)
        {
            try
            {
                this.m_tracer?.TraceInfo("Saving configuration to {0}...", this.m_configPath);
                if (!Directory.Exists(Path.GetDirectoryName(this.m_configPath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(this.m_configPath));

                using (FileStream fs = File.Create(this.m_configPath))
                {
                    config.Save(fs);
                    fs.Flush();
                }
            }
            catch (Exception e)
            {
                this.m_tracer?.TraceError(e.ToString());
            }
        }