private void LoadSettings() { try { string settingsFilePath = GetSettingsFilePath(); smng = new SettingsManager(); smng.ConverterMap.Add(typeof(Regex), new FlexibleConverter <Regex>(regex => regex.ToString(), str => new Regex(str))); smng.Load(settingsFilePath); uiContext.Send(_ => { Size size; if (smng.TryGetItem(SettingsConstants.SIZE, out size)) { this.Size = size; } FormWindowState windowState; if (smng.TryGetItem(SettingsConstants.WINDOW_STATE, out windowState)) { this.WindowState = windowState; } }, null); NicoAccessTimer timer = new NicoAccessTimer(smng); string userSession = GetUserSession(smng); string proxyHost; if (!smng.TryGetItem(SettingsConstants.PROXY_HOST, out proxyHost)) { proxyHost = "localhost"; } int proxyPort; if (!smng.TryGetItem(SettingsConstants.PROXY_PORT, out proxyPort)) { proxyPort = 8080; } downloadWorker.Setup(userSession, proxyHost, proxyPort, timer); uiContext.Send(_ => { WithEditQueueingUrls(currentLines => { return(smng.GetItems <string>(SettingsConstants.URL) .Select(x => x.Value)); }); OutputMessage(string.Format("User session: {0}", userSession)); }, null); settingsLoaded = true; } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void Setup(string userSession, string proxyHost, int proxyPort, NicoAccessTimer timer) { if (userSession == null) { throw new ArgumentNullException("userSession"); } cookies = new CookieContainer(); Cookie cookie = new Cookie("user_session", userSession, "/", ".nicovideo.jp"); cookies.Add(cookie); if (proxyHost != null && proxyPort > 0) { proxy = new WebProxy(proxyHost, proxyPort); } else { proxy = null; } Timer = timer; }
public NicoAccessTimer DeriveNewTimer(SettingsManager smng) { NicoAccessTimer timer = new NicoAccessTimer(smng, waitInfoMap); return timer; }
public NicoAccessTimer DeriveNewTimer(SettingsManager smng) { NicoAccessTimer timer = new NicoAccessTimer(smng, waitInfoMap); return(timer); }
private void queueingUrls_UpdateTimerEvent(object sender, EventArgs e) { NicoAccessTimer timer = downloadWorker.Timer; timer.UpdateLastAccess("urn:uuid:45755c6f-01e2-4a38-6f5c-7545e201384a"); }
private void reloadSettingsButton_Click(object sender, EventArgs e) { bool isOnline = pollingTimer.Enabled; if (isOnline) { pollingTimer.Stop(); } Dictionary <Control, bool> enabledStateMap = SetAllControlEnabledStatus(false); OutputMessage(""); OutputMessage(string.Format("Using : {0}", GetSettingsFilePath())); var taskFactory = new TaskFactory(); var loadSettingsTask = taskFactory.StartNew(() => { SettingsManager newSmng = new SettingsManager(); newSmng.ConverterMap.Add(typeof(Regex), new FlexibleConverter <Regex>(regex => regex.ToString(), str => new Regex(str))); settingsLoaded = false; string settingsFilePath = GetSettingsFilePath(); newSmng.Load(settingsFilePath); string usersessionFactory = newSmng.GetItem <string>(SettingsConstants.USERSESSION_FACTORY); smng.SetOrAddNewItem(SettingsConstants.USERSESSION_FACTORY, usersessionFactory); foreach (SettingsItem <string> timerNameItem in smng.GetItems <string>(SettingsConstants.TIMER_NAME)) { string timerName = timerNameItem.Value; string timerIntervalName = string.Format("{0}_{1}", SettingsConstants.TIMER_INTERVAL_PREFIX, timerName); smng.RemoveAll <TimeSpan>(timerIntervalName); string timerPatternName = string.Format("{0}_{1}", SettingsConstants.TIMER_PATTERN_PREFIX, timerName); smng.RemoveAll <Regex>(timerPatternName); } smng.RemoveAll <string>(SettingsConstants.TIMER_NAME); foreach (string timerName in newSmng.GetItems <string>(SettingsConstants.TIMER_NAME)) { smng.AddItem(SettingsConstants.TIMER_NAME, timerName); string timerIntervalName = string.Format("{0}_{1}", SettingsConstants.TIMER_INTERVAL_PREFIX, timerName); TimeSpan timerInterval = newSmng.GetItem <TimeSpan>(timerIntervalName); smng.AddItem(timerIntervalName, timerInterval); string timerPatternName = string.Format("{0}_{1}", SettingsConstants.TIMER_PATTERN_PREFIX, timerName); Regex timerPattern = newSmng.GetItem <Regex>(timerPatternName); smng.AddItem(timerPatternName, timerPattern); } string userSession = GetUserSession(smng); downloadWorker.SetUserSession(userSession); NicoAccessTimer timer = downloadWorker.Timer; NicoAccessTimer newTimer = timer.DeriveNewTimer(smng); downloadWorker.Timer = newTimer; return(userSession); }); var applySettingsTask = loadSettingsTask.ContinueWith(precedentTask => { try { // only for exception propagation precedentTask.Wait(); var userSession = precedentTask.Result; OutputMessage(string.Format("User session: {0}", userSession)); RestoreAllControlEnabledStatus(enabledStateMap); if (isOnline) { pollingTimer.Start(); } settingsLoaded = true; } catch (AggregateException exception) { Exception exp = exception; if (exception.InnerExceptions.Count == 1) { exp = exception.InnerExceptions[0]; } onlineController.Text = "Offline"; onlineController.Checked = false; statusIndicator.BackColor = Color.Gray; splitContainer1.Enabled = true; splitContainer1.Panel2.Enabled = true; exitButton.Enabled = true; outputTextBox.Enabled = true; MessageBox.Show(exp.ToString()); } }, TaskScheduler.FromCurrentSynchronizationContext()); }