private FrameworkElement AddAdapter() { AdapterType[] adapterTypes = ConfigManager.Configuration.GetAdapterTypes(); if (adapterTypes.Length == 0) { MessageBox.Show("There are no adapter plugins so it is not possible to add adapter.", "Adding adapter", MessageBoxButton.OK, MessageBoxImage.Error); return null; } #region Create unique name var adapterNames = ConfigManager.Configuration.GetAdapterConfigurations(GatewayName).Select(a => a.AdapterName); int index = 1; while (adapterNames.Contains("adapter" + index.ToString())) { index++; } string adapterName = "adapter" + index.ToString(); #endregion AdapterType adapterType = adapterTypes.First(); AdapterConfiguration adapter = new AdapterConfiguration(adapterName, GatewayName, adapterType.Name); adapter.Configuration = new SerializableXDocument(new XDocument()); adapter.Configuration.XDocument.Add(new XElement(XName.Get("objectConfig"))); ConfigManager.Configuration.SaveAdapterConfiguration(adapter); FrameworkElement adapterRepresentation = CreateAdapterRepresentation(adapter); return adapterRepresentation; }
public void ConfigureWebServiceAdapter() { var httpServiceAdapter = new XRouter.Adapters.HttpServiceAdapter() { Uri = "http://*****:*****@" //<objectConfig> // <item name='Uri'>localhost:8123</item> // <item name='AreInputTokensPersistent'>False</item> //</objectConfig> //"); var webService = new AdapterConfiguration( "floodConsumerWebService", "gateway", "httpServiceAdapter", webServiceConfig); XDocument config = new XDocument(); config.Add(new XElement("config")); XSerializer.Serializer<AdapterConfiguration>(webService, config.Root); Console.WriteLine(config.ToString().Replace('"', '\'')); }
private FrameworkElement CreateAdapterRepresentation(AdapterConfiguration adapter) { TextBox uiName = new TextBox { Text = adapter.AdapterName, Width = 150, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0) }; uiName.LostFocus += delegate { string originalName = adapter.AdapterName; var adapterNames = ConfigManager.Configuration.GetAdapterConfigurations(GatewayName).Where(a => a.AdapterName != originalName).Select(a => a.AdapterName); string newName = uiName.Text; while (adapterNames.Contains(newName)) { newName = newName + " (new)"; } uiName.Text = newName; adapter.AdapterName = newName; ConfigManager.Configuration.SaveAdapterConfiguration(adapter, originalName); }; Grid.SetColumn(uiName, 1); string[] adapterTypeNames = ConfigManager.Configuration.GetAdapterTypes().Select(at => at.Name).ToArray(); ComboBox uiAdapterType = new ComboBox { Tag = adapter, Margin = new Thickness(10, 3, 5, 3), IsEditable = false, HorizontalAlignment = HorizontalAlignment.Stretch }; foreach (string adapterTypeName in adapterTypeNames) { uiAdapterType.Items.Add(new ComboBoxItem { Tag = adapterTypeName, Content = adapterTypeName }); } uiAdapterType.SelectedIndex = adapterTypeNames.ToList().IndexOf(adapter.AdapterTypeName); uiAdapterType.SelectionChanged += delegate { string selectedAdapterTypeName = (string)(((ComboBoxItem)uiAdapterType.SelectedItem).Tag); adapter.AdapterTypeName = selectedAdapterTypeName; ConfigManager.Configuration.SaveAdapterConfiguration(adapter); SetActiveAdapter(uiAdapterType); }; Grid.SetColumn(uiAdapterType, 2); var uiAdapter = new Grid { Tag = adapter, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } }, Children = { new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Generic_Device.png")), Height = 18, Margin = new Thickness(8, 0, 0, 0) }, uiName, uiAdapterType } }; return uiAdapter; }
private void SetActiveAdapter(FrameworkElement uiAdapter) { if (uiAdapter == null) { activeAdapter = null; uiAdapterConfigurationRegion.Visibility = Visibility.Collapsed; return; } activeAdapter = (AdapterConfiguration)uiAdapter.Tag; uiAdapterConfigurationRegion.Visibility = Visibility.Visible; uiAdapterConfigurationHeader.Text = activeAdapter.AdapterName; AdapterType activeAdapterType = ConfigManager.Configuration.GetAdapterType(activeAdapter.AdapterTypeName); activeConfigurationEditor = Configurator.CreateEditor(activeAdapterType.ConfigurationMetadata); activeConfigurationEditor.LoadConfiguration(activeAdapter.Configuration.XDocument); activeConfigurationEditor.ConfigurationChanged += delegate { activeAdapter.Configuration = new SerializableXDocument(activeConfigurationEditor.SaveConfiguration()); ConfigManager.Configuration.SaveAdapterConfiguration(activeAdapter); }; uiAdapterConfigurationContainer.Child = activeConfigurationEditor; }
/// <summary> /// Sets a new configuration of a particular adapter specified by its /// name (inside the configuration) and the name of the gateway it /// belongs to. /// </summary> /// <remarks> /// The adapter need not to exist previously - a new adapter can be /// created or an existing updated. /// </remarks> /// <param name="gatewayName">name of the gateway</param> /// <param name="xAdapterConfiguration">new adapter configuration</param> public void SaveAdapterConfiguration(AdapterConfiguration adapterConfiguration, string originalName = null) { if (originalName == null) { originalName = adapterConfiguration.AdapterName; } var xOldAdapter = Content.XDocument.XPathSelectElement(string.Format( "/configuration/components/gateway[@name='{0}']/adapters/adapter[@name='{1}']", adapterConfiguration.GatewayName, originalName)); if (xOldAdapter != null) { xOldAdapter.Remove(); } var xAdapters = Content.XDocument.XPathSelectElement(string.Format( "/configuration/components/gateway[@name='{0}']/adapters", adapterConfiguration.GatewayName)); if (xAdapters == null) { throw new ArgumentException(string.Format( "Cannot find gateway named '{0}'.", adapterConfiguration.GatewayName), "gatewayName"); } XElement xAdapter = new XElement(XName.Get("adapter")); xAdapter.SetAttributeValue(XName.Get("name"), adapterConfiguration.AdapterName); XSerializer.Serializer(adapterConfiguration, xAdapter); xAdapters.Add(xAdapter); }
/// <summary> /// Removes a configuration of a particular adapter specified by its /// name and the name of the gateway it belongs to. /// </summary> /// <param name="gatewayName">name of the gateway</param> /// <param name="adapterName">name of the adapter</param> /// <exception cref="System.ArgumentException">if there is no gateway /// with a specified name or its adapter with a specified name /// </exception> public void RemoveAdapterConfiguration(AdapterConfiguration adapterConfiguration) { var xAdapter = Content.XDocument.XPathSelectElement(string.Format( "/configuration/components/gateway[@name='{0}']/adapters/adapter[@name='{1}']", adapterConfiguration.GatewayName, adapterConfiguration.AdapterName)); if (xAdapter == null) { throw new ArgumentException(string.Format( "Cannot find gateway named '{0}' or its adapter named '{1}'.", adapterConfiguration.GatewayName, adapterConfiguration.AdapterName)); } xAdapter.Remove(); }
public void ReplaceConfiguration( MessageFlowConfiguration messageFlow, XElement xrm, AdapterConfiguration[] adapters) { ReplaceConfiguration(consoleServer, messageFlow, xrm, adapters); }
/// <summary> /// Modifies the current XRouter configuration with a custom message /// flow and XML resource storage. /// </summary> public void ReplaceConfiguration( IConsoleServer consoleServer, MessageFlowConfiguration messageFlow, XElement xrm, AdapterConfiguration[] adapters) { // load current configuration var configuration = consoleServer.GetConfiguration(); var xConfig = configuration.Content.XDocument; if (adapters != null) { // remove all adapters xConfig.XPathSelectElement("/configuration/components/gateway/adapters").RemoveNodes(); var gateway = xConfig.XPathSelectElements("/configuration/components/gateway").FirstOrDefault(); if (gateway != null) { string gatewayName = gateway.Attribute("name").Value; foreach (var adapter in adapters) { configuration.SaveAdapterConfiguration(adapter); } } } // remove all message flows xConfig.XPathSelectElement("/configuration/messageflows").RemoveNodes(); // update current message flow configuration.UpdateMessageFlow(messageFlow); // remove all previous XRM items xConfig.XPathSelectElement("/configuration/xml-resource-storage").RemoveNodes(); // add needed XRM items configuration.SaveXrmContent(xrm); // update the configuration consoleServer.ChangeConfiguration(configuration); }
public void LoadSingleCbrRestaurantMenu() { #region Create message flow var terminator = MessageFlowBuilder.CreateTerminator("termination"); var sendToA = MessageFlowBuilder.CreateSender("sendToA", inputMessage: "input", outputEndpoint: "OutA", nextNode: terminator); var cbr = MessageFlowBuilder.CreateCbr(name: "restaurant", testedMessage: "input", defaultTarget: terminator, cases: new[] { new CbrCase("RestaurantMenu_schematron", sendToA), }); var messageFlow = new MessageFlowConfiguration("sendToA", 1) { Nodes = { sendToA, terminator, cbr } }; messageFlow.GetEntryNode().NextNode = sendToA; #endregion var xrm = configManager.LoadXrmItems( new[] { "RestaurantMenu_schematron" }, "Test1"); var adapters = new AdapterConfiguration[] { new AdapterConfiguration("directoryAdapter", "gateway", "directoryAdapter", XDocument.Parse( @"<objectConfig> <item name='checkingIntervalInSeconds'>0.1</item> <item name='inputEndpointToPathMap'> <pair> <key>In</key> <value>C:\XRouterTest\In</value> </pair> </item> <item name='outputEndpointToPathMap'> <pair> <key>OutB</key> <value>C:\XRouterTest\OutB</value> </pair> <pair> <key>OutA</key> <value>C:\XRouterTest\OutA</value> </pair> <pair> <key>OutC</key> <value>C:\XRouterTest\OutC</value> </pair> </item> </objectConfig>")) }; configManager.ReplaceConfiguration(messageFlow, xrm, adapters); }