public override void ProcessProperty(ref Product product, XElement property) { var stock = new Stock(); var atp = new Atp(); foreach (var item in property.Descendants()) { if (item.Name.LocalName == "inStockLocal") { stock.InStockLocal = item.Value; } else if (item.Name.LocalName == "inStockCentral") { stock.InStockCentral = item.Value; } else if (item.Name.LocalName == "nextExpectedStockDateLocal") { atp.NextExpectedStockLocal = item.Value; } else if (item.Name.LocalName == "nextExpectedStockDateCentral") { atp.NextExpectedStockCentral = item.Value; } } stock.Atp = atp; product.Stock = stock; }
void ftpClient_DownloadComplete(object sender, Atp.AsyncMethodCompletedEventArgs e) { lblProgress.Content = "Download Complete!"; }
void ParseAtpFromPage(string html, Atp atp) { var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); atp.Name = htmlDoc.DocumentNode.SelectSingleNode(".//h1[@class='profile']").InnerText; var infoUl = htmlDoc.DocumentNode.SelectSingleNode(".//ul[@id='general']"); atp.Address = ParseHelper.RemoveSpacesAndLineBreaks(infoUl.SelectSingleNode("li[@id='list_address']").SelectSingleNode("//b").InnerText); atp.Description = ParseHelper.RemoveSpacesAndLineBreaks(infoUl.SelectSingleNode("li[@id='list_short_info']").SelectSingleNode("//div[@id='gen-info']").InnerText); var coords = ParseHelper.GetSubstring(html, "coords = [", "];"); if (!String.IsNullOrEmpty(coords)) { string dolgota, shirota; ParseHelper.GetCoordinates(coords, out shirota, out dolgota); atp.Shirota = shirota; atp.Dolgota = dolgota; } }
async Task<List<Atp>> GetAtps(List<String> atpUrls) { var index = 0; var atpsDict = new ConcurrentDictionary<String, Atp>(); var tasks = new List<Task>(); foreach (var atpUrl in atpUrls) //var atpUrl = atpUrls.First(); { var executeParams = new ExecuteParams() { Step = ++index, Url = atpUrl, TimeInterval = new TimeSpan(0, 0, 1), AttemptsCount = 3, RequestFunction = async (url, proxy, step) => { var html = await HttpHelper.HttpGet(url); var atp = new Atp() { Url = url }; ParseAtpFromPage(html, atp); atpsDict[atp.Url] = atp; Logger.Instance.Info(String.Format("{0}/{1} получено АТП {2}", step, atpUrls.Count, atp.Url)); }, ExceptionAction = (url, proxy, step, ex) => { Logger.Instance.Error("Не удалось получить АТП " + url, ex); } }; tasks.Add(TasksExecuteHelper.Execute(executeParams)); await Task.Delay(Properties.Settings.Default.OrgPageAtpRequestDelay); } Task.WaitAll(tasks.ToArray()); return atpsDict.Values.ToList(); }
/// <summary> /// The upload operation completed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void FtpClient_UploadComplete(object sender, Atp.AsyncMethodCompletedEventArgs e) { Document uploadedDoc = (Document)mainVM.CurrentFtpMessage.MetaData; //Move the message to the top of the list mainVM.InformationMessages.Move(mainVM.InformationMessages.IndexOf(mainVM.CurrentFtpMessage), 0); mainVM.CurrentFtpMessage.Header = String.Format("Upload Complete - {0}", uploadedDoc.Filename); mainVM.CurrentFtpMessage.Message = uploadedDoc.Filename + " was uploaded successfully."; mainVM.CurrentFtpMessage.UpdateIcon("UploadComplete"); lstInformation.Items.Refresh(); gridLsnDocuments.Rebind(); mainVM.SaveChanges(); }
/// <summary> /// The progress of our ftp download has changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void FtpClient_ProgressUpdate(object sender, Atp.IO.FileSystemProgressEventArgs e) { mainVM.CurrentFtpMessage.Message = Math.Round(e.Percentage,1) + "% Complete"; lstInformation.Items.Refresh(); }
/// <summary> /// Our FTP download completed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void FtpClient_DownloadComplete(object sender, Atp.AsyncMethodCompletedEventArgs e) { Document downloadedDoc = (Document)mainVM.CurrentFtpMessage.MetaData; //Move the message to the top of the list mainVM.InformationMessages.Move(mainVM.InformationMessages.IndexOf(mainVM.CurrentFtpMessage), 0); mainVM.CurrentFtpMessage.Header = String.Format("Download Complete - {0}", downloadedDoc.Filename); mainVM.CurrentFtpMessage.Message = "Saved to: " + mainVM.CurrentFtpMessage.Tag; mainVM.CurrentFtpMessage.UpdateIcon("DownloadComplete"); lstInformation.Items.Refresh(); }
List<Atp> ParseAtpsPage(String html) { var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); var coords = GetCoordinates(html); var div = htmlDocument.DocumentNode.SelectSingleNode(".//div[@id='spisokfirm']"); var namesDiv = div.SelectNodes(".//div[@style='margin-bottom:5px;']"); var adressesDiv = div.SelectNodes(".//table[@style='margin-bottom:4px;']"); var list = new List<Atp>(); for(var i = 0; i < namesDiv.Count; i++) { var nameDiv = namesDiv[i]; var address = adressesDiv[i].SelectNodes(".//span")[1].InnerText; var atp = new Atp() { Name = nameDiv.InnerText, Address = address, Description = ParseAtpDescription(nameDiv.ParentNode.InnerHtml), Url = nameDiv.SelectSingleNode(".//a").GetAttributeValue("href", ""), Shirota = i < coords.Count ? coords[i].Shirota : String.Empty, Dolgota = i < coords.Count ? coords[i].Dolgota : String.Empty }; list.Add(atp); } return list; }