public static void ReadConfig <TypeOfConfig>(ref TypeOfConfig config, string configName) where TypeOfConfig : IXMLSerializable, IIsValidable, new() { string configFileName = @"\" + configName + ".xml"; string pathToConfig = CUtil.GetConfigDir() + configFileName; config = new TypeOfConfig() { FileName = pathToConfig, NeedSelfInit = false }; CSerializator.Read <TypeOfConfig>(ref config); if (!config.IsValid) { string pathToBkpConfig = CUtil.GetConfigBackupDir() + configFileName; config = new TypeOfConfig() { FileName = pathToConfig, NeedSelfInit = false }; CSerializator.Read <TypeOfConfig>(ref config); if (config.IsValid) { config.FileName = pathToConfig; CSerializator.Write <TypeOfConfig>(ref config); } else //backup is still invalid { throw new ApplicationException("Invalid config " + configName); } } }
public void WriteAllDataToDisk() { //TO DO older 2 days // if (bCopyIsBusy) // return; bCopyIsBusy = true; CopyDictTFArray(ref CopyDict); //m_timeFrameAnalyzer.Plaza2Connector.Log("ElapsedMilliseconds=" + sw.ElapsedMilliseconds + " " + m_timeFrameAnalyzer.IsinDir); // CDictTFArray cp = (CDictTFArray) this.MemberwiseClone(); try { foreach (KeyValuePair <string, SortedDictionary <DateTime, CTimeFrameArray> > kv in CopyDict)// this) { string tf = kv.Key; foreach (KeyValuePair <DateTime, CTimeFrameArray> kv2 in kv.Value) { DateTime dt = kv2.Key; CTimeFrameArray tfa = kv2.Value; if (!CUtilTime.OlderThanTwoWorkDays(dt)) { tfa.FileName = m_timeFrameAnalyzer.GetFileName(tf, dt); // tfa.mxLockFile.WaitOne(); this.m_timeFrameAnalyzer.CreateDirectoriesIfNeed(); CSerializator.Write <CTimeFrameArray>(ref tfa); tfa.DtLastWrite = DateTime.Now; // TaskCopyBackup(tfa.FileName); // tfa.mxLockFile.ReleaseMutex(); } } } } catch (Exception e) { Error("WriteAllDataToDisk", e); } bCopyIsBusy = false; }
/// <summary> /// Saves terminalc config to file /// /// Call from: /// 1. KernelTerminal.SaveWindowPosition (task called before) /// 2. SettingsTerminalWindow.SaveTerminalSettings (task) /// /// </summary> public void SaveTerminalSettings() { double parSecsWriteBackup = 60; lock (TerminalConfig) { //GUIDispatcher.Invoke(new Action(()=>ReReadSharedSettings())); CSerializator.Write <CTerminalConfig>(ref _terminalConfig); //Write backup if time to do it if ((DateTime.Now - _dtLastSave).TotalSeconds > parSecsWriteBackup) { CTerminalConfig terminalConfigBackup = _terminalConfig; terminalConfigBackup = (CTerminalConfig)_terminalConfig.Copy(); terminalConfigBackup.FileName = CUtil.GetConfigBackupDir() + @"\terminal.xml"; CSerializator.Write <CTerminalConfig>(ref terminalConfigBackup); _dtLastSave = DateTime.Now; } } }
public void Dump() { m_internalStock.Bids = ((CStocksDict)this.MemberwiseClone())[Direction.Down]; m_internalStock.Asks = ((CStocksDict)this.MemberwiseClone())[Direction.Up]; CSerializator.Write <SerializebleStock>(ref m_internalStock); }
public void SaveConfig() { CSerializator.Write <CTradeManagerConfig>(ref _tradeManagerConf); }