public string RunGetWagoState(string[] args) { ParseArgs(args, out int resourceId); var state = WagoInterlock.GetPointState(resourceId); return($"Wago point for {resourceId} is {(state ? "ON" : "OFF")}."); }
public InterlockResponse GetState(int resourceId) { bool state = WagoInterlock.GetPointState(resourceId); return(new InterlockResponse() { State = state, Message = state ? "ON" : "OFF" }); }
private bool?GetState(OnTheFlyResource res) { ActionInstance act = ActionInstanceUtility.Find(ActionType.Interlock, res.Resource.ResourceID); if (act == null) { return(null); } var point = act.GetPoint(); var blockState = GetBlockState(point.Block.BlockID); var result = WagoInterlock.GetPointState(point.PointID, blockState); return(result); }
public Task <bool> GetState(int resourceId) { var result = WagoInterlock.GetPointState(resourceId); return(result); }
/// <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}."); } } } }