private static bool TryGetSmsSyncDeviceLastSyncTime(SyncStateStorage syncStateStorage, E164Number smsSyncPhoneNumber, out ExDateTime lastSyncTime, out string deviceName)
 {
     lastSyncTime = ExDateTime.MinValue;
     deviceName   = null;
     using (CustomSyncState customSyncState = syncStateStorage.GetCustomSyncState(new GlobalSyncStateInfo
     {
         ReadOnly = true
     }, new PropertyDefinition[0]))
     {
         if (customSyncState == null)
         {
             return(false);
         }
         if (!customSyncState.GetData <BooleanData, bool>("DeviceEnableOutboundSMS", false))
         {
             return(false);
         }
         string data = customSyncState.GetData <StringData, string>("DevicePhoneNumber", null);
         if (string.IsNullOrEmpty(data))
         {
             return(false);
         }
         E164Number e164Number = null;
         if (!E164Number.TryParse(data, out e164Number))
         {
             return(false);
         }
         if (!e164Number.Equals(smsSyncPhoneNumber, true))
         {
             return(false);
         }
         deviceName = customSyncState.GetData <StringData, string>("DeviceFriendlyName", null);
     }
     lastSyncTime = syncStateStorage.CreationTime;
     using (CustomSyncState customSyncState2 = syncStateStorage.GetCustomSyncState(new SyncStatusSyncStateInfo
     {
         ReadOnly = true
     }, new PropertyDefinition[0]))
     {
         if (customSyncState2 != null)
         {
             lastSyncTime = customSyncState2.GetData <DateTimeData, ExDateTime>("LastSyncAttemptTime", ExDateTime.MinValue);
             if (ExDateTime.MinValue == lastSyncTime)
             {
                 lastSyncTime = customSyncState2.GetData <DateTimeData, ExDateTime>("LastSyncSuccessTime", syncStateStorage.CreationTime);
             }
         }
     }
     return(true);
 }
示例#2
0
 internal static PossibleRecipient GetMathed(IEnumerable <PossibleRecipient> candidates, E164Number number, bool snOnly)
 {
     if (candidates == null)
     {
         throw new ArgumentNullException("candidates");
     }
     if (null == number)
     {
         throw new ArgumentNullException("number");
     }
     foreach (PossibleRecipient possibleRecipient in candidates)
     {
         if (possibleRecipient.Ready && E164Number.Equals(possibleRecipient.PhoneNumber, number, snOnly))
         {
             return(possibleRecipient);
         }
     }
     return(null);
 }
        private static bool IsTextMessageStuckInOutbox(MailboxSession session, E164Number smsSyncPhoneNumber, ExDateTime oldestBoundary, ExDateTime newestBoundary)
        {
            bool result;

            using (Folder folder = Folder.Bind(session, DefaultFolderType.Outbox))
            {
                if (folder.ItemCount == 0)
                {
                    result = false;
                }
                else
                {
                    using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, new SortBy[]
                    {
                        new SortBy(StoreObjectSchema.LastModifiedTime, SortOrder.Ascending)
                    }, new PropertyDefinition[]
                    {
                        StoreObjectSchema.LastModifiedTime,
                        StoreObjectSchema.ItemClass,
                        ItemSchema.SentRepresentingType,
                        ItemSchema.SentRepresentingEmailAddress
                    }))
                    {
                        if (!queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.GreaterThanOrEqual, StoreObjectSchema.LastModifiedTime, oldestBoundary)))
                        {
                            result = false;
                        }
                        else
                        {
                            while (queryResult.SeekToCondition(SeekReference.OriginCurrent, new ComparisonFilter(ComparisonOperator.Equal, StoreObjectSchema.ItemClass, "IPM.Note.Mobile.SMS")))
                            {
                                IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(1);
                                if (propertyBags == null || propertyBags.Length == 0)
                                {
                                    return(false);
                                }
                                string b = propertyBags[0].TryGetProperty(ItemSchema.SentRepresentingType) as string;
                                if (string.Equals("MOBILE", b, StringComparison.OrdinalIgnoreCase))
                                {
                                    string     number     = propertyBags[0].TryGetProperty(ItemSchema.SentRepresentingEmailAddress) as string;
                                    E164Number e164Number = null;
                                    if (E164Number.TryParse(number, out e164Number) && e164Number.Equals(smsSyncPhoneNumber, true))
                                    {
                                        ExDateTime?exDateTime = propertyBags[0].TryGetProperty(StoreObjectSchema.LastModifiedTime) as ExDateTime?;
                                        if (exDateTime != null)
                                        {
                                            return(exDateTime <= newestBoundary);
                                        }
                                    }
                                }
                            }
                            result = false;
                        }
                    }
                }
            }
            return(result);
        }