public static void SaveSession(WorkingConfig config) { Task.Factory.StartNew(() => { lock (INSTANCE) { if (config.Id == Guid.Empty) { config.Id = Guid.NewGuid(); } var saved = INSTANCE.WORKS.FirstOrDefault(c => c.ServerSetting == config.ServerSetting); if (null == saved) { INSTANCE.WORKS.Add(config); } else { INSTANCE.WORKS.Remove(config); INSTANCE.WORKS.Add(config); } INSTANCE.LastId = config.Id; JsonUtils.Save(INSTANCE, CONFIG_FILE_NAME); CurrentSession = config; } }); }
public static WorkingConfig GetLastSession() { if (null != CurrentSession) { return(CurrentSession); } if (null == INSTANCE) { return(null); } CurrentSession = INSTANCE.WORKS.FirstOrDefault(c => c.Id == INSTANCE.LastId); return(CurrentSession); }
void SaveWorking(ConnectionSetting connectionSetting = null) { var setting = connectionSetting ?? GetConnectionSetting(); try { var item = WorkingConfigService.CurrentSession; if (null == item) { item = new WorkingConfig(); } item.DestDir = txtSaveTo.Text; item.ServerSetting = setting; WorkingConfigService.SaveSession(item); } catch (Exception e) { Logs.LogFactory.Error("Cannot save working session." + e.Message, e); } }