Пример #1
0
        public void Run()
        {
            this.watcher.Changed += (sender, args) => this.ReloadApp();
            this.watcher.Deleted += (sender, args) => this.ReloadApp();
            this.watcher.Created += (sender, args) => this.ReloadApp();
            this.watcher.Renamed += (sender, args) => this.ReloadApp();
            this.watcher.IncludeSubdirectories = false;
            this.watcher.EnableRaisingEvents   = true;

            this.logFile = new StreamWriter(File.OpenWrite(Path.Combine(this.directoryToWatch, "Logs", DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss"))));

            this.viewCompiler = CompilerRunner.StartWatching(
                this.directoryToWatch,
                settings,
                new ConsoleMessenger(),
                new TextWriterLoggerWithFlush(this.logFile));

            this.viewCompiler.Compile();
            this.ReloadApp();

            Console.WriteLine("Watching Directory '{0}'...", directoryToWatch);
            Console.WriteLine("Press 'Control + Z' to exit");


            var isControlC = false;

            while (!isControlC)
            {
                var keyInfo = Console.ReadKey();
                isControlC = keyInfo.Key == ConsoleKey.Z &&
                             keyInfo.Modifiers == ConsoleModifiers.Control;
            }
        }
Пример #2
0
        protected override int ExecuteInternalWithExitCode()
        {
            var opts = this.Options;
            var relativeProjectPath = "project/views.json";

            var directory = opts.Directory;

            if (string.IsNullOrWhiteSpace(directory))
            {
                directory = Environment.CurrentDirectory;
            }

            var settings = CompilerRunner.GetBuildSettings(directory, relativeProjectPath, new SharpJsonSerializer(), true);

            var            newViewSettings = new ViewsSettings();
            IViewsSettings optsSettings    = opts;

            newViewSettings.Imports    = optsSettings.Imports.Union(settings.Imports).ToArray();
            newViewSettings.References = optsSettings.References.Union(settings.References)
                                         .Select(x => new Reference {
                HintPath = x.HintPath, Name = x.Name
            })
                                         .Distinct(DelegatedEqualityComparer.Builder <Reference>().Build(x => x.Name))
                                         .ToArray();


            newViewSettings.LinkerPath = Fold(opts, settings, x => x.LinkerPath);
            newViewSettings.OutputFile = Fold(opts, settings, x => x.OutputFile);
            newViewSettings.RelativeIntermediateDirectory = Fold(opts, settings, x => x.RelativeIntermediateDirectory);
            newViewSettings.RelativeSourceDirectory       = Fold(opts, settings, x => x.RelativeSourceDirectory);
            newViewSettings.SecondaryOutputFile           = Fold(opts, settings, x => x.SecondaryOutputFile);
            newViewSettings.SkipSecondaryOutputFile       = opts.SkipSecondaryOutputFile || settings.SkipSecondaryOutputFile;


            if (opts.SingleRun)
            {
                var logFile = new StreamWriter(File.OpenWrite(Path.Combine(directory, "Logs", DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss"))));

                var logger = opts.Verbose
                        ? (ILogger) new TextWriterLogger(Console.Out)
                        : new NullLogger();

                using (var compiler = CompilerRunner.StartWatching(directory, settings, new ConsoleMessenger(), logger))
                {
                    if (compiler.Compile() == CompileResult.Success)
                    {
                        return(-1);
                    }

                    return(-2);
                }
            }


            using (var executor = new SoufflotExecutor(directory, settings, new ConsoleMessenger(), opts.Port))
            {
                executor.Run();
            }

            return(0);
        }