Beispiel #1
0
        public static async Task <TResult> ToDictionaryAsync <TKey, TValue, TKeyDictionary, TValueDictionary, TResult>(this IEnumerableAsync <KeyValuePair <TKey, TValue> > kvpItems,
                                                                                                                       Func <KeyValuePair <TKey, TValue>, TKeyDictionary> selectKey,
                                                                                                                       Func <KeyValuePair <TKey, TValue>, TValueDictionary> selectValue,
                                                                                                                       Func <Dictionary <TKeyDictionary, TValueDictionary>, KeyValuePair <TKey, TValue>[], TResult> dictionaryAndDuplicates)
        {
            var hashSet       = new HashSet <TKey>();
            var kvpItemsArray = await kvpItems.ToArrayAsync();

            var duplicates = new KeyValuePair <TKey, TValue>[] { };
            var dictionary = kvpItemsArray
                             .Select(
                kvp =>
            {
                if (hashSet.Contains(kvp.Key))
                {
                    duplicates = duplicates.Append(kvp).ToArray();
                    return(default(KeyValuePair <TKeyDictionary, TValueDictionary>?));
                }
                hashSet.Add(kvp.Key);
                return(selectValue(kvp).PairWithKey(selectKey(kvp)));
            })
                             .SelectWhereHasValue()
                             .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            return(dictionaryAndDuplicates(dictionary, duplicates));
        }
Beispiel #2
0
        public static IEnumerable <KeyValuePair <DateTime, TimeSpan> > GetCompatibleOpenSlots(IEnumerable <KeyValuePair <DateTime, TimeSpan> > openSlots, Discount discount, DateTime today)
        {
            var slots = openSlots.ToArray();
            IEnumerable <KeyValuePair <DateTime, TimeSpan> > results = new KeyValuePair <DateTime, TimeSpan> [0];

            for (int i = 0; i < slots.Length; i++)
            {
                DateTime result = slots[i].Key;
                if (i == 0 && slots[i].Key > today.Date) //Esto es por si alguien usa un descuento a ultima hora, para que lo pueda usar, aunque se entregue al dia sgte.
                {
                    result = today;
                }

                if (discount == null || Discount.IsValid(result, discount))
                {
                    results = results.Append(slots[i]);
                }

                if (discount != null && !Discount.IsValid(result, discount))
                {
                    break;
                }
            }

            return(results);
        }
Beispiel #3
0
        public static RestServiceResponse <DeviceInfoBase[]> Query(Paging paging, string deviceNumber = null, string deviceName = null)
        {
            var keyValues = new KeyValuePair[0];

            if (!string.IsNullOrWhiteSpace(deviceNumber))
            {
                keyValues = keyValues.Append(new KeyValuePair("DeviceNumber", deviceNumber.Trim()));
            }
            if (!string.IsNullOrWhiteSpace(deviceName))
            {
                keyValues = keyValues.Append(new KeyValuePair("DeviceName", deviceName.Trim()));
            }

            return(new ServiceClientBase("get-device-info-list").Call <RestServiceResponse <DeviceInfoBase[]> >(new RestServiceRequest()
            {
                KeyValues = keyValues,
                Paging = paging,
                ActionName = "ByConditions",
            }));
        }
Beispiel #4
0
        public static RestServiceResponse <RepairRecord[]> Query(Paging paging, int id = 0, string deviceNumber = null, string persons = null, string[] statuses = null, string startTime = null, string endTime = null)
        {
            var keyValues = new KeyValuePair[0];

            if (id > 0)
            {
                keyValues = keyValues.Append(new KeyValuePair("Id", id.ToString()));
            }
            if (deviceNumber.HasValue())
            {
                keyValues = keyValues.Append(new KeyValuePair("DeviceNumber", deviceNumber.Trim()));
            }
            if (persons.HasValue())
            {
                keyValues = keyValues.Append(new KeyValuePair("Persons", persons.ToString()));
            }
            if (statuses != null && statuses.Length > 0)
            {
                keyValues = keyValues.Append(new KeyValuePair("Statuses", string.Join(",", statuses)));
            }
            if (startTime.HasValue())
            {
                keyValues = keyValues.Append(new KeyValuePair("StartTime", startTime));
            }
            if (endTime.HasValue())
            {
                keyValues = keyValues.Append(new KeyValuePair("EndTime", endTime));
            }

            return(new ServiceClientBase("get-repair-record-list").Call <RestServiceResponse <RepairRecord[]> >(new RestServiceRequest()
            {
                Paging = paging,
                KeyValues = keyValues,
            }));
        }
        public static RestServiceResponse <MaintenancePlan[]> Query(Paging paging, int id = 0, string deviceNumber = null, string deviceName = null)
        {
            var keyValues = new KeyValuePair[0];

            if (id > 0)
            {
                keyValues = keyValues.Append(new KeyValuePair("Id", id.ToString()));
            }
            if (!string.IsNullOrWhiteSpace(deviceNumber))
            {
                keyValues = keyValues.Append(new KeyValuePair("DeviceNumber", deviceNumber.Trim()));
            }
            if (!string.IsNullOrWhiteSpace(deviceName))
            {
                keyValues = keyValues.Append(new KeyValuePair("DeviceName", deviceName.Trim()));
            }

            return(new ServiceClientBase("get-maintenance-plan-list").Call <RestServiceResponse <MaintenancePlan[]> >(new RestServiceRequest()
            {
                KeyValues = keyValues,
                Paging = paging,
            }));
        }
