public void Main(string argument, UpdateType updateSource) { if (updateSource.HasFlag(UpdateType.Once)) { Init(); Runtime.UpdateFrequency = UpdateFrequency.Update10; } CycleShips(); if (updateSource.HasFlag(UpdateType.Terminal)) { if (argument == "cycle") { CycleEnabled = !CycleEnabled; } } if (updateSource.HasFlag(UpdateType.Update10)) { bool pjChanged = ProjectorChanged(); bool lcdChanged = pjChanged || _CurrentProjector?.RemainingBlocks != _CurrentProjectorRemainingBlocks; if (lcdChanged) { UpdateLCD(); } } }
public static void RefreshUpdateAlerts(UpdateType flags) { var alerts = new List <XenServerUpdateAlert>(); if (flags.HasFlag(UpdateType.ServerVersion)) { alerts.AddRange(NewXenServerVersionAlerts(XenServerVersionsForAutoCheck)); } if (flags.HasFlag(UpdateType.ServerPatches)) { alerts.AddRange(NewXenServerPatchAlerts(XenServerVersions, XenServerPatches)); } bool changed = false; try { lock (updateAlertsLock) { foreach (var alert in alerts) { var existingAlert = updateAlerts.FirstOrDefault(a => a.Equals(alert)); if (existingAlert != null && alert.CanIgnore) { updateAlerts.Remove(existingAlert); changed = true; } else if (existingAlert is XenServerUpdateAlert updAlert) { updateAlerts.Remove(updAlert); updAlert.CopyConnectionsAndHosts(alert); if (!updateAlerts.Contains(updAlert)) { updateAlerts.Add(updAlert); } changed = true; } else if (!alert.CanIgnore && !updateAlerts.Contains(alert)) { updateAlerts.Add(alert); changed = true; } } } if (changed) { UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, UpdateAlerts)); } } catch (Exception e) { log.Error("Failed to refresh the updates", e); } }
public void Main(string argument, UpdateType updateSource) { if (argument == "depressurize") { airLockController.Depressurize(); } else if (argument == "pressurize") { airLockController.Pressurize(); } else if (argument == "lockdown") { airLockController.LockDown(); } if (updateSource.HasFlag(UpdateType.Update100)) { airLockController.CheckStatus(); Echo(statusReport.RetrieveFullReportText()); foreach (IMyTextPanel panel in listTextPanels) { panel.WritePublicText(statusReport.RetrieveFullReportText(), true); } statusReport.Clear(); } }
/// <summary> /// Run subscribed event handlers. /// </summary> /// <param name="argument">Main's argument parameter</param> /// <param name="updateSource">Main's updateSource</param> public void CallUpdateEventHandlers(string argument, UpdateType updateSource) { UpdateEventArgs Args = new UpdateEventArgs(argument, updateSource); // If you have a DRY way that doesn't involving updating a list on every call: send me an email 🤷 None?.Invoke(this, Args); // Always invoked if (updateSource.HasFlag(UpdateType.Terminal)) { Terminal?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Trigger)) { Trigger?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Mod)) { Mod?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Script)) { Script?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Update1)) { Update1?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Update10)) { Update10?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Update100)) { Update100?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.Once)) { Once?.Invoke(this, Args); } if (updateSource.HasFlag(UpdateType.IGC)) { IGC?.Invoke(this, Args); } foreach ( KeyValuePair <EventHandler <UpdateEventArgs>, EventHandlerMeta> EH in Subscribers.Where(pair => (updateSource & pair.Value.TargetUpdateType) != 0 || pair.Value.TargetUpdateType == UpdateType.None)) { EH.Key.Invoke(this, Args); } }
public void Main(string argument, UpdateType updateSource) { if (updateSource.HasFlag(UpdateType.Terminal)) { List <string> tokenList = commandParser.GetTokensFrom(argument); Echo(commandParser.LastCommand()); switch (tokenList[0]) { case "replace": switch (tokenList[1]) { case "one": nameChanger.Replace(tokenList[3], tokenList[4], tokenList[2]); break; case "all": nameChanger.ReplaceInAll(tokenList[2], tokenList[3]); break; case "group": nameChanger.ReplaceInGroup(tokenList[3], tokenList[4], tokenList[2]); break; default: throw new Exception("Unknown Command. Use: replace (one/all/group) {(param0),...}"); } break; case "append": switch (tokenList[1]) { case "one": nameChanger.Append(tokenList[3], tokenList[2]); break; case "all": nameChanger.AppendToAll(tokenList[2]); break; case "group": nameChanger.AppendInGroup(tokenList[3], tokenList[2]); break; default: throw new Exception("Unknown Command. Use: append (one/all/group) {(param0),...}"); } break; default: throw new Exception("Unknown Command. Use: (replace/append) (one/all/group) {(param0),...}"); } } }
public void Main(String argument, UpdateType updateType) { if (String.IsNullOrWhiteSpace(argument) && updateType.HasFlag(UpdateType.Once)) { StateMachineTick(); } if (!String.IsNullOrWhiteSpace(argument)) { ParseCommand(argument); } }
public void Main(string argumentText, UpdateType updateSource) { Echo(new Random().NextDouble().ToString()); Echo(updateSource.ToString()); Echo(argumentText); if (updateSource.HasFlag(UpdateType.Update10)) { Tick(); } if (updateSource.HasFlag(UpdateType.Update100)) { Tick100(); } if (updateSource.HasFlag(UpdateType.IGC)) { IGCTick(); } var arguments = argumentText.Split(' '); if (arguments.Length < 1) { return; } switch (arguments[0]) { case "init": Initalize(); break; case "save": Save(); break; case "command": commander.HandleCommands(arguments.Skip(1).ToArray()); break; } }
public void Main(string argument, UpdateType updateSource) { #region Initial setup // Do some initial setup on the first call if (updateSource.HasFlag(UpdateType.Once)) { Me.GetSurface(0).WriteText("Storage Overview"); // Enumerate all the LCD panels and find the ones that are configured for ingots var textSurfaceProviders = new List <IMyTextSurfaceProvider>(); GridTerminalSystem.GetBlocksOfType(textSurfaceProviders); foreach (var textSurfaceProvider in textSurfaceProviders) { string configData = ((IMyTerminalBlock)textSurfaceProvider).CustomData; if (configData.StartsWith(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX)) { string ingotType = configData.Substring(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX.Length); int ingotIndex; if (ingotLookup.TryGetValue(ingotType, out ingotIndex)) { for (var surfaceIndex = 0; surfaceIndex < textSurfaceProvider.SurfaceCount; ++surfaceIndex) { var textSurface = textSurfaceProvider.GetSurface(surfaceIndex); textSurface.Alignment = TextAlignment.CENTER; textSurface.Font = "Monospace"; textSurface.FontSize = 2.4f; textSurface.TextPadding = 8.0f; textSurface.WriteText($"{ingotType}\nInitializing..."); textSurfaces[ingotIndex].Add(textSurface); } } } } // Find all the lights and sound blocks configured for ingot GridTerminalSystem.GetBlocksOfType(alertSoundBlocks, soundBlock => soundBlock.CustomData.StartsWith(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX)); GridTerminalSystem.GetBlocksOfType(alertOrWarningLights, interiorLight => interiorLight.CustomData.StartsWith(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX)); } #endregion #region Update list of inventories // Only update the list of inventories we care about if (tenticksUntilNextUpdate == 0) { inventories.Clear(); GridTerminalSystem.GetBlocksOfType(inventoryBlocks, otherBlock => otherBlock.IsSameConstructAs(Me) && otherBlock.HasInventory); foreach (var inventoryBlock in inventoryBlocks) { for (var inventoryIndex = 0; inventoryIndex < inventoryBlock.InventoryCount; ++inventoryIndex) { inventories.Add(inventoryBlock.GetInventory(inventoryIndex)); } } tenticksUntilNextUpdate = NUMBER_OF_TENTICKS_BETWEEN_EACH_UPDATE - 1; return; } #endregion tenticksUntilNextUpdate--; // Count the ingots & ores of each ingot type foreach (var inventory in inventories) { for (var ingotIndex = 0; ingotIndex < INGOT_TYPES.Length; ++ingotIndex) { ingotCounts[ingotIndex] += inventory.GetItemAmount(MyItemType.MakeIngot(INGOT_TYPES[ingotIndex].Type)); oreCounts[ingotIndex] += inventory.GetItemAmount(MyItemType.MakeOre(INGOT_TYPES[ingotIndex].Type)); } } #region Update each ingot type // Update the status of each ingot type var anyAlerts = false; var anyWarnings = false; for (var ingotIndex = 0; ingotIndex < INGOT_TYPES.Length; ++ingotIndex) { var ingotConfig = INGOT_TYPES[ingotIndex]; var ingotCount = ingotCounts[ingotIndex].ToIntSafe(); ingotCounts[ingotIndex].RawValue = 0; var oreCount = oreCounts[ingotIndex].ToIntSafe(); oreCounts[ingotIndex].RawValue = 0; // Generate the text for the display displayBuilder.Clear(); displayBuilder.AppendLine(ingotConfig.Type); displayBuilder.AppendLine(); displayBuilder.AppendLine(ingotCount.ToString("N0")); displayBuilder.AppendLine("available"); if ((oreCount * ingotConfig.ConversionRatio) >= 1) { displayBuilder.AppendLine((oreCount * ingotConfig.ConversionRatio * REFINERY_EFFICIENCY).ToString("N0")); displayBuilder.AppendLine("processing"); } // Determine if there are any alerts or warnings, and pick the right font & background color var fontColor = Color.White; var backgroundColor = Color.Black; if (ingotCount < ingotConfig.AlertThreshold) { anyAlerts = true; fontColor = ALERT_FONT_COLOR; backgroundColor = ALERT_BACKGROUND_COLOR; } else if (ingotCount < ingotConfig.WarningThreshold) { anyWarnings = true; fontColor = WARNING_FONT_COLOR; backgroundColor = WARNING_BACKGROUND_COLOR; } foreach (var textSurface in textSurfaces[ingotIndex]) { textSurface.FontColor = fontColor; textSurface.BackgroundColor = backgroundColor; textSurface.WriteText(displayBuilder); } } #endregion #region Update global warning / alert systems // See if the worst status has changed and updated sound blocks & lights IngotStatus newIngotStatus = IngotStatus.Normal; if (anyAlerts) { newIngotStatus = IngotStatus.Alert; } else if (anyWarnings) { newIngotStatus = IngotStatus.Warning; } if (previousIngotStatus != newIngotStatus) { previousIngotStatus = newIngotStatus; bool playSound = false; Color?optionalLightColor = null; switch (newIngotStatus) { case IngotStatus.Alert: playSound = true; optionalLightColor = ALERT_BACKGROUND_COLOR; break; case IngotStatus.Warning: optionalLightColor = WARNING_BACKGROUND_COLOR; break; } foreach (var soundBlock in alertSoundBlocks) { if (playSound) { soundBlock.Play(); } else { soundBlock.Stop(); } } if (optionalLightColor.HasValue) { Color lightColor = optionalLightColor.Value; foreach (var interiorLight in alertOrWarningLights) { interiorLight.Enabled = true; interiorLight.Color = lightColor; } } else { foreach (var interiorLight in alertOrWarningLights) { interiorLight.Enabled = false; } } } #endregion }