Esempio n. 1
0
        private async void ChangeSettings()
        {
            if (isInitialized)
            {
                lastModify = DateTime.Now;
                await Task.Delay(1000);

                if (DateTime.Now - lastModify > new TimeSpan(0, 0, 1))
                {
                    IsLoading      = true;
                    LoadingMessage = "Sending air con settings...";

                    var settings = Appliance.settings;
                    settings.temp = CurrentDegree;
                    settings.mode = CurrentMode;
                    settings.dir  = CurrentDirection;
                    settings.vol  = CurrentVolume;
                    try
                    {
                        var client = new NatureRemoClient(Appliance.Token);
                        Appliance.settings = await client.PostAirConSettings(Appliance.id, settings);
                    }
                    catch (Exception ex)
                    {
                        Debugger.WriteErrorLog("Error occured while " + LoadingMessage, ex);
                        await new MessageDialog(ex.Message, "Error occured while " + LoadingMessage).ShowAsync();
                    }

                    IsLoading = false;
                }
            }
        }
Esempio n. 2
0
        public async void PowerButton_Toggled(object sender, RoutedEventArgs e)
        {
            Appliance.settings.button = Appliance.settings.button.Replace("power-on", "");
            var currentState = ((ToggleSwitch)sender).IsOn ? "" : "power-off";

            if (currentState != Appliance.settings.button)
            {
                IsLoading      = true;
                LoadingMessage = "Switching " + Appliance.nickname + "...";
                try
                {
                    ((ToggleSwitch)sender).IsEnabled = false;
                    var client         = new NatureRemoClient(Appliance.Token);
                    var button         = Appliance.settings.button == "" ? "power-off" : "";
                    var settingsString = await client.PostButton(Appliance.id, "aircon_settings", button);

                    Appliance.settings = JsonSerializer.Deserialize <Models.NatureRemo.Settings>(settingsString);
                    ((ToggleSwitch)sender).IsEnabled = true;
                }
                catch (Exception ex)
                {
                    Debugger.WriteErrorLog("Error occured while " + LoadingMessage, ex);
                    await new MessageDialog(ex.Message, "Error occured while " + LoadingMessage).ShowAsync();
                }
                finally
                {
                    ((ToggleSwitch)sender).IsEnabled = true;
                }
                IsLoading = false;
            }
        }
Esempio n. 3
0
        public async void OKButton_Click(object sender, RoutedEventArgs e)
        {
            IsLoading      = true;
            LoadingMessage = "Verifying token...";

            var client = new NatureRemoClient(new NatureRemoToken(TokenString));
            var user   = await client.GetUserDataAsync();

            AccountManager.SaveUserToVault(user);
            AppGlobalVariables.Users.Add(user);
            Debugger.WriteDebugLog("Successfully verified Remo token.");

            dialogHost.Hide();
        }
Esempio n. 4
0
        private async Task <List <Device> > GetRemoDevices(Models.Auth.UserBase user)
        {
            var devices = new List <Device>();

            try
            {
                var remoClient = new NatureRemoClient(user.Token);
                devices.AddRange(await remoClient.GetDevicesAsync());
            }
            catch (Exception ex)
            {
                Debugger.WriteErrorLog("Error occured while retrieving Nature Remo status. User="******". User="******".", "Error occured while retrieving Nature Remo status.").ShowAsync();
            }

            return(devices);
        }
        public async void PowerButton_Click(object sender, RoutedEventArgs e)
        {
            IsLoading      = true;
            LoadingMessage = "Sending tv signal...";

            try
            {
                var client = new NatureRemoClient(Appliance.Token);
                await client.PostTvButton(Appliance.id, "power");
            }
            catch (Exception ex)
            {
                Debugger.WriteErrorLog("Error occured while " + LoadingMessage, ex);
                await new MessageDialog(ex.Message, "Error occured while " + LoadingMessage).ShowAsync();
            }

            IsLoading = false;
        }
        public async void Button_Click(object sender, RoutedEventArgs e)
        {
            LoadingMessage = "Sending signal...";
            IsLoading      = true;
            var button = (FrameworkElement)sender;
            var signal = (Signal)button.DataContext;

            try
            {
                var client = new NatureRemoClient(Appliance.Token);
                await client.PostSignal(signal.id);
            }
            catch (Exception ex)
            {
                Debugger.WriteErrorLog("Error occured while " + LoadingMessage, ex);
                await new MessageDialog(ex.Message, "Error occured while " + LoadingMessage).ShowAsync();
            }

            IsLoading = false;
        }
        public static async Task <UserBase> AcquireUserFromToken(TokenBase token)
        {
            try
            {
                switch (token.UserType)
                {
                case UserType.Google:
                    var googleClient = new GoogleClient(token);
                    return(await googleClient.GetUserDataAsync());

                case UserType.Microsoft:
                    var msClient = new MicrosoftClient(token);
                    return(await msClient.GetUserDataAsync());

                case UserType.NatureRemo:
                    var remoClient = new NatureRemoClient(token);
                    return(await remoClient.GetUserDataAsync());

                case UserType.Hue:
                    return(await HueAuthClient.FindHueBridge(token));

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Debugger.WriteErrorLog("Exception occured on acquiring user info. Type=" + token.UserType.ToString(), ex);
                //var message = new MessageDialog("Type=" + token.UserType.ToString() + " Exception=" + ex.Message, "Exception occured on acquiring user info.");
                //await message.ShowAsync();
                var user = new UserBase();
                user.Token             = token;
                user.UserType          = token.UserType;
                user.UserName          = "******";
                user.ProfilePictureUrl = "/Assets/Square150x150Logo.scale-200.png";
                user.Id = token.Id;

                return(user);
            }
            return(null);
        }