Пример #1
0
        public void XmlLoadFromStreamTest()
        {
            FileStream stream = new FileStream("PodAddress.xml", FileMode.Open);
            var        lists  = AddressBuilder.Load(stream);

            Assert.IsNotNull(lists);
        }
Пример #2
0
        public void XmlLoadTest()
        {
            var addressList = AddressBuilder.Load("PodAddress.xml");
            var urls        = AddressBuilder.GetEffectiveAddresses(addressList);

            foreach (var url in urls)
            {
                Console.WriteLine(url);
            }
        }
Пример #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var messageList = FindViewById <ListView>(Resource.Id.msgList);

            adapter             = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1);
            messageList.Adapter = adapter;
            var progressBar = FindViewById <ProgressBar>(Resource.Id.downloadProgressBar);

            progressBar.Max = 100;

            var datePicker = FindViewById <DatePicker>(Resource.Id.downloadDatePicker);
            var button     = FindViewById <Button>(Resource.Id.downloadButton);

            button.Click += async(object sender, EventArgs e) =>
            {
                var cm = GetSystemService(ConnectivityService) as ConnectivityManager;
                if (cm?.ActiveNetworkInfo.Type != ConnectivityType.Wifi)
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetMessage("Connect without wifi?");
                    builder.SetNegativeButton("Cancel", (obj, x) => { });
                    builder.SetPositiveButton("Ok", async(obj, which) =>
                    {
                        await StartBatchDownload();
                    });
                    builder.Show();
                }
                else
                {
                    await StartBatchDownload();
                }
            };

            Task StartBatchDownload()
            {
                return(Task.Run(() =>
                {
                    var savePath = GetSavePath();

                    AddressBuilder.Date = datePicker.DateTime;
                    var addrs = AddressBuilder.Load(Assets.Open("PodAddress.xml"));
                    var urls = AddressBuilder.GetEffectiveAddresses(addrs);

                    List <string> failedList = new List <string>();
                    failedList.AddRange(BatchDownloader.DownloadFromUrls(savePath, urls, DownloadProgressHandler));

                    RunOnUiThread(() =>
                    {
                        failedList
                        .Select(msg => "failed url: " + msg)
                        .ToList()
                        .ForEach(msg =>
                        {
                            Log.Info(typeof(MainActivity).ToString(), msg);
                            adapter.Add(msg);
                        });
                        adapter.Add("Download complete");
                        adapter.NotifyDataSetChanged();
                        Toast.MakeText(this, "Download complete", ToastLength.Long).Show();
                    });
                }));
            }

            void DownloadProgressHandler(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar.SetProgress(e.ProgressPercentage, true);
            }
        }