@@ -11,138 +11,138 @@ class ProcessCleanup : ProcessHandlerBase
1111 private SettingsCleanupTriggerItem _triggerdItem ;
1212 private DateTime _start ;
1313
14- public ProcessCleanup ( )
14+ public ProcessCleanup ( )
1515 {
1616 _start = DateTime . Now ;
1717 }
1818
19- public override int GetUpdateResolution ( )
19+ public override int GetUpdateResolution ( )
2020 {
2121 return 1000 ;
2222 }
2323
24- public override void Handle ( )
24+ public override void Handle ( )
2525 {
2626 try
2727 {
28- if ( ! PluginSettings . Instance . CleanupEnabled )
28+ if ( ! PluginSettings . Instance . CleanupEnabled )
2929 return ;
3030
31- foreach ( SettingsCleanupTimedItem item in PluginSettings . Instance . CleanupTimedItems )
31+ foreach ( SettingsCleanupTimedItem item in PluginSettings . Instance . CleanupTimedItems )
3232 {
33- if ( ! item . Enabled )
33+ if ( ! item . Enabled )
3434 continue ;
3535
36- ProcessTimedItem ( item ) ;
36+ ProcessTimedItem ( item ) ;
3737 }
3838
39- foreach ( SettingsCleanupTriggerItem item in PluginSettings . Instance . CleanupTriggerItems )
39+ foreach ( SettingsCleanupTriggerItem item in PluginSettings . Instance . CleanupTriggerItems )
4040 {
41- if ( ! item . Enabled )
41+ if ( ! item . Enabled )
4242 continue ;
4343
44- ProcessTriggerItem ( item ) ;
44+ ProcessTriggerItem ( item ) ;
4545 }
4646 }
47- catch ( Exception ex )
47+ catch ( Exception ex )
4848 {
49- Logging . WriteLineAndConsole ( string . Format ( "ProcessCleanup.Handle(): {0}" , ex ) ) ;
50- }
51-
52- base . Handle ( ) ;
49+ Logging . WriteLineAndConsole ( string . Format ( "ProcessCleanup.Handle(): {0}" , ex ) ) ;
50+ }
51+
52+ base . Handle ( ) ;
5353 }
5454
5555 /// <exception cref="OverflowException"></exception>
56- private void ProcessTimedItem ( SettingsCleanupTimedItem item )
56+ private void ProcessTimedItem ( SettingsCleanupTimedItem item )
5757 {
58- DateTime time = new DateTime ( _start . Year , _start . Month , _start . Day , item . Restart . Hour , item . Restart . Minute , 0 ) ;
59- if ( time - DateTime . Now < TimeSpan . FromSeconds ( - 20 ) )
58+ DateTime time = new DateTime ( _start . Year , _start . Month , _start . Day , item . Restart . Hour , item . Restart . Minute , 0 ) ;
59+ if ( time - DateTime . Now < TimeSpan . FromSeconds ( - 20 ) )
6060 {
61- time = new DateTime ( _start . Year , _start . Month , _start . Day + 1 , item . Restart . Hour , item . Restart . Minute , 0 ) ;
61+ time = new DateTime ( _start . Year , _start . Month , _start . Day + 1 , item . Restart . Hour , item . Restart . Minute , 0 ) ;
6262 }
6363
64- if ( DateTime . Now - item . LastRan < TimeSpan . FromMinutes ( 1 ) )
64+ if ( DateTime . Now - item . LastRan < TimeSpan . FromMinutes ( 1 ) )
6565 return ;
6666
67- if ( time - DateTime . Now < TimeSpan . FromSeconds ( 1 ) && DateTime . Now - item . LastRan > TimeSpan . FromMinutes ( 1 ) )
67+ if ( time - DateTime . Now < TimeSpan . FromSeconds ( 1 ) && DateTime . Now - item . LastRan > TimeSpan . FromMinutes ( 1 ) )
6868 {
6969 string command = item . ScanCommand + " quiet" ;
70- HashSet < IMyEntity > entities = CubeGrids . ScanGrids ( 0 , command . Split ( ' ' ) ) ;
71- CubeGrids . DeleteGrids ( entities ) ;
72- Communication . SendPublicInformation ( string . Format ( "[NOTICE]: Timed cleanup has run. {0} entities removed. Have a nice day." , entities . Count ) ) ;
70+ HashSet < IMyEntity > entities = CubeGrids . ScanGrids ( 0 , command . Split ( ' ' ) ) ;
71+ CubeGrids . DeleteGrids ( entities ) ;
72+ Communication . SendPublicInformation ( string . Format ( "[NOTICE]: Timed cleanup has run. {0} entities removed. Have a nice day." , entities . Count ) ) ;
7373 item . LastRan = DateTime . Now ;
74- item . NotificationItemsRan . Clear ( ) ;
74+ item . NotificationItemsRan . Clear ( ) ;
7575 return ;
7676 }
7777
78- foreach ( SettingsCleanupNotificationItem notifyItem in PluginSettings . Instance . CleanupNotificationItems )
78+ foreach ( SettingsCleanupNotificationItem notifyItem in PluginSettings . Instance . CleanupNotificationItems )
7979 {
80- if ( item . NotificationItemsRan . Contains ( notifyItem ) )
80+ if ( item . NotificationItemsRan . Contains ( notifyItem ) )
8181 continue ;
8282
83- if ( time - DateTime . Now < TimeSpan . FromMinutes ( notifyItem . MinutesBeforeCleanup ) )
83+ if ( time - DateTime . Now < TimeSpan . FromMinutes ( notifyItem . MinutesBeforeCleanup ) )
8484 {
85- item . NotificationItemsRan . Add ( notifyItem ) ;
85+ item . NotificationItemsRan . Add ( notifyItem ) ;
8686
87- if ( DateTime . Now - notifyItem . lastRan > TimeSpan . FromMinutes ( 1 ) )
87+ if ( DateTime . Now - notifyItem . lastRan > TimeSpan . FromMinutes ( 1 ) )
8888 {
8989 notifyItem . lastRan = DateTime . Now ;
90- string notification = notifyItem . Message . Replace ( "%cleanup_reason%" , item . Reason ) ;
91- Communication . SendPublicInformation ( notification ) ;
90+ string notification = notifyItem . Message . Replace ( "%cleanup_reason%" , item . Reason ) ;
91+ Communication . SendPublicInformation ( notification ) ;
9292 }
9393
9494 }
9595 }
9696 }
9797
9898 /// <exception cref="OverflowException"></exception>
99- private void ProcessTriggerItem ( SettingsCleanupTriggerItem item )
99+ private void ProcessTriggerItem ( SettingsCleanupTriggerItem item )
100100 {
101- if ( _triggerdItem != null && _triggerdItem != item )
101+ if ( _triggerdItem != null && _triggerdItem != item )
102102 return ;
103103
104- if ( _triggerdItem == null )
104+ if ( _triggerdItem == null )
105105 {
106106 // Increase to 5 minutes
107- if ( DateTime . Now - item . LastRan > TimeSpan . FromSeconds ( 300 ) )
107+ if ( DateTime . Now - item . LastRan > TimeSpan . FromSeconds ( 300 ) )
108108 {
109109 item . LastRan = DateTime . Now ;
110110 string command = item . ScanCommand + " quiet" ;
111- HashSet < IMyEntity > entities = CubeGrids . ScanGrids ( 0 , command . Split ( ' ' ) ) ;
112- if ( entities . Count >= item . MaxCapacity )
111+ HashSet < IMyEntity > entities = CubeGrids . ScanGrids ( 0 , command . Split ( ' ' ) ) ;
112+ if ( entities . Count >= item . MaxCapacity )
113113 {
114- 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 ) ) ;
115- item . NotificationItemsRan . Clear ( ) ;
114+ 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 ) ) ;
115+ item . NotificationItemsRan . Clear ( ) ;
116116 _triggerdItem = item ;
117117 return ;
118118 }
119119 }
120120 }
121121 else
122122 {
123- if ( DateTime . Now - item . LastRan > TimeSpan . FromMinutes ( item . MinutesAfterCapacity ) )
123+ if ( DateTime . Now - item . LastRan > TimeSpan . FromMinutes ( item . MinutesAfterCapacity ) )
124124 {
125125 string command = item . ScanCommand + " quiet" ;
126- HashSet < IMyEntity > entities = CubeGrids . ScanGrids ( 0 , command . Split ( ' ' ) ) ;
127- CubeGrids . DeleteGrids ( entities ) ;
128- Communication . SendPublicInformation ( string . Format ( "[NOTICE]: Triggered cleanup has run. {0} entities removed. Have a nice day." , entities . Count ) ) ;
126+ HashSet < IMyEntity > entities = CubeGrids . ScanGrids ( 0 , command . Split ( ' ' ) ) ;
127+ CubeGrids . DeleteGrids ( entities ) ;
128+ Communication . SendPublicInformation ( string . Format ( "[NOTICE]: Triggered cleanup has run. {0} entities removed. Have a nice day." , entities . Count ) ) ;
129129 _triggerdItem = null ;
130130 return ;
131131 }
132132
133- foreach ( SettingsCleanupNotificationItem notifyItem in PluginSettings . Instance . CleanupNotificationItems )
133+ foreach ( SettingsCleanupNotificationItem notifyItem in PluginSettings . Instance . CleanupNotificationItems )
134134 {
135- if ( item . NotificationItemsRan . Contains ( notifyItem ) )
135+ if ( item . NotificationItemsRan . Contains ( notifyItem ) )
136136 continue ;
137137
138- if ( notifyItem . MinutesBeforeCleanup > item . MinutesAfterCapacity )
138+ if ( notifyItem . MinutesBeforeCleanup > item . MinutesAfterCapacity )
139139 continue ;
140140
141- if ( DateTime . Now - item . LastRan > TimeSpan . FromMinutes ( item . MinutesAfterCapacity - notifyItem . MinutesBeforeCleanup ) )
141+ if ( DateTime . Now - item . LastRan > TimeSpan . FromMinutes ( item . MinutesAfterCapacity - notifyItem . MinutesBeforeCleanup ) )
142142 {
143- item . NotificationItemsRan . Add ( notifyItem ) ;
144- string notification = notifyItem . Message . Replace ( "%cleanup_reason%" , item . Reason ) ;
145- Communication . SendPublicInformation ( notification ) ;
143+ item . NotificationItemsRan . Add ( notifyItem ) ;
144+ string notification = notifyItem . Message . Replace ( "%cleanup_reason%" , item . Reason ) ;
145+ Communication . SendPublicInformation ( notification ) ;
146146 }
147147 }
148148 }
0 commit comments