예제 #1
0
        public MainWindow(IGraphService graphService, IHueService hueService, IOptionsMonitor <ConfigWrapper> optionsAccessor)
        {
            _options = optionsAccessor.CurrentValue;


            InitializeComponent();

            if (string.IsNullOrEmpty(_options.ApplicationId) || string.IsNullOrEmpty(_options.TenantId) || string.IsNullOrEmpty(_options.RedirectUri))
            {
                configErrorPanel.Visibility = Visibility.Visible;
                dataPanel.Visibility        = Visibility.Hidden;
                signInPanel.Visibility      = Visibility.Hidden;
            }
            else
            {
                _graphservice       = graphService;
                _graphServiceClient = _graphservice.GetAuthenticatedGraphClient(typeof(WPFAuthorizationProvider));
            }

            if (_options.IconType == "Transparent")
            {
                Transparent.IsChecked = true;
            }
            else
            {
                White.IsChecked = true;
            }


            _hueService = hueService;

            notificationIcon.ToolTipText = PresenceConstants.Inactive;
            notificationIcon.IconSource  = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));
        }
예제 #2
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            lightMode = "Graph";
            var accounts = await WPFAuthorizationProvider.Application.GetAccountsAsync().ConfigureAwait(true);

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider.Application.RemoveAsync(accounts.FirstOrDefault()).ConfigureAwait(true);

                    this.signInPanel.Visibility = Visibility.Visible;
                    dataPanel.Visibility        = Visibility.Collapsed;

                    notificationIcon.Text = PresenceConstants.Inactive;
                    notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));

                    if (Config.LightSettings.Hue.IsPhillipsHueEnabled && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId))
                    {
                        await _hueService.SetColor("Off", Config.LightSettings.Hue.SelectedHueLightId).ConfigureAwait(true);
                    }

                    if (lightMode == "Graph")
                    {
                        await SetColor("Off").ConfigureAwait(true);
                    }
                }
                catch (MsalException)
                {
                }
            }
            await _settingsService.SaveSettings(Config).ConfigureAwait(true);
        }
예제 #3
0
        private async Task SignOut()
        {
            _logger.LogInformation("Signing out of Graph PresenceLight Sync");

            _appState.SetLightMode("Graph");
            var accounts = await WPFAuthorizationProvider.Application.GetAccountsAsync().ConfigureAwait(true);

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider.Application.RemoveAsync(accounts.FirstOrDefault()).ConfigureAwait(true);

                    _appState.SignedIn = false;
                    _appState.SetUserInfo(null, null, null);
                    notificationIcon.Text = $"PresenceLight Status - {PresenceConstants.Inactive}";
                    notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, string.Empty)));

                    await SetColor("Off").ConfigureAwait(true);
                }
                catch (MsalException)
                {
                }
            }
            await _settingsService.SaveSettings(_appState.Config).ConfigureAwait(true);
        }
예제 #4
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            var accounts = await WPFAuthorizationProvider._application.GetAccountsAsync();

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider._application.RemoveAsync(accounts.FirstOrDefault());

                    this.signInPanel.Visibility = Visibility.Visible;
                    dataPanel.Visibility        = Visibility.Collapsed;
                    stopPolling = true;

                    notificationIcon.ToolTipText = PresenceConstants.Inactive;
                    notificationIcon.IconSource  = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));
                    hueIpAddress.IsEnabled       = true;
                    clientId.IsEnabled           = true;
                    tenantId.IsEnabled           = true;
                }
                catch (MsalException)
                {
                }
            }
        }
예제 #5
0
        private async void OnTurnOffSyncClick(object sender, RoutedEventArgs e)
        {
            try
            {
                lightMode = "Custom";

                if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId))
                {
                    await _hueService.SetColor("Off", Config.LightSettings.Hue.SelectedHueLightId).ConfigureAwait(true);
                }

                if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey))
                {
                    await _lifxService.SetColor("Off", (Selector)Config.LightSettings.LIFX.SelectedLIFXItemId).ConfigureAwait(true);
                }

                turnOffButton.Visibility = Visibility.Collapsed;
                turnOnButton.Visibility  = Visibility.Visible;

                notificationIcon.Text = PresenceConstants.Inactive;
                notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));

                this.WindowState = this.lastWindowState;
            }
            catch (Exception ex)
            {
                _diagClient.TrackException(ex);
            }
        }
