public SynchronizationLogger(Guid profileId, string profileName) { _startTime = DateTime.UtcNow; _profileName = profileName; _profileId = profileId; _aLoadEntityLogger = new LoadEntityLogger(_loadErrors, _loadErrorsLock, true); _bLoadEntityLogger = new LoadEntityLogger(_loadErrors, _loadErrorsLock, false); }
public EntityContainer( Synchronizer <TAtypeEntityId, TAtypeEntityVersion, TAtypeEntity, TBtypeEntityId, TBtypeEntityVersion, TBtypeEntity> context, ITotalProgressLogger totalProgress, ILoadEntityLogger logger) { _context = context; _totalProgress = totalProgress; _logger = logger; }
public SynchronizationLogger(Guid profileId, string profileName) { _startTime = DateTime.UtcNow; _profileName = profileName; _profileId = profileId; _currentSynchronitzationLogger = new EntitySynchronizationLogger(); _currentSynchronitzationLogger.Disposed += CurrentSynchronitzationLogger_Disposed; _aLoadEntityLogger = new LoadEntityLogger(_loadErrors, _loadErrorsLock, true); _bLoadEntityLogger = new LoadEntityLogger(_loadErrors, _loadErrorsLock, false); }
public EntityContainer( Synchronizer <TAtypeEntityId, TAtypeEntityVersion, TAtypeEntity, TBtypeEntityId, TBtypeEntityVersion, TBtypeEntity, TContext> context, ITotalProgressLogger totalProgress, ILoadEntityLogger aLogger, ILoadEntityLogger bLogger) { _context = context; _totalProgress = totalProgress; _aLogger = aLogger; _bLogger = bLogger; }
public EntityContainer( Synchronizer <TAtypeEntityId, TAtypeEntityVersion, TAtypeEntity, TBtypeEntityId, TBtypeEntityVersion, TBtypeEntity, TContext> context, ITotalProgressLogger totalProgress, ILoadEntityLogger aLogger, ILoadEntityLogger bLogger) { _context = context; _totalProgress = totalProgress; _aLogger = aLogger; _bLogger = bLogger; _loadedAEntities = new Dictionary <TAtypeEntityId, TAtypeEntity>(context._atypeIdComparer); _loadedBEntities = new Dictionary <TBtypeEntityId, TBtypeEntity>(context._btypeIdComparer); }
private static bool TryDeserializeCalendar( string iCalData, out IICalendar calendar, WebResourceName uriOfCalendarForLogging, IStringSerializer calendarSerializer, ILoadEntityLogger logger) { calendar = null; try { calendar = DeserializeCalendar(iCalData, calendarSerializer); return(true); } catch (Exception x) { s_logger.Error(string.Format("Could not deserialize ICalData of '{0}'.", uriOfCalendarForLogging.OriginalAbsolutePath)); s_logger.Debug(string.Format("ICalData:\r\n{0}", iCalData), x); logger.LogSkipLoadBecauseOfError(uriOfCalendarForLogging, x); return(false); } }
private static bool TryDeserialize( string vcardData, out vCard vcard, WebResourceName uriOfAddressbookForLogging, vCardStandardReader deserializer, ILoadEntityLogger logger) { vcard = null; string fixedVcardData = ContactDataPreprocessor.FixRevisionDate(vcardData); string fixedVcardData2 = ContactDataPreprocessor.FixUrlType(fixedVcardData); try { vcard = Deserialize(fixedVcardData2, deserializer); return(true); } catch (Exception x) { s_logger.Error(string.Format("Could not deserialize vcardData of '{0}':\r\n{1}", uriOfAddressbookForLogging, fixedVcardData2), x); logger.LogSkipLoadBecauseOfError(uriOfAddressbookForLogging, x); return(false); } }
protected override bool TryDeserialize( string vcardData, out vCard vcard, WebResourceName uriOfAddressbookForLogging, vCardStandardReader deserializer, ILoadEntityLogger logger) { vcard = null; // fix some linebreak issues with Open-Xchange string normalizedVcardData = vcardData.Contains("\r\r\n") ? ContactDataPreprocessor.NormalizeLineBreaks(vcardData) : vcardData; try { vcard = Deserialize(normalizedVcardData, deserializer); return(true); } catch (Exception x) { s_logger.Error(string.Format("Could not deserialize vcardData of '{0}':\r\n{1}", uriOfAddressbookForLogging, normalizedVcardData), x); logger.LogSkipLoadBecauseOfError(uriOfAddressbookForLogging, x); return(false); } }
public async Task <IReadOnlyList <EntityWithId <string, Task> > > Get(ICollection <string> ids, ILoadEntityLogger logger, int context) { var items = new List <EntityWithId <string, Task> > (); // All the requests are awaited sequentially in a loop, because creating all the requests at once ant awaiting them after the loop would // probably open up too many connections foreach (var id in ids) { var item = await _tasksService.Tasks.Get(_taskList.Id, id).ExecuteAsync(); items.Add(EntityWithId.Create(item.Id, item)); } return(items); }
public async Task <IReadOnlyList <EntityWithId <string, GoogleContactWrapper> > > Get(ICollection <string> ids, ILoadEntityLogger logger, GoogleContactContext context) { var result = new List <EntityWithId <string, GoogleContactWrapper> >(); foreach (var id in ids) { Contact contact; if (context.ContactsById.TryGetValue(id, out contact)) { result.Add(EntityWithId.Create(contact.Id, new GoogleContactWrapper(contact))); } } var groups = context.GroupCache.Groups.ToDictionary(g => g.Id); foreach (var contactWrapper in result) { foreach (var group in contactWrapper.Entity.Contact.GroupMembership) { if (!context.GroupCache.IsDefaultGroupId(group.HRef)) { contactWrapper.Entity.Groups.Add(groups[group.HRef].Title); } } } if (_contactMappingConfiguration.MapContactPhoto) { await Task.Run(() => { foreach (var contactWrapper in result) { if (contactWrapper.Entity.Contact.PhotoEtag != null) { using (var photoStream = _apiOperationExecutor.Execute(f => f.Service.Query(contactWrapper.Entity.Contact.PhotoUri))) { var memoryStream = new MemoryStream(); photoStream.CopyTo(memoryStream); // ReSharper disable once PossibleAssignmentToReadonlyField contactWrapper.Entity.PhotoOrNull = memoryStream.ToArray(); } } } }); } return(result); }
public async Task <IEnumerable <EntityWithId <WebResourceName, vCard> > > Get(ICollection <WebResourceName> ids, ILoadEntityLogger logger, TContext context) { return((await _decorated.Get(ids, logger, context)).Where(c => _typeDetector.GetVCardType(c.Entity) == _typeToFilter)); }
/* * BEGIN:VLIST * UID:4250-58658600-5-45D0678.vlf * VERSION:1.0 * FN:Simpsons * CARD;[email protected];FN="Simpson, Homer":5228bf7b-f3a6-4c16-ae3e-90102d86ab43.vcf * CARD;[email protected];FN="Simpson, Marge":c520e3ad-3d19-4c2f-b093-3f17736bce8e.vcf * END:VLIST */ protected override bool TryDeserialize(string vcardData, out DistributionList vcard, WebResourceName uriOfAddressbookForLogging, int deserializationThreadLocal, ILoadEntityLogger logger) { var cardReader = new vCardStandardReader(); vcard = new DistributionList(); using (var reader = new StringReader(vcardData)) { vCardProperty property; do { property = cardReader.ReadProperty(reader); if (!string.IsNullOrEmpty(property?.Name)) { var propNameToProcess = property.Name.ToUpperInvariant(); switch (propNameToProcess) { case "UID": vcard.Uid = property.ToString(); break; case "FN": vcard.Name = property.ToString(); break; case "DESCRIPTION": vcard.Description = property.ToString(); break; case "NICKNAME": vcard.Nickname = property.ToString(); break; case "CARD": if (property.Value != null) { var emailAddress = property.Subproperties.GetValue("EMAIL"); var displayName = property.Subproperties.GetValue("FN"); vcard.Members.Add(new KnownDistributionListMember(emailAddress, displayName, property.Value.ToString())); } break; case NonAddressBookMemberValueName: if (property.Value != null) { var displayName = property.Subproperties.GetValue("CN"); string emailAddress = null; var value = property.Value.ToString(); if (!string.IsNullOrEmpty(value)) { if (value.StartsWith("mailto:", StringComparison.InvariantCultureIgnoreCase)) { emailAddress = value.Substring(7); //skip mailto: } } vcard.NonAddressBookMembers.Add(new DistributionListMember(emailAddress, displayName)); } break; } } } while (property != null); } return(true); }
public Task <IEnumerable <EntityWithId <WebResourceName, vCard> > > Get(ICollection <WebResourceName> ids, ILoadEntityLogger logger, TContext context) { return(_decorated.Get(ids, logger, context)); }
#pragma warning disable 1998 public async Task <IReadOnlyList <EntityWithId <string, ContactItemWrapper> > > Get(ICollection <string> ids, ILoadEntityLogger logger) #pragma warning restore 1998 { return(ids .Select(id => EntityWithId.Create( id, new ContactItemWrapper( (ContactItem)_mapiNameSpace.GetItemFromID(id, _folderStoreId), entryId => (ContactItem)_mapiNameSpace.GetItemFromID(entryId, _folderStoreId)))) .ToArray()); }
/* * BEGIN:VLIST * UID:4250-58658600-5-45D0678.vlf * VERSION:1.0 * FN:Simpsons * CARD;[email protected];FN="Simpson, Homer":5228bf7b-f3a6-4c16-ae3e-90102d86ab43.vcf * CARD;[email protected];FN="Simpson, Marge":c520e3ad-3d19-4c2f-b093-3f17736bce8e.vcf * END:VLIST */ protected override bool TryDeserialize(string vcardData, out DistributionList vcard, WebResourceName uriOfAddressbookForLogging, int deserializationThreadLocal, ILoadEntityLogger logger) { vcardData = vcardData.Replace("\r\n\t", string.Empty).Replace("\r\n ", string.Empty); vcard = new DistributionList(); foreach (var contentLine in vcardData.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)) { var valueStartIndex = contentLine.LastIndexOf(':') + 1; var value = contentLine.Substring(valueStartIndex); if (contentLine.StartsWith("UID")) { vcard.Uid = value; } else if (contentLine.StartsWith("FN")) { vcard.Name = vCardStandardReader.DecodeEscaped(value); } else if (contentLine.StartsWith("DESCRIPTION")) { vcard.Description = vCardStandardReader.DecodeEscaped(value); } else if (contentLine.StartsWith("NICKNAME")) { vcard.Nickname = vCardStandardReader.DecodeEscaped(value); } else if (contentLine.StartsWith("CARD")) { string displayName = null; string emailAddress = null; ParseMemberContentLineParameters(contentLine.Substring(0, valueStartIndex - 1), out emailAddress, out displayName); vcard.Members.Add(new KnownDistributionListMember(emailAddress, displayName, value)); } else if (contentLine.StartsWith(NonAddressBookMemberValueName)) { string displayName = null; string emailAddress = value; var contentWithoutMailto = contentLine.Substring(0, valueStartIndex - 8); // substract :mailto: ParseXAddressBookServerMemberContentLineParameters(contentWithoutMailto, out displayName); vcard.NonAddressBookMembers.Add(new DistributionListMember(emailAddress, displayName)); } } return(true); }
private Task <IReadOnlyList <EntityWithId <WebResourceName, IICalendar> > > ParallelDeserialize(IReadOnlyList <EntityWithId <WebResourceName, string> > serializedEntities, ILoadEntityLogger logger) { return(Task.Factory.StartNew(() => { var result = new List <EntityWithId <WebResourceName, IICalendar> >(); Parallel.ForEach( serializedEntities, () => Tuple.Create(new iCalendarSerializer(), new List <Tuple <WebResourceName, IICalendar> >()), (serialized, loopState, threadLocal) => { IICalendar calendar; string normalizedICalData, fixedICalData; // fix some linebreak issues with Open-Xchange if (serialized.Entity.Contains("\r\r\n")) { normalizedICalData = CalendarDataPreprocessor.NormalizeLineBreaks(serialized.Entity); } else { normalizedICalData = serialized.Entity; } // emClient sets DTSTART in VTIMEZONE to year 0001, which causes a 90 sec delay in DDay.iCal to evaluate the recurrence rule. // If we find such a DTSTART we replace it 0001 with 1970 since the historic data is not valid anyway and avoid the performance issue. if (normalizedICalData.Contains("DTSTART:00010101")) { fixedICalData = CalendarDataPreprocessor.FixInvalidDTSTARTInTimeZoneNoThrow(normalizedICalData); s_logger.InfoFormat("Changed DTSTART from year 0001 to 1970 in VTIMEZONE of ICalData '{0}'.", serialized.Id); } else { fixedICalData = normalizedICalData; } if (TryDeserializeCalendar(fixedICalData, out calendar, serialized.Id, threadLocal.Item1, NullLoadEntityLogger.Instance)) { threadLocal.Item2.Add(Tuple.Create(serialized.Id, calendar)); } else { // maybe deserialization failed because of the iCal-TimeZone-Bug => try to fix it var fixedICalData2 = CalendarDataPreprocessor.FixTimeZoneComponentOrderNoThrow(fixedICalData); if (TryDeserializeCalendar(fixedICalData2, out calendar, serialized.Id, threadLocal.Item1, logger)) { threadLocal.Item2.Add(Tuple.Create(serialized.Id, calendar)); s_logger.Info(string.Format("Deserialized ICalData with reordering of TimeZone data '{0}'.", serialized.Id)); } } return threadLocal; }, threadLocal => { lock (result) { foreach (var calendar in threadLocal.Item2) { result.Add(EntityWithId.Create(calendar.Item1, calendar.Item2)); } } }); IReadOnlyList <EntityWithId <WebResourceName, IICalendar> > readOnlyResult = result; return readOnlyResult; })); }
public async Task <IReadOnlyDictionary <TEntityId, TEntity> > GetEntities(ICollection <TEntityId> ids, ILoadEntityLogger logger, TContext context) { var entitesToCleanup = new List <TEntity>(); var entitiesToLoad = new HashSet <TEntityId>(ids, _idComparer); foreach (var kvPair in _cachedEntities.ToArray()) { if (ids.Contains(kvPair.Key)) { entitiesToLoad.Remove(kvPair.Key); } else { _cachedEntities.Remove(kvPair.Key); entitesToCleanup.Add(kvPair.Value); } } _repository.Cleanup(entitesToCleanup); if (entitiesToLoad.Any()) { AddToDictionary(_cachedEntities, await _repository.Get(entitiesToLoad, logger, context)); } return(_cachedEntities); }
public async Task <IReadOnlyList <T> > SelectEntities <T>(ICollection <TEntityId> ids, ILoadEntityLogger logger, TContext context, Func <EntityWithId <TEntityId, TEntity>, T> selector) { return(await _chunkedExecutor.ExecuteAsync( new List <T>(), ids, async (chunk, transformedEntities) => { var entites = CacheOrClenaup(await _repository.Get(chunk, logger, context)); transformedEntities.AddRange(entites.Select(selector)); })); }
public async Task <IReadOnlyDictionary <TEntityId, T> > GetTransformedEntities <T>(ICollection <TEntityId> ids, ILoadEntityLogger logger, TContext context, Func <EntityWithId <TEntityId, TEntity>, T> transform) { return(await _chunkedExecutor.ExecuteAsync( new Dictionary <TEntityId, T>(_idComparer), ids, async (chunk, transformedEntities) => { var entites = CreateEnumerableWhichCachesOrCleansUp(await _repository.Get(chunk, logger, context)); foreach (var entity in entites) { if (!transformedEntities.ContainsKey(entity.Id)) { transformedEntities.Add(entity.Id, transform(entity)); } else { s_logger.WarnFormat("Entitiy '{0}' was contained multiple times in repository response. Ignoring redundant entity", entity.Id); } } })); }
#pragma warning disable 1998 public async Task <IReadOnlyList <EntityWithId <AppointmentId, AppointmentItemWrapper> > > Get(ICollection <AppointmentId> ids, ILoadEntityLogger logger, IEventSynchronizationContext context) #pragma warning restore 1998 { return(ids .Select(id => EntityWithId.Create( id, new AppointmentItemWrapper( (AppointmentItem)_mapiNameSpace.GetItemFromID(id.EntryId, _folderStoreId), entryId => (AppointmentItem)_mapiNameSpace.GetItemFromID(entryId, _folderStoreId)))) .ToArray()); }
#pragma warning disable 1998 public async Task <IEnumerable <EntityWithId <AppointmentId, IAppointmentItemWrapper> > > Get(ICollection <AppointmentId> ids, ILoadEntityLogger logger, IEventSynchronizationContext context) #pragma warning restore 1998 { return(ids .Select(id => EntityWithId.Create( id, _comWrapperFactory.Create( _session.GetAppointmentItem(id.EntryId, _folderStoreId), entryId => _session.GetAppointmentItem(entryId, _folderStoreId))))); }
#pragma warning disable 1998 public async Task <IReadOnlyList <EntityWithId <string, GenericComObjectWrapper <DistListItem> > > > Get(ICollection <string> ids, ILoadEntityLogger logger, Tcontext context) #pragma warning restore 1998 { return(ids .Select(id => EntityWithId.Create( id, GenericComObjectWrapper.Create( (DistListItem)_mapiNameSpace.GetItemFromID(id, _folderStoreId)))) .ToArray()); }
protected abstract bool TryDeserialize( string vcardData, out TEntity vcard, WebResourceName uriOfAddressbookForLogging, TDeserializationThreadLocal deserializationThreadLocal, ILoadEntityLogger logger);
public async Task <IReadOnlyList <EntityWithId <WebResourceName, IICalendar> > > Get(ICollection <WebResourceName> ids, ILoadEntityLogger logger) { if (ids.Count == 0) { return new EntityWithId <WebResourceName, IICalendar>[] { } } ; using (AutomaticStopwatch.StartInfo(s_logger, string.Format("CalDavRepository.Get ({0} entitie(s))", ids.Count))) { var entities = await _calDavDataAccess.GetEntities(ids); return(await ParallelDeserialize(entities, logger)); } }
public async Task <IReadOnlyList <EntityWithId <WebResourceName, TEntity> > > Get(ICollection <WebResourceName> ids, ILoadEntityLogger logger, TContext context) { if (ids.Count == 0) { return new EntityWithId <WebResourceName, TEntity>[] { } } ; return(await _chunkedExecutor.ExecuteAsync( new List <EntityWithId <WebResourceName, TEntity> >(), ids, async (chunk, result) => { var entities = await GetInternal(chunk, logger); result.AddRange(entities); })); }
public async Task <IEnumerable <EntityWithId <WebResourceName, TEntity> > > Get(ICollection <WebResourceName> ids, ILoadEntityLogger logger, TContext context) { if (ids.Count == 0) { return new EntityWithId <WebResourceName, TEntity>[] { } } ; using (AutomaticStopwatch.StartInfo(s_logger, string.Format("CardDavRepository.Get ({0} entitie(s))", ids.Count))) { var entities = await _cardDavDataAccess.GetEntities(ids); return(ParallelDeserialize(entities, logger)); } }
public async Task <IEnumerable <EntityWithId <WebResourceName, vCard> > > Get(ICollection <WebResourceName> ids, ILoadEntityLogger logger, ICardDavRepositoryLogger context) { var result = await _inner.Get(ids, logger, 0); foreach (var entity in result) { context.LogEntityExists(entity.Id, entity.Entity); } return(result); }
public Task <IReadOnlyList <EntityWithId <Identifier, string> > > Get(ICollection <Identifier> ids, ILoadEntityLogger logger) { return(Task.FromResult <IReadOnlyList <EntityWithId <Identifier, string> > > ( ids.Select(id => EntityWithId.Create(id, EntityVersionAndContentById[id].Item2)).ToArray())); }
#pragma warning disable 1998 public async Task <IEnumerable <EntityWithId <string, IContactItemWrapper> > > Get(ICollection <string> ids, ILoadEntityLogger logger, Tcontext context) #pragma warning restore 1998 { return(ids .Select(id => EntityWithId.Create( id, _comWrapperFactory.Create( _session.GetContactItem(id, _folderStoreId), entryId => _session.GetContactItem(entryId, _folderStoreId))))); }
private IReadOnlyList <EntityWithId <WebResourceName, TEntity> > ParallelDeserialize(IReadOnlyList <EntityWithId <WebResourceName, string> > serializedEntities, ILoadEntityLogger logger) { var result = new List <EntityWithId <WebResourceName, TEntity> >(); Parallel.ForEach( serializedEntities, () => Tuple.Create(new TDeserializationThreadLocal(), new List <Tuple <WebResourceName, TEntity> >()), (serialized, loopState, threadLocal) => { TEntity entity; if (TryDeserialize(serialized.Entity, out entity, serialized.Id, threadLocal.Item1, logger)) { threadLocal.Item2.Add(Tuple.Create(serialized.Id, entity)); } return(threadLocal); }, threadLocal => { lock (result) { foreach (var card in threadLocal.Item2) { result.Add(EntityWithId.Create(card.Item1, card.Item2)); } } }); return(result); }