ToFile() публичный Метод

Write configuration to a file. If the filename is not supplied then the path used when reading in the configuration will be used, or the default path of Constants.Data_DIR\netlog.json will be used
public ToFile ( string filename = null ) : void
filename string
Результат void
        /// <summary>
        /// Obtain configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\netlog.json is used
        /// </summary>
        public static NetLogConfiguration FromFile(string filename=null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\netlog.json";
            }

            NetLogConfiguration configuration = new NetLogConfiguration();
            try
            {
                string configurationData = File.ReadAllText(filename);
                configuration = JsonConvert.DeserializeObject<NetLogConfiguration>(configurationData);
                configuration.dataPath = filename;
            }
            catch
            {
                configuration = new NetLogConfiguration();
                configuration.dataPath = filename;
                // See if there was old information present
                string oldFilename = Constants.DATA_DIR + @"\productpath";
                try
                {
                    string path = File.ReadAllText(oldFilename);
                    if (path != null)
                    {
                        configuration.path = path;
                        configuration.ToFile();
                        File.Delete(oldFilename);
                    }
                }
                catch { }
            }

            return configuration;
        }
 private void updateNetLogConfiguration()
 {
     NetLogConfiguration netLogConfiguration = new NetLogConfiguration();
     if (!string.IsNullOrWhiteSpace(netLogPathTextBox.Text))
     {
         netLogConfiguration.path = netLogPathTextBox.Text.Trim();
     }
     netLogConfiguration.ToFile();
     EDDI.Instance.Reload("Netlog monitor");
 }
Пример #3
0
        private void updateNetLogConfiguration()
        {
            NetLogConfiguration netLogConfiguration = new NetLogConfiguration();

            if (!string.IsNullOrWhiteSpace(netLogPathTextBox.Text))
            {
                netLogConfiguration.path = netLogPathTextBox.Text.Trim();
            }
            netLogConfiguration.ToFile();
            EDDI.Instance.Reload("Netlog monitor");
        }
        /// <summary>
        /// Obtain configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\netlog.json is used
        /// </summary>
        public static NetLogConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\netlog.json";
            }

            NetLogConfiguration configuration = new NetLogConfiguration();

            try
            {
                string configurationData = File.ReadAllText(filename);
                configuration          = JsonConvert.DeserializeObject <NetLogConfiguration>(configurationData);
                configuration.dataPath = filename;
            }
            catch
            {
                configuration          = new NetLogConfiguration();
                configuration.dataPath = filename;
                // See if there was old information present
                string oldFilename = Constants.DATA_DIR + @"\productpath";
                try
                {
                    string path = File.ReadAllText(oldFilename);
                    if (path != null)
                    {
                        configuration.path = path;
                        configuration.ToFile();
                        File.Delete(oldFilename);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Debug("Failed to read netlog configuration", ex);
                }
            }
            if (configuration == null)
            {
                configuration          = new NetLogConfiguration();
                configuration.dataPath = filename;
            }

            return(configuration);
        }