예제 #6
0
        private void LoadApp()
        {
            try
            {
                CheckHue(true);
                CheckLIFX();
                CheckYeelight();
                CheckWiz();
                CheckAAD();

                previousRemoteFlag = Config.LightSettings.Hue.UseRemoteApi;

                if (Config.IconType == "Transparent")
                {
                    settings.Transparent.IsChecked = true;
                }
                else
                {
                    settings.White.IsChecked = true;
                }

                switch (Config.LightSettings.HoursPassedStatus)
                {
                case "Keep":
                    settings.HourStatusKeep.IsChecked = true;
                    break;

                case "White":
                    settings.HourStatusWhite.IsChecked = true;
                    break;

                case "Off":
                    settings.HourStatusOff.IsChecked = true;
                    break;

                default:
                    settings.HourStatusKeep.IsChecked = true;
                    break;
                }

                PopulateWorkingDays();

                landingPage.notificationIcon.Text = PresenceConstants.Inactive;
                landingPage.notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));

                landingPage.turnOffButton.Visibility = Visibility.Collapsed;
                landingPage.turnOnButton.Visibility  = Visibility.Collapsed;

                Config.LightSettings.WorkingHoursStartTimeAsDate = string.IsNullOrEmpty(Config.LightSettings.WorkingHoursStartTime) ? null : DateTime.Parse(Config.LightSettings.WorkingHoursStartTime, null);
                Config.LightSettings.WorkingHoursEndTimeAsDate   = string.IsNullOrEmpty(Config.LightSettings.WorkingHoursEndTime) ? null : DateTime.Parse(Config.LightSettings.WorkingHoursEndTime, null);


                CallGraph().ConfigureAwait(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occured - {e.Message}");
                _diagClient.TrackException(e);
            }
        }
예제 #7
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            _logger.LogInformation("Signing out of Graph PresenceLight Sync");

            lightMode = "Graph";
            var accounts = await WPFAuthorizationProvider.Application.GetAccountsAsync().ConfigureAwait(true);

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider.Application.RemoveAsync(accounts.FirstOrDefault()).ConfigureAwait(true);

                    landingPage.signInPanel.Visibility = Visibility.Visible;
                    landingPage.dataPanel.Visibility   = Visibility.Collapsed;

                    landingPage.notificationIcon.Text = PresenceConstants.Inactive;
                    landingPage.notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));


                    await SetColor("Off").ConfigureAwait(true);
                }
                catch (MsalException)
                {
                }
            }
            await _settingsService.SaveSettings(Config).ConfigureAwait(true);
        }
예제 #8
0
        private void LoadApp()
        {
            CheckHue();
            CheckLIFX();
            CheckYeelight();
            CheckAAD();

            if (Config.IconType == "Transparent")
            {
                Transparent.IsChecked = true;
            }
            else
            {
                White.IsChecked = true;
            }

            PopulateWorkingDays();

            notificationIcon.Text = PresenceConstants.Inactive;
            notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));

            turnOffButton.Visibility = Visibility.Collapsed;
            turnOnButton.Visibility  = Visibility.Collapsed;

            CallGraph();
        }
예제 #9
0
        private async void CallGraphButton_Click(object sender, RoutedEventArgs e)
        {
            var(profile, presence) = await System.Threading.Tasks.Task.Run(() => GetBatchContent());

            var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto());

            MapUI(presence, profile, LoadImage(photo));
            //await _hueService.SetColor(presence.Availability);
            this.signInPanel.Visibility = Visibility.Collapsed;
            dataPanel.Visibility        = Visibility.Visible;
            while (true)
            {
                if (stopPolling)
                {
                    stopPolling = false;
                    notificationIcon.ToolTipText = PresenceConstants.Inactive;
                    notificationIcon.IconSource  = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));
                    return;
                }
                await Task.Delay(5000);

                try
                {
                    presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                    //await _hueService.SetColor(presence.Availability);
                    MapUI(presence, null, null);
                }
                catch { }
            }
        }
