private async void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            SetEnableState(false);

            ResultTextBox.Text = "";

            var variable = (KeyValuePair <string, string>)VariablesComboBox.SelectedItem;

            try
            {
                var variableValue = await particleDevice.GetVariableAsync(variable.Key);

                if (variableValue != null)
                {
                    ResultTextBox.Text = Convert.ToString(variableValue.Result);
                }
            }
            catch
            {
                ResourceLoader resourceLoader = new ResourceLoader();
                ErrorText.Text         = resourceLoader.GetString("Error");
                ErrorBorder.Visibility = Visibility.Visible;
            }

            SetEnableState(true);
        }
        public async Task <double> RequestCurrentLightLevelPercentage(DeviceConfiguration deviceConfig)
        {
            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleVariableResponse response = await device.GetVariableAsync(SPARKVARIABLE_LIGHTLEVEL);

            return(double.Parse(response.Result));
        }
        public async Task <double> RequestCurrentAirDewpoint(DeviceConfiguration deviceConfig)
        {
            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleVariableResponse response = await device.GetVariableAsync(SPARKVARIABLE_AIRDEWPOINT);

            return(double.Parse(response.Result));
        }
        public async Task <double> RequestCurrentAirHumidityPercentage(DeviceConfiguration deviceConfig)
        {
            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleVariableResponse response = await device.GetVariableAsync(SPARKVARIABLE_AIRHUMIDITY);

            return(double.Parse(response.Result));
        }
        public async Task <double> RequestCurrentTemperature(DeviceConfiguration deviceConfig)
        {
            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleVariableResponse response = await device.GetVariableAsync(SPARKVARIABLE_AIRTEMPERATURE);

            return(double.Parse(response.Result));
        }
        public async Task <double> RequestCurrentSoilMoisturePercentage(DeviceConfiguration deviceConfig, WateringLocation wateringLocation)
        {
            string variableName = wateringLocation == WateringLocation.First
                ? SPARKVARIABLE_ZONEONE_SOILHUMIDITY
                : SPARKVARIABLE_ZONETWO_SOILHUMIDITY;

            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleVariableResponse response = await device.GetVariableAsync(variableName);

            return(double.Parse(response.Result));
        }
        public async Task <SparkDeviceOperationState> RequestCurrentState(DeviceConfiguration deviceConfig)
        {
            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleVariableResponse currentStateResult = await device.GetVariableAsync(SPARKVARIABLE_CURRENTSTATE);

            try
            {
                SparkDeviceOperationState operationState = (SparkDeviceOperationState)int.Parse(currentStateResult.Result);
                return(operationState);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Enum value not supported for SparkDeviceOperationState");
            }
        }
        public async Task RefreshVariableValuesAsync()
        {
            if (!Device.Connected)
            {
                return;
            }

            Dictionary <string, string> updatedValues = new Dictionary <string, string>();

            foreach (var variable in Variables)
            {
                var currentValue = await _device.GetVariableAsync(variable.Key);

                System.Diagnostics.Debug.WriteLine(currentValue.Result.ToString());
                updatedValues.Add(variable.Key, currentValue.Result.ToString());
            }

            Variables = updatedValues;
        }
Esempio n. 9
0
        private async Task ChackHostNamesAndEndNotifier()
        {
            if (myDevice == null)
            {
                await LoginToCloudAndGetDevice();
            }

            if (deviceSuccessfullyInitiated)
            {
                ParticleVariableResponse variableResponse = await myDevice.GetVariableAsync("hostNames");

                if (variableResponse != null)
                {
                    string   hostNames     = variableResponse.Result;
                    string[] hostNamesList = hostNames.Split(',').Where(s => !string.IsNullOrWhiteSpace(s) && !s.Equals(Environment.UserName)).ToArray();
                    if (hostNamesList.Length > 0)
                    {
                        string       message      = string.Format("Please note that following nodes has also trigged the notifier,{0}{1}{2}Are you sure you want to turn this off?", Environment.NewLine, string.Join(",", hostNamesList), Environment.NewLine);
                        DialogResult dialogResult = MessageBox.Show(message, "Are you sure you want to turn this off", MessageBoxButtons.YesNo);

                        if (dialogResult == DialogResult.Yes)
                        {
                            await EndNotifier(true);
                        }
                        else
                        {
                            string funcRemoveCurrentUser = myDevice.Functions[2];
                            await myDevice.RunFunctionAsync(funcRemoveCurrentUser, Environment.UserName);
                        }
                    }
                    else
                    {
                        await EndNotifier();
                    }
                }
                else
                {
                    await EndNotifier();
                }
            }
        }