/// <summary> /// /// </summary> /// <returns></returns> public int DelService() { // Create a config interface var mConfigInterface = new ConfigInterface(); var serviceMenu = new TypedMenu <MenuChoice>(_services, "Choose a service type to delete", x => x.Name); var ynMenu = new TypedMenu <MenuChoice>(_yesNo, "Save this configuration", x => x.Name); var service = serviceMenu.Display(); switch (service.Id) { case "slack": // get the slack models or create a new list var slackModels = mConfigInterface.Config.SlackModels; if (slackModels == null || !slackModels.Any()) { Console.WriteLine("No Slack configurations to delete!"); return(2); } var slackMenu = new TypedMenu <SlackModel>(slackModels, "Choose a slack config delete", x => x.Label); var choice = slackMenu.Display(); slackModels.Remove(choice); mConfigInterface.Config.SlackModels = slackModels; break; case "cancel": Console.WriteLine("Oh well maybe next time."); return(130); default: Console.WriteLine("You dirty dog, you!"); return(2); // No way you should have gotten here! } // Prompt to confirm var shouldSave = ynMenu.Display(); switch (shouldSave.Id) { case "yes": Console.Write("Saving... "); if (mConfigInterface.WriteConfig()) { Console.WriteLine("Saved!"); return(0); } else { Console.WriteLine("Save Error!"); return(2); } default: // If we did not get yes return a 130 Console.WriteLine("Oh well maybe next time."); return(130); } }
// receive event notifications from MusicBee // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event public void ReceiveNotification(string sourceFileUrl, NotificationType type) { // perform some action depending on the notification type switch (type) { case NotificationType.PluginStartup: // Establish a websocket connection if enabled and initialize the messages. config = new StaticConfig(); wsClient = new WebSocketClient(config); trackChangedMessage = new TrackChangedMessage(mbApiInterface); playStateChangedMessage = new PlayStateChangedMessage(); trackTimeTimer = new TrackTimeTimer(mbApiInterface, wsClient); break; case NotificationType.TrackChanged: trackChangedMessage.Send(wsClient); break; case NotificationType.PlayStateChanged: switch (mbApiInterface.Player_GetPlayState()) { case PlayState.Playing: playStateChangedMessage.Send(wsClient, true); trackTimeTimer.Start(); break; case PlayState.Paused: case PlayState.Stopped: playStateChangedMessage.Send(wsClient, false); trackTimeTimer.Stop(); break; } break; } }
public void InitializeConfigInstance() { var configProperties = ConfigInterface.GetProperties(); foreach (var prop in configProperties) { InitializeConfigProperty(prop); } }
/// <summary> /// Adds a new service to our config /// </summary> /// <returns></returns> public int AddService() { // Create a config interface var mConfigInterface = new ConfigInterface(); var serviceMenu = new TypedMenu <MenuChoice>(_services, "Choose a service to configure", x => x.Name); var ynMenu = new TypedMenu <MenuChoice>(_yesNo, "Save this configuration", x => x.Name); var service = serviceMenu.Display(); switch (service.Id) { case "slack": // Create a new slack config var slackConfig = new SlackModel(); // get the slack models or create a new list var slackModels = mConfigInterface.Config.SlackModels ?? new List <SlackModel>(); // Prompt for the config options slackConfig.PromptForNew(); // Add the config to our main config slackModels.Add(slackConfig); // Set the new array mConfigInterface.Config.SlackModels = slackModels; break; case "cancel": Console.WriteLine("Oh well maybe next time."); return(130); default: Console.WriteLine("You dirty dog, you!"); return(2); // No way you should have gotten here! } // Prompt to confirm var shouldSave = ynMenu.Display(); switch (shouldSave.Id) { case "yes": Console.Write("Saving... "); if (mConfigInterface.WriteConfig()) { Console.WriteLine("Saved!"); return(0); } else { Console.WriteLine("Save Error!"); return(2); } default: // If we did not get yes return a 130 Console.WriteLine("Oh well maybe next time."); return(130); } }
public WebSocketClient(ConfigInterface appConfig) { subscribers = new List <WebSocketSubscriberInterface>(); config = appConfig; ws = new WebSocket(config.GetWebSocketPath()); ws.OnMessage += Ws_OnMessage; ws.OnError += Ws_OnError; ws.OnOpen += Ws_OnOpen; ws.Connect(); }
// MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down) public void Close(PluginCloseReason reason) { if (wsClient != null) { wsClient.Dispose(); wsClient = null; } config = null; }
private void lbDevices_MouseDoubleClick(object sender, MouseEventArgs e) { int index = this.lbDevices.IndexFromPoint(e.Location); if (index != ListBox.NoMatches) { ChosenDevice = lbDevices.Items[index] as ConfigInterface; DialogResult = DialogResult.OK; Close(); } }
private void BuildConfigBody(TypeBuilder typeBuilder) { var configInterfaceProperties = ConfigInterface.GetProperties(); var eventAggregatorField = BuildEventAggregatorField(typeBuilder); foreach (var prop in configInterfaceProperties) { var fieldBuilder = BuildConfigPropertyField(typeBuilder, prop); var propertyBuilder = BuildConfigProperty(typeBuilder, prop); var propGetter = BuildConfigPropertyGetter(typeBuilder, fieldBuilder, prop); var propSetter = BuildConfigPropertySetter(typeBuilder, eventAggregatorField, fieldBuilder, prop); propertyBuilder.SetGetMethod(propGetter); propertyBuilder.SetSetMethod(propSetter); } }
private void AssertConfigInterface() { if (!ConfigInterface.IsInterface) { throw new Exception($"Error : {ConfigInterface.Name} must be an interface"); } var properties = ConfigInterface.GetProperties(); var propGetterMethodNames = properties.Select(prop => ReflectionUtils.GetPropertyGetterMethodName(prop)); var propSetterMethodNames = properties.Select(prop => ReflectionUtils.GetPropertySetterMethodName(prop)); var propMethodNames = propGetterMethodNames.Concat(propSetterMethodNames); if (ConfigInterface.GetMethods().Any(method => !propMethodNames.Contains(method.Name))) { throw new Exception($"Error : Cannot create config implementation type for {ConfigInterface.Name} because it contains methods. A config type can only contain properties."); } }
private void BtnAccept_Click(object sender, EventArgs e) { ChosenDevice = lbDevices.SelectedItem as ConfigInterface; }
public TrackRequestWebSocketSubscriber(MusicBeeApiInterface apiInterface, ConfigInterface conf) { api = apiInterface; config = conf; }
public ConfigInterfaceMember(ConfigMember configMember, ConfigInterface configInterface, Dictionary <string, jsduck.Class> jsClassMap) : base(configMember.Name, configMember.comments, configMember.Params, configInterface, configMember.JsMember, jsClassMap) { this.configMember = configMember; }
public LaunchWindow() { InitializeComponent(); mNavigationService = ContentFrame.NavigationService; UpdateNavigation(); // Attempt to load configuration ConfigInterface.ConfigStatus status = ConfigInterface.LoadConfig(); string errorMessage; // Get result of configuration load // ReSharper disable RedundantCaseLabel // ReSharper disable PossibleNullReferenceException switch (status) { case ConfigInterface.ConfigStatus.OK: return; case ConfigInterface.ConfigStatus.ConfigDoesNotExist: errorMessage = Application.Current.FindResource("PromptConfigFileDoesNotExist")?.ToString(); break; case ConfigInterface.ConfigStatus.InvalidBaseTag: errorMessage = Application.Current.FindResource("PromptConfigBaseTagInvalid")?.ToString(); break; case ConfigInterface.ConfigStatus.DatabaseTagDoesNotExist: errorMessage = string.Format(Application.Current.FindResource("PromptConfigTagMissing").ToString(), @"database"); break; case ConfigInterface.ConfigStatus.ApiTagDoesNotExist: errorMessage = string.Format(Application.Current.FindResource("PromptConfigTagMissing").ToString(), @"api"); break; case ConfigInterface.ConfigStatus.MapTagDoesNotExist: errorMessage = string.Format(Application.Current.FindResource("PromptConfigTagMissing").ToString(), @"map"); break; case ConfigInterface.ConfigStatus.DatabaseTagIsMissingField: errorMessage = string.Format(Application.Current.FindResource("PromptConfigFieldInvalid").ToString(), @"database"); break; case ConfigInterface.ConfigStatus.ApiTagIsMissingField: errorMessage = string.Format(Application.Current.FindResource("PromptConfigFieldInvalid").ToString(), @"api"); break; case ConfigInterface.ConfigStatus.MapTagIsMissingField: errorMessage = string.Format(Application.Current.FindResource("PromptConfigFieldInvalid").ToString(), @"map"); break; case ConfigInterface.ConfigStatus.ErrorLoadingConfig: case ConfigInterface.ConfigStatus.Unknown: default: errorMessage = Application.Current.FindResource("PromptConfigSomethingWentWrong")?.ToString(); break; } // Display error MessageBoxResult result = MessageBox.Show( errorMessage, Application.Current.FindResource("PromptConfigTitle")?.ToString(), MessageBoxButton.YesNo); // Check if user has requested to regenerate the config if (result == MessageBoxResult.Yes) { // Generate a new configuration ConfigInterface.GenerateEmptyConfigFile(FileIO.GetConfigDirectory() + "\\config.xml"); } // Inform the user to fix the configuration file MessageBox.Show( Application.Current.FindResource("PromptConfigNeedsAttention")?.ToString(), Application.Current.FindResource("PromptConfigTitle")?.ToString()); // Close the application Application.Current.Shutdown(); }