public static void VA_Init1(dynamic vaProxy) { Logging.Info("Initialising EDDI VoiceAttack plugin"); EDDI.FromVA = true; try { GetEddiInstance(ref vaProxy); Logging.incrementLogs(); App.StartRollbar(); App.ApplyAnyOverrideCulture(); EDDI.Instance.Start(); // Set up our event responder VoiceAttackResponder.RaiseEvent += (s, theEvent) => { try { eventQueue.Enqueue(theEvent); Thread eventHandler = new Thread(() => dequeueEvent(ref vaProxy)) { Name = "VoiceAttackEventHandler", IsBackground = true }; eventHandler.Start(); eventHandler.Join(); } catch (ThreadAbortException tax) { Thread.ResetAbort(); Logging.Debug("Thread aborted", tax); } catch (Exception ex) { Dictionary <string, object> data = new Dictionary <string, object> { { "event", JsonConvert.SerializeObject(theEvent) }, { "exception", ex.Message }, { "stacktrace", ex.StackTrace } }; Logging.Error("VoiceAttack failed to handle event.", data); } }; // Add notifiers for changes in variables we want to react to // (we can only use event handlers with classes which are always constructed - nullable objects will be updated via responder events) EDDI.Instance.State.CollectionChanged += (s, e) => setDictionaryValues(EDDI.Instance.State, "state", ref vaProxy); SpeechService.Instance.PropertyChanged += (s, e) => setSpeaking(SpeechService.Instance.eddiSpeaking, ref vaProxy); CargoMonitor cargoMonitor = (CargoMonitor)EDDI.Instance.ObtainMonitor("Cargo monitor"); cargoMonitor.InventoryUpdatedEvent += (s, e) => { lock (vaProxyLock) { setCargo(cargoMonitor, ref vaProxy); } }; ShipMonitor shipMonitor = (ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor"); shipMonitor.ShipyardUpdatedEvent += (s, e) => { lock (vaProxyLock) { setShipValues(shipMonitor?.GetCurrentShip(), "Ship", ref vaProxy); Task.Run(() => setShipyardValues(shipMonitor?.shipyard?.ToList(), ref vaProxy)); } }; StatusMonitor statusMonitor = (StatusMonitor)EDDI.Instance.ObtainMonitor("Status monitor"); statusMonitor.StatusUpdatedEvent += (s, e) => { lock (vaProxyLock) { setStatusValues(statusMonitor?.currentStatus, "Status", ref vaProxy); } }; // Display instance information if available if (EDDI.Instance.UpgradeRequired) { vaProxy.WriteToLog("Please shut down VoiceAttack and run EDDI standalone to upgrade", "red"); string msg = Properties.VoiceAttack.run_eddi_standalone; SpeechService.Instance.Say(((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetCurrentShip(), msg, 0); } else if (EDDI.Instance.UpgradeAvailable) { vaProxy.WriteToLog("Please shut down VoiceAttack and run EDDI standalone to upgrade", "orange"); string msg = Properties.VoiceAttack.run_eddi_standalone; SpeechService.Instance.Say(((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetCurrentShip(), msg, 0); } if (EDDI.Instance.Motd != null) { vaProxy.WriteToLog("Message from EDDI: " + EDDI.Instance.Motd, "black"); string msg = String.Format(Eddi.Properties.EddiResources.msg_from_eddi, EDDI.Instance.Motd); SpeechService.Instance.Say(((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetCurrentShip(), msg, 0); } // Set the initial values from the main EDDI objects setStandardValues(ref vaProxy); vaProxy.WriteToLog("The EDDI plugin is fully operational.", "green"); setStatus(ref vaProxy, "Operational"); // Fire an event once the VA plugin is initialized Event @event = new VAInitializedEvent(DateTime.UtcNow); if (initEventEnabled(@event.type)) { EDDI.Instance.enqueueEvent(@event); } // Set a variable indicating the version of VoiceAttack in use System.Version v = vaProxy.VAVersion; EDDI.Instance.vaVersion = v.ToString(); // Set a variable indicating whether EDDI is speaking try { setSpeaking(SpeechService.Instance.eddiSpeaking, ref vaProxy); } catch (Exception ex) { Logging.Error("Failed to set initial speaking status", ex); } Logging.Info("EDDI VoiceAttack plugin initialization complete"); } catch (Exception e) { Logging.Error("Failed to initialize VoiceAttack plugin", e); vaProxy.WriteToLog("Unable to fully initialize EDDI. Some functions may not work.", "red"); } }
public static void VA_Init1(dynamic vaProxy) { Logging.Info("Initialising EDDI VoiceAttack plugin"); try { GetEddiInstance(ref vaProxy); Logging.incrementLogs(); App.StartRollbar(); App.ApplyAnyOverrideCulture(); EDDI.Instance.Start(); // Add notifiers for events we want to react to EDDI.Instance.State.CollectionChanged += (s, e) => setDictionaryValues(EDDI.Instance.State, "state", ref vaProxy); SpeechService.Instance.PropertyChanged += (s, e) => setSpeaking(SpeechService.eddiSpeaking, ref vaProxy); VoiceAttackResponder.RaiseEvent += (s, theEvent) => updateValuesOnEvent(theEvent, ref vaProxy); // Display instance information if available if (EDDI.Instance.UpgradeRequired) { vaProxy.WriteToLog("Please shut down VoiceAttack and run EDDI standalone to upgrade", "red"); string msg = Properties.VoiceAttack.run_eddi_standalone; SpeechService.Instance.Say(((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetCurrentShip(), msg, false); } else if (EDDI.Instance.UpgradeAvailable) { vaProxy.WriteToLog("Please shut down VoiceAttack and run EDDI standalone to upgrade", "orange"); string msg = Properties.VoiceAttack.run_eddi_standalone; SpeechService.Instance.Say(((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetCurrentShip(), msg, false); } if (EDDI.Instance.Motd != null) { vaProxy.WriteToLog("Message from EDDI: " + EDDI.Instance.Motd, "black"); string msg = String.Format(Eddi.Properties.EddiResources.msg_from_eddi, EDDI.Instance.Motd); SpeechService.Instance.Say(((ShipMonitor)EDDI.Instance.ObtainMonitor("Ship monitor")).GetCurrentShip(), msg, false); } // Set the initial values from the main EDDI objects setStandardValues(ref vaProxy); vaProxy.WriteToLog("The EDDI plugin is fully operational.", "green"); setStatus(ref vaProxy, "Operational"); // Fire an event once the VA plugin is initialized Event @event = new VAInitializedEvent(DateTime.UtcNow); if (initEventEnabled(@event.type)) { EDDI.Instance.eventHandler(@event); } // Set a variable indicating whether EDDI is speaking try { setSpeaking(SpeechService.eddiSpeaking, ref vaProxy); } catch (Exception ex) { Logging.Error("Failed to set initial speaking status", ex); } Logging.Info("EDDI VoiceAttack plugin initialization complete"); } catch (Exception e) { Logging.Error("Failed to initialize VoiceAttack plugin", e); vaProxy.WriteToLog("Unable to fully initialize EDDI. Some functions may not work.", "red"); } }