Beispiel #1
0
        private void CheckEvent(string eventData, AppointmentId appointmentId, int[] expectedSequenceNumbers)
        {
            var calendar = OutlookTestContext.DeserializeICalendar(eventData);

            Assert.That(calendar.Events.Count, Is.EqualTo(3));

            var masterEvent    = calendar.Events.Single(e => e.Summary == "Treffen");
            var exeption1Event = calendar.Events.Single(e => e.Summary == "Ex 1");
            var exeption2Event = calendar.Events.Single(e => e.Summary == "Ex 2");

            CollectionAssert.AreEquivalent(expectedSequenceNumbers, calendar.Events.Select(e => e.Sequence));
            Assert.That(exeption1Event.UID, Is.EqualTo(masterEvent.UID));
            Assert.That(exeption2Event.UID, Is.EqualTo(masterEvent.UID));

            using (var masterAppointment = OutlookTestContext.GetOutlookEvent(appointmentId))
            {
                GenericComObjectWrapper <AppointmentItem> exeption1Appointment;
                GenericComObjectWrapper <AppointmentItem> exeption2Appointment;

                using (var r = GenericComObjectWrapper.Create(masterAppointment.Inner.GetRecurrencePattern()))
                {
                    exeption1Appointment = GenericComObjectWrapper.Create(r.Inner.Exceptions[1].AppointmentItem);
                    exeption2Appointment = GenericComObjectWrapper.Create(r.Inner.Exceptions[2].AppointmentItem);
                }

                Assert.That(masterEvent.Start.Value, Is.EqualTo(masterAppointment.Inner.Start));
                Assert.That(exeption1Event.Start.Value, Is.EqualTo(exeption1Appointment.Inner.Start));
                Assert.That(exeption2Event.Start.Value, Is.EqualTo(exeption2Appointment.Inner.Start));
            }
        }
Beispiel #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (UserId != 0)
            {
                hash ^= UserId.GetHashCode();
            }
            if (AppointmentId != 0)
            {
                hash ^= AppointmentId.GetHashCode();
            }
            if (ActiveState != 0)
            {
                hash ^= ActiveState.GetHashCode();
            }
            hash ^= activeGates_.GetHashCode();
            hash ^= finishGates_.GetHashCode();
            if (CreateTime != 0L)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (LastModifyTime != 0L)
            {
                hash ^= LastModifyTime.GetHashCode();
            }
            return(hash);
        }
Beispiel #3
0
 private ImportRequest CreateAppendRequest()
 => new ImportRequest(
     "mboc_upsertAppointmentUrl",
     new List <string> {
     "pSourceApp", "pSourceType", "pAppointmentId", "pAppointmentGuid", "pUrl", "pUrlDesc"
 }.ToArray(),
     new List <string> {
     SourceApp, SourceType, AppointmentId.ToString(), AppointmentGuid?.ToString(), Uri, Description
 }.ToArray());
Beispiel #4
0
        public override bool Equals(object obj)
        {
            var appointment = obj as Appointment;

            return(appointment != null &&
                   AppointmentId.Equals(appointment.AppointmentId) &&
                   Title == appointment.Title &&
                   StartTime == appointment.StartTime &&
                   EndTime == appointment.EndTime);
        }
        public async Task HandleAsync(ScheduleAppointmentCommand command, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var unitOfWork = await _unitOfWorkFactory.CreateAsync())
            {
                // Convert from external representations to domain representations
                var appointmentId       = new AppointmentId(command.AppointmentId);
                var doctorId            = new DoctorId(command.DoctorId);
                var patientId           = new PatientId(command.PatientId);
                var appointmentDuration = new AppointmentDuration(command.AppointmentDurationInMinutes);

                // Invoke domain logic
                await _scheduleAppointmentService.ScheduleAsync(appointmentId, doctorId, patientId, command.AppointmentAt,
                                                                appointmentDuration, cancellationToken);

                await unitOfWork.CommitAsync();
            }
        }
 public static AppointmentItemWrapper GetOutlookEvent (AppointmentId id)
 {
   return OutlookEventRepository.GetOutlookEventForTesting (id.EntryId, s_mapiNameSpace, s_outlookFolderStoreId);
 }
    public static string SyncOutlookToCalDav_EventsExistsInCalDav (string existingEventData, AppointmentId existingAppointmentId)
    {
      var entityRelationStorage = new InMemoryEntityRelationStorage<AppointmentId, DateTime, IEntityRelationData<AppointmentId, DateTime, WebResourceName, string>, WebResourceName, string>();
      entityRelationStorage.SaveEntityRelationData (new List<IEntityRelationData<AppointmentId, DateTime, WebResourceName, string>>()
                                                    {
                                                        new OutlookEventRelationData()
                                                        {
                                                            AtypeId = existingAppointmentId,
                                                            AtypeVersion = new DateTime (1),
                                                            BtypeId = new WebResourceName("/e1"),
                                                            BtypeVersion = "v1"
                                                        }
                                                    });

      return SyncOutlookToCalDav_EventsExistsInCalDav (existingEventData, entityRelationStorage);
    }
