// Get Block data public static InterlockData GetInterlockData(int resourceId, ActionType action = ActionType.Interlock, string username = "", string password = "") { var inst = ActionInstances.Find(action, resourceId); BlockState blockState = null; if (inst == null) { return(new InterlockData(0, null, "No Interlock is associated with this resource.")); } IPoint point = ServiceProvider.Current.Control.GetPoint(inst.Point); string message = string.Empty; int blockId = 0; try { blockId = point.BlockID; BlockResponse resp = ServiceProvider.Current.Control.GetBlockState(blockId); blockState = resp.BlockState; if (blockState == null) { message = "Failed to connect with WAGO block.<br />Please try to reload the page and repeat your action again (click the Maintenance tab above).<br />If the problem persists, please contact administrator."; } } catch (Exception ex) { message = string.Format("Wago block {0} fault detected. Please contact system administrator. [{0}]", blockId, ex.Message); } return(new InterlockData(blockId, blockState, message)); }
public static void ByPass(int actionId, uint duration) { var inst = ActionInstances.Find(ActionType.ByPass, actionId); if (inst != null) { ServiceProvider.Current.Control.SetPointState(inst.Point, true, duration); } }
public static StartReservationItem CreateStartReservationItem(HttpContextBase context, IProvider provider, IReservationItem rsv) { var now = DateTime.Now; var item = new StartReservationItem { ReservationID = rsv.ReservationID, ResourceID = rsv.ResourceID, ResourceName = rsv.ResourceName, ReservedByClientID = rsv.ClientID, ReservedByClientName = string.Format("{0} {1}", rsv.FName, rsv.LName) }; var currentUser = context.CurrentUser(provider); if (rsv.ClientIDBegin.HasValue) { if (rsv.ClientIDBegin.Value > 0) { IClient startedBy = provider.Data.Client.GetClient(rsv.ClientIDBegin.Value); item.StartedByClientID = startedBy.ClientID; item.StartedByClientName = string.Format("{0} {1}", startedBy.FName, startedBy.LName); } else { item.StartedByClientID = 0; item.StartedByClientName = string.Empty; } } else { item.StartedByClientID = currentUser.ClientID; item.StartedByClientName = string.Format("{0} {1}", currentUser.FName, currentUser.LName); } var reservationItem = provider.Scheduler.Reservation.GetReservationWithInvitees(rsv.ReservationID); var helper = new SchedulerContextHelper(context, provider); var args = ReservationStateArgs.Create(reservationItem, helper.GetReservationClient(reservationItem), now); var stateUtil = ReservationStateUtility.Create(now); ReservationState state = stateUtil.GetReservationState(args); item.Startable = stateUtil.IsStartable(state); item.NotStartableMessage = GetNotStartableMessage(state); var inst = ActionInstances.Find(ActionType.Interlock, rsv.ResourceID); item.HasInterlock = inst != null; var res = provider.Scheduler.Resource.GetResource(rsv.ResourceID); item.ReturnUrl = GetResourceUrl(context, res); return(item); }
public static bool GetPointState(int resourceId) { var inst = ActionInstances.Find(ActionType.Interlock, resourceId); if (inst == null) { throw new ArgumentException(string.Format("No record found for ResourceID {0}", resourceId)); } IPoint p = ServiceProvider.Current.Control.GetPoint(inst.Point); var bs = GetBlockState(p.BlockID); return(GetPointState(p.PointID, bs)); }
// Turn On/Off the points that are associated with the resource public static bool ToggleInterlock(int resourceId, bool state, uint duration) { // Not every tool has an interlock setup, so only set point state if // an ActionInstance is found. It's not an error if one is not found. var inst = ActionInstances.Find(ActionType.Interlock, resourceId); if (inst != null) { ServiceProvider.Current.Control.SetPointState(inst.Point, state, duration); return(true); } else { return(false); } }