Beispiel #1
0
        private static Dictionary <string, List <CompiledScheduleSettingsContract> > InvalidSchedules(
            IEnumerable <CompiledScheduleContract> scheduleContracts)
        {
            var invalidSchedules = new Dictionary <string, List <CompiledScheduleSettingsContract> >();

            foreach (var scheduleContract in scheduleContracts)
            {
                var scheduleSettings = new List <CompiledScheduleSettingsContract>();
                foreach (var scheduleSetting in scheduleContract.ScheduleSettings)
                {
                    try
                    {
                        ScheduleConstraintContract.Validate(scheduleSetting);
                    }
                    catch
                    {
                        scheduleSettings.Add(scheduleSetting);
                    }
                }

                if (scheduleSettings.Any())
                {
                    invalidSchedules.Add(scheduleContract.AssetPairId, scheduleSettings);
                }
            }

            return(invalidSchedules);
        }
Beispiel #2
0
 private static ScheduleConstraintContract Clone(this ScheduleConstraintContract constraint)
 => new ScheduleConstraintContract
 {
     Date      = constraint.Date,
     DayOfWeek = constraint.DayOfWeek,
     Time      = constraint.Time,
 };
Beispiel #3
0
        private static List <ScheduleSettingsContract> InvalidSchedules(
            IEnumerable <ScheduleSettingsContract> scheduleContracts)
        {
            var scheduleSettings = new List <ScheduleSettingsContract>();

            foreach (var scheduleSetting in scheduleContracts)
            {
                try
                {
                    ScheduleConstraintContract.Validate(scheduleSetting);
                }
                catch
                {
                    scheduleSettings.Add(scheduleSetting);
                }
            }

            return(scheduleSettings);
        }
Beispiel #4
0
        private async Task ValidateScheduleSettings(ScheduleSettingsContract scheduleSetting)
        {
            if (scheduleSetting == null)
            {
                throw new ArgumentNullException(nameof(scheduleSetting), "Model is incorrect");
            }

            if (string.IsNullOrWhiteSpace(scheduleSetting.Id))
            {
                throw new ArgumentNullException(nameof(scheduleSetting.Id), "scheduleSetting Id must be set");
            }

            if (!string.IsNullOrEmpty(scheduleSetting.MarketId) &&
                await _marketRepository.GetAsync(scheduleSetting.MarketId) == null)
            {
                throw new InvalidOperationException($"Market {scheduleSetting.MarketId} does not exist");
            }

            ScheduleConstraintContract.Validate(scheduleSetting);

            if (scheduleSetting.Start.DayOfWeek != null && !Enum.IsDefined(typeof(DayOfWeek), scheduleSetting.Start.DayOfWeek))
            {
                throw new ArgumentNullException(nameof(scheduleSetting.Start.DayOfWeek), "AssetPair Start DayOfWeek is set to an incorrect value");
            }

            if (scheduleSetting.End.DayOfWeek != null && !Enum.IsDefined(typeof(DayOfWeek), scheduleSetting.End.DayOfWeek))
            {
                throw new ArgumentNullException(nameof(scheduleSetting.End.DayOfWeek), "AssetPair End DayOfWeek is set to an incorrect value");
            }

            foreach (var assetPair in scheduleSetting.AssetPairs)
            {
                if (await _assetPairsRepository.GetAsync(assetPair) == null)
                {
                    throw new InvalidOperationException($"Asset pair {assetPair} does not exist");
                }
            }
        }