예제 #10
0
        private void LoadApp()
        {
            CheckHue();
            CheckLIFX();
            CheckYeelight();
            CheckAAD();

            if (Config.IconType == "Transparent")
            {
                Transparent.IsChecked = true;
            }
            else
            {
                White.IsChecked = true;
            }

            switch (Config.LightSettings.HoursPassedStatus)
            {
            case "Keep":
                HourStatusKeep.IsChecked = true;
                break;

            case "White":
                HourStatusWhite.IsChecked = true;
                break;

            case "Off":
                HourStatusOff.IsChecked = true;
                break;

            default:
                HourStatusKeep.IsChecked = true;
                break;
            }

            PopulateWorkingDays();

            notificationIcon.Text = PresenceConstants.Inactive;
            notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));

            turnOffButton.Visibility = Visibility.Collapsed;
            turnOnButton.Visibility  = Visibility.Collapsed;

            Config.LightSettings.WorkingHoursStartTimeAsDate = string.IsNullOrEmpty(Config.LightSettings.WorkingHoursStartTime) ? null : DateTime.Parse(Config.LightSettings.WorkingHoursStartTime, null);
            Config.LightSettings.WorkingHoursEndTimeAsDate   = string.IsNullOrEmpty(Config.LightSettings.WorkingHoursEndTime) ? null : DateTime.Parse(Config.LightSettings.WorkingHoursEndTime, null);

            CallGraph().ConfigureAwait(true);
        }
예제 #11
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            lightMode = "Graph";
            var accounts = await WPFAuthorizationProvider.Application.GetAccountsAsync();

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider.Application.RemoveAsync(accounts.FirstOrDefault());

                    this.signInPanel.Visibility = Visibility.Visible;
                    dataPanel.Visibility        = Visibility.Collapsed;

                    notificationIcon.Text  = PresenceConstants.Inactive;
                    notificationIcon.Icon  = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));
                    hueIpAddress.IsEnabled = true;

                    if (Config.IsPhillipsEnabled && !string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
                    {
                        await _hueService.SetColor("Off", Config.SelectedHueLightId);
                    }

                    //if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
                    //{
                    //    if (ddlLIFXLights.SelectedItem != null && ddlLIFXLights.SelectedItem.GetType() == typeof(LifxCloud.NET.Models.Group))
                    //    {
                    //        Config.SelectedLIFXItemId = $"group_id:{((LifxCloud.NET.Models.Group)ddlLIFXLights.SelectedItem).Id}";
                    //    }

                    //    if (ddlLIFXLights.SelectedItem != null && ddlLIFXLights.SelectedItem.GetType() == typeof(LifxCloud.NET.Models.Light))
                    //    {
                    //        Config.SelectedLIFXItemId = $"id:{((LifxCloud.NET.Models.Light)ddlLIFXLights.SelectedItem).Id}";
                    //    }

                    //    await _lifxService.SetColor("Off", (Selector)Config.SelectedLIFXItemId);
                    //}
                    if (lightMode == "Graph")
                    {
                        await SetColor("Off");
                    }
                }
                catch (MsalException)
                {
                }
            }
            await SettingsService.SaveSettings(Config);
        }
예제 #12
0
        private void LoadApp()
        {
            CheckHueSettings();

            if (Config.IconType == "Transparent")
            {
                Transparent.IsChecked = true;
            }
            else
            {
                White.IsChecked = true;
            }

            notificationIcon.ToolTipText = PresenceConstants.Inactive;
            notificationIcon.IconSource  = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));
        }
예제 #13
0
        private void LoadApp()
        {
            try
            {
                notificationIcon.Text = $"PresenceLight Status - {PresenceConstants.Inactive}";
                notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, string.Empty)));

                _appState.Config.LightSettings.WorkingHoursStartTimeAsDate = string.IsNullOrEmpty(_appState.Config.LightSettings.WorkingHoursStartTime) ? null : DateTime.Parse(_appState.Config.LightSettings.WorkingHoursStartTime, null);
                _appState.Config.LightSettings.WorkingHoursEndTimeAsDate   = string.IsNullOrEmpty(_appState.Config.LightSettings.WorkingHoursEndTime) ? null : DateTime.Parse(_appState.Config.LightSettings.WorkingHoursEndTime, null);

                CallGraph().ConfigureAwait(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occured - {e.Message}");
            }
        }
예제 #14
0
 public void MapUI(Presence presence)
 {
     try
     {
         SolidColorBrush mySolidColorBrush = new SolidColorBrush();
         if (presence != null)
         {
             notificationIcon.Text = $"PresenceLight Status - {Helpers.HumanifyText(presence.Availability)}";
             notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(_appState.Config.IconType, presence.Availability)));
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Error Occurred Mapping UI");
         throw;
     }
 }
