Esempio n. 1
0
        //public override void OnActivityCreated(Bundle savedInstanceState)
        //{
        //    base.OnActivityCreated(savedInstanceState);
        //    DoWork();
        //}

        private async void DoWork()
        {
            var pr = new Android.App.ProgressDialog(globalContext);

            pr.SetMessage("Loading data");
            pr.SetCancelable(false);
            pr.Show();

            var repository = new Respository();
            //var channel = await await Task.Factory.StartNew(async() =>await repository.ReadPsi());//repository.ReadPsi();
            //var channel = await await await Task.Factory.StartNew(() =>repository.ReadPsi().ContinueWith<Task<Channel>>(t=>t,TaskContinuationOptions.OnlyOnFaulted));
            await Task.Factory.StartNew(() => BigLongImportantMethodAsync());

            var channel      = _channelResult;
            var psiInfo      = PsiInformation.Parse(channel);
            var view         = globalView;
            var foundTextbox = view.FindViewById <TextView>(Resource.Id.textViewUpdateTime);

            foundTextbox.Text = psiInfo.DisplayUpdateTime;
            foundTextbox      = view.FindViewById <TextView>(Resource.Id.textView3hrPsi);
            foundTextbox.Text = psiInfo.Psi3Hour;
            foundTextbox      = view.FindViewById <TextView>(Resource.Id.textView24hrPsi);
            foundTextbox.Text = psiInfo.Psi24Hour;

            var root = view.FindViewById <LinearLayout>(Resource.Id.linearLayoutRoot);

            root.Visibility = ViewStates.Visible;

            pr.Hide();
        }
Esempio n. 2
0
        public static PsiInformation Parse(Channel info)
        {
            var result = new PsiInformation();

            if (info == null || info.Item == null || info.Item.Count < 1)
            {
                return(result);
            }
            DateTime updateTime;

            if (!DateTime.TryParseExact(info.Item[0].Record.Timestamp, PsiDatetimeFormat,
                                        System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out updateTime))
            {
                return(result);
            }
            var allRecords = (from item in info.Item from record in item.Record.PsiReadings select record);
            var psi3Hr     = allRecords.Where(x => x.Type == "NPSI_PM25_3HR").Sum(x => int.Parse(x.Value)) / RegionCount;
            var psi24Hr    = allRecords.Where(x => x.Type == "PM25_24HR").Sum(x => int.Parse(x.Value)) / RegionCount;

            result.LastUpdateTime    = updateTime;
            result.DisplayUpdateTime = updateTime.Hour.ToString("D2") + ":" + updateTime.Minute.ToString("D2");
            result.Psi3Hour          = psi3Hr.ToString();
            result.Psi24Hour         = psi24Hr.ToString();
            return(result);
        }