/// <summary>
        /// This method will allow you to load the configuration
        /// </summary>
        /// <param name="pathToFile">The path to the file to load</param>
        /// <returns></returns>
        public ILoaderConfiguration Load(string pathToFile)
        {
            ILoaderConfiguration returnConfiguration = null;

            if (!File.Exists(pathToFile))
            {
                return(returnConfiguration);
            }

            try
            {
                string content = File.ReadAllText(pathToFile);
                JsonSimpleConfiguration container = JsonConvert.DeserializeObject <JsonSimpleConfiguration>(content);
                returnConfiguration = container.GetLoaderConfiguration();
            }
            catch (Exception ex)
            {
                EventHandler handler = LoadingError;
                if (handler != null)
                {
                    EventArgs loadingError = new ErrorLoadingEvent(ex);
                    handler.Invoke(this, loadingError);
                }
            }

            return(returnConfiguration);
        }
        /// <summary>
        /// This method will allow you to save the configuration
        /// </summary>
        /// <param name="configuration">The configuration interface to save</param>
        /// <param name="filePath">The path to save the file to</param>
        /// <returns>Saving was successful or not</returns>
        public bool Save(ILoaderConfiguration configuration, string filePath)
        {
            JsonSerializer jsonSerializer = new JsonSerializer();

            using (StreamWriter writer = new StreamWriter(filePath))
            {
                jsonSerializer.Serialize(writer, configuration.GetSaveableObject());
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function will get you the correct loader for the configuration provided
        /// </summary>
        /// <param name="configuration">The configuration to use</param>
        /// <returns>This will return you an ILoader to load your configuration</returns>
        public ILoader GetLoader(ILoaderConfiguration configuration)
        {
            ILoader returnValue = null;

            if (configuration == null)
            {
                return(returnValue);
            }

            switch (configuration.LoaderType)
            {
            case LoaderTypeEnum.FileLoader:
                returnValue = new FileLoader();
                break;

            default:
                break;
            }

            returnValue.SetConfiguration(configuration);

            return(returnValue);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Set the configuration
 /// </summary>
 /// <param name="configuration">The configuration to set</param>
 public void SetConfiguration(ILoaderConfiguration newConfiguration)
 {
     configuration = newConfiguration;
 }