Ejemplo n.º 1
0
        public virtual IDateRange GetPreviousRange()
        {
            DateTime to   = From.AddDays(-1);
            DateTime from = _dayCount > 0 ? to.AddDays(-_dayCount + 1) : to.AddDays(-(To - From).TotalDays + 1);

            return(new RangeCustom(from, to, _dayCount));
        }
Ejemplo n.º 2
0
                /// <summary>
                /// Generates a single random date between the defined lower and upper bounds.
                /// </summary>
                /// <returns>A date between the defined ranges.</returns>
                public DateTime Single()
                {
                    Random rnd      = new Random();
                    int    dayRange = (To - From).Days;

                    return(From.AddDays(rnd.Next(dayRange)));
                }
Ejemplo n.º 3
0
 private void SetRequestInformation(Email email)
 {
     // parse the email content and retrieves holiday request information
     EmployeeName  = email.Title;
     EmployeeEmail = "EmployeeEmail";
     ManagerEmail  = "ManagerEmail";
     From          = DateTime.Now.AddDays(3);
     To            = From.AddDays(7);
 }
Ejemplo n.º 4
0
                /// <summary>
                /// Generated an infinite succession of random dates between the defined lower and upper bounds.
                /// </summary>
                /// <returns>An infinite series of dates between the defined ranges.</returns>
                public IEnumerable <DateTime> Stream()
                {
                    Random rnd      = new Random();
                    int    dayRange = (To - From).Days;

                    while (true)
                    {
                        yield return(From.AddDays(rnd.Next(dayRange)));
                    }
                }
Ejemplo n.º 5
0
 internal Reservation(Employee employee, Member member, List <Book> book)
 {
     Id      = new Random().Next(100, 1000);
     From    = DateTime.Now;
     To      = From.AddDays(14);
     Expedit = employee;
     Member  = member;
     foreach (var item  in book)
     {
         books.Add(item);
         item.ChangeStatus();
     }
 }
Ejemplo n.º 6
0
        public WorkingWeek(ObjectId employeeId)
        {
            Id              = ObjectId.GenerateNewId();
            Project         = new Project();
            Activity        = new Activity();
            BillingCategory = new BillingCategory();
            EmployeeId      = employeeId;

            From = Utilities.GetMonday(DateTime.Today);
            To   = From.AddDays(6);

            WorkingDays = new List <WorkingDay>();

            for (var i = 0; i < 7; i++)
            {
                var workingDay = new WorkingDay(Id);
                WorkingDays.Add(workingDay);
            }

            Order = 1;
        }
Ejemplo n.º 7
0
        public ShowTodoCommand(string args, DateTime now, int timeAdjustment)
        {
            _args = args;
            if (string.IsNullOrWhiteSpace(args))
            {
                From = now.AddMinutes(timeAdjustment).Date;
            }
            else if (args.Length == 4)
            {
                int year  = now.AddMinutes(timeAdjustment).Year;
                int month = int.Parse(args.Substring(0, 2));
                int day   = int.Parse(args.Substring(2, 2));
                From = new DateTime(year, month, day);
            }
            else if (args.Length == 8)
            {
                int year  = int.Parse(args.Substring(0, 4));
                int month = int.Parse(args.Substring(4, 2));
                int day   = int.Parse(args.Substring(6, 2));
                From = new DateTime(year, month, day);
            }

            To = From.AddDays(1);
        }
Ejemplo n.º 8
0
        public QueryDateRange(QueryDateRangeEnum dateRange)
        {
            switch (dateRange)
            {
            case QueryDateRangeEnum.LastQuarterHour:
                From = DateTime.Now.AddMinutes(-15);
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.LastHalfHour:
                From = DateTime.Now.AddMinutes(-30);
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.LastHour:
                From = DateTime.Now.AddMinutes(-60);
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.LastTwoHours:
                From = DateTime.Now.AddMinutes(-120);
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.LastEightHours:
                From = DateTime.Now.AddHours(-8);
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.LastTwentyFourHours:
                From = DateTime.Now.AddHours(-24);
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.Today:
                From = DateTime.Today;
                To   = DateTime.Now;
                break;

            case QueryDateRangeEnum.Yesterday:
                From = DateTime.Today.AddDays(-1);
                To   = DateTime.Today.AddSeconds(-1);
                break;

            case QueryDateRangeEnum.ThisWeek:
                From = DateTime.Today.AddDays(-1 * (DateTime.Today.DayOfWeek == DayOfWeek.Sunday
                        ? 6
                        : (int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Monday));
                To = DateTime.Now;
                break;

            case QueryDateRangeEnum.LastWeek:
                From = DateTime.Today.AddDays(-1 *
                                              ((DateTime.Today.DayOfWeek == DayOfWeek.Sunday
                                                      ? 6
                                                      : (int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Monday) + 7));
                To = From.AddDays(7).AddSeconds(-1);
                break;

            case QueryDateRangeEnum.ThisMonth:
                From = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                To   = From.AddMonths(1).AddSeconds(-1);
                break;

            case QueryDateRangeEnum.LastMonth:
                From = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(-1);
                To   = From.AddMonths(1).AddSeconds(-1);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dateRange), dateRange, null);
            }
        }
