Пример #1
0
        private void SwitchAudio(ProfileSetting profile, uint processId = 0)
        {
            foreach (var device in new[] { profile.Playback, profile.Recording }.Where((info) => info != null))
            {
                if (processId != 0)
                {
                    _audioSwitcher.SwitchProcessTo(
                        device.Id,
                        ERole.ERole_enum_count,
                        (EDataFlow)device.Type,
                        processId);
                }

                //Always switch the default device.
                //Easy way to be sure a notification will be send.
                //And to be consistent with the default audio device.
                _audioSwitcher.SwitchTo(device.Id, ERole.ERole_enum_count);
            }
        }
Пример #2
0
        /// <summary>
        /// Add a profile to the system
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public Result <string, VoidSuccess> AddProfile(ProfileSetting profile)
        {
            return(ValidateAddProfile(profile)
                   .Map(success =>
            {
                if (!string.IsNullOrEmpty(profile.ApplicationPath))
                {
                    _profileByApplication.Add(profile.ApplicationPath.ToLower(), profile);
                }
                if (profile.HotKey != null)
                {
                    _profileByHotkey.Add(profile.HotKey, profile);
                }

                AppConfigs.Configuration.ProfileSettings.Add(profile);
                AppConfigs.Configuration.Save();

                return Result.Success();
            }));
        }
Пример #3
0
        private Result <string, VoidSuccess> ValidateAddProfile(ProfileSetting profile)
        {
            if (string.IsNullOrEmpty(profile.ProfileName))
            {
                return(SettingsStrings.profile_error_no_name);
            }

            if (string.IsNullOrEmpty(profile.ApplicationPath) && profile.HotKey == null)
            {
                return(SettingsStrings.profile_error_needHKOrPath);
            }

            if (profile.Recording == null && profile.Playback == null)
            {
                return(SettingsStrings.profile_error_needPlaybackOrRecording);
            }

            if (profile.HotKey != null && _profileByHotkey.ContainsKey(profile.HotKey))
            {
                return(string.Format(SettingsStrings.profile_error_hotkey, profile.HotKey));
            }

            if (!string.IsNullOrEmpty(profile.ApplicationPath) && _profileByApplication.ContainsKey(profile.ApplicationPath.ToLower()))
            {
                return(string.Format(SettingsStrings.profile_error_application, profile.ApplicationPath));
            }

            if (AppConfigs.Configuration.ProfileSettings.Contains(profile))
            {
                return(string.Format(SettingsStrings.profile_error_name, profile.ProfileName));
            }

            if (profile.HotKey != null && !WindowsAPIAdapter.RegisterHotKey(profile.HotKey))
            {
                return(string.Format(SettingsStrings.profile_error_hotkey, profile.HotKey));
            }

            return(Result.Success());
        }