コード例 #1
0
        public async void ChangeSetting(Settings settings)
        {
            _mainThread?.Abort();
            RefreshTime = settings.RefreshTime;
            Field       = settings.Field;
            Channel     = settings.Channel;
            ApiKey      = settings.Api_Key;
            Timezone    = settings.Timezone;

            if (settings.ChartSettings != null)
            {
                _dataCount = settings.ChartSettings.NumberOfData;
            }
            _data = (await GetDataAsync(Field)).Item1;


            ChannelName = GetChannelName();
            FieldName   = GetFieldName(Field);

            SetNameLabel?.Invoke(ChannelName, FieldName);
            if (_mainThread?.IsAlive == false)
            {
                Start();
            }
        }
コード例 #2
0
        private async void GetTemperatureAsync()
        {
            System.Net.HttpStatusCode status;
            (_data, status) = await GetDataAsync(Field, _dataCount);

            //(_data, status) = await getDataAsync(Field);

            if (status.Equals(System.Net.HttpStatusCode.OK))
            {
                ShowNoConnIcon?.Invoke(false);

                ChannelName = GetChannelName();
                FieldName   = GetFieldName(Field);
                SetNameLabel?.Invoke(ChannelName, FieldName);

                List <Data <dynamic> > dataList = new List <Data <dynamic> >();

                for (int i = 0; i < _data.Feeds.Count; i++)
                {
                    string value = TemperatureFromFieldAsync(_data, i);

                    if (value != null)
                    {
                        string[] dateTime = _data.Feeds[i].created_at.Split('T');
                        string[] time     = Regex.Split(dateTime[1], @"(?=[+-])");
                        DateTime date     = Convert.ToDateTime(dateTime[0] + " " + time[0]);

                        dataList.Add(new Data <dynamic>()
                        {
                            date = date, value = value
                        });
                    }
                }
                SetTemperatureLabel?.Invoke(dataList[dataList.Count - 1].value);
                SetUpdateDataLabel?.Invoke(dataList[dataList.Count - 1].date);
                SetData?.Invoke(dataList);
            }
            else if (status.Equals(System.Net.HttpStatusCode.ServiceUnavailable))
            {
                ShowNoConnIcon?.Invoke(true);
            }

            if (!status.Equals(System.Net.HttpStatusCode.OK) && _internetConnection)
            {
                _internetConnection = false;
                Stop();
                _tmpRefreshTime = RefreshTime;
                RefreshTime     = 1000;
                Start();
            }
            else if (status.Equals(System.Net.HttpStatusCode.OK) && !_internetConnection)
            {
                _internetConnection = true;
                Stop();
                RefreshTime = _tmpRefreshTime;
                Start();
            }

            GC.Collect(2, GCCollectionMode.Forced);
        }