public IHttpContext breakEdit(IHttpContext context, string breakId) { try { if (!context.token().hasPermission("breaks.write")) { context.Response.StatusCode = HttpStatusCode.NotFound; context.Response.SendResponse(""); return(context); } ValidationBuilder valBuilder = new ValidationBuilder(); ValidationCollection valCollection; string[] valArray = { "name=StartTime, isRequired=,isTime=", "name=EndTime, isRequired=,isTime=", }; valCollection = valBuilder.build(valArray); Breaks brk = BaseController.getUserInput <Breaks>(context, valCollection); brk.Id = uint.Parse(breakId); Breaks.edit(brk.Id, brk); context.Response.SendResponse(""); } catch (Exception ex) { context.Response.StatusCode = HttpStatusCode.InternalServerError; context.Response.SendResponse(ex.Message); } return(context); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is Shift other && ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) && ((EmployeeId == null && other.EmployeeId == null) || (EmployeeId?.Equals(other.EmployeeId) == true)) && ((LocationId == null && other.LocationId == null) || (LocationId?.Equals(other.LocationId) == true)) && ((Timezone == null && other.Timezone == null) || (Timezone?.Equals(other.Timezone) == true)) && ((StartAt == null && other.StartAt == null) || (StartAt?.Equals(other.StartAt) == true)) && ((EndAt == null && other.EndAt == null) || (EndAt?.Equals(other.EndAt) == true)) && ((Wage == null && other.Wage == null) || (Wage?.Equals(other.Wage) == true)) && ((Breaks == null && other.Breaks == null) || (Breaks?.Equals(other.Breaks) == true)) && ((Status == null && other.Status == null) || (Status?.Equals(other.Status) == true)) && ((Version == null && other.Version == null) || (Version?.Equals(other.Version) == true)) && ((CreatedAt == null && other.CreatedAt == null) || (CreatedAt?.Equals(other.CreatedAt) == true)) && ((UpdatedAt == null && other.UpdatedAt == null) || (UpdatedAt?.Equals(other.UpdatedAt) == true)) && ((TeamMemberId == null && other.TeamMemberId == null) || (TeamMemberId?.Equals(other.TeamMemberId) == true))); }
/// <summary> /// Remove breakpoints in the past /// </summary> public void UpdateBreakpoints() { while (Time > Breaks.First) { Breaks.ClearBreakpoint(); } }
public IHttpContext breakList(IHttpContext context) { try { if (!context.token().hasPermission("breaks.read")) { context.Response.StatusCode = HttpStatusCode.NotFound; context.Response.SendResponse(""); return(context); } var data = context.Request.QueryString; int pageSize = data["pagesize"] != null?int.Parse(data["pagesize"]) : 0; int skip = data["skip"] != null?int.Parse(data["skip"]) : 0; var breaks = Breaks.list(pageSize, skip); context.Response.SendResponse(JsonConvert.SerializeObject(breaks)); } catch (Exception ex) { context.Response.StatusCode = HttpStatusCode.InternalServerError; context.Response.SendResponse(ex.Message); } return(context); }
private async Task DeleteBreakExecuteAsync(Break @break) { IsEnable = false; await Task.Delay(100); var result = await Application.Current.MainPage.DisplayAlert( TranslationCodeExtension.GetTranslation("DeleteBreakTitle"), TranslationCodeExtension.GetTranslation("DeleteBreakText"), TranslationCodeExtension.GetTranslation("YesDeleteBreakText"), TranslationCodeExtension.GetTranslation("NoText")); if (result) { await Task.Delay(50); if (!_currentAccounting.IsClosed) { _timeAccountingContext.Breaks.Remove(@break); await _timeAccountingContext.SaveChangesAsync() .ConfigureAwait(false); } Breaks.Remove(@break); } IsEnable = true; }
/// <summary> /// Show error message for each invalid break. /// </summary> /// <param name="invalidBreaks">Collection with invalid breaks.</param> private void _AddErrorMessages(Breaks invalidBreaks) { // If there is only one break at route. if (_route.Breaks.Count == 1) { this.LogValidationResult(_validationResults, Properties.Messages.Error_VRP_BreakCannotBeVisited, _route, _key); } // If all breaks on route are invalid. else if (invalidBreaks.Count == _route.Breaks.Count) { this.LogValidationResult(_validationResults, Properties.Messages.Error_VRP_AllBreaksCannotBeVisited, _route, _key); } // If some of the breaks are invalid. else if (invalidBreaks.Count != 0) { var invalidBreak = invalidBreaks[0] as TimeWindowBreak; string message; int indexOfInvalidBreak = _IndexInUnsortedCollection(invalidBreak); // If only last break is invalid. if (indexOfInvalidBreak == _route.Breaks.Count - 1) { message = string.Format(Properties.Messages.Error_VRP_LastBreakCannotBeVisited); } // If invalid some breaks, starting from the middle. else { message = string.Format(Properties.Messages.Error_VRP_TheBreakAndAllAfterItCannotBeVisited, BreaksHelper.GetOrdinalNumberName(indexOfInvalidBreak)); } this.LogValidationResult(_validationResults, message, _route, _key); } }
/// <summary> /// If breaks are not valid - show message in MessageWindow. /// </summary> /// <param name="breaks"><c>Breaks</c> to validate.</param> public static void ShowErrorMessagesInMessageWindow(Breaks breaks) { List <MessageDetail> details = new List <MessageDetail>(); string invalidPropertyFormat = ((string)App.Current. FindResource("SolveValidationPropertyInvalidFormat")); // Check that break has errors. foreach (var breakObject in breaks) { Debug.Assert(breakObject as IDataErrorInfo != null); string errorString = (breakObject as IDataErrorInfo).Error; // If it has - add new MessageDetail. if (!string.IsNullOrEmpty(errorString)) { details.Add(new MessageDetail(MessageType.Warning, errorString)); } } // If we have MessageDetails add new Message to message window. if (details.Count > 0) { string errorMessage = ((string)App.Current. FindResource("SetupPanelValidationError")); App.Current.Messenger.AddMessage(MessageType.Warning, errorMessage, details); } }
private static String CheckForBreaks(String str) { LOG.Debug("Check for breaks..."); StringBuilder calc = new StringBuilder(str); Match match = null; do { LOG.Debug("Current: " + calc.ToString()); match = Breaks.Match(calc.ToString()); if (match.Success) { LOG.Debug("Found match: " + match.Value); //Get part String part = match.Value.Substring(1, match.Value.Length - 2); //Compute all operations to one double number double value = CheckForOperatorsAndFunctions(part); //Remove position included breaks calc.Remove(match.Index, match.Length); //Insert double number value on this place calc.Insert(match.Index, value.ToString(CreateForToStringZeros())); LOG.Debug("New string: " + calc.ToString()); } } while (match.Success); LOG.Debug("Breaks result: " + str); return(calc.ToString()); }
public TaxTable() { Breaks.Add(150); Breaks.Add(350); Percents.Add(.1); Percents.Add(.2); Percents.Add(.3); }
/// <summary> /// Raise propepty changed event for property 'Breaks' for routes, which property is the same /// as parameter. /// </summary> /// <param name="collection">IEnumerable collection with routes.</param> /// <param name="breaks">Breaks.</param> internal static void RaisePropertyChangedForRoutesBreaks(IEnumerable collection, Breaks breaks) { Debug.Assert(collection != null); foreach (Route route in collection) (route as IForceNotifyPropertyChanged).RaisePropertyChangedEvent(Route.PropertyNameBreaks); }
/// <summary> /// Return sorted route breaks collection, which breaks are normalized. /// </summary> /// <returns>Sorted collection of normalized time window breaks.</returns> private Breaks _GetSortedBreaks() { Breaks sortedBreaks = _route.Breaks.Clone() as Breaks; sortedBreaks.Sort(); return(sortedBreaks); }
public bool IsInBreak() { if (Breaks == null || !Breaks.Any()) { return(false); } return(!Breaks.Last().IsFinished); }
public static int Main () { Breaks b = new Breaks (3.0); b[0, 0] += 3.0; if (b[0, 0] != 6.0) return 1; return 0; }
/// <summary> /// Raise propepty changed event for property 'Breaks' for routes, which property is the same /// as parameter. /// </summary> /// <param name="collection">IEnumerable collection with routes.</param> /// <param name="breaks">Breaks.</param> internal static void RaisePropertyChangedForRoutesBreaks(IEnumerable collection, Breaks breaks) { Debug.Assert(collection != null); foreach (Route route in collection) { (route as IForceNotifyPropertyChanged).RaisePropertyChangedEvent(Route.PropertyNameBreaks); } }
public static void Main (string [] args) { // this works Works w = new Works (3.0); w [0, 0] += 3.0; // this breaks Breaks b = new Breaks (3.0); b [0, 0] += 3.0; }
public Car(int Id) { this.Id = Id; Accessories = new List <string>(); Engine = new Engine(); Base = new Base(); Breaks = new Breaks(); Electronics = new Electronics(); ExhaustingSystem = new ExhaustingSystem(); }
/// <summary> /// Returns sorted List of <c>Break</c>. /// </summary> /// <param name="breaks">Breaks.</param> /// <returns> Sorted List of <c>Break</c>.</returns> public static List <Break> GetSortedList(Breaks breaks) { List <Break> tempBreaks = new List <Break>(); for (int i = 0; i < breaks.Count; i++) { tempBreaks.Add(breaks[i]); } tempBreaks.Sort(BreaksHelper.Compare); return(tempBreaks); }
public static int Main() { Breaks b = new Breaks(3.0); b[0, 0] += 3.0; if (b[0, 0] != 6.0) { return(1); } return(0); }
/// <summary> /// Returns index of Break in breaks collection. /// </summary> /// <param name="breaks"><c>Breaks</c>.</param> /// <param name="br"><c>Break</c>.</param> /// <returns>Index of break if break is in Breaks and -1 if not.</returns> public static int IndexOf(Breaks breaks, Break br) { for (int i = 0; i < breaks.Count; i++) { if (breaks[i] as Break == br) { return(i); } } // If no such break - return -1. return(-1); }
/// <summary> /// Validator for <c>Breaks</c>. /// </summary> /// <param name="objects"><c>Breaks</c> to validate.</param> /// <returns>True if all breaks in collection are valid and false otherwise.</returns> public static bool IsValid(Breaks collection) { // If any item is invalid - return false. foreach (var item in collection) { if (!string.IsNullOrEmpty(item.Error)) { return(false); } } return(true); }
public USchedule[] Build() { if (MinFinancialHours > MaxFinancialHours) { throw new Exception($"{nameof(MinFinancialHours)} can't be >= {nameof(MaxFinancialHours)}."); } if (MinStartTime > MaxStartTime) { throw new Exception($"{nameof(MinStartTime)} can't be >= {nameof(MaxStartTime)}."); } if (MinEndTime > MaxEndTime) { throw new Exception($"{nameof(MinEndTime)} can't be >= {nameof(MaxEndTime)}."); } if (Days.Count == 0) { throw new Exception($"There must be at least one day in collection {nameof(Days)}"); } if (Classes.Count == 0) { throw new Exception($"There must be at least one class in collection {nameof(Classes)}"); } _buildClasses = Classes .Where(c => c.Days.Except(Days.AsEnumerable()).Any() == false) .Where(c => c.StartTime >= MinStartTime && c.EndTime <= MaxEndTime) .Where(c => Breaks.Where(b => c.Intersects(b)).Any() == false) .OrderBy(a => a.StartTime).ToArray(); _builtSchedules = new List <USchedule>(); _buildingSchedule = new USchedule(); BuildFrom(0); var result = _builtSchedules //Filter the schedules and take the ones that fit our conditions .Where(s => s.HasCourses(ObligatoryCourses)) .Where(s => s.FirstStartTime >= MinStartTime && s.FirstStartTime <= MaxStartTime) .Where(s => s.LastEndTime >= MinEndTime && s.LastEndTime <= MaxEndTime) .OrderBy(c => c.Days.Count()) .ThenBy(c => c.MaximumBreaksTotal) .ThenByDescending(c => c.FinancialHours) .ThenByDescending(c => c.FirstStartTime) .ThenBy(c => c.LastEndTime) .ToArray(); _builtSchedules.Clear(); _buildClasses = null; _buildingSchedule = null; return(result); }
public static void Main(string[] args) { System.Console.WriteLine("This works"); Works w = new Works(3.0); w[0, 0] += 3.0; System.Console.WriteLine("This breaks"); Breaks b = new Breaks(3.0); b[0, 0] += 3.0; }
/// <summary> /// Check that all route's breaks can be visited. /// For invalid breaks add error messages. /// </summary> /// <param name="tripTimeRange">Trip start time window.</param> /// <rereturns>'True' if all breaks can be visited, 'false' otherwise.</rereturns> private bool _CheckBreaksCanBeVisited(TimeRange tripTimeRange) { var result = true; // Prepare breaks for validation. Breaks sortedBreaks = _GetSortedBreaks(); // Collection with breaks, which cannot be completed at time. Breaks invalidBreaks = new Breaks(); // Check that all breaks can be completed in time. for (int i = 0; i < sortedBreaks.Count; i++) { TimeWindowBreak breakToCheck = sortedBreaks[i] as TimeWindowBreak; // Try to calculate break start. var breakStart = tripTimeRange.Intersection(breakToCheck.EffectiveFrom, breakToCheck.EffectiveTo); // If break cannot be started - it is invalid. Check next break. if (breakStart == null) { invalidBreaks.Add(breakToCheck); } // Check that break can be finished. else { // Try calculate break finish. var breakFinish = breakStart.Shift(TimeSpan.FromMinutes(breakToCheck.Duration)); breakFinish = breakFinish.Intersection(tripTimeRange); // If break cannot be finished - it is invalid. if (breakFinish == null) { invalidBreaks.Add(breakToCheck); } } } // If there was invalid breaks - show error messages. if (invalidBreaks.Count != 0) { _AddErrorMessages(invalidBreaks); result = false; } return(result); }
/// <summary> /// Given a break slider's new position, this will update the category related to that break. /// </summary> /// <param name="slider">The break slider.</param> public void UpdateCategory(BreakSlider slider) { slider.Category.Maximum = slider.Value; slider.Category.ApplyMinMax(_scheme.EditorSettings); int index = Breaks.IndexOf(slider); if (index < 0) { return; } if (index < Breaks.Count - 1) { Breaks[index + 1].Category.Minimum = slider.Value; Breaks[index + 1].Category.ApplyMinMax(_scheme.EditorSettings); } }
private bool OnTimerTick() { if (DateTime.Today > WorkDate) { if (_isTimerStarted) { CloseEndedDayAsync(); } return(_isTimerStarted = false); } if (!_currentAccounting.IsStarted) { return(_isTimerStarted); } var currentWorkTime = Breaks == null ? (DateTime.Now.TimeOfDay - StartWorkTime).TotalMinutes + _workedTime : (DateTime.Now.TimeOfDay - StartWorkTime).TotalMinutes - Breaks.Sum(d => d.EndBreakTime - d.StartBreakTime) + _workedTime; CurrentOverWork = _currentAccounting.IsWorking ? TimeSpan.FromMinutes(currentWorkTime - DateService.WorkingTime(DateTime.Now.DayOfWeek)) : TimeSpan.FromMinutes(currentWorkTime); var halfTime = TimeSpan.FromMinutes(currentWorkTime - DateService.WorkingTime(DateTime.Now.DayOfWeek) / 2); if (CurrentOverWork > default(TimeSpan) && CurrentOverWork <= TimeSpan.FromSeconds(1) && _currentAccounting.IsWorking && _isTimerStarted) { ShowWorkingEndAsync(); } if (halfTime > default(TimeSpan) && halfTime <= TimeSpan.FromSeconds(1) && _currentAccounting.IsWorking && _isTimerStarted) { ShowWorkingHalfAsync(); } TotalOverWork = CurrentOverWork + _totalDbOverWork; return(_isTimerStarted); }
private void Start() { engine = new Engine(rigidbody, axles, maxSpeed, maxMotorTorque, this); wheels = new Wheels(rigidbody, axles, maxSteeringAngle); breaks = new Breaks(axles, breakTorque); wheelAnimation = new WheelAnimation(rigidbody, axles, this); var mainWeapons = weapons; weapons = new Weapon[mainWeapons.Length]; for (int i = 0; i < mainWeapons.Length; i++) { var newWeapon = ScriptableObject.Instantiate(mainWeapons[i]); weapons[i] = newWeapon; } }
private async void CloseEndedDayAsync() { if (WorkDate == DateTime.Today) { return; } IsEnable = false; await Task.Delay(100); if (!_currentAccounting.IsStarted) { _timeAccountingContext.TimeAccounts.Remove(_currentAccounting); } else { _currentAccounting.IsClosed = true; _currentAccounting.EndWorkTime = new TimeSpan(23, 59, 59); if (_currentAccounting.StartWorkTime > _currentAccounting.EndWorkTime) { _currentAccounting.StartWorkTime = _currentAccounting.EndWorkTime; } var workTime = Breaks == null ? (_currentAccounting.EndWorkTime - _currentAccounting.StartWorkTime).TotalMinutes : (_currentAccounting.EndWorkTime - _currentAccounting.StartWorkTime).TotalMinutes - Breaks.Sum(d => d.EndBreakTime - d.StartBreakTime); _currentAccounting.OverWork = _currentAccounting.IsWorking ? workTime - DateService.WorkingTime(_currentAccounting.WorkDate.DayOfWeek) : workTime; _timeAccountingContext.Entry(_currentAccounting).State = EntityState.Modified; DependencyService.Get <IShowNotify>() .CancelAll(); } await _timeAccountingContext.SaveChangesAsync() .ConfigureAwait(false); var isWorkDay = DateService.IsWorking(DateTime.Today.DayOfWeek); var currentAccounting = new TimeAccount { WorkDate = DateTime.Today, IsWorking = isWorkDay, IsStarted = IsStarted, StartWorkTime = default,
private async Task AddBreakExecuteAsync() { var newBreak = new Break { StartBreakTime = DateTime.Now.TimeOfDay.TotalMinutes, EndBreakTime = DateTime.Now.TimeOfDay.TotalMinutes, TimeAccount = _currentAccounting }; if (!_currentAccounting.IsClosed) { _timeAccountingContext.Breaks.Add(newBreak); await _timeAccountingContext.SaveChangesAsync() .ConfigureAwait(false); } else { Breaks.Add(newBreak); } }
public IHttpContext breakDelete(IHttpContext context, string breakId) { try { if (!context.token().hasPermission("breaks.write")) { context.Response.StatusCode = HttpStatusCode.NotFound; context.Response.SendResponse(""); return(context); } Breaks.delete(uint.Parse(breakId)); context.Response.SendResponse(""); } catch (Exception ex) { context.Response.StatusCode = HttpStatusCode.InternalServerError; context.Response.SendResponse(ex.Message); } return(context); }
public IHttpContext breakGet(IHttpContext context, string breakId) { try { if (!context.token().hasPermission("breaks.read")) { context.Response.StatusCode = HttpStatusCode.NotFound; context.Response.SendResponse(""); return(context); } Breaks brk = Breaks.get(uint.Parse(breakId)); context.Response.SendResponse(JsonConvert.SerializeObject(brk)); } catch (Exception ex) { context.Response.StatusCode = HttpStatusCode.InternalServerError; context.Response.SendResponse(ex.Message); } return(context); }
/// <summary> /// Initialize/reset the integration method /// </summary> public virtual void Initialize() { // Initialize variables Time = 0.0; Breaks.Clear(); Order = 1; Delta = double.NaN; Prediction = null; DeltaOld = new double[MaxOrder + 1]; Solutions = new Vector <double> [MaxOrder + 1]; savetime = double.NaN; savedelta = double.NaN; // Last point was START so the current point is the point after a breakpoint (start) Break = true; // Initialize the old timesteps - none for (int i = 0; i < DeltaOld.Length; i++) { DeltaOld[i] = double.NaN; } }
/// <summary> /// Method converts breaks from routes to GPRecordSet. /// </summary> /// <param name="routes">Routes collection to get breaks.</param> /// <param name="addSequence">Flag, showing that we must /// add sequence attribute to break gp feature.</param> /// <returns>Breaks GPRecordSet.</returns> public GPRecordSet ConvertBreaks(ICollection <Route> routes, bool addSequence) { Debug.Assert(routes != null); List <GPFeature> features = new List <GPFeature>(); // Convert all breaks for every route to GP Features. foreach (Route route in routes) { Breaks breaks = (Breaks)route.Breaks.Clone(); features.AddRange(_ConvertToGPBreaks(breaks, route, addSequence)); } GPRecordSet rs = null; if (features.Count > 0) { rs = new GPRecordSet(); rs.Features = features.ToArray(); } return(rs); }
/// <summary> /// Simple logic - If 2 out of 3 fail scenario fails /// </summary> /// <param name="breaks"></param> /// <returns></returns> public TestingResult AreBreaksUsable(Breaks breaks) { int testsFailed = 0; StringBuilder sb = new StringBuilder(); if (!breaks.CableNotBroke) { testsFailed++; sb.Append("Breaks have the cable broken" + "\n"); } if (breaks.Overheat > 100) { testsFailed++; sb.Append("Breaks are overheating" + "\n"); } if (breaks.BrakeDistance > 20) { testsFailed++; sb.Append("Breaks have the break distance too big > 20" + "\n"); } if (testsFailed >= 2) { return(new TestingResult() { Passed = false, ResultOfInvestigation = sb.ToString(), }); } else { return(new TestingResult() { Passed = true, }); } }
/// <summary> /// Initializes a new instance of the <c>Route</c> class. /// </summary> /// <param name="entity">Entity initialize datas.</param> internal Route(DataModel.Routes entity) : base(entity) { Debug.Assert(0 < entity.CreationTime); // NOTE: must be inited _InitTimeWindow(entity); _breaks = Breaks.CreateFromDBString(entity.Breaks); _days = Days.CreateFromDBString(entity.Days); // If collection is in schedule - remember it schedule.routes and // subscribe to collection changed event. if (this.Schedule != null) { this.Schedule.RoutesCollectionInitialized += _ScheduleRoutesCollectionInitialized; } _InitPropertiesEvents(); }
/// <summary> /// Constructor. /// </summary> public DefaultBreaksController() { IsCheckEnabled = true; _oldDefaultBreaks = new Breaks(); }
/// <summary> /// Returns sorted List of <c>Break</c>. /// </summary> /// <param name="breaks">Breaks.</param> /// <returns> Sorted List of <c>Break</c>.</returns> public static List<Break> GetSortedList(Breaks breaks) { List<Break> tempBreaks = new List<Break>(); for (int i = 0; i < breaks.Count; i++) { tempBreaks.Add(breaks[i]); } tempBreaks.Sort(BreaksHelper.Compare); return tempBreaks; }
/// <summary> /// Returns index of Break in breaks collection. /// </summary> /// <param name="breaks"><c>Breaks</c>.</param> /// <param name="br"><c>Break</c>.</param> /// <returns>Index of break if break is in Breaks and -1 if not.</returns> public static int IndexOf(Breaks breaks, Break br) { for (int i = 0; i < breaks.Count; i++) if (breaks[i] as Break == br) return i; // If no such break - return -1. return -1; }