Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit f8af18f

Browse files
author
John Kordich
committed
Support for MI_DatetimeA marshalling
1 parent be8cfdd commit f8af18f

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

src/Microsoft.Management.Infrastructure/CimProperty.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,37 @@ internal static MI_Value ConvertToNativeLayer(object value, CimType cimType)
361361
{
362362
array[i] = MI_Datetime.ConvertToDateTime(arrayOfObjects[i]);
363363
}
364+
364365
miv.DatetimeA = array;
365366
return miv;
366367
}
367-
break;
368+
369+
var arrayOfDateTime = value as DateTime[];
370+
if (arrayOfDateTime != null)
371+
{
372+
MI_Datetime[] array = new MI_Datetime[arrayOfDateTime.Length];
373+
for (int i = 0; i < arrayOfDateTime.Length; i++)
374+
{
375+
array[i] = MI_Datetime.ConvertToDateTime(arrayOfDateTime[i]);
376+
}
377+
378+
miv.DatetimeA = array;
379+
return miv;
380+
}
381+
382+
var arrayOfTimeSpan = value as TimeSpan[];
383+
if (arrayOfTimeSpan != null)
384+
{
385+
MI_Datetime[] array = new MI_Datetime[arrayOfTimeSpan.Length];
386+
for (int i = 0; i < arrayOfTimeSpan.Length; i++)
387+
{
388+
array[i] = MI_Datetime.ConvertToDateTime(arrayOfTimeSpan[i]);
389+
}
390+
391+
miv.DatetimeA = array;
392+
return miv;
393+
}
394+
return miv;
368395

369396
case CimType.Unknown:
370397
miv.String = "UnknownType";

src/Microsoft.Management.Infrastructure/Internal/ValueHelpers.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ internal static void ThrowIfMismatchedType(MI_Type type, object managedValue)
3232
internal static object CloneManagedObject(object managedValue, CimType type)
3333
{
3434
if (managedValue != null &&
35-
((type.FromCimType() & MI_TypeFlags.MI_ARRAY) == MI_TypeFlags.MI_ARRAY ||
36-
type == CimType.Reference || type == CimType.Instance))
35+
(type == CimType.Reference || type == CimType.Instance))
3736
{
3837
throw new NotImplementedException();
3938
}
@@ -140,11 +139,17 @@ internal static object ConvertFromNativeLayer(
140139
}
141140
else if (type == MI_Type.MI_DATETIME)
142141
{
143-
return value.Datetime.ConvertToNativeLayer();
142+
return value.Datetime.ConvertFromNativeLayer();
144143
}
145144
else if (type == MI_Type.MI_DATETIMEA)
146145
{
147-
throw new NotImplementedException();
146+
int length = value.DatetimeA.Length;
147+
object[] arrayOfDatetimes = new object[length];
148+
for (int i = 0; i < length; i++)
149+
{
150+
arrayOfDatetimes[i] = value.DatetimeA[i].ConvertFromNativeLayer();
151+
}
152+
return arrayOfDatetimes;
148153
}
149154
else
150155
{

src/Microsoft.Management.Infrastructure/Native/Structures/MI_Datetime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal static MI_Datetime ConvertToDateTime(object value)
3333
}
3434
}
3535

36-
internal object ConvertToNativeLayer()
36+
internal object ConvertFromNativeLayer()
3737
{
3838
if (this.isTimestamp)
3939
{

test/Microsoft.Management.Infrastructure.Tests/UnitTests/CimInstanceTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ public void Properties_Add_ValueAndType_Char16Array()
943943
Assert.Equal(CimType.Char16Array, addedProperty.CimType, "addedProperty.CimType is not correct");
944944
}
945945

946-
[TDDFact]
946+
[Fact]
947947
public void Properties_Add_ValueAndType_DateTimeArray_DateTime()
948948
{
949949
DateTime myDate1 = new DateTime(2010, 09, 22, 7, 30, 0, DateTimeKind.Local);
@@ -964,7 +964,7 @@ public void Properties_Add_ValueAndType_DateTimeArray_DateTime()
964964
Assert.Equal(CimType.DateTimeArray, addedProperty.CimType, "addedProperty.CimType is not correct");
965965
}
966966

967-
[TDDFact]
967+
[Fact]
968968
public void Properties_Add_ValueAndType_DateTimeArray_TimeSpan()
969969
{
970970
TimeSpan myInterval1 = TimeSpan.FromSeconds(123);
@@ -985,7 +985,7 @@ public void Properties_Add_ValueAndType_DateTimeArray_TimeSpan()
985985
Assert.Equal(CimType.DateTimeArray, addedProperty.CimType, "addedProperty.CimType is not correct");
986986
}
987987

988-
[TDDFact]
988+
[Fact]
989989
public void Properties_Add_ValueAndType_DateTimeArray_Mixed()
990990
{
991991
DateTime myDate1 = new DateTime(2010, 09, 22, 7, 30, 0, DateTimeKind.Local);
@@ -1006,7 +1006,7 @@ public void Properties_Add_ValueAndType_DateTimeArray_Mixed()
10061006
Assert.Equal(CimType.DateTimeArray, addedProperty.CimType, "addedProperty.CimType is not correct");
10071007
}
10081008

1009-
[TDDFact]
1009+
[Fact]
10101010
public void Properties_Add_ValueAndType_DateTimeArray_Mixed_InferredType()
10111011
{
10121012
DateTime myDate1 = new DateTime(2010, 09, 22, 7, 30, 0, DateTimeKind.Local);

0 commit comments

Comments
 (0)