private void WaitAndProcessProbeResponses(MapiFolder folder, string fromAddress, Dictionary <string, string> subjectTargets, ExDateTime probeSentTime) { List <byte[]> list = new List <byte[]>(); List <string> list2 = new List <string>(); for (int i = 0; i < base.Task.ExecutionTimeout; i++) { foreach (KeyValuePair <string, string> keyValuePair in subjectTargets) { if (!string.IsNullOrEmpty(keyValuePair.Value)) { using (MapiMessage deliveryReceipt = TestMailFlowHelper.GetDeliveryReceipt(folder, keyValuePair.Key, false)) { if (deliveryReceipt != null) { PropValue prop = deliveryReceipt.GetProp(PropTag.MessageDeliveryTime); PropValue prop2 = deliveryReceipt.GetProp(PropTag.EntryId); PropValue prop3 = deliveryReceipt.GetProp(PropTag.Subject); if (!prop.IsError() && prop.Value != null && prop3.Value != null) { string text = prop3.Value.ToString(); if (text.StartsWith("RSP: CrossPremiseMailFlowMonitoring-", StringComparison.OrdinalIgnoreCase)) { EnhancedTimeSpan latency = ((ExDateTime)prop.GetDateTime() > probeSentTime) ? ((ExDateTime)prop.GetDateTime() - probeSentTime) : EnhancedTimeSpan.Zero; base.OutputResult(Strings.TestMailflowSucceeded(fromAddress, keyValuePair.Value), latency, base.IsRemoteTest); } else if (text.StartsWith("Undeliverable: CrossPremiseMailFlowMonitoring-", StringComparison.OrdinalIgnoreCase)) { EnhancedTimeSpan latency2 = EnhancedTimeSpan.FromSeconds(0.0); string info = (string)deliveryReceipt.GetProp(PropTag.Body).Value; base.OutputResult(Strings.CrossPremiseProbeNdred(fromAddress, keyValuePair.Value, info), latency2, base.IsRemoteTest); } list2.Add(keyValuePair.Key); list.Add(prop2.GetBytes()); } } } } } foreach (string key in list2) { subjectTargets.Remove(key); } list2.Clear(); if (subjectTargets.Count == 0) { break; } Thread.Sleep(1000); } foreach (KeyValuePair <string, string> keyValuePair2 in subjectTargets) { if (!string.IsNullOrEmpty(keyValuePair2.Value)) { EnhancedTimeSpan latency3 = EnhancedTimeSpan.FromSeconds(0.0); base.OutputResult(Strings.MapiTransactionResultFailure, latency3, base.IsRemoteTest); } } folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list.ToArray()); }
private void WaitAndProcessDeliveryReceipt(MapiFolder folder, string subject, string fromAddress, string toAddress, string perfInstance) { using (MapiMessage mapiMessage = this.WaitForDeliveryReceipt(folder, subject, base.Task.ErrorLatency, base.Task.ExecutionTimeout, fromAddress, toAddress)) { if (mapiMessage != null) { PropValue prop = mapiMessage.GetProp(PropTag.MessageDeliveryTime); PropValue prop2 = mapiMessage.GetProp(PropTag.OriginalSubmitTime); EnhancedTimeSpan enhancedTimeSpan = prop.GetDateTime() - prop2.GetDateTime(); if (enhancedTimeSpan < EnhancedTimeSpan.Zero) { enhancedTimeSpan = EnhancedTimeSpan.Zero; } base.OutputResult(Strings.MapiTransactionResultSuccess, enhancedTimeSpan, base.IsRemoteTest); base.AddSuccessMonitoringEvent(1000, Strings.TestMailflowSucceeded(fromAddress, toAddress)); base.AddPerfCounter("Mailflow Latency", perfInstance, enhancedTimeSpan.TotalSeconds); } else { EnhancedTimeSpan latency = EnhancedTimeSpan.FromSeconds(0.0); base.OutputResult(Strings.MapiTransactionResultFailure, latency, base.IsRemoteTest); base.AddErrorMonitoringEvent(1001, Strings.TestMailflowFailed(fromAddress, toAddress, base.Task.ExecutionTimeout)); base.AddPerfCounter("Mailflow Latency", perfInstance, -1.0); } } }
public static DateTime GetDateTimeOrDefault(PropValue pv) { if (pv.IsError() || pv.IsNull() || pv.Value == null) { return(DateTime.MinValue); } return(pv.GetDateTime()); }
public static DateTime GetLastLogonTime(PropValue[] propvalueArray) { PropValue mailboxProperty = MailboxTableQuery.GetMailboxProperty(propvalueArray, PropTag.LastLogonTime); if (mailboxProperty.PropType != PropType.SysTime) { return(DateTime.MinValue); } return(mailboxProperty.GetDateTime()); }
public static object Extract(PropValue value, MapiPropertyDefinition propertyDefinition) { bool isReadOnly = propertyDefinition.IsReadOnly; Type type = propertyDefinition.Type; Type underlyingType = Nullable.GetUnderlyingType(type); if (null != underlyingType) { type = underlyingType; } if (propertyDefinition.PropertyTag.Id() != value.PropTag.Id()) { throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ExceptionUnmatchedPropTag(propertyDefinition.PropertyTag.ToString(), value.PropTag.ToString())); } if (PropType.Binary == value.PropType) { if (typeof(Guid) == type) { return(new Guid(value.GetBytes())); } if (typeof(Schedule) == type) { return(Schedule.FromByteArray(value.GetBytes())); } if (typeof(MapiEntryId) == type) { return(new MapiEntryId(value.GetBytes())); } } if (typeof(short) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <short>(isReadOnly, propertyDefinition, value.GetShortArray())); } return(value.GetShort()); } else if (typeof(int) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <int>(isReadOnly, propertyDefinition, value.GetIntArray())); } return(value.GetInt()); } else if (typeof(long) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <long>(isReadOnly, propertyDefinition, value.GetLongArray())); } return(value.GetLong()); } else if (typeof(float) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <float>(isReadOnly, propertyDefinition, value.GetFloatArray())); } return(value.GetFloat()); } else if (typeof(double) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <double>(isReadOnly, propertyDefinition, value.GetDoubleArray())); } return(value.GetDouble()); } else if (typeof(DateTime) == type) { if (propertyDefinition.IsMultivalued) { DateTime[] dateTimeArray = value.GetDateTimeArray(); List <DateTime> list = new List <DateTime>(dateTimeArray.Length); foreach (DateTime dateTime in dateTimeArray) { list.Add(dateTime.ToLocalTime()); } return(new MultiValuedProperty <DateTime>(isReadOnly, propertyDefinition, list.ToArray())); } return(value.GetDateTime().ToLocalTime()); } else if (typeof(bool) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <bool>(isReadOnly, propertyDefinition, value.GetBoolArray())); } return(value.GetBoolean()); } else if (typeof(string) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <string>(isReadOnly, propertyDefinition, value.GetStringArray())); } return(value.GetString()); } else if (typeof(Guid) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <Guid>(isReadOnly, propertyDefinition, value.GetGuidArray())); } return(value.GetGuid()); } else if (typeof(byte[]) == type) { if (propertyDefinition.IsMultivalued) { return(new MultiValuedProperty <byte[]>(isReadOnly, propertyDefinition, value.GetBytesArray())); } return(value.GetBytes()); } else { if (typeof(short[]) == type) { return(value.GetShortArray()); } if (typeof(int[]) == type) { return(value.GetIntArray()); } if (typeof(long[]) == type) { return(value.GetLongArray()); } if (typeof(float[]) == type) { return(value.GetFloatArray()); } if (typeof(double[]) == type) { return(value.GetDoubleArray()); } if (typeof(DateTime[]) == type) { DateTime[] dateTimeArray2 = value.GetDateTimeArray(); List <DateTime> list2 = new List <DateTime>(dateTimeArray2.Length); foreach (DateTime dateTime2 in dateTimeArray2) { list2.Add(dateTime2.ToLocalTime()); } return(list2.ToArray()); } if (typeof(bool[]) == type) { return(value.GetBoolArray()); } if (typeof(string[]) == type) { return(value.GetStringArray()); } if (typeof(Guid[]) == type) { return(value.GetGuidArray()); } if (typeof(byte[][]) == type) { return(value.GetBytesArray()); } if (type.IsAssignableFrom(MapiPropValueConvertor.TypeFromPropType(value.PropType, false))) { return(value.RawValue); } object result = null; if (MapiPropValueConvertor.TryCastValueToExtract(value, type, out result)) { return(result); } throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa); } }
internal static PropertyValue ConvertFromMapiPropValue(PropValue mapiPropValue, int codePage) { PropertyValue result; try { PropertyTag propertyTag = new PropertyTag((uint)mapiPropValue.PropTag); object obj = null; PropertyType propertyType = propertyTag.PropertyType; if (propertyType <= PropertyType.Guid) { if (propertyType <= PropertyType.Object) { switch (propertyType) { case PropertyType.Null: goto IL_2E7; case PropertyType.Int16: obj = mapiPropValue.GetShort(); goto IL_2E7; case PropertyType.Int32: obj = mapiPropValue.GetInt(); goto IL_2E7; default: switch (propertyType) { case PropertyType.Error: obj = (ErrorCode)mapiPropValue.GetErrorValue(); goto IL_2E7; case PropertyType.Bool: obj = mapiPropValue.GetBoolean(); goto IL_2E7; case PropertyType.Object: goto IL_2E7; } break; } } else { switch (propertyType) { case PropertyType.String8: obj = ConvertHelper.ConvertMapiPtString8ToString8(mapiPropValue.Value, codePage); goto IL_2E7; case PropertyType.Unicode: obj = mapiPropValue.GetString(); goto IL_2E7; default: if (propertyType == PropertyType.SysTime) { DateTime dateTime = mapiPropValue.GetDateTime(); obj = (ExDateTime)dateTime; goto IL_2E7; } if (propertyType == PropertyType.Guid) { obj = mapiPropValue.GetGuid(); goto IL_2E7; } break; } } } else if (propertyType <= PropertyType.MultiValueUnicode) { if (propertyType == PropertyType.Binary) { obj = mapiPropValue.GetBytes(); goto IL_2E7; } switch (propertyType) { case PropertyType.MultiValueInt16: obj = mapiPropValue.GetShortArray(); goto IL_2E7; case PropertyType.MultiValueInt32: obj = mapiPropValue.GetIntArray(); goto IL_2E7; default: switch (propertyType) { case PropertyType.MultiValueString8: if (mapiPropValue.Value is string[]) { string[] array = (string[])mapiPropValue.Value; String8[] array2 = new String8[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = ConvertHelper.ConvertMapiPtString8ToString8(array[i], codePage); } obj = array2; goto IL_2E7; } if (mapiPropValue.Value is byte[][]) { byte[][] array3 = (byte[][])mapiPropValue.Value; String8[] array4 = new String8[array3.Length]; for (int j = 0; j < array3.Length; j++) { array4[j] = ConvertHelper.ConvertMapiPtString8ToString8(array3[j], codePage); } obj = array4; goto IL_2E7; } goto IL_2E7; case PropertyType.MultiValueUnicode: obj = mapiPropValue.GetStringArray(); goto IL_2E7; } break; } } else if (propertyType != PropertyType.MultiValueSysTime) { if (propertyType == PropertyType.MultiValueGuid) { obj = mapiPropValue.GetGuidArray(); goto IL_2E7; } if (propertyType == PropertyType.MultiValueBinary) { obj = mapiPropValue.GetBytesArray(); goto IL_2E7; } } else { DateTime[] dateTimeArray = mapiPropValue.GetDateTimeArray(); if (dateTimeArray != null) { ExDateTime[] array5 = new ExDateTime[dateTimeArray.Length]; for (int k = 0; k < dateTimeArray.Length; k++) { array5[k] = (ExDateTime)dateTimeArray[k]; } obj = array5; goto IL_2E7; } goto IL_2E7; } throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert unsupported property type {0} on property {1}.", propertyTag.PropertyType, propertyTag)); IL_2E7: if (obj == null) { result = PropertyValue.NullValue(propertyTag); } else { result = new PropertyValue(propertyTag, obj); } } catch (InvalidPropertyValueTypeException inner) { throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert invalid PropValue on property {0}.", mapiPropValue), inner); } catch (NotSupportedException inner2) { throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert invalid PropValue as it contains unsupported PropType on property {0}.", mapiPropValue), inner2); } return(result); }
public static T GetValue <T>(PropValue pv, T defaultValue) { object obj = null; PropType propType = pv.PropType; if (propType <= PropType.String) { if (propType != PropType.Int) { if (propType != PropType.Boolean) { if (propType == PropType.String) { obj = pv.GetString(); } } else { obj = pv.GetBoolean(); } } else { obj = pv.GetInt(); } } else if (propType != PropType.SysTime) { if (propType != PropType.Guid) { if (propType == PropType.Binary) { obj = pv.GetBytes(); if (typeof(T) == typeof(Guid)) { byte[] array = obj as byte[]; if (array != null && array.Length == 16) { obj = new Guid(array); } else { obj = null; } } } } else { obj = pv.GetGuid(); } } else { obj = pv.GetDateTime(); } if (obj == null) { return(defaultValue); } T result; try { result = (T)((object)obj); } catch (InvalidCastException) { result = defaultValue; } return(result); }
public static PropertyValue MoMTPvFromPv(PropValue pv) { PropertyValue result; if (pv.PropType == PropType.SysTime) { result = new PropertyValue(new PropertyTag((uint)pv.PropTag), (ExDateTime)pv.GetDateTime()); } else { result = new PropertyValue(new PropertyTag((uint)pv.PropTag), pv.Value); } return(result); }