private void SetCorrentPage(Page newCorrentPage) { if (сorrentPage != null) { l.Debug("Удаляю страницу " + сorrentPage.GetType().ToString() ); this.Controls.Remove(сorrentPage); settings = сorrentPage.GetSetting(); } сorrentPage = newCorrentPage; if (сorrentPage != null) { l.Debug("Добавляю страницу " + сorrentPage.GetType().ToString()); this.Controls.Add(сorrentPage); try { сorrentPage.SetSetting(settings); } catch (Exception e) { l.Error("Необробатываемое исключение в " + сorrentPage.GetType() + " " + e); } buttonNext.Enabled = сorrentPage.NextExists(); buttonPrevious.Enabled = сorrentPage.PreviousExists(); } else { buttonNext.Enabled = false; buttonPrevious.Enabled = false; } }
public override void SetSetting(Settings settings) { base.SetSetting(settings); if (!backgroundWorker.IsBusy) backgroundWorker.RunWorkerAsync(); else l.Error("backgroundWorker.IsBusy"); }
public override void SetSetting(Settings settings) { base.SetSetting(settings); if (settings == null) return; checkBoxProxy.Checked = settings.useProxy; textBoxProxy.Text = settings.proxy; checkBoxProxyPassword.Checked = settings.proxyWithPassword; textBoxLogin.Text = settings.proxyUser; textBoxPassword.Text = settings.proxyPassword; if ((settings.from > dateTimePickerFrom.MinDate) && (settings.from < dateTimePickerFrom.MaxDate)) dateTimePickerFrom.Value = settings.from; else dateTimePickerFrom.Value = DateTime.Today; if ((settings.to > dateTimePickerTo.MinDate) && (settings.to < dateTimePickerTo.MaxDate)) dateTimePickerTo.Value = settings.to; else dateTimePickerTo.Value = DateTime.Today; checkBoxToday.Checked = settings.toToday; if (settings.toToday) dateTimePickerTo.Value = DateTime.Today; switch (settings.fromType) { case 0: checkBoxFromType.Checked = false; break; case 1: radioButton1.Checked = true; break; case 2: radioButton2.Checked = true; break; case 3: radioButton3.Checked = true; break; default: l.Error("settings.fromType=" + settings.fromType); break; } saveCSVCheckBox.Checked = settings.saveCSVChecked ; saveCSVFolderTextBox.Text = settings.saveCSVFolder; analyzeCheckBox.Checked = settings.analyzeChecked; downloadCheckBox.Checked = settings.downloadChecked; }
public override void SetSetting(Settings settings) { base.SetSetting(settings); lock (FinamHelper.Lock) { if (FinamHelper.Emitents == null) FinamHelper.Emitents = FinamHelper.LoadEmitents(settings.EmitentsFileName); if (FinamHelper.Emitents.Count == 0) buttonRefresh_Click(null, null); else finamTreeView.SetEmitents(FinamHelper.Emitents); } }
public static string Download(Settings settings, EmitentInfo emitent, DateTime date) { string link = String.Format("http://195.128.78.52/{0}.{1}?d=d&market={2}&em={3}&p={4}&df={5}&mf={6}&yf={7}&dt={8}&mt={9}&yt={10}&f={11}&e=.{12}&datf={13}&cn={14}&dtf=1&tmf=1&MSOR=0&sep=3&sep2=1&at=1", emitent.Code, "csv", emitent.MarketId, emitent.Id, 1,//settings.period, date.Day, date.Month - 1, date.Year, date.Day, date.Month - 1, date.Year, emitent.Code, "csv", 11,//format, if (settings.period == 1) format = 11; else format = 5; emitent.Code ); l.Debug("Скачиваю " + link); System.Net.WebClient webClient = InitWebClient(settings); webClient.Headers.Add("Referer", @"http://www.finam.ru/analysis/export/default.asp"); string result = string.Empty; try { result = webClient.DownloadString(link); } catch (Exception e) { result = "Exception"; l.Info("Ошибка при скачивании " + e); } return result; }
/// <summary> /// Создается, и инициируется WebClient /// </summary> /// <param name="settings">Настройки прокси</param> /// <returns></returns> private static System.Net.WebClient InitWebClient(Settings settings) { l.Debug("Создаю WebClient"); System.Net.WebClient webClient = new TimeoutWebClient(); // настраиваю прокси if (settings.useProxy) { System.Net.WebProxy webProxy = new System.Net.WebProxy(); webProxy.Address = new Uri(settings.proxy); if (settings.proxyWithPassword) { webProxy.Credentials = new System.Net.NetworkCredential(settings.proxyUser, settings.proxyPassword); } webClient.Proxy = webProxy; } return webClient; }
/// <summary> /// Скачиваю список эмитентов из финама /// </summary> /// <param name="settings">Настройки прокси</param> /// <returns>Список эмитентов</returns> public static List<EmitentInfo> DownloadEmitents(Settings settings) { l.Debug("Скачиваю список эмитентов из финама"); System.Net.WebClient webClient = InitWebClient(settings); string marketsString = string.Empty; try { // скачиваю интерфейс marketsString = webClient.DownloadString(@"http://www.finam.ru/analysis/export/default.asp"); } catch (Exception e) { l.Error("Не смог скачать интерфейс с финама " + e); return null; } String sOption = @"<option\s+?.*?value=""(?<id>[0-9]+)"".*?>(?<name>.+?)</option>"; String sSelect = @"<select(.|\n)+?id=""market""(.|\n)+?(" + sOption + ")+?(.|\n)*?</select>"; // Поиск нужного <select id="market"> System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(marketsString, sSelect, System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (!m.Success) { l.Error("Ошибка парсинга <select id=market>"); return null; } marketsString = m.Value; // поиск всех секций System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(marketsString, sOption, System.Text.RegularExpressions.RegexOptions.IgnoreCase); List<EmitentInfo> markets = new List<EmitentInfo>(); foreach (System.Text.RegularExpressions.Match match in mc) { markets.Add(new EmitentInfo(Convert.ToInt32(match.Groups["id"].Value), match.Groups["name"].Value, -1, String.Empty, String.Empty)); } // скачиваю js string instruments = webClient.DownloadString(@"http://www.finam.ru/scripts/export.js"); instruments = instruments.Replace("\\'", "-"); // убрать кавычки из списка эмитентов, в противном случае строка не парситься String pattern = @"var\saEmitentIds=new\sArray\((?<EmitentIds>.*?)\);" + "(.|\n)*?" + @"var\saEmitentNames=new\sArray\((?<EmitentNames>.*?)\);" + "(.|\n)*?" + @"var\saEmitentCodes=new\sArray\((?<EmitentCodes>.*?)\);" + "(.|\n)*?" + @"var\saEmitentMarkets=new\sArray\((?<EmitentMarkets>.*?)\);" + "(.|\n)*?" + @"var\saDataFormatStrs=new Array\(.*?\);"; System.Text.RegularExpressions.Match emitentMarkets = System.Text.RegularExpressions.Regex.Match(instruments, pattern); System.Text.RegularExpressions.MatchCollection sEmitentIds = System.Text.RegularExpressions.Regex.Matches(emitentMarkets.Groups["EmitentIds"].Value, @"[0-9]+"); System.Text.RegularExpressions.MatchCollection sEmitentNames = System.Text.RegularExpressions.Regex.Matches(emitentMarkets.Groups["EmitentNames"].Value, @"'.+?'"); System.Text.RegularExpressions.MatchCollection sEmitentCodes = System.Text.RegularExpressions.Regex.Matches(emitentMarkets.Groups["EmitentCodes"].Value, @"'.+?'"); System.Text.RegularExpressions.MatchCollection sEmitentMarkets = System.Text.RegularExpressions.Regex.Matches(emitentMarkets.Groups["EmitentMarkets"].Value, @"[0-9]+"); if ((sEmitentIds.Count != 0) && (sEmitentIds.Count == sEmitentNames.Count) && (sEmitentIds.Count == sEmitentCodes.Count) && (sEmitentNames.Count == sEmitentMarkets.Count)) { List<EmitentInfo> emitents = new List<EmitentInfo>(); for (int i = 0; i < sEmitentMarkets.Count; ++i) { foreach (EmitentInfo market in markets) { if (Convert.ToInt32(sEmitentMarkets[i].Value) == market.MarketId) { String chars4trim = "' "; String instrumentName = sEmitentNames[i].Value.Trim(chars4trim.ToCharArray()); emitents.Add(new EmitentInfo( market.MarketId, market.MarketName, Convert.ToInt32(sEmitentIds[i].Value), instrumentName, sEmitentCodes[i].Value.Trim(chars4trim.ToCharArray()) )); break; } } } return emitents; } else { l.Error("Ошибка парсинга export.js"); return null; } }
private void timerOnlyOne_Tick(object sender, EventArgs e) { if (onlyOne.WaitOne(0,false)) { timerOnlyOne.Enabled = false; labelOnlyOne.Visible = false; labelStarting.Visible = true; settings = new Settings(); SetCorrentPage(new SettingsPage()); labelStarting.Visible = false; } else { labelOnlyOne.Visible = true; labelStarting.Visible = false; } }
public virtual void SetSetting(Settings settings) { this.settings = settings; }