ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexey Kukushkin <kukushkinale...@gmail.com>
Subject Re: Persistence store(MSSQL) using cross-platform c#(Ignite Client windows) and java(Ignite Server linux version)
Date Tue, 10 Oct 2017 17:55:06 GMT
Siva, JP,

This approach to add cache configuration at runtime actually works!!! Just
tested it:

Assuming initially you have no caches:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="igniteConfiguration"
type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" />
  </configSections>
  <igniteConfiguration xmlns="
http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection"
gridName="myGrid1" clientMode="true">
    <cacheConfiguration>
    </cacheConfiguration>
  </igniteConfiguration>
  <discoverySpi ... />
</configuration>

This application adds a dynamic cache at runtime using XML configuration
approach instead of code-based approach!

    class Program
    {
        private static Configuration appConfig =
ConfigurationManager.OpenExeConfiguration(Environment.GetCommandLineArgs()[0]);

        static void Main(string[] args)
        {
            AddCacheConfiguration("dynamic-cache-1");

            using (IIgnite ignite =
Ignition.StartFromApplicationConfiguration())
            {
                ignite.GetCache<int, string>("dynamic-cache-1");
            }
        }

        public static void AddCacheConfiguration(string name)
        {
            const string IgniteNS = "
http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection";
            var appConfigPath = Environment.GetCommandLineArgs()[0] +
".config";
            var appConfig = XDocument.Load(appConfigPath);
            var cachesConfig = appConfig
                .Element("configuration")
                .Element(XName.Get("igniteConfiguration", IgniteNS))
                .Element(XName.Get("cacheConfiguration", IgniteNS));
            var cacheConfig = new XElement(XName.Get("cacheConfiguration",
IgniteNS));
            cacheConfig.Add(new XAttribute("name", name));
            cachesConfig.Add(cacheConfig);
            appConfig.Save(appConfigPath);
        }
    }

Mime
View raw message