Exemple #1
0
        /// <summary>
        /// Checks if content files exist and checks watched files.
        /// </summary>
        public void CheckIntegrity(WatchSnapshot snapshot, string rootPath)
        {
            Console.WriteLine("Checking integrity of the final config.");
            Console.WriteLine();

            var checkedItems = new Dictionary <string, Item>();

            foreach (Item item in ContentItems.Values)
            {
                var fullItemPath = Path.Combine(rootPath, item.Path);
                Console.WriteLine("Checking " + fullItemPath);

                if (File.Exists(fullItemPath))
                {
                    checkedItems.Add(item.Path, item);

                    // Watched files are files which aren't tracked by the content pipeline.
                    // But they are tracked by us! We look at the watched files and, if any of them were added, deleted or modified,
                    // we "modify" the tracked file by changing its Last Modified date. This way
                    // Pipeline thinks the file has been updated and rebuilds it.
                    if (!snapshot.CheckMatch(item))
                    {
                        Console.WriteLine("Watched filed were modified! Updating: " + item.Path);
                        File.SetLastWriteTime(Path.Combine(rootPath, item.Path), DateTime.Now);
                    }
                }
            }
            ContentItems = checkedItems;

            Console.WriteLine();

            var checkedReferences = new HashSet <string>();

            foreach (var reference in _references)
            {
                Console.WriteLine("Checking reference: " + Path.Combine(rootPath, reference));
                if (File.Exists(Path.Combine(rootPath, reference)))
                {
                    checkedReferences.Add(reference);
                }
                else
                {
                    Console.WriteLine(reference + " wasn't found! Deleting it from the config.");
                }
            }
            _references = checkedReferences;
        }
Exemple #2
0
        private static void Run()
        {
            Console.WriteLine("Nopipeline v" + Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString());

            var rootPath = Path.GetDirectoryName(_mgcbConfigPath);
            var content  = new Content();
            var snapshot = new WatchSnapshot(content, rootPath);

            // Create MGCB object to read mgcb file.
            var MGCBReader = new MGCBConfigReader();

            MGCBReader.Read(content, _mgcbConfigPath);

            Console.WriteLine();
            Console.WriteLine("-------------------------------------");
            Console.WriteLine();

            // Create ContentProcessor object to read config file and update content
            // content will be overwrited from config file.
            var NPLReader = new NPLConfigReader();

            NPLReader.Read(content, _nplConfigPath);

            Console.WriteLine("-------------------------------------");
            Console.WriteLine();

            // Check all rules in content object and update timestamp of files if required.
            content.CheckIntegrity(snapshot, rootPath);
            snapshot.WriteSnapshot();

            // Saving MGCB file.

            Console.WriteLine();
            Console.WriteLine("-------------------------------------");
            Console.WriteLine();

            Console.WriteLine("Saving new config as " + _mgcbConfigPath);
            Console.WriteLine();

            File.WriteAllText(_mgcbConfigPath, content.Build());

            Console.WriteLine("DONE. o-o");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
        }