public InterlockResponse Off(int resourceId) { WagoInterlock.ToggleInterlock(resourceId, false, 0); return(new InterlockResponse() { State = true, Message = "TURN_OFF_OK" }); }
public InterlockResponse Bypass(int resourceId, int duration) { uint d = (uint)Math.Max(0, duration); WagoInterlock.ToggleInterlock(resourceId, true, d); return(new InterlockResponse() { State = true, Message = "BYPASS_OK" }); }
public void End(IReservationItem rsv, DateTime actualEndDateTime, int?endedByClientId) { if (rsv == null) { throw new ArgumentNullException($"The argument rsv cannot be null."); } // Make sure this reservation hasn't already been ended some how // [2016-01-21 jg] Allow FacilityDownTime because they already have ActualEndDateTime set if (rsv.ActualEndDateTime != null && !rsv.IsFacilityDownTime) { return; } // must set these for future use rsv.ActualEndDateTime = actualEndDateTime; rsv.ClientIDEnd = endedByClientId.GetValueOrDefault(-1); // End reservation Provider.Scheduler.Reservation.EndReservation(new EndReservationArgs { ReservationID = rsv.ReservationID, ActualEndDateTime = actualEndDateTime, EndedByClientID = endedByClientId.GetValueOrDefault(-1) }); // Turn Interlock Off if (CacheManager.Current.WagoEnabled) { WagoInterlock.ToggleInterlock(rsv.ResourceID, false, 0); } // Check for other open reservation slots between now and the reservation fence DateTime?nextBeginDateTime = OpenResSlot(rsv.ResourceID, TimeSpan.FromMinutes(rsv.ReservFence), TimeSpan.FromMinutes(rsv.MinReservTime), rsv.EndDateTime); if (nextBeginDateTime == null) { return; } // Get the next reservation start time DateTime currentEndDateTime = rsv.GetNextGranularity(actualEndDateTime, GranularityDirection.Previous); // Send email notifications to all clients who want to be notified of open reservation slots Provider.Scheduler.Email.EmailOnOpenSlot(rsv.ReservationID, currentEndDateTime, nextBeginDateTime.Value, EmailNotify.Always, endedByClientId.GetValueOrDefault(-1)); if (nextBeginDateTime.Value.Subtract(currentEndDateTime).TotalMinutes >= rsv.MinReservTime) { Provider.Scheduler.Email.EmailOnOpenSlot(rsv.ReservationID, currentEndDateTime, nextBeginDateTime.Value, EmailNotify.OnOpening, endedByClientId.GetValueOrDefault(-1)); } }
public async Task <bool> SetStateOn(int resourceId, string state, int duration = 0) { if (new[] { "on", "off" }.Contains(state)) { uint d = Convert.ToUInt32(Math.Max(0, duration)); await WagoInterlock.ToggleInterlock(resourceId, state == "on", d); return(await GetState(resourceId)); } else { throw new ArgumentException("Invalid state. Allowed values are on|off", "state"); } }
public string RunSetWagoState(string[] args) { ParseArgs(args, out int resourceId, out bool state); WagoInterlock.ToggleInterlock(resourceId, state, 0); return($"Wago point for {resourceId} set to {(state ? "ON" : "OFF")}."); }
/// <summary> /// Starts a reservation, and turns on Interlock. /// </summary> /// <param name="item">The reservation to start</param> /// <param name="client">The current user starting the reservation</param> public void Start(IReservationItem item, ReservationClient client, int?modifiedByClientId) { if (item == null) { throw new ArgumentNullException("item", "A null ReservationItem object is not allowed."); } if (item.IsStarted) { return; } var args = ReservationStateArgs.Create(item, client, Now); ReservationState state = ReservationStateUtility.Create(Now).GetReservationState(args); if (state != ReservationState.StartOnly && state != ReservationState.StartOrDelete) { if (!args.IsInLab) { throw new Exception($"Reservation #{item.ReservationID} is not startable at this time. You must be inside the lab to start reservations."); } else if (!args.IsAuthorized) { throw new Exception($"Reservation #{item.ReservationID} is not startable at this time. You are not authorized to start reservations on this tool."); } else { throw new Exception($"Reservation #{item.ReservationID} is not startable at this time. State: {state}."); } } // End Previous un-ended reservations var endableQuery = Provider.Scheduler.Reservation.SelectEndableReservations(item.ResourceID); foreach (var endable in endableQuery) { // no need to disable interlock or send open slot notifications for each of these // so calling IReservationManager.EndReservation directly instead of ReservationUtility.End Provider.Scheduler.Reservation.EndReservation(new EndReservationArgs { ReservationID = endable.ReservationID, ActualEndDateTime = Now, EndedByClientID = modifiedByClientId.GetValueOrDefault(-1) }); } // Start Reservation Provider.Scheduler.Reservation.StartReservation(item.ReservationID, modifiedByClientId); // If Resource authorization type is rolling and the reserver is a regular user for the resource then reset reserver's expiration date int authLevel = 0, resourceClientId = 0; var resourceClients = Provider.Scheduler.Resource.GetResourceClients(item.ResourceID, clientId: client.ClientID); if (resourceClients.Any()) { var rc = resourceClients.First(); authLevel = Convert.ToInt32(rc.AuthLevel); resourceClientId = rc.ResourceClientID; } if (item.AuthState && (authLevel == (int)ClientAuthLevel.AuthorizedUser)) { DateTime expiration = Now.AddMonths(item.AuthDuration); Provider.Scheduler.Resource.UpdateExpiration(resourceClientId, expiration); } // Turn Interlock On if (CacheManager.Current.WagoEnabled) { uint duration = OnTheFlyUtility.GetStateDuration(item.ResourceID); bool hasInterlock = WagoInterlock.ToggleInterlock(item.ResourceID, true, duration); if (hasInterlock) { bool interlockState = WagoInterlock.GetPointState(item.ResourceID); if (!interlockState) { throw new InvalidOperationException($"Failed to start interlock for ResourceID {item.ResourceID}."); } } } }