示例#1
0
        /// <summary>
        /// Adds a <see cref="ConfigMirror"/> to this <see cref="XConfiguration"/> and mirrors it.
        /// </summary>
        /// <param name="handler"></param>
        public void AddMirror(XFileHandler handler)
        {
            ConfigMirror mirror = new ConfigMirror(this, handler);

            mirror.MirrorNow();
            MirrorsInternal.Add(mirror);
        }
示例#2
0
        /// <summary>
        /// Causes this mirror to copy all contents of the current base <see cref="XConfiguration"/> in its current state to the mirror file destination.
        /// </summary>
        public void MirrorNow()
        {
            string baseName = "\\GlobalStorageContext\\";

            if (SourceConfig.Context != null)
            {
                baseName = SourceConfig.Context.DataPersistenceName;
            }

            string filePath   = baseName + @"\" + SourceConfig.ConfigFileName;
            string oldCfgText = SourceConfig.BaseHandler.ReadText(SourceConfig.ConfigFileName);

            //Console.WriteLine(ThisHandler.BasePath + filePath);
            XFileHandler.CreateEntirePathIfDoesntExist(Path.Combine(ThisHandler.BasePath, filePath));
            ThisHandler.WriteText(filePath, oldCfgText);
        }
示例#3
0
        /// <summary>
        /// Creates a new <see cref="XConfiguration"/> (or gets an existing one) from an underlying <see cref="XFileHandler"/>. This caches the object.
        /// </summary>
        /// <param name="handler">The underlying <see cref="XFileHandler"/> that this <see cref="XConfiguration"/> should extend.</param>
        /// <returns></returns>
        public static XConfiguration GetConfigurationUtility(XFileHandler handler, string cfgFileName = DEFAULT_CFG_FILE_NAME)
        {
            if (ConfigurationTies.ContainsKey(handler) && ConfigurationTies[handler].ContainsKey(cfgFileName))
            {
                return(ConfigurationTies[handler][cfgFileName]);
            }

            if (!ConfigurationTies.ContainsKey(handler))
            {
                ConfigurationTies[handler] = new Dictionary <string, XConfiguration>();
            }


            XConfiguration cfg = new XConfiguration(handler, cfgFileName);

            ConfigurationTies[handler][cfgFileName] = cfg;
            return(cfg);
        }
示例#4
0
        /// <summary>
        /// Returns an <see cref="XFileHandler"/> targetting the specified <seealso cref="BotContext"/>. This caches the handler internally.<para/>
        /// </summary>
        /// <param name="context">The bot context that this targets. If this is null, it will return <see cref="GLOBAL_HANDLER"/></param>
        /// <returns></returns>
        public static XFileHandler GetFileHandlerForBotContext(BotContext context, string subDir = "")
        {
            if (context == null)
            {
                return(GLOBAL_HANDLER);
            }
            //if (StoredContextBindings.TryGetValue(context, out XFileHandler handler)) return handler;
            if (StoredContextBindings.ContainsKey(context) && StoredContextBindings[context].ContainsKey(subDir))
            {
                return(StoredContextBindings[context][subDir]);
            }

            if (!StoredContextBindings.ContainsKey(context))
            {
                StoredContextBindings[context] = new Dictionary <string, XFileHandler>();
            }

            XFileHandler handler = new XFileHandler(Path.Combine(BOT_FILE_DIR, context.DataPersistenceName, subDir), context);

            StoredContextBindings[context][subDir] = handler;
            return(handler);
        }
示例#5
0
 /// <summary>
 /// Mirrors the specified <see cref="XConfiguration"/> so that it saves under <paramref name="handler"/>.
 /// </summary>
 /// <param name="source">The source <see cref="XConfiguration"/></param>
 /// <param name="dataPersistenceFolder">The folder to treat like an alternate data persistence folder.</param>
 public ConfigMirror(XConfiguration source, XFileHandler handler)
 {
     SourceConfig = source;
     ThisHandler  = handler;
     source.OnConfigValueChanged += OnConfigValueChanged;
 }
示例#6
0
 protected XConfiguration(XFileHandler handler, string cfgFileName = DEFAULT_CFG_FILE_NAME)
 {
     BaseHandler    = handler;
     ConfigFileName = cfgFileName;
     LoadConfigurationFile();
 }
示例#7
0
 /// <summary>
 /// Creates a new <see cref="XConfiguration"/> (or gets an existing one) from the specified <see cref="BotContext"/> by automatically creating or getting the <see cref="XFileHandler"/> for said context. This caches the object.
 /// </summary>
 /// <param name="context">The <see cref="BotContext"/> that this <see cref="XConfiguration"/> should target.</param>
 /// <returns></returns>
 public static XConfiguration GetConfigurationUtility(BotContext context, string cfgFileName = DEFAULT_CFG_FILE_NAME)
 {
     return(GetConfigurationUtility(XFileHandler.GetFileHandlerForBotContext(context), cfgFileName));
 }
示例#8
0
 /// <summary>
 /// Adds a <see cref="ConfigMirror"/> to this <see cref="XConfiguration"/>.
 /// </summary>
 /// <param name="handler"></param>
 public void AddMirror(DirectoryInfo baseDirectory)
 {
     AddMirror(XFileHandler.CreateNewHandlerInCustomDirectory(baseDirectory));
 }