Ejemplo n.º 1
0
        private bool DeviceIsBusy(Device device)
        {
            bool busy = false;

            if (device.ThrottleMaxConnections != UNLIMITED)
            {
                if (_tempBlackoutDevices.ContainsKey(device.Key))
                {
                    busy = true;
                }
                else
                {
                    List <Model.WorkQueue> currentMoves;

                    using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                    {
                        currentMoves = device.GetAllCurrentMoveEntries(context);
                    }

                    if (currentMoves != null && currentMoves.Count > device.ThrottleMaxConnections)
                    {
                        Platform.Log(LogLevel.Warn, "Connection limit on device {0} has been reached. Max = {1}.",
                                     device.AeTitle, device.ThrottleMaxConnections);

                        // blackout for 5 seconds
                        _tempBlackoutDevices.Add(device.Key, device);
                        busy = true;
                    }
                }
            }

            return(busy);
        }
        private bool DeviceIsBusy(Device device)
        {
            bool busy = false;

            if (device.ThrottleMaxConnections != UNLIMITED)
            {
                if (_tempBlackoutDevices.ContainsKey(device.Key))
                {
                    busy = true;
                }
                else
                {
                    List <Model.WorkQueue> currentMoves;

                    using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                    {
                        currentMoves = device.GetAllCurrentMoveEntries(context);
                    }

                    if (currentMoves != null && currentMoves.Count > device.ThrottleMaxConnections)
                    {
                        // sort the list to see where this entry is
                        // and postpone it if its position is greater than the ThrottleMaxConnections
                        currentMoves.Sort(delegate(Model.WorkQueue item1, Model.WorkQueue item2)
                        {
                            return(item1.ScheduledTime.CompareTo(item2.ScheduledTime));
                        });
                        int index = currentMoves.FindIndex(delegate(Model.WorkQueue item) { return(item.Key.Equals(WorkQueueItem.Key)); });

                        if (index >= device.ThrottleMaxConnections)
                        {
                            Platform.Log(LogLevel.Warn, "Connection limit on device {0} has been reached. Max = {1}.", device.AeTitle, device.ThrottleMaxConnections);

                            // blackout for 5 seconds
                            _tempBlackoutDevices.Add(device.Key, device);
                            busy = true;
                        }
                    }
                }
            }

            return(busy);
        }