Exemple #1
0
 private AddressHouseNumberPositionWasImportedFromCrab(
     int addressPositionId,
     int houseNumberId,
     string addressPosition,
     CrabAddressPositionOrigin addressPositionOrigin,
     string addressNature,
     LocalDateTime?beginDateTime,
     LocalDateTime?endDateTime,
     Instant timestamp,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation) :
     this(
         new CrabAddressPositionId(addressPositionId),
         new CrabHouseNumberId(houseNumberId),
         new WkbGeometry(addressPosition.ToByteArray()),
         addressPositionOrigin,
         new CrabAddressNature(addressNature),
         new CrabLifetime(beginDateTime, endDateTime),
         new CrabTimestamp(timestamp),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }
 public LocalInterval(LocalDateTime?start = null, LocalDateTime?end = null, TimePayloadBase payload = null, string name = null)
 {
     Name    = name;
     Start   = start;
     End     = end;
     Payload = payload;
 }
 private void CheckChangedStatus(LocalDateTime?endTime, CrabModification?crabModification)
 {
     if (!IsRetired && endTime != null)
     {
         if (crabModification == CrabModification.Correction)
         {
             ApplyChange(
                 new MunicipalityWasCorrectedToRetired(
                     _municipalityId,
                     new RetirementDate(endTime.Value.ToCrabInstant())));
         }
         else
         {
             ApplyChange(
                 new MunicipalityWasRetired(
                     _municipalityId,
                     new RetirementDate(endTime.Value.ToCrabInstant())));
         }
     }
     else if (!IsCurrent && endTime == null)
     {
         if (crabModification == CrabModification.Correction)
         {
             ApplyChange(new MunicipalityWasCorrectedToCurrent(_municipalityId));
         }
         else
         {
             ApplyChange(new MunicipalityBecameCurrent(_municipalityId));
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Operation{TOperationState}"/> class.
        /// </summary>
        /// <param name="id">Operation id.</param>
        /// <param name="state">Operation state.</param>
        /// <param name="status">Operation status.</param>
        /// <param name="startedAt">Date and time of start.</param>
        /// <param name="finishedAt">Date and time of finish.</param>
        /// <param name="exception">Exception occured on task execution.</param>
        /// <param name="metadata">Optional metadata.</param>
        public Operation(
            OperationId id,
            [DisallowNull] TOperationState state,
            OperationStatus status,
            LocalDateTime?startedAt,
            LocalDateTime?finishedAt,
            Exception?exception,
            IPropertyContainer?metadata)
        {
            state.AssertArgumentNotNull(nameof(state));

            Id     = id;
            State  = state;
            Status = status;

            StartedAt  = startedAt;
            FinishedAt = finishedAt;
            Exception  = exception;

            if (metadata == null)
            {
                // If state is metadata provider itself then use it as operation metadata.
                if (state is IMetadataProvider stateMetadataProvider &&
                    stateMetadataProvider.GetMetadataContainer(autoCreate: false) is { } stateMetadata)
                {
                    Metadata = stateMetadata.ToReadOnly();
                }
                else
                {
                    Metadata = PropertyContainer.Empty;
                }
            }
 private MunicipalityWasImportedFromCrab(
     int crabMunicipalityId,
     string nisCode,
     CrabLanguage?primaryLanguage,
     CrabLanguage?secondaryLanguage,
     int?numberOfFlags,
     LocalDateTime?beginDate,
     LocalDateTime?endDate,
     string wkbGeometry,
     Instant timestamp,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation) :
     this(
         new CrabMunicipalityId(crabMunicipalityId),
         new NisCode(nisCode),
         primaryLanguage,
         secondaryLanguage,
         numberOfFlags.HasValue ? new NumberOfFlags(numberOfFlags.Value) : null,
         new CrabLifetime(beginDate, endDate),
         string.IsNullOrWhiteSpace(wkbGeometry) ? null : new WkbGeometry(wkbGeometry),
         new CrabTimestamp(timestamp),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }
Exemple #6
0
 private PostalInformationWasImportedFromCrab(
     string postalCode,
     int subCantonId,
     string subCantonCode,
     string nisCode,
     string municipalityName,
     CrabLanguage?municipalityNameLanguage,
     LocalDateTime?beginDate,
     Instant timestamp,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation)
     : this(
         new PostalCode(postalCode),
         new CrabSubCantonId(subCantonId),
         new CrabSubCantonCode(subCantonCode),
         new NisCode(nisCode),
         new CrabMunicipalityName(municipalityName, municipalityNameLanguage),
         new CrabLifetime(beginDate, null),
         new CrabTimestamp(timestamp),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }
Exemple #7
0
 /// <summary>Error message if null or equal to the default constructed value.</summary>
 public static void CheckHasValue(this LocalDateTime?value)
 {
     if (!value.HasValue())
     {
         throw new Exception("Required datetime value is not set.");
     }
 }
Exemple #8
0
 private TerrainObjectWasImportedFromCrab(
     int terrainObjectId,
     string identifierTerrainObject,
     string terrainObjectNatureCode,
     decimal?xCoordinate,
     decimal?yCoordinate,
     string buildingNature,
     LocalDateTime?begin,
     LocalDateTime?end,
     Instant timestamp,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation) :
     this(
         new CrabTerrainObjectId(terrainObjectId),
         new CrabIdentifierTerrainObject(identifierTerrainObject),
         new CrabTerrainObjectNatureCode(terrainObjectNatureCode),
         xCoordinate.HasValue ? new CrabCoordinate(xCoordinate.Value) : null,
         yCoordinate.HasValue ? new CrabCoordinate(yCoordinate.Value) : null,
         new CrabBuildingNature(buildingNature),
         new CrabLifetime(begin, end),
         new CrabTimestamp(timestamp),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }
 private StreetNameWasImportedFromCrab(
     int streetNameId,
     int municipalityId,
     string primaryStreetName,
     string secondaryStreetName,
     string primaryTransStreetName,
     string secondaryTransStreetName,
     CrabLanguage?primaryLanguage,
     CrabLanguage?secondaryLanguage,
     Instant timestamp,
     LocalDateTime?beginDateTime,
     LocalDateTime?endDateTime,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation) :
     this(
         new CrabStreetNameId(streetNameId),
         new CrabMunicipalityId(municipalityId),
         string.IsNullOrEmpty(primaryStreetName) ? null : new CrabStreetName(primaryStreetName, primaryLanguage),
         string.IsNullOrEmpty(secondaryStreetName) ? null : new CrabStreetName(secondaryStreetName, secondaryLanguage),
         string.IsNullOrEmpty(primaryTransStreetName) ? null : new CrabTransStreetName(primaryTransStreetName, primaryLanguage),
         string.IsNullOrEmpty(secondaryTransStreetName) ? null : new CrabTransStreetName(secondaryTransStreetName, secondaryLanguage),
         primaryLanguage,
         secondaryLanguage,
         new CrabTimestamp(timestamp),
         new CrabLifetime(beginDateTime, endDateTime),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }
        [TestMethod] // ReSharper disable once InconsistentNaming
        public void GetEnumerator_Iterating_DifferenceBetweenIterationsMatchesStepSize()
        {
            Period        length = RandomPeriod(MinPeriod, MaxPeriod);
            LocalDateTime start  = RandomLocalDateTime(MinLocalDateTime, MaxLocalDateTime - length);
            LocalDateTime end    = start + length;
            // note that the number of steps is limited to 100 or fewer
            Period step = PeriodDivideApprox(length, Random.Next(4, 100));

            LocalDateTimeRange localRange = new LocalDateTimeRange(start, end, step);

            LocalDateTime?previous = null;

            foreach (LocalDateTime d in localRange)
            {
                if (previous.HasValue)
                {
                    IComparer <Period> comparer = Period.CreateComparer(previous.Value);

                    Assert.AreEqual(
                        0,
                        comparer.Compare(Period.Between(previous.Value, d), step),
                        "Difference between iteration values should match the step value supplied");
                }
                previous = d;
            }
        }
 private LocalInterval(string name, LocalDateTime?start, LocalDateTime?end, TimePayloadBase payload)
 {
     Name    = name;
     Start   = start;
     End     = end;
     Payload = payload;
 }
Exemple #12
0
        public static bool FindSeasEpDateCheck(string?filename, out int seas, out int ep, ShowConfiguration?si)
        {
            ep   = -1;
            seas = -1;

            if (filename is null || si is null)
            {
                return(false);
            }

            // look for a valid airdate in the filename
            // check for YMD, DMY, and MDY
            // only check against airdates we expect for the given show
            CachedSeriesInfo ser = si.CachedShow;

            if (ser is null)
            {
                return(false);
            }

            string[] dateFormats = { "yyyy-MM-dd", "dd-MM-yyyy", "MM-dd-yyyy", "yy-MM-dd", "dd-MM-yy", "MM-dd-yy" };

            // force possible date separators to a dash
            filename = filename.Replace("/", "-");
            filename = filename.Replace(".", "-");
            filename = filename.Replace(",", "-");
            filename = filename.Replace(" ", "-");

            foreach (Episode epi in si.EpisodesToUse())
            {
                LocalDateTime?dt = epi.GetAirDateDt();  // file will have local timezone date, not ours
                if (dt is null)
                {
                    continue;
                }

                TimeSpan closestDate = TimeSpan.MaxValue;

                foreach (string dateFormat in dateFormats)
                {
                    string datestr = dt.Value.ToString(dateFormat, CultureInfo.CurrentCulture);

                    if (filename.Contains(datestr) && DateTime.TryParseExact(datestr, dateFormat,
                                                                             new CultureInfo("en-GB"), DateTimeStyles.None, out DateTime dtInFilename))
                    {
                        TimeSpan timeAgo = DateTime.Now.Subtract(dtInFilename);

                        if (timeAgo < closestDate)
                        {
                            seas        = epi.GetSeasonNumber(si.Order);
                            ep          = epi.GetEpisodeNumber(si.Order);
                            closestDate = timeAgo;
                        }
                    }
                }
            }

            return(ep != -1 && seas != -1);
        }
Exemple #13
0
 public static LocalDateTime?Max(LocalDateTime?val1, LocalDateTime?val2)
 {
     if (val1 == null || val2 == null)
     {
         return(null);
     }
     return(val1 > val2 ? val1 : val2);
 }
Exemple #14
0
 /// <summary>
 ///     Match nullable <see cref="LocalDateTime" />
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static LocalDateTimeAssertions Should(this LocalDateTime?value)
 {
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     return(new LocalDateTimeAssertions(value));
 }
        public LocalInterval Map(DateTimeZone from, DateTimeZone to)
        {
            LocalDateTime?start = Start.HasValue && from != null?from.AtLeniently(Start.Value).ToInstant().InZone(to).LocalDateTime : (LocalDateTime?)null;

            LocalDateTime?end = End.HasValue && to != null?from.AtLeniently(End.Value).ToInstant().InZone(to).LocalDateTime : (LocalDateTime?)null;

            return(new LocalInterval(start, end, Payload, Name));
        }
        LocalDateTime ValueOrNull(LocalDateTime?reference)
        {
            if (reference == null)
            {
                return(Now());
            }

            return(reference.Value);
        }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalInterval"/> struct from two nullable <see cref="LocalDateTime"/>
 /// values.
 /// </summary>
 /// <remarks>
 /// If the start is null, the LocalInterval is deemed to stretch to the start of time. If the end is null,
 /// the LocalInterval is deemed to stretch to the end of time.
 /// </remarks>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="end"/> is earlier than <paramref name="start"/>,
 /// if they are both non-null.</exception>
 /// <param name="start">The start <see cref="LocalDateTime"/> or null.</param>
 /// <param name="end">The end <see cref="LocalDateTime"/> or null.</param>
 public LocalInterval(LocalDateTime?start, LocalDateTime?end)
 {
     this.start = start;
     this.end   = end;
     if (end < start)
     {
         throw new ArgumentOutOfRangeException(nameof(end), "The end parameter must be equal to or later than the start parameter");
     }
 }
        /// <summary>
        /// Get a date in the past between <paramref name="reference"/> and years past that date.
        /// </summary>
        /// <param name="daysToGoBack">Days to go back from <paramref name="reference"/>. Default is 100.</param>
        /// <param name="reference">The date to start calculations. Default is SystemClock.Instance.GetCurrentInstant().</param>
        public LocalDateTime Past(int daysToGoBack = 100, LocalDateTime?reference = null)
        {
            var max = ValueOrNull(reference);

            var ticks = TimeSpan.TicksPerDay * daysToGoBack;

            var partTicks = Random.Long(0, ticks);

            return(max.PlusTicks(-partTicks));
        }
        /// <summary>
        /// Get a date in the future between <paramref name="reference"/> and years forward of that date.
        /// </summary>
        /// <param name="daysToGoForward">Days to go forward from <paramref name="reference"/>. Default is 100.</param>
        /// <param name="reference">The date to start calculations. Default is SystemClock.Instance.GetCurrentInstant().</param>
        public LocalDateTime Future(int daysToGoForward = 100, LocalDateTime?reference = null)
        {
            var min = ValueOrNull(reference);

            var ticks = TimeSpan.TicksPerDay * daysToGoForward;

            var partTicks = Random.Long(0, ticks);

            return(min.PlusTicks(partTicks));
        }
    /// <summary>
    /// Get a random <see cref="Period"/>. Default 1 week/7 days.
    /// </summary>
    public Period Period(Period?maximum = null, LocalDateTime?anchor = null, PeriodUnits units = global::NodaTime.PeriodUnits.AllUnits)
    {
        var anchorTime = anchor ?? LocalDateTime.Now();
        var span       = maximum ?? global::NodaTime.Period.FromDays(7);

        var periodTicks = global::NodaTime.Period.Between(anchorTime, anchorTime + span, global::NodaTime.PeriodUnits.Ticks);
        var randomTicks = global::NodaTime.Period.FromTicks(Random.Long(0, periodTicks.Ticks));

        return(global::NodaTime.Period.Between(anchorTime, anchorTime + randomTicks, units));
    }
Exemple #21
0
 public void NullableLocalDateTimeArrayTest()
 {
     LocalDateTime?[] ldt = new LocalDateTime?[] {
         null,
         null,
         null,
         null,
         null
     };
     Assert.Equal(TestTools.Convert(ldt), ldt);
 }
Exemple #22
0
        public override string ToString(LocalDateTime?start, LocalDateTime?end)
        {
            if (!start.HasValue || !end.HasValue)
            {
                return(ToString());
            }
            var period = Period.Between(start.Value, end.Value);
            var factor = period.Hours + period.Minutes / 60m;

            return(string.Join(", ", craftHours.Select(c => c.Key + ": " + c.Value * factor)));
        }
Exemple #23
0
        public DateTime?GetAirDateDt(DateTimeZone tz)
        {
            LocalDateTime?dt = GetAirDateDt();

            if (dt is null)
            {
                return(null);
            }

            return(TimeZoneHelper.AdjustTzTimeToLocalTime(dt.Value, tz));
        }
Exemple #24
0
 public static Shift CreateShift(
     Sitter sitter           = null,
     LocalDateTime?startTime = null,
     LocalDateTime?bedtime   = null,
     LocalDateTime?endtime   = null,
     HourlyRates hourlyRates = null)
 {
     return(new Shift
     {
         Bedtime = bedtime ?? new LocalDateTime(2018, 6, 30, 21, 0),
         EndTime = endtime ?? new LocalDateTime(2018, 7, 1, 0, 0),
         HourlyRates = hourlyRates ?? HourlyRates.FromStandardRates(),
         Sitter = sitter ?? CreateSitter(),
         StartTime = startTime ?? new LocalDateTime(2018, 6, 30, 17, 0)
     });
 }
Exemple #25
0
        public DateTime?GetAirDateDt(bool inLocalTime)
        {
            LocalDateTime?x = GetAirDateDt();

            if (!inLocalTime && x.HasValue)
            {
                return(x.Value.ToDateTimeUnspecified());
            }

            if (!inLocalTime)
            {
                return(null);
            }

            // do timezone adjustment
            return(GetAirDateDt(Show.GetTimeZone()));
        }
Exemple #26
0
 /// <summary>
 /// Creates new instance of operation with changed properties.
 /// </summary>
 /// <typeparam name="TOperationState">Operation state.</typeparam>
 /// <param name="operation">Source operation.</param>
 /// <param name="id">New id.</param>
 /// <param name="status">New status.</param>
 /// <param name="startedAt">New startedAt.</param>
 /// <param name="finishedAt">New finishedAt.</param>
 /// <param name="exception">New exception.</param>
 /// <param name="metadata">New metadata.</param>
 /// <returns>New instance of operation with changed properties.</returns>
 public static Operation <TOperationState> With <TOperationState>(
     this IOperation <TOperationState> operation,
     OperationId?id              = default,
     OperationStatus?status      = default,
     LocalDateTime?startedAt     = default,
     LocalDateTime?finishedAt    = default,
     Exception?exception         = null,
     IPropertyContainer?metadata = null)
 {
     return(new Operation <TOperationState>(
                id: id ?? operation.Id,
                state: operation.State,
                status: status ?? operation.Status,
                startedAt: startedAt ?? operation.StartedAt,
                finishedAt: finishedAt ?? operation.FinishedAt,
                exception: exception ?? operation.Exception,
                metadata: metadata ?? operation.Metadata));
 }
Exemple #27
0
        public static TSaga Create <TSaga>(
            SagaId id,
            SagaContextId contextId,
            LocalDateTime startedOn,
            LocalDateTime nextProcessingTimeDueOn,
            LocalDateTime?nextRetryTime,
            bool isExpired,
            bool isCompleted) where TSaga : Saga
        {
            var instance = Create <TSaga>(id);

            instance.ContextId = contextId;
            instance.StartedOn = startedOn;
            instance.NextProcessingTimeDueOn = nextProcessingTimeDueOn;
            instance.NextRetryTime           = nextRetryTime;
            instance.IsExpired   = isExpired;
            instance.IsCompleted = isCompleted;
            return(instance);
        }
Exemple #28
0
        public static Saga Create(
            Type sagaType,
            SagaId id,
            SagaContextId contextId,
            LocalDateTime startedOn,
            LocalDateTime nextProcessingTimeDueOn,
            LocalDateTime?nextRetryTime,
            bool isExpired,
            bool isCompleted)
        {
            var instance = Create(sagaType, id);

            instance.ContextId = contextId;
            instance.StartedOn = startedOn;
            instance.NextProcessingTimeDueOn = nextProcessingTimeDueOn;
            instance.NextRetryTime           = nextRetryTime;
            instance.IsExpired   = isExpired;
            instance.IsCompleted = isCompleted;
            return(instance);
        }
 private StreetNameStatusWasImportedFromCrab(
     int streetNameStatusId,
     int streetNameId,
     CrabStreetNameStatus streetNameStatus,
     LocalDateTime?beginDateTime,
     LocalDateTime?endDateTime,
     Instant timestamp,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation) :
     this(
         new CrabStreetNameStatusId(streetNameStatusId),
         new CrabStreetNameId(streetNameId),
         streetNameStatus,
         new CrabLifetime(beginDateTime, endDateTime),
         new CrabTimestamp(timestamp),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }
Exemple #30
0
 private TerrainObjectHouseNumberWasImportedFromCrab(
     int terrainObjectHouseNumberId,
     int terrainObjectId,
     int houseNumberId,
     LocalDateTime?beginDateTime,
     LocalDateTime?endDateTime,
     Instant timestamp,
     string @operator,
     CrabModification?modification,
     CrabOrganisation?organisation)
     : this(
         new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberId),
         new CrabTerrainObjectId(terrainObjectId),
         new CrabHouseNumberId(houseNumberId),
         new CrabLifetime(beginDateTime, endDateTime),
         new CrabTimestamp(timestamp),
         new CrabOperator(@operator),
         modification,
         organisation)
 {
 }