Example #1
0
        public ResourceState[] GetResources()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ResourceID", typeof(int));
            dt.Columns.Add("ResourceName", typeof(string));
            dt.Columns.Add("BuildingName", typeof(string));
            dt.Columns.Add("LabName", typeof(string));
            dt.Columns.Add("ProcessTechName", typeof(string));

            ResourceInfo[] query = DataSession.Query <ResourceInfo>().Where(x => x.ResourceIsActive).ToArray();
            foreach (var r in query)
            {
                dt.Rows.Add(r.ResourceID, r.ResourceName, r.BuildingName, r.LabName, r.ProcessTechName);
            }

            WagoInterlock.AllToolStatus(dt);

            ResourceState[] result = dt.AsEnumerable().Select(x => new ResourceState()
            {
                ResourceID      = x.Field <int>("ResourceID"),
                ResourceName    = x.Field <string>("ResourceName"),
                BuildingName    = x.Field <string>("BuildingName"),
                LabName         = x.Field <string>("LabName"),
                ProcessTechName = x.Field <string>("ProcessTechName"),
                PointID         = x.Field <int>("PointID"),
                InterlockStatus = x.Field <string>("InterlockStatus"),
                InterlockState  = x.Field <bool>("InterlockState"),
                InterlockError  = x.Field <bool>("InterlockError"),
                IsInterlocked   = x.Field <bool>("IsInterlocked")
            }).ToArray();

            return(result);
        }
Example #2
0
        public IEnumerable <ToolStatus> GetToolStatus()
        {
            DataTable dt = new DataTable();

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnSselData"].ConnectionString))
                using (var cmd = new SqlCommand("SELECT * FROM sselControl.dbo.v_ToolStatus WHERE IsActive = 1 ORDER BY BuildingName, LabDisplayName, ProcessTechName, ResourceName", conn))
                    using (var adap = new SqlDataAdapter(cmd))
                    {
                        adap.Fill(dt);
                        conn.Close();
                    }

            WagoInterlock.AllToolStatus(dt);

            var result = dt.AsEnumerable().Select(x => new ToolStatus()
            {
                BuildingID      = x.Field <int>("BuildingID"),
                BuildingName    = x.Field <string>("BuildingName"),
                LabID           = x.Field <int>("LabID"),
                LabName         = x.Field <string>("LabName"),
                LabDisplayName  = x.Field <string>("LabDisplayName"),
                ProcessTechID   = x.Field <int>("ProcessTechID"),
                ProcessTechName = x.Field <string>("ProcessTechName"),
                ResourceID      = x.Field <int>("ResourceID"),
                ResourceName    = x.Field <string>("ResourceName"),
                PointID         = x.Field <int>("PointID"),
                InterlockStatus = x.Field <string>("InterlockStatus"),
                InterlockState  = x.Field <bool>("InterlockState"),
                InterlockError  = x.Field <bool>("InterlockError"),
                IsInterlocked   = x.Field <bool>("IsInterlocked")
            }).ToList();

            return(result);
        }
Example #3
0
        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 Off(int resourceId)
 {
     WagoInterlock.ToggleInterlock(resourceId, false, 0);
     return(new InterlockResponse()
     {
         State = true, Message = "TURN_OFF_OK"
     });
 }
        public InterlockResponse GetState(int resourceId)
        {
            bool state = WagoInterlock.GetPointState(resourceId);

            return(new InterlockResponse()
            {
                State = state, Message = state ? "ON" : "OFF"
            });
        }
        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"
            });
        }
Example #7
0
        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");
            }
        }
Example #9
0
        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);
        }
Example #10
0
        private BlockState GetBlockState(int blockId)
        {
            BlockState result = null;

            if (blocks.ContainsKey(blockId))
            {
                result = blocks[blockId];
            }
            else
            {
                result = WagoInterlock.GetBlockState(blockId);
                blocks.Add(blockId, result);
            }

            return(result);
        }
Example #11
0
        public string GetInterlockStatus(int resourceId)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ResourceID", typeof(int));
            dt.Columns.Add("InterlockStatus", typeof(string));
            dt.Rows.Add(resourceId, string.Empty);
            WagoInterlock.AllToolStatus(dt);
            DataRow dr = dt.Select($"ResourceID = {resourceId}").FirstOrDefault();

            string result;

            if (dr != null)
            {
                result = Convert.ToString(dr["InterlockStatus"]);
            }
            else
            {
                result = $"{resourceId} not found";
            }

            return(result);
        }
Example #12
0
 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")}.");
 }
        public Task <bool> GetState(int resourceId)
        {
            var result = WagoInterlock.GetPointState(resourceId);

            return(result);
        }
Example #14
0
        /// <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}.");
                    }
                }
            }
        }