public Sample ConvertRawBmpAsSample(Bitmap RawBmp, short VertDpi = 700, short HorDpi = 700) { VariantConverter VConverter; Enroller = new DPFP.Processing.Enrollment(); RawBmp = EncodeBitmap(RawBmp, VertDpi, HorDpi); try { // converts raw image to dpSample using DFC 2.0--------------------------------------- // encode the bmp variable using the bitmap Loader BitmapLoader BmpLoader = new BitmapLoader(RawBmp, (int)RawBmp.HorizontalResolution, (int)RawBmp.VerticalResolution); BmpLoader.ProcessBitmap(); // return the required result inputData = BmpLoader.RawData; inpRaw = BmpLoader.DPInputParam; // dispose the object BmpLoader.Dispose(); // start the conversion process VConverter = new VariantConverter(VariantConverter.OutputType.dp_sample, DataType.RawSample, inpRaw, inputData, false); MemoryStream DStream = new MemoryStream(VConverter.Convert()); DPsample = new DPFP.Sample(DStream); return(DPsample); } catch (Exception ex) { return(null /* TODO Change to default(_) if this is not a reference type */); } }
public Type Test_ObjectConversion_IConvertible(VARENUM vt, TypeCode code) { var convertible = new ConvertibleTest(code); var result = VariantConverter.ChangeType(convertible, vt); return(result.GetType()); }
public void Test_ObjectConversion_IConvertible_Null() { var convertible = new ConvertibleTest(TypeCode.Empty); var result = VariantConverter.ChangeType(convertible, VARENUM.VT_EMPTY); Assert.IsNull(result); }
public object Test_ObjectConversion_Date_Localized(string value, Type targetType, string locale) { var culture = new CultureInfo(locale); var date = DateTime.ParseExact(value, TheOneTrueDateFormat, culture); return(VariantConverter.ChangeType(date, targetType, culture)); }
public void Test_Error_Is_Not_Convertible(Type targetType) { Assert.Throws <COMException>(() => { var err = new ErrorWrapper(1); VariantConverter.ChangeType(err, targetType); }); }
public object Test_ObjectConversion_SimpleValues(object value, Type targetType) { var result = VariantConverter.ChangeType(value, targetType); if (result is DateTime dt) { return(dt.ToString(TheOneTrueDateFormat)); } return(result); }
public void Test_ObjectConversion_Object() { var obj = new object(); var unk = new UnknownWrapper(obj); var result = VariantConverter.ChangeType(unk, typeof(DispatchWrapper)); Assert.AreSame(obj, result); var result2 = VariantConverter.ChangeType(result, typeof(UnknownWrapper)); Assert.AreSame(unk.WrappedObject, result2); }
public object Test_ObjectConversion_Currency(decimal value, Type targetType) { var cy = new CurrencyWrapper(value); var result = VariantConverter.ChangeType(cy, targetType); if (result is DateTime dt) { return(dt.ToString(TheOneTrueDateFormat)); } return(result); }
public string Test_US_format_String_To_Date_Localized(string locale, object value, Type targetType) { var culture = new CultureInfo(locale); var result = VariantConverter.ChangeType(value, targetType, culture); if (result is DateTime dt) { return(dt.ToString(TheOneTrueDateFormat)); } // Invalid result return(string.Empty); }
public string Test_ObjectConversion_SimpleValues_To_Date(object value, Type targetType) { var culture = new CultureInfo("en-US"); var result = VariantConverter.ChangeType(value, targetType, culture); if (result is DateTime dt) { return(dt.ToString(TheOneTrueDateFormat)); } // Invalid result return(string.Empty); }
/// <summary> /// Tests equity between 2 objects using VBA's type promotion rules. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns>VBA equity</returns> public new bool Equals(object x, object y) { if (x == null) { return(y == null); } if (y == null) { return(false); } var converted = VariantConverter.ChangeType(y, x.GetType()); return(x.Equals(converted)); }
public DPFP.Template ConvertRawBmpAsTemplate(Bitmap RawBmp, DataPurpose ProcessPurpose = DataPurpose.Enrollment, short VertDpi = 700, short HorDpi = 700) { VariantConverter VConverter; Enroller = new DPFP.Processing.Enrollment(); RawBmp = EncodeBitmap(RawBmp, VertDpi, HorDpi); try { // converts raw image to dpSample using DFC 2.0--------------------------------------- // encode the bmp variable using the bitmap Loader BitmapLoader BmpLoader = new BitmapLoader(RawBmp, (int)RawBmp.HorizontalResolution, (int)RawBmp.VerticalResolution); BmpLoader.ProcessBitmap(); // return the required result inputData = BmpLoader.RawData; inpRaw = BmpLoader.DPInputParam; // dispose the object BmpLoader.Dispose(); // start the conversion process VConverter = new VariantConverter(VariantConverter.OutputType.dp_sample, DataType.RawSample, inpRaw, inputData, false); MemoryStream DStream = new MemoryStream(VConverter.Convert()); DPsample = new DPFP.Sample(DStream); // DPsample = DirectCast(VConverter.Convert(), DPFP.Sample) // converts dpSample to DPFeatures using the OTW''''''''''''''''''''''''''''''''''''''' DPFeatures = ExtractFeatures(DPsample, ProcessPurpose); // convert DPfeatures to ISO FMD using the DFC 2.0''''''''''''''''''''''''''''''''''''''' byte[] SerializedFeatures = null; DPFeatures.Serialize(ref SerializedFeatures); // serialized features into the array of bytes ISOFMD = DigitalPersona.Standards.Converter.Convert(SerializedFeatures, DigitalPersona.Standards.DataType.DPFeatureSet, DataType.ISOFeatureSet); // convert ISO FMD to DPTemplate using DFC 2.0''''''''''''''''''''''''''''''''''''''' byte[] DPTemplateData = DigitalPersona.Standards.Converter.Convert(ISOFMD, DigitalPersona.Standards.DataType.ISOTemplate, DataType.DPTemplate); // deserialize data to Template DPTemplate = new DPFP.Template(); DPTemplate.DeSerialize(DPTemplateData); // required for database purpose // ============================================================================ DStream.Close(); return(DPTemplate); } catch (Exception ex) { return(null /* TODO Change to default(_) if this is not a reference type */); } }
public void Test_ObjectConversion_Null(object value) { var result = VariantConverter.ChangeType(value, VARENUM.VT_EMPTY); Assert.IsNull(result); }
public void Test_ObjectConversion_DbNull(object value) { var result = VariantConverter.ChangeType(value, VARENUM.VT_NULL); Assert.IsInstanceOf <DBNull>(result); }
[TestCase("9999-12-31 23:59:59", typeof(double), ExpectedResult = 2958465.999988426d)] // Note: VBA returns 2958465.99998843d but accepts the other values as equal public object Test_ObjectConversion_Date(string value, Type targetType) { var date = DateTime.ParseExact(value, TheOneTrueDateFormat, CultureInfo.InvariantCulture); return(VariantConverter.ChangeType(date, targetType)); }
public object Test_ObjectConversion_Currency_Localized(decimal value, Type targetType, string locale) { var cy = new CurrencyWrapper(value); return(VariantConverter.ChangeType(cy, targetType, new CultureInfo(locale))); }