Exemple #1
0
        /// <summary>
        /// Retrieves the current ISO speed of the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns the current ISO speed of the camera. If the ISO speed is set to Auto, then 0 is returned.</returns>
        public async Task <int> GetIsoSpeedAsync()
        {
            // Gets the ISO speed camera configuration
            CameraConfiguration isoSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.IsoSpeed);

            // Retrieves the current ISO speed of the camera
            try
            {
                // Retrieves the textual representation of the ISO speed
                string currentIsoSpeedTextualRepresentation = await isoSpeedCameraConfiguration.GetValueAsync();

                // Checks if the ISO speed is set to Auto, if so then 0 is returned, otherwise the ISO speed is converted to an integer and returned
                if (currentIsoSpeedTextualRepresentation.ToUpperInvariant() == "AUTO")
                {
                    return(IsoSpeeds.Auto);
                }
                else
                {
                    return(int.Parse(currentIsoSpeedTextualRepresentation, CultureInfo.InvariantCulture));
                }
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the ISO speed is not supported by this camera.", exception);
            }
        }
Exemple #2
0
        /// <summary>
        /// Retrieves the battery level of the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns the battery level of the camera.</returns>
        public async Task <string> GetBatteryLevelAsync()
        {
            // Gets the battery level camera configuration
            CameraConfiguration batteryLevelCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.BatteryLevel);

            // Retrieves the battery level of the camera and returns it
            try
            {
                return(await batteryLevelCameraConfiguration.GetValueAsync());
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the battery level is not supported by this camera.", exception);
            }
        }
Exemple #3
0
        /// <summary>
        /// Retrieves the name of the lens of the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns the name of the lens of the camera.</returns>
        public async Task <string> GetLensNameAsync()
        {
            // Gets the lens name camera configuration
            CameraConfiguration lensNameCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.LensName);

            // Retrieves the name of the lens of the camera and returns it
            try
            {
                return(await lensNameCameraConfiguration.GetValueAsync());
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the lens name is not supported by this camera.", exception);
            }
        }
Exemple #4
0
        /// <summary>
        /// Retrieves the name of the manufacturer of the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns the name of the manufacturer of the camera.</returns>
        public async Task <string> GetManufacturerAsync()
        {
            // Gets the manufacturer camera configuration
            CameraConfiguration manufacturerCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.Manufacturer);

            // Retrieves the manufacturer and returns it
            try
            {
                return(await manufacturerCameraConfiguration.GetValueAsync());
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the camera manufacturer is not supported by this camera.", exception);
            }
        }
Exemple #5
0
        /// <summary>
        /// Sets the name of the owner of the camera.
        /// </summary>
        /// <param name="name">The new name of the owner of the camera, that is to be set.</param>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        public async Task SetOwnerNameAsync(string name)
        {
            // Gets the owner name camera configuration
            CameraConfiguration ownerNameCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.OwnerName);

            // Sets the new name of the owner of the camera
            try
            {
                await ownerNameCameraConfiguration.SetValueAsync(name);
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the owner name is not supported by this camera.", exception);
            }
        }
Exemple #6
0
        /// <summary>
        /// Gets all apertures, that are supported by the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns a list of all the apertures that are supported by the camera.</returns>
        public async Task <IEnumerable <double> > GetSupportedAperturesAsync()
        {
            // Gets the aperture camera configuration
            CameraConfiguration apertureCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.Aperture);

            // Gets all the choices, converts them to intergers and returns them
            try
            {
                return((await apertureCameraConfiguration.GetChoicesAsync()).Select(choice => double.Parse(choice, CultureInfo.InvariantCulture)));
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the aperture is not supported by this camera.", exception);
            }
        }
