Esempio n. 1
0
        void marketplace_XmlDocChanged(object sender, EventArgs a)
        {
            contentview.SuppressSelectionChanged();
            _content.RaiseListChangedEvents = false;
            _batchhandler.Abort();
            //while (!batchhandler.WorkDone) Task.Delay(10);
            _content.Clear();
            var xdoc = _helper.XmlDoc;

            if (xdoc != null)
            {
                var entries = xdoc.Descendants(Constants.NetworkConnectivity.Namespaces.Atom + "entry");
                foreach (var entry in entries)
                {
                    MarketPlaceContent tempContent = new MarketPlaceContent(entry, (Language)querylanguage_sel.SelectedItem);
                    tempContent.Load();
                    _content.Add(tempContent);
                }
                numitems_sync_label.Text = xdoc.Descendants(Constants.NetworkConnectivity.Namespaces.Live + "totalItems").First().Value;
                cat_sync_label.Text      = _helper.MediaTypes.Name;
                int numItems;
                if (Int32.TryParse(numitems_sync_label.Text, out numItems))
                {
                    int max = (int)Math.Ceiling(numItems / entrys_num.Value);
                    if (max < page_num.Value)
                    {
                        page_num.Value = max;
                    }
                    page_num.Maximum = max;
                    Constants.BindingLists.Categorys[Constants.BindingLists.Categorys.IndexOf((MediaId)cat_select.SelectedItem)].TotalCount = numItems;
                }
            }
            _content.RaiseListChangedEvents = true;
            _content.ResetBindings();
            _batchhandler.StartUrlCheck(false);
            contentview.ResumeSelectionChanged();
        }
Esempio n. 2
0
        private void StartBatchUrlCheck(ThreadedBindingList <MarketPlaceContent> boundList, SynchronizationContext threadToInvoke, DoWorkEventArgs e, BackgroundWorker worker)
        {
            int progressbarMax = 100;

            bgw.ReportProgress(0);
            if (NetworkDelay == 0)
            {
                bgw.ReportProgress(progressbarMax);
                return;
            }
            try
            {
                List <MarketPlaceContent> workingContent = boundList.ToList();

                foreach (MarketPlaceContent oneContent in workingContent)
                {                               //e.argument is ForceRecheck true/false
                    int     DelayModifier = 40; //todo Math Over here, Fill progress bar with correct value
                    int     Delay         = 1000 / DelayModifier;
                    decimal InnerCount;
                    decimal OuterCount      = workingContent.IndexOf(oneContent) + 1;
                    int     InnerTotal      = DelayModifier * Delay * NetworkDelay;
                    int     OuterTotal      = workingContent.Count;
                    int     ProgressPercent = (int)Math.Ceiling(OuterCount / OuterTotal * progressbarMax);



                    if (worker.CancellationPending && !(bool)e.Argument)
                    {
                        break;
                    }
                    if (!oneContent.DownloadChecked || (bool)e.Argument)
                    {
                        oneContent.CheckDownloadUrl(worker.CancellationPending, (bool)e.Argument);
                    }
                    else
                    {
                        bgw.ReportProgress(ProgressPercent);
                        continue;
                    }
                    var elementAtOrDefault = boundList.ElementAtOrDefault(workingContent.IndexOf(oneContent));
                    if (elementAtOrDefault != null && elementAtOrDefault.TitleId == oneContent.TitleId)
                    {
                        //boundList.RaiseListChangedEvents = false;
                        boundList[workingContent.IndexOf(oneContent)] = oneContent;
                        //boundList.RaiseListChangedEvents = true;
                        //threadToInvoke.Post(delegate { boundList.ResetItem(boundList.IndexOf(oneContent)); }, null);
                    }
                    bgw.ReportProgress(ProgressPercent);
                    //networkdelay * 10 * sleep = TotalDelay
                    if (oneContent.DownloadChecked || (bool)e.Argument)
                    {
                        if (!(workingContent.IndexOf(oneContent) >= workingContent.Count)) //Skip the Delay
                        {
                            //NetworkDelay is Delay as Int Value in Seconds
                            for (int i = 0; i < NetworkDelay * DelayModifier; i++)
                            {
                                InnerCount = Delay * i;

                                ProgressPercent = (int)Math.Ceiling((InnerCount + OuterCount * InnerTotal) / (InnerTotal * (OuterTotal + 1)) * progressbarMax);


                                bgw.ReportProgress(ProgressPercent);
                                if (worker.CancellationPending)
                                {
                                    break;
                                }
                                Thread.Sleep(Delay);
                            }
                            if (worker.CancellationPending)
                            {
                                break;
                            }
                        }
                        else
                        {
                            ProgressPercent = (int)Math.Ceiling((OuterCount + 1 / OuterTotal) * progressbarMax);
                        }
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                boundList.ResetBindings();
                //Do Nothing Here, This Exception Is Intentional
                //And is Caused by allcontent being changed from user switching the page they are viewing
                Console.WriteLine(e.ToString());
                throw;
            }
        }