Beispiel #8
0
 public static AppointmentItemWrapper GetOutlookEvent(AppointmentId id)
 {
     return(OutlookEventRepository.GetOutlookEventForTesting(id.EntryId, s_mapiNameSpace, s_outlookFolderStoreId));
 }
Beispiel #9
0
        public static string SyncOutlookToCalDav_EventsExistsInCalDav(string existingEventData, AppointmentId existingAppointmentId)
        {
            var entityRelationStorage = new InMemoryEntityRelationStorage <AppointmentId, DateTime, IEntityRelationData <AppointmentId, DateTime, WebResourceName, string>, WebResourceName, string>();

            entityRelationStorage.SaveEntityRelationData(new List <IEntityRelationData <AppointmentId, DateTime, WebResourceName, string> >()
            {
                new OutlookEventRelationData()
                {
                    AtypeId      = existingAppointmentId,
                    AtypeVersion = new DateTime(1),
                    BtypeId      = new WebResourceName("/e1"),
                    BtypeVersion = "v1"
                }
            });

            return(SyncOutlookToCalDav_EventsExistsInCalDav(existingEventData, entityRelationStorage));
        }
        List <AppointmentSlim> IQueryOutlookAppointmentItemFolderStrategy.QueryAppointmentFolder(IOutlookSession session, Folder calendarFolder, string filter, IGetVersionsLogger logger)
        {
            var events = new List <AppointmentSlim>();

            using (var tableWrapper = GenericComObjectWrapper.Create(
                       calendarFolder.GetTable(filter)))
            {
                var table = tableWrapper.Inner;
                table.Columns.RemoveAll();
                table.Columns.Add(PR_GLOBAL_OBJECT_ID);
                table.Columns.Add(PR_LONG_TERM_ENTRYID_FROM_TABLE);
                table.Columns.Add(PR_ENTRYID);
                table.Columns.Add(LastModificationTimeColumnId);
                table.Columns.Add(SubjectColumnId);
                table.Columns.Add(StartColumnId);
                table.Columns.Add(EndColumnId);

                while (!table.EndOfTable)
                {
                    var row = table.GetNextRow();

                    string entryId;
                    byte[] entryIdArray = row[PR_LONG_TERM_ENTRYID_FROM_TABLE] as byte[];
                    if (entryIdArray != null && entryIdArray.Length > 0)
                    {
                        entryId = row.BinaryToString(PR_LONG_TERM_ENTRYID_FROM_TABLE);
                    }
                    else
                    {
                        // Fall back to short-term ENTRYID if long-term ID not available
                        entryId = row.BinaryToString(PR_ENTRYID);
                        s_logger.Warn($"Could not access long-term ENTRYID of appointment '{entryId}', use short-term ENTRYID as fallback.");
                    }

                    string globalAppointmentId = null;
                    try
                    {
                        byte[] globalIdArray = row[PR_GLOBAL_OBJECT_ID] as byte[];
                        if (globalIdArray != null && globalIdArray.Length > 0)
                        {
                            globalAppointmentId = row.BinaryToString(PR_GLOBAL_OBJECT_ID);
                        }
                    }
                    catch (Exception ex)
                    {
                        s_logger.Warn($"Could not access GlobalAppointmentID of appointment '{entryId}'.", ex);
                    }

                    var subject       = (string)row[SubjectColumnId];
                    var appointmentId = new AppointmentId(entryId, globalAppointmentId);

                    var      lastModificationTimeObject = row[LastModificationTimeColumnId];
                    DateTime lastModificationTime;
                    if (lastModificationTimeObject != null)
                    {
                        lastModificationTime = ((DateTime)lastModificationTimeObject).ToUniversalTime();
                    }
                    else
                    {
                        s_logger.Warn($"Column '{nameof(LastModificationTimeColumnId)}' of event '{entryId}' is NULL.");
                        logger.LogWarning(entryId, $"Column '{nameof(LastModificationTimeColumnId)}' is NULL.");
                        lastModificationTime = OutlookUtility.OUTLOOK_DATE_NONE;
                    }

                    var      startObject = row[StartColumnId];
                    DateTime?start;
                    if (startObject != null)
                    {
                        start = (DateTime)startObject;
                    }
                    else
                    {
                        s_logger.Warn($"Column '{nameof(StartColumnId)}' of event '{entryId}' is NULL.");
                        logger.LogWarning(entryId, $"Column '{nameof(StartColumnId)}' is NULL.");
                        start = null;
                    }

                    var      endObject = row[EndColumnId];
                    DateTime?end;
                    if (endObject != null)
                    {
                        end = (DateTime)endObject;
                    }
                    else
                    {
                        s_logger.Warn($"Column '{nameof(EndColumnId)}' of event '{entryId}' is NULL.");
                        logger.LogWarning(entryId, $"Column '{nameof(EndColumnId)}' is NULL.");
                        end = null;
                    }

                    events.Add(new AppointmentSlim(EntityVersion.Create(appointmentId, lastModificationTime.ToUniversalTime()), start, end, subject));
                }
            }

            return(events);
        }
 private async Task<Tuple<AppointmentId, AppointmentItemWrapper>[]> GetAppointmentsWithId (AppointmentId[] ids)
 {
   return (await Task.WhenAll (ids.Select (async i => Tuple.Create( i, await GetOrNull (i) )))).Where (a => a.Item2 != null).ToArray();
 }
 private async Task<AppointmentItemWrapper[]> GetAppointments(AppointmentId[] ids)
 {
   return (await Task.WhenAll(ids.Select(GetOrNull).Where(a => a != null))).ToArray();
 }
 private async Task DeleteAppointment (AppointmentItemWrapper item, Dictionary<AppointmentId, IEntityRelationData<AppointmentId, DateTime, WebResourceName, string>> relations)
 {
   IEntityRelationData<AppointmentId, DateTime, WebResourceName, string> relation;
   var appointmentId = new AppointmentId(item.Inner.EntryID, item.Inner.GlobalAppointmentID);
   if (relations.TryGetValue (appointmentId, out relation))
   {
     await _btypeRepository.TryDelete (relation.BtypeId, relation.BtypeVersion, NullEventSynchronizationContext.Instance);
     relations.Remove (appointmentId);
   }
   item.Inner.Delete();
 }
