/// <summary> /// Encodes the specified <see cref="IDeviceIdComponent"/> as a string. /// </summary> /// <param name="component">The component to encode.</param> /// <returns>The component encoded as a string.</returns> public string Encode(IDeviceIdComponent component) { var value = component.GetValue() ?? string.Empty; var bytes = Encoding.UTF8.GetBytes(value); var algorithm = _hashAlgorithm.Invoke(); var hash = algorithm.ComputeHash(bytes); var output = _byteArrayEncoder.Encode(hash); return(output); }
private string GetValue(IDeviceIdComponent component) { try { return(_encoder.Encode(component)); } catch (DeviceIdComponentFailedToObtainValueException) { return(""); } }
/// <summary> /// Returns an <see cref="XElement"/> representing the specified <see cref="IDeviceIdComponent"/> instance. /// </summary> /// <param name="component">The <see cref="IDeviceIdComponent"/> to represent.</param> /// <returns>An <see cref="XElement"/> representing the specified <see cref="IDeviceIdComponent"/> instance.</returns> private XElement GetElement(IDeviceIdComponent component) { try { return(new XElement("Component", new XAttribute("Name", component.Name), new XAttribute("Value", _encoder.Encode(component)))); } catch { return(new XElement("Component", new XAttribute("Name", component.Name))); } }
/// <summary> /// Adds the specified component to the device identifier. /// </summary> /// <param name="builder">The <see cref="DeviceIdBuilder"/> to add the component to.</param> /// <param name="component">The <see cref="IDeviceIdComponent"/> to add.</param> /// <returns>The <see cref="DeviceIdBuilder"/> instance.</returns> public static DeviceIdBuilder AddComponent(this DeviceIdBuilder builder, IDeviceIdComponent component) { builder.Components.Add(component); return(builder); }
/// <summary> /// Encodes the specified <see cref="IDeviceIdComponent"/> as a string. /// </summary> /// <param name="component">The component to encode.</param> /// <returns>The component encoded as a string.</returns> public string Encode(IDeviceIdComponent component) { return(component.GetValue() ?? string.Empty); }