Exemple #7
0
        /// <summary>
        /// Sets the aperture of the camera.
        /// </summary>
        /// <param name="aperture">The aperture to which the camera is to be set.</param>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        public async Task SetApertureAsync(double aperture)
        {
            // Gets the aperture camera configuration
            CameraConfiguration apertureCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.Aperture);

            // Tries to set the new aperture, if an exception is thrown, then the aperture is not supported by the camera
            try
            {
                await apertureCameraConfiguration.SetValueAsync(aperture.ToString(CultureInfo.InvariantCulture));
            }
            catch (CameraException exception)
            {
                throw new CameraException(string.Format(CultureInfo.InvariantCulture, "Either the aperture configuration is not supported by the camera or the aperture of {0} is not supported by the camera.", aperture), exception);
            }
        }
Exemple #8
0
        /// <summary>
        /// Gets all shutter speeds, that are supported by the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns a list of all the shutter speeds that are supported by the camera.</returns>
        public async Task <IEnumerable <ShutterSpeed> > GetSupportedShutterSpeedsAsync()
        {
            // Gets the shutter speed camera configuration
            CameraConfiguration shutterSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.ShutterSpeed);

            // Gets all the choices, converts them to ShutterSpeed objects and returns them
            try
            {
                return((await shutterSpeedCameraConfiguration.GetChoicesAsync()).Select(shutterSpeed => new ShutterSpeed(shutterSpeed)));
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the shutter speed is not supported by this camera.", exception);
            }
        }
Exemple #9
0
        /// <summary>
        /// Sets the shutter speed of the camera.
        /// </summary>
        /// <param name="shutterSpeed">The shutter speed to which the camera is to be set.</param>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        public async Task SetShutterSpeedAsync(ShutterSpeed shutterSpeed)
        {
            // Gets the shutter speed camera configuration
            CameraConfiguration shutterSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.ShutterSpeed);

            // Tries to set the shutter speed
            try
            {
                await shutterSpeedCameraConfiguration.SetValueAsync(shutterSpeed.TextualRepresentation);
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the shutter speed is not supported by this camera.", exception);
            }
        }
Exemple #10
0
        /// <summary>
        /// Gets all ISO speeds, that are supported by the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>
        /// Returns a list of all the ISO speeds that are supported by the camera. The ISO speed 0 means that the camera automatically detects the
        /// correct ISO speed for the current lighting conditions (Auto).
        /// </returns>
        public async Task <IEnumerable <int> > GetSupportedIsoSpeedsAsync()
        {
            // Gets the ISO speed camera configuration
            CameraConfiguration isoSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.IsoSpeed);

            // Gets all the choices, converts them to intergers and returns them
            try
            {
                return((await isoSpeedCameraConfiguration.GetChoicesAsync()).Select(choice => choice.ToUpperInvariant() == "AUTO" ? 0 : int.Parse(choice, CultureInfo.InvariantCulture)));
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the ISO speed is not supported by this camera.", exception);
            }
        }
Exemple #11
0
        /// <summary>
        /// Sets the ISO speed of the camera.
        /// </summary>
        /// <param name="isoSpeed">
        /// The ISO speed to which the camera is to be set. An ISO speed of 0 sets the camera to an Auto ISO speed, which means that the camera
        /// determines the correct ISO speed for the current lighting conditions
        /// </param>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        public async Task SetIsoSpeedAsync(int isoSpeed)
        {
            // Gets the ISO speed camera configuration
            CameraConfiguration isoSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.IsoSpeed);

            // Tries to set the new ISO speed, if an exception is thrown, then the ISO speed is not supported by the camera
            try
            {
                await isoSpeedCameraConfiguration.SetValueAsync(isoSpeed == 0? "Auto" : isoSpeed.ToString(CultureInfo.InvariantCulture));
            }
            catch (CameraException exception)
            {
                throw new CameraException(string.Format(CultureInfo.InvariantCulture, "Either the ISO speed configuration is not supported by the camera or the ISO speed of {0} is not supported by the camera.", isoSpeed == 0 ? "Auto" : isoSpeed.ToString(CultureInfo.InvariantCulture)), exception);
            }
        }