예제 #15
0
        private async void CallGraphButton_Click(object sender, RoutedEventArgs e)
        {
            signInPanel.Visibility  = Visibility.Collapsed;
            loadingPanel.Visibility = Visibility.Visible;
            var(profile, presence)  = await System.Threading.Tasks.Task.Run(() => GetBatchContent());

            var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto());

            MapUI(presence, profile, LoadImage(photo));

            if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && ((Light)ddlLights.SelectedItem) != null)
            {
                await _hueService.SetColor(presence.Availability, ((Light)ddlLights.SelectedItem).Id);
            }

            loadingPanel.Visibility     = Visibility.Collapsed;
            this.signInPanel.Visibility = Visibility.Collapsed;
            hueIpAddress.IsEnabled      = false;
            clientId.IsEnabled          = false;
            tenantId.IsEnabled          = false;
            dataPanel.Visibility        = Visibility.Visible;
            while (true)
            {
                if (stopPolling)
                {
                    stopPolling = false;
                    notificationIcon.ToolTipText = PresenceConstants.Inactive;
                    notificationIcon.IconSource  = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));
                    return;
                }
                await Task.Delay(5000);

                try
                {
                    presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                    if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && ddlLights.SelectedItem != null)
                    {
                        await _hueService.SetColor(presence.Availability, ((Light)ddlLights.SelectedItem).Id);
                    }
                    MapUI(presence, null, null);
                }
                catch { }
            }
        }
예제 #16
0
        private async void OnTurnOffSyncClick(object sender, RoutedEventArgs e)
        {
            try
            {
                _appState.SetLightMode("Custom");
                await SetColor("Off", "Off");

                notificationIcon.Text = PresenceConstants.Inactive;
                notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, string.Empty)));

                this.WindowState = this.lastWindowState;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error Occured turning Off Sync");
            }
            _logger.LogInformation("Turning Off PresenceLight Sync");
        }
예제 #17
0
        private void LoadApp()
        {
            CheckHueSettings();
            CheckLIFXSettings();
            CheckYeelightSettings();
            CheckAAD();

            if (Config.IconType == "Transparent")
            {
                Transparent.IsChecked = true;
            }
            else
            {
                White.IsChecked = true;
            }

            notificationIcon.Text = PresenceConstants.Inactive;
            notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));

            CallGraph();
        }
예제 #18
0
        private async void OnTurnOffSyncClick(object sender, RoutedEventArgs e)
        {
            try
            {
                lightMode = "Custom";

                await SetColor("Off", "Off");

                landingPage.turnOffButton.Visibility = Visibility.Collapsed;
                landingPage.turnOnButton.Visibility  = Visibility.Visible;

                landingPage.notificationIcon.Text = PresenceConstants.Inactive;
                landingPage.notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));

                this.WindowState = this.lastWindowState;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error Occured turning Off Sync");
            }
            _logger.LogInformation("Turning Off PresenceLight Sync");
        }
예제 #19
0
        public void MapUI(Presence presence, User?profile, BitmapImage?profileImageBit)
        {
            try
            {
                SolidColorBrush            mySolidColorBrush = new SolidColorBrush();
                System.Windows.Media.Color color;
                BitmapImage image;
                switch (presence.Availability)
                {
                case "Available":
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(Config.IconType, IconConstants.Available)));
                    color = MapColor("#009933");
                    landingPage.notificationIcon.Text = PresenceConstants.Available;
                    break;

                case "Busy":
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(Config.IconType, IconConstants.Busy)));
                    color = MapColor("#ff3300");
                    landingPage.notificationIcon.Text = PresenceConstants.Busy;
                    break;

                case "BeRightBack":
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(Config.IconType, IconConstants.BeRightBack)));
                    color = MapColor("#ffff00");
                    landingPage.notificationIcon.Text = PresenceConstants.BeRightBack;
                    break;

                case "Away":
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(Config.IconType, IconConstants.Away)));
                    color = MapColor("#ffff00");
                    landingPage.notificationIcon.Text = PresenceConstants.Away;
                    break;

                case "DoNotDisturb":
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(Config.IconType, IconConstants.DoNotDisturb)));
                    color = MapColor("#B03CDE");
                    landingPage.notificationIcon.Text = PresenceConstants.DoNotDisturb;
                    break;

                case "OutOfOffice":
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(Config.IconType, IconConstants.OutOfOffice)));
                    color = MapColor("#800080");
                    landingPage.notificationIcon.Text = PresenceConstants.OutOfOffice;
                    break;

                default:
                    image = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));
                    color = MapColor("#FFFFFF");
                    landingPage.notificationIcon.Text = PresenceConstants.Inactive;
                    break;
                }

                if (profileImageBit != null)
                {
                    landingPage.profileImage.Source = profileImageBit;
                }

                landingPage.notificationIcon.Icon  = image;
                mySolidColorBrush.Color            = color;
                landingPage.status.Fill            = mySolidColorBrush;
                landingPage.status.StrokeThickness = 1;
                landingPage.status.Stroke          = System.Windows.Media.Brushes.Black;

                if (profile != null)
                {
                    landingPage.userName.Content = profile.DisplayName;
                }

                landingPage.activity.Content     = "Activity: " + presence.Activity;
                landingPage.availability.Content = "Availability: " + presence.Availability;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error Occurred Mapping UI");
                throw;
            }
        }
