private void checkTimeLimits() { // create minimum values intervals and times can be if (m_pollInterval < 1000) // 1 second min { m_pollInterval = 1000; } if (m_pollInterval > 300000) // 5 minutes max { m_pollInterval = 300000; } if (m_userPrefs.getInt(PrefsData.PrefInt.LogInterval) < 300000) // 5 minutes min { m_userPrefs.setInt(300000, PrefsData.PrefInt.LogInterval); } if (m_userPrefs.getInt(PrefsData.PrefInt.IdleTime) < m_pollInterval) // can not be shorter than poll interval { m_userPrefs.setInt(m_pollInterval, PrefsData.PrefInt.LogInterval); } if (m_userPrefs.getInt(PrefsData.PrefInt.TimeoutTime) < m_userPrefs.getInt(PrefsData.PrefInt.IdleTime)) // can not be shorter than idle time { m_userPrefs.setInt(m_userPrefs.getInt(PrefsData.PrefInt.IdleTime), PrefsData.PrefInt.TimeoutTime); } }
private static PrefsData loadPrefs() { PrefsData result = new PrefsData(); string filePath = System.Environment.CurrentDirectory + m_fileName; if (File.Exists(filePath)) { PrefsData.PrefLogIndex currentSpreadheetIndex = PrefsData.PrefLogIndex.Log01; foreach (string line in File.ReadLines(filePath)) { if (line.Length == 0) { continue; } if (line.StartsWith(m_commentToken)) { continue; } if (line.StartsWith(m_versionToken)) { checkVersion(line.TrimStart(m_versionToken.ToCharArray())); } // get ints if (line.StartsWith(m_intToken)) { // remove the line token that shows this line contains int data string intData = line.Remove(0, m_intToken.Length); string logInterval = m_dataTokens[(int)PrefsData.PrefInt.LogInterval]; string idleTime = m_dataTokens[(int)PrefsData.PrefInt.IdleTime]; string timeoutTime = m_dataTokens[(int)PrefsData.PrefInt.TimeoutTime]; string ActiveLog = m_dataTokens[(int)PrefsData.PrefInt.ActiveLog]; if (intData.StartsWith(logInterval)) { int defaultValue = m_defaultLogInterval; int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue); result.setInt(defaultValue, PrefsData.PrefInt.LogInterval); } if (intData.StartsWith(idleTime)) { int defaultValue = m_defaultIdleTime; int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue); result.setInt(defaultValue, PrefsData.PrefInt.IdleTime); } if (intData.StartsWith(timeoutTime)) { int defaultValue = m_defaultTimeoutTime; int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue); result.setInt(defaultValue, PrefsData.PrefInt.TimeoutTime); } if (intData.StartsWith(ActiveLog)) { int defaultValue = m_defaultActiveLog; int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue); result.setInt(defaultValue, PrefsData.PrefInt.ActiveLog); } } // END get ints // get strings if (line.StartsWith(m_stringToken)) { // remove the line token shwoing this line contains a string of strings of data // then split each string into its own string string[] strData = (line.Remove(0, m_stringToken.Length)) .Split(m_sheetsSeperator.ToCharArray()); // if token was the only character continue if (strData.Length == 0) { continue; } // if data storage is full continue if (currentSpreadheetIndex >= PrefsData.PrefLogIndex.Count) { continue; } result.setLogName(strData[0], currentSpreadheetIndex); result.setProjectName(strData[1], currentSpreadheetIndex); result.setProjectDescription(strData[2], currentSpreadheetIndex); result.setLogGoogleId(strData[3], currentSpreadheetIndex); currentSpreadheetIndex++; } // END get strings } Console.WriteLine("Pref file loaded"); } else // file did not exist { Console.WriteLine("Pref file not found"); // create a default user preference file result.setInt(m_defaultLogInterval, PrefsData.PrefInt.LogInterval); result.setInt(m_defaultIdleTime, PrefsData.PrefInt.IdleTime); result.setInt(m_defaultTimeoutTime, PrefsData.PrefInt.TimeoutTime); result.setInt(m_defaultActiveLog, PrefsData.PrefInt.ActiveLog); // preset first log profile result.setLogName("Default Log", 0); result.setProjectName("Default Project", 0); result.setProjectDescription("Default Description", 0); result.setLogGoogleId("", 0); // set the other profiles as empty for (PrefsData.PrefLogIndex i = PrefsData.PrefLogIndex.Log02; i < PrefsData.PrefLogIndex.Count; i++) { result.setLogName("", i); result.setProjectName("", i); result.setProjectDescription("", i); result.setLogGoogleId("", i); } } return(result); }