Exemple #12
0
        /// <summary>
        /// Retrieves the current aperture of the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns the current aperture of the camera.</returns>
        public async Task <double> GetApertureAsync()
        {
            // Gets the aperture camera configuration
            CameraConfiguration apertureCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.Aperture);

            // Retrieves the current aperture of the camera
            try
            {
                // Retrieves and parses the aperture and returns it
                string currentApertureTextualRepresentation = await apertureCameraConfiguration.GetValueAsync();

                return(double.Parse(currentApertureTextualRepresentation, CultureInfo.InvariantCulture));
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the aperture is not supported by this camera.", exception);
            }
        }
Exemple #13
0
        /// <summary>
        /// Gets the current shutter speed of the camera.
        /// </summary>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera or the shutter speed could not be retrieved properly, then a
        /// <see cref="CameraException"/> exception is thrown.
        /// </exception>
        /// <returns>Returns the current shutter speed of the camera.</returns>
        public async Task <ShutterSpeed> GetShutterSpeedAsync()
        {
            // Gets the shutter speed camera configuration
            CameraConfiguration shutterSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.ShutterSpeed);

            // Retrieves the current shutter speed of the camera
            try
            {
                // Gets the textual representation of the shutter speed
                string currentShutterSpeedTextualRepresentation = await shutterSpeedCameraConfiguration.GetValueAsync();

                // Converts the textual representation of the shutter speed into a shutter speed object and returns it
                return(new ShutterSpeed(currentShutterSpeedTextualRepresentation));
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the shutter speed is not supported by this camera.", exception);
            }
        }
Exemple #14
0
        /// <summary>
        /// Sets the shutter speed of the camera.
        /// </summary>
        /// <param name="shutterSpeed">
        /// The shutter speed to which the camera is to be set. A shutter speed of <c>TimeSpan.MaxValue</c> sets the camera to a Bulb shutter
        /// speed, which means that the camera exposes the image for as long as the release is pressed.
        /// </param>
        /// <exception cref="CameraException">
        /// If the camera configuration is not supported by the camera, then a <see cref="CameraException"/> exception is thrown.
        /// </exception>
        public async Task SetShutterSpeedAsync(TimeSpan shutterSpeed)
        {
            // Gets the shutter speed camera configuration
            CameraConfiguration shutterSpeedCameraConfiguration = await this.GetConfigurationAsync(CameraConfigurations.ShutterSpeed);

            // Gets all the choices and converts them to TimeSpans, which is needed to determine the correct value for the shutter speed to set
            try
            {
                // Gets all supported shutter speeds
                IEnumerable <ShutterSpeed> supportedShutterSpeeds = await this.GetSupportedShutterSpeedsAsync();

                // Chooses the correct shutter speed value from the available choices and sets it, if the shutter speed could not be detected,
                // then an exception is thrown
                if (!supportedShutterSpeeds.Any(speed => speed.Speed == shutterSpeed))
                {
                    throw new CameraException(string.Format(CultureInfo.InvariantCulture, "The shutter speed {0} is not supported by the camera.", shutterSpeed));
                }
                await shutterSpeedCameraConfiguration.SetValueAsync(supportedShutterSpeeds.FirstOrDefault(speed => speed.Speed == shutterSpeed).TextualRepresentation);
            }
            catch (CameraException exception)
            {
                throw new CameraException("The camera configuration for the shutter speed is not supported by this camera.", exception);
            }
        }
Exemple #15
0
 /// <summary>
 /// Gets the configuration settings of the camera. The configuration should be retrieved regularly, because the configuration
 /// settings retrieved can change when the camera is in a different mode (e.g. there are more configurations when the camera
 /// is in "Manual" mode than when the camera is in "Auto" mode).
 /// </summary>
 /// <returns>Returns a list of all the configuration settings of the camera.</returns>
 public Task <IEnumerable <CameraConfiguration> > GetSupportedConfigurationAsync()
 {
     return(CameraConfiguration.GetCameraConfigurationsAsync(this.gPhoto2IpcWrapper));
 }