Пример #1
0
        /// <exception cref="OverflowException"></exception>
        private void ProcessTriggerItem(SettingsCleanupTriggerItem item)
        {
            if (_triggerdItem != null && _triggerdItem != item)
            {
                return;
            }

            if (_triggerdItem == null)
            {
                // Increase to 5 minutes
                if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(5))
                {
                    item.LastRan = DateTime.Now;
                    string command = string.Format("{0} quiet", item.ScanCommand);
                    HashSet <IMyEntity> entities = CubeGrids.ScanGrids(0, command);
                    if (entities.Count >= item.MaxCapacity)
                    {
                        Communication.SendPublicInformation(string.Format("[NOTICE]: Cleanup triggered.  ({0} of {1}) triggered grids found.  Cleanup will run in {2} minutes.  Reason: {3}", entities.Count, item.MaxCapacity, item.MinutesAfterCapacity, item.Reason));
                        item.NotificationItemsRan.Clear( );
                        _triggerdItem = item;
                        return;
                    }
                }
            }
            else
            {
                if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity))
                {
                    string command = string.Format("{0} quiet", item.ScanCommand);
                    HashSet <IMyEntity> entities = CubeGrids.ScanGrids(0, command);
                    CubeGrids.DeleteGrids(entities);
                    Communication.SendPublicInformation(string.Format("[NOTICE]: Triggered cleanup has run.  {0} entities removed.  Have a nice day.", entities.Count));
                    _triggerdItem = null;
                    return;
                }

                foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems)
                {
                    if (item.NotificationItemsRan.Contains(notifyItem))
                    {
                        continue;
                    }

                    if (notifyItem.MinutesBeforeCleanup > item.MinutesAfterCapacity)
                    {
                        continue;
                    }

                    if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity - notifyItem.MinutesBeforeCleanup))
                    {
                        item.NotificationItemsRan.Add(notifyItem);
                        string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason);
                        Communication.SendPublicInformation(notification);
                    }
                }
            }
        }
Пример #2
0
        /// <exception cref="OverflowException"></exception>
        private void ProcessTriggerItem( SettingsCleanupTriggerItem item )
        {
            if ( _triggeredItem != null && _triggeredItem != item )
                return;

            if ( _triggeredItem == null )
            {
                // Increase to 5 minutes
                if ( DateTime.Now - item.LastRan > _fiveMinutes )
                {
                    item.LastRan = DateTime.Now;
                    string command = item.ScanCommand + " quiet";
                    HashSet<GridGroup> groups = CubeGrids.ScanGrids( 0, CommandParser.GetCommandParts( command ).ToArray( ) );
                    int gridsCount = 0;
                    foreach (var group in groups)
                        gridsCount += group.Grids.Count;

                    if ( gridsCount >= item.MaxCapacity )
                    {
                        Communication.SendPublicInformation( $"[NOTICE]: Cleanup triggered.  ({gridsCount} of {item.MaxCapacity}) triggered grids found.  Cleanup will run in {item.MinutesAfterCapacity} minutes.{(item.Reason == string.Empty ? "" : $"  Reason: {item.Reason}")}" );
                        item.NotificationItemsRan.Clear( );
                        _triggeredItem = item;
                    }
                }
            }
            else
            {
                if ( DateTime.Now - item.LastRan > TimeSpan.FromMinutes( item.MinutesAfterCapacity ) )
                {
                    string command = item.ScanCommand + " quiet";
                    HashSet<GridGroup> groups = CubeGrids.ScanGrids( 0, CommandParser.GetCommandParts( command ).ToArray( ) );

                    int groupCount = groups.Count;
                    int gridCount = 0;
                    foreach (var group in groups)
                    {
                        gridCount += group.Grids.Count;
                        group.Close();
                    }
                    Communication.SendPublicInformation( $"[NOTICE]: Triggered cleanup has run. {gridCount} grids in {groupCount} groups removed." );
                    _triggeredItem = null;
                    return;
                }

                foreach ( SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems )
                {
                    if ( item.NotificationItemsRan.Contains( notifyItem ) )
                        continue;

                    if ( notifyItem.MinutesBeforeCleanup > item.MinutesAfterCapacity )
                        continue;

                    if ( DateTime.Now - item.LastRan > TimeSpan.FromMinutes( item.MinutesAfterCapacity - notifyItem.MinutesBeforeCleanup ) )
                    {
                        item.NotificationItemsRan.Add( notifyItem );
                        string notification = notifyItem.Message.Replace( "%cleanup_reason%", item.Reason );
                        Communication.SendPublicInformation( notification );
                    }
                }
            }
        }
Пример #3
0
        /// <exception cref="OverflowException"></exception>
        private void ProcessTriggerItem(SettingsCleanupTriggerItem item)
        {
            if (_triggeredItem != null && _triggeredItem != item)
            {
                return;
            }

            if (_triggeredItem == null)
            {
                // Increase to 5 minutes
                if (DateTime.Now - item.LastRan > _fiveMinutes)
                {
                    item.LastRan = DateTime.Now;
                    string command             = item.ScanCommand + " quiet";
                    HashSet <GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray( ));
                    int gridsCount             = 0;
                    foreach (var group in groups)
                    {
                        gridsCount += group.Grids.Count;
                    }

                    if (gridsCount >= item.MaxCapacity)
                    {
                        Communication.SendPublicInformation($"[NOTICE]: Cleanup triggered.  ({gridsCount} of {item.MaxCapacity}) triggered grids found.  Cleanup will run in {item.MinutesAfterCapacity} minutes.{(item.Reason == string.Empty ? "" : $"  Reason: {item.Reason}")}");
                        item.NotificationItemsRan.Clear( );
                        _triggeredItem = item;
                    }
                }
            }
            else
            {
                if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity))
                {
                    string command             = item.ScanCommand + " quiet";
                    HashSet <GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray( ));

                    int groupCount = groups.Count;
                    int gridCount  = 0;
                    foreach (var group in groups)
                    {
                        gridCount += group.Grids.Count;
                        group.Close();
                    }
                    Communication.SendPublicInformation($"[NOTICE]: Triggered cleanup has run. {gridCount} grids in {groupCount} groups removed.");
                    _triggeredItem = null;
                    return;
                }

                foreach (SettingsCleanupNotificationItem notifyItem in PluginSettings.Instance.CleanupNotificationItems)
                {
                    if (item.NotificationItemsRan.Contains(notifyItem))
                    {
                        continue;
                    }

                    if (notifyItem.MinutesBeforeCleanup > item.MinutesAfterCapacity)
                    {
                        continue;
                    }

                    if (DateTime.Now - item.LastRan > TimeSpan.FromMinutes(item.MinutesAfterCapacity - notifyItem.MinutesBeforeCleanup))
                    {
                        item.NotificationItemsRan.Add(notifyItem);
                        string notification = notifyItem.Message.Replace("%cleanup_reason%", item.Reason);
                        Communication.SendPublicInformation(notification);
                    }
                }
            }
        }