Example #1
0
        /// <summary>
        /// Adds linked config file to this instance.
        /// </summary>
        /// <param name="configFileToAdd">The config file to add.</param>
        public void AddLinkedConfigFile(ConfigFile configFileToAdd)
        {
            foreach (var configFile in _configFilesLinked)
                if (configFile.Id == configFileToAdd.Id)
                    return;

            _configFilesLinked.Add(configFileToAdd);
        }
Example #2
0
        /// <summary>
        /// Loads the specified config file attached to a parent config file.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="file">The file.</param>
        /// <returns>The loaded config</returns>
        private static ConfigFile Load(ConfigFile parent, string file, string[] macros = null)
        {
            var deserializer = new XmlSerializer(typeof(ConfigFile));
            ConfigFile config = null;
            try
            {
                Logger.PushLocation(file);
                config = (ConfigFile)deserializer.Deserialize(new StringReader(Preprocessor.Preprocess(File.ReadAllText(file), macros)));

                if (config != null)
                    config.PostLoad(parent, file, macros);
            }
            catch (Exception ex)
            {
                Logger.Error("Unable to parse file [{0}]", ex, file);
            }
            finally
            {
                Logger.PopLocation();
            }
            return config;
        }
Example #3
0
        private void PostLoad(ConfigFile parent, string file, string[] macros = null)
        {
            FilePath = file;
            Parent = parent;

            Variables.Add(new KeyValue("THIS_CONFIG_PATH", Path.GetDirectoryName(AbsoluteFilePath)));

            // Load all dependencies
            foreach (var dependFile in Files)
            {
                var dependFilePath = ExpandString(dependFile, false);
                if (!Path.IsPathRooted(dependFilePath))
                    dependFilePath = Path.Combine(Path.GetDirectoryName(AbsoluteFilePath), dependFilePath);
                
                var subMapping = Load(this, dependFilePath, macros);
                if (subMapping != null)
                {
                    subMapping.FilePath = dependFile;
                    References.Add(subMapping);
                }
            }

            // Clear all depends file
            Files.Clear();

            // Add this mapping file
            GetRoot().MapIdToFile.Add(Id, this);            
        }
Example #4
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
 /// </returns>
 public bool Equals(ConfigFile other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Id, Id);
 }
Example #5
0
        /// <summary>
        /// Initializes the specified instance with a config root file.
        /// </summary>
        /// <returns>true if the config or assembly changed from the last run; otherwise returns false</returns>
        public bool Init()
        {
            _thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
            _assemblyCheckFile = Path.ChangeExtension(_thisAssemblyPath, ".check");
            _assemblyDatetime = File.GetLastWriteTime(_thisAssemblyPath);
            _isAssemblyNew = (File.GetLastWriteTime(_thisAssemblyPath) != File.GetLastWriteTime(_assemblyCheckFile));
            _generatedPath = Path.GetDirectoryName(_configRootPath);

            if (_isAssemblyNew)
                Logger.Message("Assembly [{0}] changed. All files will be generated", _thisAssemblyPath);

            Logger.Message("Loading config files...");

#if WIN8METRO
            // Load configuration
            Macros.Add("WIN8METRO");
            Macros.Add("W8CORE");
#endif
#if WP8
            // Load configuration
            Macros.Add("WP8");
            Macros.Add("W8CORE");
#endif
#if DIRECTX11_1
            // Load configuration
            Macros.Add("DIRECTX11_1");
#else
            if (GccXml.GetWindowsFramework7Version("7.0a", "7.1") == "7.0a")
            {
                Macros.Add("WINSDK_70a");
            }
            else
            {
                Macros.Add("WINSDK_71");
            }
#endif
            Config = ConfigFile.Load(_configRootPath, Macros.ToArray());
            var latestConfigTime = ConfigFile.GetLatestTimestamp(Config.ConfigFilesLoaded);

            _allConfigCheck = Config.Id + "-CodeGen.check";

            // Return true if a config file changed or the assembly changed
            return !File.Exists(_allConfigCheck) || latestConfigTime > File.GetLastWriteTime(_allConfigCheck) || _isAssemblyNew;
        }
Example #6
0
        /// <summary>
        /// Initializes the specified instance with a config root file.
        /// </summary>
        /// <returns>true if the config or assembly changed from the last run; otherwise returns false</returns>
        public bool Init()
        {
            _thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
            _assemblyCheckFile = Path.ChangeExtension(_thisAssemblyPath, ".check");
            _assemblyDatetime = File.GetLastWriteTime(_thisAssemblyPath);
            _isAssemblyNew = (File.GetLastWriteTime(_thisAssemblyPath) != File.GetLastWriteTime(_assemblyCheckFile));
            _generatedPath = Path.GetDirectoryName(_configRootPath);

            Logger.Message("Loading config files...");

#if STORE_APP
            Macros.Add("DIRECTX11_1");
            Macros.Add("STORE_APP");
#else
            Macros.Add("DIRECTX11_1");
            Macros.Add("DESKTOP_APP");
#endif

            Config = ConfigFile.Load(_configRootPath, Macros.ToArray());
            var latestConfigTime = ConfigFile.GetLatestTimestamp(Config.ConfigFilesLoaded);

            _allConfigCheck = Config.Id + "-CodeGen.check";

            var isConfigFileChanged = !File.Exists(_allConfigCheck) || latestConfigTime > File.GetLastWriteTime(_allConfigCheck);
            if(_isAssemblyNew)
            {
                Logger.Message("Assembly [{0}] changed. All files will be generated", _thisAssemblyPath);
            }
            else if(isConfigFileChanged)
            {
                Logger.Message("Config files [{0}] changed", string.Join(",", Config.ConfigFilesLoaded.Select(file => Path.GetFileName(file.AbsoluteFilePath))));
            }

            // Return true if a config file changed or the assembly changed
            return isConfigFileChanged || _isAssemblyNew;
        }