Beispiel #6
0
        public static IEnumerable <KeyValuePair <DateTime, TimeSpan> > GetOpenSlots(DateTime orderReady, IEnumerable <IWorkingHours> openHours, IEnumerable <PublicHoliday> holidays, IEnumerable <Vacation> vacations)
        {
            IEnumerable <DateTime> days = Enumerable.Range(0, 365).Select(i => orderReady.Date.AddDays(i));


            /*List<DateTime> daysCountingVacation = new List<DateTime>();
             * foreach(var day in days)
             * {
             * if (vacations.Count(x => x.StartDate.Date <= day && x.EndDate >= day) == 0)
             * daysCountingVacation.Add(day);
             * }*/

            IEnumerable <DateTime> daysCountingVacation = days.Where(day => vacations.Count(x => x.StartDate.Date <= day && x.EndDate >= day) == 0);

            //List<KeyValuePair<DateTime, TimeSpan>> preliminarResults = new List<KeyValuePair<DateTime, TimeSpan>>();

            var preliminarResultsGroups = daysCountingVacation.Select(day =>
            {
                var openHoursSlotsInHolidays = holidays.Where(x => x.Date.Date == day.Date);
                if (openHoursSlotsInHolidays.Count() > 0)
                {
                    return(openHoursSlotsInHolidays.Where(x => x.OpenHours != null)
                           .Select(x => new KeyValuePair <DateTime, TimeSpan>(day.Add(x.OpenHours.StartingAt), x.OpenHours.Duration)));
                }
                else
                {
                    var ordinaryHours = openHours.Where(x => x.DayId == (int)day.DayOfWeek).Select(x => new KeyValuePair <DateTime, TimeSpan>(day.Add(x.StartingAt), x.Duration));
                    return(ordinaryHours);
                }
            }).ToArray();

            IEnumerable <KeyValuePair <DateTime, TimeSpan> > preliminarResults = new KeyValuePair <DateTime, TimeSpan> [0];

            for (int i = 0; i < preliminarResultsGroups.Count(); i++)
            {
                preliminarResults = preliminarResults.Concat(preliminarResultsGroups[i]);
            }


            foreach (var day in daysCountingVacation)
            {
                var openHoursSlotsInHolidays = holidays.Where(x => x.Date.Date == day.Date);
                if (openHoursSlotsInHolidays.Count() > 0)
                {
                    var holidayHours = openHoursSlotsInHolidays.Where(x => x.OpenHours != null)
                                       .Select(x => new KeyValuePair <DateTime, TimeSpan>(day.Add(x.OpenHours.StartingAt), x.OpenHours.Duration));
                    preliminarResults = preliminarResults.Concat(holidayHours);
                }
                else
                {
                    var ordinaryHours = openHours.Where(x => x.DayId == (int)day.DayOfWeek)
                                        .Select(x => new KeyValuePair <DateTime, TimeSpan>(day.Add(x.StartingAt), x.Duration));
                    preliminarResults = preliminarResults.Concat(ordinaryHours);
                }
            }

            var onlyAfterOrIncludingOrderReady = preliminarResults.Where(x => x.Key.Add(x.Value) > orderReady);

            IEnumerable <KeyValuePair <DateTime, TimeSpan> > results = new KeyValuePair <DateTime, TimeSpan> [0];

            foreach (var item in onlyAfterOrIncludingOrderReady)
            {
                if (item.Key <= orderReady)
                {
                    TimeSpan offset = orderReady.Subtract(item.Key);
                    results = results.Append(new KeyValuePair <DateTime, TimeSpan>(orderReady, item.Value.Subtract(offset)));
                }
                else
                {
                    results = results.Append(item);
                }
            }

            return(results);
        }