Beispiel #14
0
        private void SwitchEventCategories(ChangedOptions changedOption, string oldCategory, string newCategory, AppointmentId eventId)
        {
            using (var eventWrapper = new AppointmentItemWrapper(
                       (AppointmentItem)_session.GetItemFromID(eventId.EntryId, changedOption.New.OutlookFolderStoreId),
                       entryId => (AppointmentItem)_session.GetItemFromID(entryId, changedOption.New.OutlookFolderStoreId)))
            {
                var categories = eventWrapper.Inner.Categories
                                 .Split(new[] { CultureInfo.CurrentCulture.TextInfo.ListSeparator }, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(c => c.Trim());

                eventWrapper.Inner.Categories = string.Join(
                    CultureInfo.CurrentCulture.TextInfo.ListSeparator,
                    categories
                    .Except(new[] { oldCategory })
                    .Concat(new[] { newCategory })
                    .Distinct());

                eventWrapper.Inner.Save();
            }
        }
 public async Task Handle(LocationSet @event)
 {
     var command = new AppointmentBookCommand(AppointmentId.With(@event.Id));
     await commandBus.PublishAsync(command, cancellationToken : CancellationToken.None);
 }
    private void CheckEvent (string eventData, AppointmentId appointmentId, int[] expectedSequenceNumbers)
    {
      var calendar = OutlookTestContext.DeserializeICalendar (eventData);

      Assert.That (calendar.Events.Count, Is.EqualTo (3));

      var masterEvent = calendar.Events.Single (e => e.Summary == "Treffen");
      var exeption1Event = calendar.Events.Single (e => e.Summary == "Ex 1");
      var exeption2Event = calendar.Events.Single (e => e.Summary == "Ex 2");

      CollectionAssert.AreEquivalent (expectedSequenceNumbers, calendar.Events.Select (e => e.Sequence));
      Assert.That (exeption1Event.UID, Is.EqualTo (masterEvent.UID));
      Assert.That (exeption2Event.UID, Is.EqualTo (masterEvent.UID));

      using (var masterAppointment = OutlookTestContext.GetOutlookEvent (appointmentId))
      {
        GenericComObjectWrapper<AppointmentItem> exeption1Appointment;
        GenericComObjectWrapper<AppointmentItem> exeption2Appointment;

        using (var r = GenericComObjectWrapper.Create (masterAppointment.Inner.GetRecurrencePattern()))
        {
          exeption1Appointment = GenericComObjectWrapper.Create (r.Inner.Exceptions[1].AppointmentItem);
          exeption2Appointment = GenericComObjectWrapper.Create (r.Inner.Exceptions[2].AppointmentItem);
        }

        Assert.That (masterEvent.Start.Value, Is.EqualTo (masterAppointment.Inner.Start));
        Assert.That (exeption1Event.Start.Value, Is.EqualTo (exeption1Appointment.Inner.Start));
        Assert.That (exeption2Event.Start.Value, Is.EqualTo (exeption2Appointment.Inner.Start));
      }
    }
    async Task<AppointmentItemWrapper> GetOrNull (AppointmentId id)
    {
      try
      {
        var itemById =
          await _outlookRepository.Get (
            new[] { id },
            NullLoadEntityLogger.Instance,
            NullEventSynchronizationContext.Instance);

        return itemById.FirstOrDefault ()?.Entity;
      }
      catch (COMException x) when (x.HResult == unchecked((int) 0x8004010F))
      {
        return null;
      }
    }
Beispiel #18
0
 public Task HandleAsync(IDomainEvent <OrderAggregate, OrderId, OrderPaymentCompleted> domainEvent, ISagaContext sagaContext, CancellationToken cancellationToken)
 {
     completed = true;
     Publish(new AppointmentCompletedCommand(AppointmentId.With(base.Id.Value)));
     return(Task.CompletedTask);
 }
 public void AnnounceAppointmentDeleted (AppointmentId id)
 {
   _hashesById.Remove (id);
 }
        public async Task ScheduleAsync(AppointmentId appointmentId, DoctorId doctorId, PatientId patientId, DateTime requestedAppointmentAt, AppointmentDuration requestedAppointmentDuration,
                                        CancellationToken cancellationToken = default)
        {
            if (requestedAppointmentAt < _systemClockService.UtcNow.DateTime)
            {
                throw new DomainValidationException("The appointment could not be scheduled because it occurs in the past.");
            }

            var doctor = await _doctorRepository.GetByIdAsync(doctorId, cancellationToken);

            if (doctor == null)
            {
                throw new EntityNotFoundException("The requested doctor was not found.");
            }

            var patient = await _patientRepository.GetByIdAsync(patientId, cancellationToken);

            if (patient == null)
            {
                throw new EntityNotFoundException("The requested patient was not found.");
            }

            // Does the requested appointment occur during the doctor's availability?

            var doctorAvailabilities = await _doctorAvailabilityRepository.GetAllForDoctorAsync(doctorId, cancellationToken);

            var doctorIsAvailable = doctorAvailabilities.Any(a =>
                                                             a.DayOfWeek == requestedAppointmentAt.DayOfWeek &&                            // Occurs on an available day of the week
                                                             a.StartsAt <= requestedAppointmentAt.TimeOfDay && // After that day of the week's start time
                                                             a.EndsAt >= requestedAppointmentAt.TimeOfDay + requestedAppointmentDuration); // And ends before that day of the week's end time

            if (!doctorIsAvailable)
            {
                throw new DomainValidationException("The appointment could not be scheduled because it is outside of the doctor's availability.");
            }

            // Determine if there are any scheduling conflicts.
            // Algorithm description: Two time periods overlap if each one starts before the other one ends.

            var doctorAppointments = await _appointmentRepository.GetAllUpcomingForDoctorAsync(doctorId, cancellationToken);

            var doctorHasConflictingAppointment = doctorAppointments.Any(existingAppointment =>
                                                                         requestedAppointmentAt < existingAppointment.AppointmentAt.Add(existingAppointment.AppointmentDuration) &&
                                                                         existingAppointment.AppointmentAt < requestedAppointmentAt.Add(requestedAppointmentDuration));

            if (doctorHasConflictingAppointment)
            {
                throw new DomainValidationException("The appointment could not be scheduled because the doctor has a conflicting appointment.");
            }

            var patientAppointments = await _appointmentRepository.GetAllUpcomingForPatientAsync(patientId, cancellationToken);

            var patientHasConflictingAppointment = patientAppointments.Any(existingAppointment =>
                                                                           requestedAppointmentAt < existingAppointment.AppointmentAt.Add(existingAppointment.AppointmentDuration) &&
                                                                           existingAppointment.AppointmentAt < requestedAppointmentAt.Add(requestedAppointmentDuration));

            if (patientHasConflictingAppointment)
            {
                throw new DomainValidationException("The appointment could not be scheduled because the patient has a conflicting appointment.");
            }

            var appointment = new Appointment(appointmentId, doctorId, patientId, requestedAppointmentAt, requestedAppointmentDuration);

            await _appointmentRepository.CreateAsync(appointment, cancellationToken);
        }
 public void AnnounceAppointmentDeleted (AppointmentId id)
 {
  
 }