예제 #20
0
        private async Task CallGraph()
        {
            if (_graphServiceClient == null)
            {
                _graphServiceClient = _graphservice.GetAuthenticatedGraphClient(typeof(WPFAuthorizationProvider));
            }

            stopThemePolling        = true;
            stopGraphPolling        = false;
            signInPanel.Visibility  = Visibility.Collapsed;
            lblTheme.Visibility     = Visibility.Collapsed;
            loadingPanel.Visibility = Visibility.Visible;
            var(profile, presence)  = await System.Threading.Tasks.Task.Run(() => GetBatchContent());

            var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto());

            if (photo == null)
            {
                MapUI(presence, profile, new BitmapImage(new Uri("pack://application:,,,/PresenceLight;component/images/UnknownProfile.png")));
            }
            else
            {
                MapUI(presence, profile, LoadImage(photo));
            }
            if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
            {
                await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId);
            }

            if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
            {
                await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId);
            }

            loadingPanel.Visibility     = Visibility.Collapsed;
            this.signInPanel.Visibility = Visibility.Collapsed;
            hueIpAddress.IsEnabled      = false;

            dataPanel.Visibility = Visibility.Visible;
            await SettingsService.SaveSettings(Config);

            while (true)
            {
                if (stopGraphPolling)
                {
                    stopGraphPolling      = false;
                    notificationIcon.Text = PresenceConstants.Inactive;
                    notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));
                    return;
                }
                await Task.Delay(Convert.ToInt32(Config.PollingInterval * 1000));

                try
                {
                    presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                    if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
                    {
                        await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId);
                    }

                    if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
                    {
                        await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId);
                    }

                    MapUI(presence, null, null);
                }
                catch { }
            }
        }
예제 #21
0
        public void MapUI(Presence presence, User profile, BitmapImage profileImageBit)
        {
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            System.Windows.Media.Color color;
            BitmapImage image;

            switch (presence.Availability)
            {
            case "Available":
                image = new BitmapImage(new Uri(IconConstants.GetIcon(_options.IconType, IconConstants.Available)));
                color = MapColor("#009933");
                notificationIcon.ToolTipText = PresenceConstants.Available;
                break;

            case "Busy":
                image = new BitmapImage(new Uri(IconConstants.GetIcon(_options.IconType, IconConstants.Busy)));
                color = MapColor("#ff3300");
                notificationIcon.ToolTipText = PresenceConstants.Busy;
                break;

            case "BeRightBack":
                image = new BitmapImage(new Uri(IconConstants.GetIcon(_options.IconType, IconConstants.BeRightBack)));
                color = MapColor("#ffff00");
                notificationIcon.ToolTipText = PresenceConstants.BeRightBack;
                break;

            case "Away":
                image = new BitmapImage(new Uri(IconConstants.GetIcon(_options.IconType, IconConstants.Away)));
                color = MapColor("#ffff00");
                notificationIcon.ToolTipText = PresenceConstants.Away;
                break;

            case "DoNotDisturb":
                image = new BitmapImage(new Uri(IconConstants.GetIcon(_options.IconType, IconConstants.DoNotDisturb)));
                color = MapColor("#800000");
                notificationIcon.ToolTipText = PresenceConstants.DoNotDisturb;
                break;

            default:
                image = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));
                color = MapColor("#FFFFFF");
                notificationIcon.ToolTipText = PresenceConstants.Inactive;
                break;
            }

            if (profileImageBit != null)
            {
                profileImage.Source = profileImageBit;
            }

            notificationIcon.IconSource = image;
            mySolidColorBrush.Color     = color;
            status.Fill            = mySolidColorBrush;
            status.StrokeThickness = 1;
            status.Stroke          = System.Windows.Media.Brushes.Black;

            if (profile != null)
            {
                Name.Content = profile.DisplayName;
            }
        }