Ejemplo n.º 9
0
 public IDateRange GetPreviousRange() => new RangeYesterday(From.AddDays(-1));
Ejemplo n.º 10
0
 public IDateRange GetPreviousRange() => new RangeLastYear(new RangeYear(From.AddDays(-1)));
Ejemplo n.º 11
0
 public Period AddDays(int days)
 {
     return(new Period(From.AddDays(days), To.AddDays(days)));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Created a list of device definitions from the passed in reference. Needs work....
        /// </summary>
        /// <param name="InputReference"></param>
        /// <param name="InLocalTempDir"></param>
        /// <param name="ObeyConstraints"></param>
        public void AddDevices(UnrealTargetPlatform DefaultPlatform, string InputReference, bool ObeyConstraints = true)
        {
            lock (LockObject)
            {
                List <ITargetDevice> NewDevices = new List <ITargetDevice>();

                int SlashIndex = InputReference.IndexOf("\\") >= 0 ? InputReference.IndexOf("\\") : InputReference.IndexOf("/");

                bool PossibleFileName = InputReference.IndexOfAny(Path.GetInvalidPathChars()) < 0 &&
                                        (InputReference.IndexOf(":") == -1 || (InputReference.IndexOf(":") == SlashIndex - 1));
                // Did they specify a file?
                if (PossibleFileName && File.Exists(InputReference))
                {
                    Gauntlet.Log.Info("Adding devices from {0}", InputReference);
                    List <DeviceDefinition> DeviceDefinitions = JsonConvert.DeserializeObject <List <DeviceDefinition> >(File.ReadAllText(InputReference));

                    foreach (DeviceDefinition Def in DeviceDefinitions)
                    {
                        Gauntlet.Log.Info("Adding {0}", Def);

                        // use Legacy field if it exists
                        if (Def.Platform == null)
                        {
                            Def.Platform = Def.Type;
                        }

                        // check for an availability constraint
                        if (string.IsNullOrEmpty(Def.Available) == false && ObeyConstraints)
                        {
                            // check whether disabled
                            if (String.Compare(Def.Available, "disabled", true) == 0)
                            {
                                Gauntlet.Log.Info("Skipping {0} due to being disabled", Def.Name);
                                continue;
                            }

                            // availability is specified as a range, e.g 21:00-09:00.
                            Match M = Regex.Match(Def.Available, @"(\d{1,2}:\d\d)\s*-\s*(\d{1,2}:\d\d)");

                            if (M.Success)
                            {
                                DateTime From, To;

                                if (DateTime.TryParse(M.Groups[1].Value, out From) && DateTime.TryParse(M.Groups[2].Value, out To))
                                {
                                    // these are just times so when parsed will have todays date. If the To time is less than
                                    // From (22:00-06:00) time it spans midnight so move it to the next day
                                    if (To < From)
                                    {
                                        To = To.AddDays(1);
                                    }

                                    // if From is in the future (e.g. it's 01:00 and range is 22:00-08:00) we may be in the previous days window,
                                    // so move them both back a day
                                    if (From > DateTime.Now)
                                    {
                                        From = From.AddDays(-1);
                                        To   = To.AddDays(-1);
                                    }

                                    if (DateTime.Now < From || DateTime.Now > To)
                                    {
                                        Gauntlet.Log.Info("Skipping {0} due to availability constraint {1}", Def.Name, Def.Available);
                                        continue;
                                    }
                                }
                                else
                                {
                                    Gauntlet.Log.Warning("Failed to parse availability {0} for {1}", Def.Available, Def.Name);
                                }
                            }
                        }

                        Def.RemoveOnShutdown = true;

                        if (Def.Platform == null)
                        {
                            Def.Platform = DefaultPlatform;
                        }

                        UnprovisionedDevices.Add(Def);
                    }

                    // randomize devices so if there's a bad device st the start so we don't always hit it (or we do if its later)
                    UnprovisionedDevices = UnprovisionedDevices.OrderBy(D => Guid.NewGuid()).ToList();
                }
                else
                {
                    if (string.IsNullOrEmpty(InputReference) == false)
                    {
                        string[] DevicesList = InputReference.Split(',');

                        foreach (string DeviceRef in DevicesList)
                        {
                            // check for <platform>:<address>:<port>|<model>. We pass address:port to device constructor
                            Match M = Regex.Match(DeviceRef, @"(.+?):(.+)");

                            UnrealTargetPlatform DevicePlatform = DefaultPlatform;
                            string DeviceAddress = DeviceRef;
                            string Model         = string.Empty;

                            // when using device service, skip adding local non-desktop devices to pool
                            bool IsDesktop = UnrealBuildTool.Utils.GetPlatformsInClass(UnrealPlatformClass.Desktop).Contains(DevicePlatform);
                            if (!IsDesktop && DeviceRef.Equals("default", StringComparison.OrdinalIgnoreCase) && !String.IsNullOrEmpty(DeviceURL))
                            {
                                continue;
                            }

                            if (M.Success)
                            {
                                if (!UnrealTargetPlatform.TryParse(M.Groups[1].ToString(), out DevicePlatform))
                                {
                                    throw new AutomationException("platform {0} is not a recognized device type", M.Groups[1].ToString());
                                }

                                DeviceAddress = M.Groups[2].ToString();

                                // parse device model
                                if (DeviceAddress.Contains("|"))
                                {
                                    string[] Components = DeviceAddress.Split(new char[] { '|' });
                                    DeviceAddress = Components[0];
                                    Model         = Components[1];
                                }
                            }

                            Log.Info("Added device {0}:{1} to pool", DevicePlatform, DeviceAddress);
                            DeviceDefinition Def = new DeviceDefinition();
                            Def.Address  = DeviceAddress;
                            Def.Name     = DeviceAddress;
                            Def.Platform = DevicePlatform;
                            Def.Model    = Model;
                            UnprovisionedDevices.Add(Def);
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public void PrevWeek()
 {
     From = From.AddDays(-7);
 }
Ejemplo n.º 14
0
 public IDateRange GetPreviousRange() => new RangeLastMonth(new RangeMonth(From.AddDays(-1)));
Ejemplo n.º 15
0
        public IDateRange GetPreviousRange()
        {
            var prevFirstDate = From.AddDays(-1).GetYearFirstDate();

            return(new RangeYearToDate(prevFirstDate, _initialTo));
        }
 public IEnumerable <DateTime> AsDays()
 {
     return(Enumerable.Range(0, To.Subtract(From).Days + 1).Select(d => From.AddDays(d)));
 }
Ejemplo n.º 17
0
 public IDateRange GetPreviousRange() => new RangeTheLastYear(From.AddYears(-1), From.AddDays(-1));
Ejemplo n.º 18
0
        public override IDateRange GetPreviousRange()
        {
            var prevFirstDate = From.AddDays(-1).GetWeekFirstDate(FirstDayOfWeekProvider.Value);

            return(new RangeWeekToDate(prevFirstDate, prevFirstDate.AddDays((To - From).TotalDays), FirstDayOfWeekProvider));
        }
Ejemplo n.º 19
0
 public override string ToString()
 {
     return($"From {From.AddDays(-1):d}");
 }
Ejemplo n.º 20
0
 public void NextWeek()
 {
     From = From.AddDays(7);
 }
Ejemplo n.º 21
0
 public override IDateRange GetPreviousRange() => new RangeWeek(From.AddDays(-1), FirstDayOfWeekProvider);
Ejemplo n.º 22
0
        public IDateRange GetPreviousRange()
        {
            var prevFirstDate = From.AddDays(-1).GetMonthFirstDate();

            return(new RangeMonthToDate(prevFirstDate, _dayCount));
        }