Beispiel #1
0
        private static bool GetConfigFileFromArgs(string[] args, out string configPath)
        {
            int index = args.Length - 1;
            IEnumerable <Bundle> bundles;
            bool fileExists     = false;
            bool fallbackExists = fileExists = File.Exists(DefaultConfigFileName);

            if (index > -1)
            {
                fileExists = File.Exists(args[index]);

                if (BundleHandler.TryGetBundles(args[index], out bundles))
                {
                    configPath = args[index];
                    return(true);
                }
            }

            if (BundleHandler.TryGetBundles(DefaultConfigFileName, out bundles))
            {
                configPath = new FileInfo(DefaultConfigFileName).FullName;
                return(false);
            }

            if (args.Length > 0)
            {
                if (!fileExists)
                {
                    Console.WriteLine($"A configuration file called {args[index]} could not be found".Red().Bright());
                }
                else
                {
                    Console.WriteLine($"Configuration file {args[index]} has errors".Red().Bright());
                }
            }

            if (!fallbackExists)
            {
                Console.WriteLine($"A configuration file called {DefaultConfigFileName} could not be found".Red().Bright());
            }
            else
            {
                Console.WriteLine($"Configuration file {DefaultConfigFileName} has errors".Red().Bright());
            }

            configPath = null;
            return(false);
        }
Beispiel #2
0
        internal static bool Configure(BundleFileProcessor processor, List <string> configurations, string configPath)
        {
            _processor = processor;

            IEnumerable <Bundle> bundles;

            if (!BundleHandler.TryGetBundles(configPath, out bundles))
            {
                return(false);
            }

            if (configurations.Count > 0)
            {
                foreach (string config in configurations)
                {
                    Bundle bundle = bundles.FirstOrDefault(x => string.Equals(x.OutputFileName, config, StringComparison.OrdinalIgnoreCase));

                    if (bundle != null)
                    {
                        ChangeHandlers.Add(new ChangeHandler(processor, configPath, bundle));
                    }
                }
            }
            else
            {
                foreach (Bundle bundle in bundles)
                {
                    ChangeHandlers.Add(new ChangeHandler(processor, configPath, bundle));
                }

                _watchingAll = true;
            }

            if (ChangeHandlers.Count > 0)
            {
                ConfigureWatcher(configPath);
            }

            return(ChangeHandlers.Count > 0);
        }
Beispiel #3
0
        private static bool ReloadConfig()
        {
            bool anyChanges = false;
            IEnumerable <Bundle> bundles;

            if (!BundleHandler.TryGetBundles(_configPath, out bundles))
            {
                throw new Exception("Unable to load bundles.");
            }

            var oldHandlers = ChangeHandlers.ToList();

            if (!_watchingAll)
            {
                foreach (ChangeHandler handler in oldHandlers)
                {
                    Bundle bundle = bundles.FirstOrDefault(x => string.Equals(x.OutputFileName, handler.Bundle.OutputFileName, StringComparison.OrdinalIgnoreCase));

                    if (bundle != null)
                    {
                        ChangeHandler newHandler = new ChangeHandler(_processor, bundle.FileName, bundle);

                        if (!newHandler.Equals(handler))
                        {
                            ChangeHandlers.Remove(handler);
                            ChangeHandlers.Add(newHandler);
                            _processor.Process(_configPath, new[] { bundle });
                            anyChanges = true;
                        }
                    }
                    else
                    {
                        ChangeHandlers.Remove(handler);
                        Console.WriteLine($"Cannot find configuration {handler.Bundle.OutputFileName}".Orange().Bright());
                    }
                }
            }
            else
            {
                HashSet <Bundle> bundlesToProcess = new HashSet <Bundle>(bundles);

                foreach (ChangeHandler handler in oldHandlers)
                {
                    Bundle bundle = bundles.FirstOrDefault(x => string.Equals(x.OutputFileName, handler.Bundle.OutputFileName, StringComparison.OrdinalIgnoreCase));

                    if (bundle != null)
                    {
                        bundlesToProcess.Remove(bundle);
                        ChangeHandler newHandler = new ChangeHandler(_processor, bundle.FileName, bundle);

                        if (!newHandler.Equals(handler))
                        {
                            ChangeHandlers.Remove(handler);
                            ChangeHandlers.Add(newHandler);
                            _processor.Process(_configPath, new[] { bundle });
                            anyChanges = true;
                        }
                    }
                }

                foreach (Bundle bundle in bundlesToProcess)
                {
                    ChangeHandlers.Add(new ChangeHandler(_processor, _configPath, bundle));
                    _processor.Process(_configPath, new[] { bundle });
                    anyChanges = true;
                }
            }

            return(anyChanges);
        }