private IEnumerable <IStorePropertyBag> EnumerateCandidatesThatMatchDefaultNamingConvention() { string defaultFolderDisplayName; if (!OscProviderRegistry.TryGetDefaultFolderDisplayName(this.provider, out defaultFolderDisplayName)) { OscProviderCandidateFolderEnumerator.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "Candidate folder enumerator: provider {0} is unknown. Cannot enumerate candidates that match naming convention", this.provider); } else { TextFilter displayNameStartsWithProviderName = new TextFilter(FolderSchema.DisplayName, defaultFolderDisplayName, MatchOptions.Prefix, MatchFlags.IgnoreCase); OscProviderCandidateFolderEnumerator.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "Candidate folder enumerator: the default folder display name for provider {0} is {1}", this.provider, defaultFolderDisplayName); using (IFolder rootFolder = this.xsoFactory.BindToFolder(this.session, this.session.GetDefaultFolderId(DefaultFolderType.Root))) { using (IQueryResult subFoldersQuery = rootFolder.IFolderQuery(FolderQueryFlags.None, null, OscProviderCandidateFolderEnumerator.SortByDisplayNameAscending, OscProviderCandidateFolderEnumerator.FolderPropertiesToLoad)) { if (!subFoldersQuery.SeekToCondition(SeekReference.OriginBeginning, displayNameStartsWithProviderName, SeekToConditionFlags.AllowExtendedFilters)) { OscProviderCandidateFolderEnumerator.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Candidate folder enumerator: SeekToCondition = false. No folder has display name matching {0}", defaultFolderDisplayName); yield break; } IStorePropertyBag[] folders = subFoldersQuery.GetPropertyBags(10); while (folders.Length > 0) { foreach (IStorePropertyBag folder in folders) { string displayName = folder.GetValueOrDefault <string>(FolderSchema.DisplayName, string.Empty); VersionedId folderId = folder.GetValueOrDefault <VersionedId>(FolderSchema.Id, null); if (folderId == null) { OscProviderCandidateFolderEnumerator.Tracer.TraceError <string>((long)this.GetHashCode(), "Candidate folder enumerator: skipping bogus folder '{0}' because it has a blank id.", displayName); } else { string containerClass = folder.GetValueOrDefault <string>(StoreObjectSchema.ContainerClass, string.Empty); if (string.IsNullOrEmpty(containerClass) || !ObjectClass.IsContactsFolder(containerClass)) { OscProviderCandidateFolderEnumerator.Tracer.TraceDebug <string, VersionedId>((long)this.GetHashCode(), "Candidate folder enumerator: skipping folder '{0}' (ID={1}) because it's not a contacts folder.", displayName, folderId); } else { if (string.IsNullOrEmpty(displayName) || !displayName.StartsWith(defaultFolderDisplayName, StringComparison.OrdinalIgnoreCase)) { OscProviderCandidateFolderEnumerator.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Candidate folder enumerator: we've iterated past candidates that follow the naming convention. Current folder is '{0}'", displayName); yield break; } OscProviderCandidateFolderEnumerator.Tracer.TraceDebug <string, VersionedId>((long)this.GetHashCode(), "Candidate folder enumerator: folder: {0}; id: {1}; is a good candidate.", displayName, folderId); yield return(folder); } } } folders = subFoldersQuery.GetPropertyBags(10); } } } } yield break; }
public OscFolderDisplayNameGenerator(Guid provider, int count) { if (count < 1) { throw new ArgumentOutOfRangeException("count", count, "At least 1 name must be generated."); } this.defaultFolderDisplayName = OscProviderRegistry.GetDefaultFolderDisplayName(provider); this.namesToGenerate = count; }
internal static Guid GetGuidFromName(string name) { Guid result; if (!OscProviderRegistry.TryGetGuidFromName(name, out result)) { throw new ArgumentException("Unknown provider", "name"); } return(result); }
public StoreObjectId Find(string provider, string userId) { Util.ThrowOnNullOrEmptyArgument(provider, "provider"); Util.ThrowOnNullOrEmptyArgument(userId, "userId"); string networkId; if (OscProviderRegistry.TryGetNetworkId(provider, out networkId)) { return(this.Find(provider, userId, networkId)); } return(this.Find(provider, userId, string.Empty)); }
public OscFolderCreateResult Create(string provider, string userId) { Util.ThrowOnNullOrEmptyArgument(provider, "provider"); Util.ThrowOnNullOrEmptyArgument(userId, "userId"); Guid guidFromName = OscProviderRegistry.GetGuidFromName(provider); string networkId; if (OscProviderRegistry.TryGetNetworkId(provider, out networkId)) { return(this.Create(provider, guidFromName, userId, networkId)); } return(this.Create(provider, guidFromName, userId, string.Empty)); }
internal StoreObjectId Find(string provider, string userId, string networkId) { Util.ThrowOnNullOrEmptyArgument(provider, "provider"); Util.ThrowOnNullOrEmptyArgument(userId, "userId"); Guid providerGuid; if (!OscProviderRegistry.TryGetGuidFromName(provider, out providerGuid)) { OscSyncLockLocator.Tracer.TraceError <string>((long)this.GetHashCode(), "SyncLock locator: cannot find for unknown provider: {0}", provider); throw new ObjectNotFoundException(ServerStrings.UnknownOscProvider(provider)); } OscNetworkMoniker oscNetworkMoniker = new OscNetworkMoniker(providerGuid, networkId, userId); foreach (IStorePropertyBag storePropertyBag in new OscSyncLockEnumerator(this.session, this.session.GetDefaultFolderId(DefaultFolderType.Contacts), this.xsoFactory)) { VersionedId valueOrDefault = storePropertyBag.GetValueOrDefault <VersionedId>(ItemSchema.Id, null); if (valueOrDefault == null) { OscSyncLockLocator.Tracer.TraceError((long)this.GetHashCode(), "SyncLock locator: skipping SyncLock because its id is missing."); } else { string text = this.ExtractNetworkMonikerFromSyncLock(storePropertyBag); OscSyncLockLocator.Tracer.TraceDebug <StoreObjectId, string>((long)this.GetHashCode(), "SyncLock locator: SyncLock with id '{0}' has network moniker '{1}'", valueOrDefault.ObjectId, text); if (oscNetworkMoniker.Equals(text)) { OscSyncLockLocator.Tracer.TraceDebug((long)this.GetHashCode(), "SyncLock locator: found for provider '{0}', user id '{1}', and network id '{2}'. Id is '{3}'", new object[] { provider, userId, networkId, valueOrDefault.ObjectId }); return(valueOrDefault.ObjectId); } } } OscSyncLockLocator.Tracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "SyncLock locator: for provider '{0}', user id '{1}', and network id '{2}' not found.", provider, userId, networkId); throw new ObjectNotFoundException(ServerStrings.OscSyncLockNotFound(provider, userId, networkId)); }
internal StoreObjectId Find(string provider, string userId, string networkId) { Util.ThrowOnNullOrEmptyArgument(provider, "provider"); Util.ThrowOnNullOrEmptyArgument(userId, "userId"); Guid guid; if (!OscProviderRegistry.TryGetGuidFromName(provider, out guid)) { OscFolderLocator.Tracer.TraceError <string>((long)this.GetHashCode(), "Folder locator: cannot find folder for unknown provider: {0}", provider); throw new ObjectNotFoundException(ServerStrings.UnknownOscProvider(provider)); } OscNetworkMoniker arg = new OscNetworkMoniker(guid, networkId, userId); foreach (IStorePropertyBag storePropertyBag in new OscProviderCandidateFolderEnumerator(this.session, guid, this.xsoFactory)) { VersionedId valueOrDefault = storePropertyBag.GetValueOrDefault <VersionedId>(FolderSchema.Id, null); if (valueOrDefault == null) { OscFolderLocator.Tracer.TraceError((long)this.GetHashCode(), "Folder locator: skipping folder with invalid id"); } else { OscFolderLocator.Tracer.TraceDebug <string, OscNetworkMoniker, StoreObjectId>((long)this.GetHashCode(), "Folder locator: looking for ContactSync FAI for provider '{0}' and moniker '{1}' in folder '{2}'", provider, arg, valueOrDefault.ObjectId); foreach (IStorePropertyBag item in new OscContactSyncFAIEnumerator(this.session, valueOrDefault.ObjectId, this.xsoFactory)) { foreach (OscNetworkMoniker oscNetworkMoniker in new OscFolderContactSourcesEnumerator(item)) { OscFolderLocator.Tracer.TraceDebug <OscNetworkMoniker, StoreObjectId>((long)this.GetHashCode(), "Folder locator: found network moniker '{0}' in folder '{1}'", oscNetworkMoniker, valueOrDefault.ObjectId); if (arg.Equals(oscNetworkMoniker)) { OscFolderLocator.Tracer.TraceDebug <string, StoreObjectId>((long)this.GetHashCode(), "Folder locator: found folder for provider '{0}'. Folder id is '{1}'", provider, valueOrDefault.ObjectId); return(valueOrDefault.ObjectId); } } } } } OscFolderLocator.Tracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "Folder locator: folder for provider: {0}; user id: {1}; network id: {2}; not found.", provider, userId, networkId); throw new ObjectNotFoundException(ServerStrings.OscFolderForProviderNotFound(provider)); }
private StoreObjectId GetParentFolderId(Guid provider) { return(this.session.GetDefaultFolderId(OscProviderRegistry.GetParentFolder(provider))); }
public OscNetworkProperties ReadOscContactSource(byte[] property) { if (property == null || property.Length == 0) { return(null); } OscNetworkProperties result; using (MemoryStream memoryStream = new MemoryStream(property)) { using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { try { short num = binaryReader.ReadInt16(); if (num < 2) { throw new OscContactSourcesForContactParseException(string.Format("Header version not supported: {0}", num)); } binaryReader.ReadInt16(); short num2 = binaryReader.ReadInt16(); if (num2 < 1) { throw new OscContactSourcesForContactParseException("No entries found in the property."); } short num3 = binaryReader.ReadInt16(); if (num3 < 2) { throw new OscContactSourcesForContactParseException(string.Format("Entry version not supported: {0}", num3)); } binaryReader.ReadInt16(); byte[] array = binaryReader.ReadBytes(16); if (array == null || array.Length != 16) { throw new OscContactSourcesForContactParseException("Corrupted provider GUID."); } Guid providerGuid = new Guid(array); string networkId; if (!OscProviderRegistry.TryGetNameFromGuid(providerGuid, out networkId)) { networkId = providerGuid.ToString("N"); } short count = binaryReader.ReadInt16(); binaryReader.ReadBytes((int)count); short count2 = binaryReader.ReadInt16(); string @string = Encoding.Unicode.GetString(binaryReader.ReadBytes((int)count2)); result = new OscNetworkProperties { NetworkId = networkId, NetworkUserId = @string }; } catch (ArgumentOutOfRangeException ex) { throw new OscContactSourcesForContactParseException(ex.Message); } catch (EndOfStreamException ex2) { throw new OscContactSourcesForContactParseException(ex2.Message); } } } return(result); }