Exemplo n.º 1
0
        private Faturalar getFatura(string numara, string htmlDoc)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(htmlDoc);
            var    node      = doc.GetElementbyId("Table3");
            string sonucText = "";
            var    nodes     = doc.DocumentNode.SelectNodes("//input");

            if (nodes != null)
            {
                foreach (var item in nodes)
                {
                    if (item.OuterHtml.Contains("checkbox"))
                    {
                        sonucText = item.OuterHtml.ToString();
                    }
                }
            }
            string[] sonuc = sonucText.Split('@');
            if (sonuc.Length >= 10)
            {
                string    isim = sonuc[10]; string faturaDonemi = sonuc[2]; string fiyat = sonuc[1];
                Faturalar fatura = new Faturalar(numara, isim, faturaDonemi, fiyat);
                return(fatura);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private async Task <List <Faturalar> > getTelFatura()
        {
            object state = new object();

            telFaturaListe = new List <Faturalar>();
            List <Task> taskList = new List <Task>();

            sourceTel = new CancellationTokenSource();
            tokenTel  = new CancellationToken();
            tokenTel  = sourceTel.Token;
            string[] numaralar = txtTelefon.Text.Split('\n');

            if (txtTelefon.Text.Length > 9)
            {
                telStatus = TelTaskStatus.Running;
            }

            float progress = (float)100 / (float)numaralar.Length;
            Dictionary <string, string> keyList = objCrm.getHesapNo();

            if (keyList.Count < 15)
            {
                MessageBox.Show("Oturumunuz kapatılmıştır lütfen oturum açınız");
                return(null);
            }
            int i = 0;

            foreach (var numara in numaralar)
            {
                //if (numara == "")
                //    continue;
                Sorgula objSorgula = new Sorgula();
                //objSorgula.Container = objCrm.Container;
                objSorgula.Container = objCrm.Container;
                objSorgula.List      = keyList;
                var sonTask = Task.Run(() => objSorgula.telefonFatura(numara, tokenTel), tokenTel).ContinueWith(async(t) => {
                    string telNo = numara;
                    await t;
                    i++;
                    progressBar1.Value = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(progress * i)));

                    lock (state)
                    {
                        Faturalar telFatura = t.Result;
                        if (telFatura != null)
                        {
                            telFaturaListe.Add(telFatura);
                            dtTel.Rows.Add(new[] { telFatura.AboneNo, telFatura.Isim, telFatura.FaturaDonemi, telFatura.Fiyat });
                        }
                        else
                        {
                            Faturalar bosTelFatura = new Faturalar(telNo, "---", "---", "---");
                            // telFaturaListe.Add(bosTelFatura);
                            dtTel.Rows.Add(new[] { bosTelFatura.AboneNo, bosTelFatura.Isim, bosTelFatura.FaturaDonemi, bosTelFatura.Fiyat });
                        }
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext()
                                                                                                                );
                taskList.Add(sonTask);

                if (taskList.Count % 50 == 0)
                {
                    await Task.WhenAll(taskList);
                }
            }
            await Task.WhenAll(taskList);

            if (progressBar1.Value == 100)
            {
                MessageBox.Show("Sorgulama tamamlandı", "Padok", MessageBoxButtons.OK, MessageBoxIcon.Information);
                telStatus = TelTaskStatus.Completed;
            }
            else if (tokenTel.IsCancellationRequested)
            {
                telStatus = TelTaskStatus.Cancelled;
                MessageBox.Show("İptal edildi.", "Padok", MessageBoxButtons.OK, MessageBoxIcon.Information);
                progressBar1.Value = 0;
            }
            else
            {
                telStatus = TelTaskStatus.Waiting;
            }
            return(telFaturaListe);
        }
Exemplo n.º 3
0
        private async Task <List <Faturalar> > getAdslFatura()
        {
            object state = new object();

            adslStatus      = AdslTaskStatus.Running;
            adslFaturaListe = new List <Faturalar>();
            List <Task> taskList = new List <Task>();

            sourceAdsl = new CancellationTokenSource();
            tokenAdsl  = new CancellationToken();
            tokenAdsl  = sourceAdsl.Token;
            string[] numaralar = txtAdsl.Text.Split('\n');
            float    progress  = (float)100 / (float)numaralar.Length;
            Dictionary <string, string> keyList = objCrm.getHesapNo();
            int i = 0;

            foreach (var numara in numaralar)
            {
                //if (numara == "")
                //    continue;
                //Her sorgulama için ayrı obje
                Sorgula objSorgula = new Sorgula();
                //daha önceki cookieler yeni objeye aktarılıyor
                objSorgula.Container = objCrm.Container;
                objSorgula.List      = keyList;
                var sonTask = Task.Run(() => objSorgula.adslFatura(numara, tokenAdsl), tokenAdsl).ContinueWith(async(t) =>
                {
                    string adslNo = numara;

                    await t;
                    lock (state)
                    {
                        i++;
                        prgAdsl.Value        = Convert.ToInt32(progress * i);
                        Faturalar adslFatura = t.Result;
                        if (adslFatura != null)
                        {
                            // Task.Factory.StartNew(() => printToScreenAdsl(adslFatura.ToString() + "\n"), tokenAdsl, TaskCreationOptions.AttachedToParent, TaskScheduler.FromCurrentSynchronizationContext());
                            adslFaturaListe.Add(adslFatura);
                            dtAdsl.Rows.Add(new[] { adslFatura.AboneNo, adslFatura.Isim, adslFatura.FaturaDonemi, adslFatura.Fiyat });
                        }
                        else
                        {
                            Faturalar bosAdslFatura = new Faturalar(adslNo, "---", "---", "---");
                            //textbox'a ekler
                            //  Task.Factory.StartNew(() => printToScreenAdsl(bosAdslFatura.ToString()), tokenAdsl, TaskCreationOptions.AttachedToParent, TaskScheduler.FromCurrentSynchronizationContext());
                            //listeye ekler
                            adslFaturaListe.Add(bosAdslFatura);
                            //data table a ekler
                            dtAdsl.Rows.Add(new[] { bosAdslFatura.AboneNo, bosAdslFatura.Isim, bosAdslFatura.FaturaDonemi, bosAdslFatura.Fiyat });
                        }
                    }
                },
                                                                                                               TaskScheduler.FromCurrentSynchronizationContext());

                taskList.Add(sonTask);
                if (taskList.Count % 50 == 0)
                {
                    await Task.WhenAll(taskList);
                }
            }
            //sorgulama bitti yada iptal edildi
            await Task.WhenAll(taskList);

            if (prgAdsl.Value == 100)
            {
                MessageBox.Show("Sorgulama tamamlandı", "Padok", MessageBoxButtons.OK, MessageBoxIcon.Information);
                adslStatus = AdslTaskStatus.Completed;
            }
            //iptal edilmiş sorgu
            else if (tokenAdsl.IsCancellationRequested)
            {
                adslStatus = AdslTaskStatus.Cancelled;
                MessageBox.Show("İptal edildi.", "Padok", MessageBoxButtons.OK, MessageBoxIcon.Information);
                prgAdsl.Value = 0;
            }
            //ne bitti nede iptal edildi
            else
            {
                adslStatus = AdslTaskStatus.Waiting;
            }
            return(adslFaturaListe);
        }