예제 #1
0
        public CClashResponse ProcessRequest(CClashRequest req)
        {
            var rv = new CClashResponse()
            {
                supported = false
            };

            Logging.Emit("{0}", DateTime.Now.ToString("s"));
            Logging.Emit("server req: cmd = {0}, workdir = {1}",
                         req.cmd, req.workdir);

            switch (req.cmd)
            {
            case Command.GetStats:
                rv.exitcode = 0;
                cache.SetupStats();     // commits stats to disk
                rv.stdout = StatOutputs.GetStatsString(req.compiler, cache);
                break;

            case Command.DisableCache:
                DisableCaching = true;
                rv.supported   = true;
                break;

            case Command.ClearCache:
                DisableCaching = true;
                cache.SetupStats();
                cache.Lock(CacheLockType.ReadWrite);
                cache.OutputCache.ClearLocked();
                cache.IncludeCache.ClearLocked();
                cache.Unlock(CacheLockType.ReadWrite);
                rv.supported = true;
                break;

            case Command.EnableCache:
                DisableCaching = false;
                rv.supported   = true;
                break;

            case Command.Run:
                var stdout = new StringBuilder();
                var stderr = new StringBuilder();
                var comp   = cache.SetCompilerEx(req.pid, req.compiler, req.workdir, new Dictionary <string, string>(req.envs));
                cache.SetCaptureCallback(comp, (so) => { stdout.Append(so); }, (se) => { stderr.Append(se); });
                if (DisableCaching)
                {
                    rv.exitcode = comp.InvokeCompiler(req.argv, null, null, false, new List <string>());
                }
                else
                {
                    rv.exitcode = cache.CompileOrCache(comp, req.argv, req);
                }
                rv.supported = true;
                rv.stderr    = stderr.ToString();
                rv.stdout    = stdout.ToString();

                break;

            case Command.Quit:
                cache.SetupStats();
                Stop();
                break;
            }

            Logging.Emit("server resp: {0}", rv.exitcode);

            return(rv);
        }