Exemplo n.º 1
0
 private void MetroTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     Dispatcher.Invoke<Task>(async () =>
     {
         waterfallFlow.Children.Clear();
         MaterialCircular _addUser;
         Control _currentUser;
         var parsedValues = myClass.Where(x=>x.Title.Contains(txtSearch.Text) || x.Date.Contains(txtSearch.Text));
         foreach (var item in parsedValues)
         {
             
             await Task.Delay(10);                   
             _addUser = new MaterialCircular(item.Row, item.Title, item.Category, item.Type, item.SubType, item.Date, item.link);
             _currentUser = _addUser;
             waterfallFlow.Children.Add(_currentUser);
             waterfallFlow.Refresh();
         }
     }, DispatcherPriority.ContextIdle);
 }
Exemplo n.º 2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            
            Dispatcher.Invoke<Task>(async () =>
        {
            waterfallFlow.Children.Clear();
            MaterialCircular _addUser;
            Control _currentUser;
            try
            {
                using (WebClient webClient = new WebClientWithTimeout())
                {
                    webClient.Headers.Add("User-Agent: Other");
                    var page = webClient.DownloadString(FindElement.Settings.DefaultServer ?? AppVariable.DefaultServer2);
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(page);
                    var query = doc.DocumentNode.SelectNodes("//table[@class='table table-striped table-hover']/tbody/tr")
                .Select(r =>
                {
                    var linkNode = r.Descendants("a").Select(node => node.Attributes["href"].Value).ToArray();
                    var linkNode2 = r.SelectSingleNode("th|td");
                    return new DelegationLink()
                    {
                        Row = r.SelectSingleNode(".//td").InnerText,
                        link = FindElement.Settings.DefaultServer + linkNode.FirstOrDefault(),
                        Category = r.SelectSingleNode(".//td[2]").InnerText,
                        Title = r.SelectSingleNode(".//td[3]").InnerText,
                        Date = r.SelectSingleNode(".//td[4]").InnerText,
                        Type = r.SelectSingleNode(".//td[5]").InnerText,
                        SubType = r.SelectSingleNode(".//td[6]").InnerText
                    };
                }
                ).ToList();
                    var parsedValues = query.Take(Limited ? 20 : query.Count).ToList();
                    myClass = parsedValues;
                    prgUpdate.Maximum = parsedValues.Count;

                    foreach (var item in parsedValues)
                    {
                        if (!Permission)
                            return;

                        await Task.Delay(10);
                        prgUpdate.Value += 1;
                        prgUpdate.Hint = string.Format("{0}%", ((prgUpdate.Value * 100) / parsedValues.Count).ToString("0"));
                        _addUser = new MaterialCircular(item.Row, item.Title, item.Category, item.Type, item.SubType, item.Date, item.link);
                        _currentUser = _addUser;
                        waterfallFlow.Children.Add(_currentUser);
                        waterfallFlow.Refresh();
                    }
                    if (prgUpdate.Hint == "100%")
                    {
                        Permission = false;
                        txtStop.Text = "دریافت";
                        Style style = this.FindResource("WorkButtonGreen") as Style;
                        btnStop.Style = style;
                        img.Source = new BitmapImage(new Uri("pack://application:,,,/MoalemYar;component/Resources/start.png", UriKind.Absolute));
                        txtSearch.IsEnabled = true;
                    }
                }
            }
            catch (WebException)
            {
                MainWindow.main.ShowRecivedCircularNotification(false);
            }
        }, DispatcherPriority.ContextIdle);
        }