コード例 #1
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);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ChrisVV3/MVP
 private void Reload()
 {
     SetData?.Invoke();
     dgvWebsites.DataSource = websites;
 }
コード例 #3
0
ファイル: FormEdit.cs プロジェクト: Pumpet/Robin
        /// <summary>Процесс сохранения данных из редактора</summary>
        protected bool SaveData()
        {
            error.Clear();

            // принудительно заносим из контролов в объект-источник
            foreach (var b in Source.CurrencyManager.Bindings)
            {
                (b as Binding).WriteValue();
            }

            var eaSaveParams = new ParamsCheckEventArgs {
                Pars = CtrlsProc.PrepareParams(SourceObject)
            };

            SaveParamsCheck?.Invoke(this, eaSaveParams);
            var errs = eaSaveParams.CheckResult;

            CheckData(eaSaveParams.Pars, errs);

            if (errs?.Count > 0)
            {
                var msg = new StringBuilder();
                foreach (var err in errs)
                {
                    var c = this.GetControl(err.Key, true, Source) ?? this.GetControl(err.Key);
                    if (c != null)
                    {
                        error.SetError(c, err.Value);
                    }
                    else
                    {
                        msg.AppendLine(err.Value);
                    }
                }
                if (msg.Length > 0)
                {
                    Loger.SendMess($"Ошибки ввода данных!\n{msg}", true);
                }
                return(false);
            }

            var eaSetData = new ProcessDataEventArgs()
            {
                Pars = eaSaveParams.Pars
            };

            SetData?.Invoke(this, eaSetData);

            object res = null;
            var    dt  = (eaSetData.Result as DataTable);

            if (dt != null)
            {
                res = dt.Rows.Count > 0 ? CtrlsProc.PrepareParams(dt.Rows[0]) : null;
            }
            else if (eaSetData.Result != null)
            {
                res = CtrlsProc.PrepareParams(eaSetData.Result);
            }

            Ctx.TransferObject = res;
            if (res == null)
            {
                Loger.SendMess("Не получен результат операции!", true);
            }

            var ok = (res != null);

            if (ok)
            {
                Changed  = false;
                WasSaved = true;
                Ctx.SaveLog("SAVE_FORM", $"Form {Name} ({Text}) was saved");
            }
            return(ok);
        }