Ejemplo n.º 1
0
        private void UploadData(object sender, RoutedEventArgs e)
        {
            List <UploadData> rdList = new List <UploadData>();
            UploadData        raw    = new UploadData();

            if (string.IsNullOrEmpty(timestamp.Text))
            {
                timestamp.Text = DateTime.UtcNow.ToString();
            }
            raw.Timestamp = DateTime.Parse(timestamp.Text);
            raw.HID       = hwID.Text;
            if (string.IsNullOrEmpty(uploadData.Text))
            {
                raw.Data = string.Empty;
                var devConfig = (from z in gatewayConfig.devices where z.HID == hwID.Text select z).FirstOrDefault();
                if (devConfig == null)
                {
                    AddMessage(string.Format("DeviceConfig not found for {0}", hwID.Text));
                    return;
                }
                for (int i = 0; i < devConfig.Registers.Count(); i++)
                {
                    RegInfo ri = devConfig.Registers[i];
                    string  val;
                    switch (ri.DataType)
                    {
                    case RawDataType.Int:
                        val = string.Format("{0}", ri.RegNum);
                        break;

                    default:
                        val = string.Format("{0:0.00}", ri.RegNum / 100.0);
                        break;
                    }
                    raw.Data += (i == 0) ? val : ("," + val);
                }
                uploadData.Text = raw.Data;
            }
            else
            {
                raw.Data = uploadData.Text;
            }
            rdList.Add(raw);
            UploadResult result = api.UploadRawData(login.SessionID, rdList);

            if ((AEResultCodes)result.Code == AEResultCodes.OK)
            {
                AddMessage(string.Format("*** Uploaded {0} rows", result.UploadCount));
            }
            else
            {
                AddMessage(string.Format("*** UploadData returned {0}", result.ResultCodeString()));
            }

            Registry.CurrentUser.SetValue(RegGateway, gatewayID.Text);
            Registry.CurrentUser.SetValue(RegUploadData, uploadData.Text);
        }