Example #1
0
        public void RunCached(string proj, string workingDir, string command, params object[] args)
        {
            if (!Path.IsPathRooted(workingDir))
            {
                workingDir = Path.Combine("R:\\", proj, workingDir);
            }
            var arr2 = new List <string>();

            arr2.Add("Run");
            arr2.Add(workingDir);
            arr2.Add(command);
            arr2.AddRange(args.Select(x => x.ToString()));

            var key = string.Join("\n", arr2);

            RunCached(proj, key, () =>
            {
                Console.WriteLine("Running from " + workingDir + ": " + ProcessUtils.GetCommandLine(command, args));
                command = BuildFsApi.FindPath(command, workingDir);
                if (command.EndsWith(".cmd") || command.EndsWith(".bat"))
                {
                    args    = new[] { "/c", command }.Concat(args).ToArray();
                    command = "cmd.exe";
                }
                ProcessUtils.RunPassThroughFrom(workingDir, command, args);
            });
        }
Example #2
0
        static void Main(string[] args)
        {
            var letter = 'R';

            var chan = new IpcChannel(BuildFs.BuildFsApi.IpcChannelName);

            ChannelServices.RegisterChannel(chan, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(BuildFsApiImpl), BuildFsApi.IpcChannelName, WellKnownObjectMode.Singleton);

            var fs = BuildFsFileSystem.Mount(letter, DokanOptions.FixedDrive);

            //fs.ForceRun = true;
            BuildFsApiImpl.Run = (location, commandLine, folder, custom) =>
            {
                try
                {
                    if (custom)
                    {
                        folder = Path.GetFullPath(folder);
                        var components = folder.SplitFast('\\', StringSplitOptions.RemoveEmptyEntries);
                        if (components[0].ToUpper() != letter + ":")
                        {
                            throw new Exception("Must be run in BuildFs drive.");
                        }

                        string exe;
                        string arguments;
                        BuildFsApi.ParseCommandLine(commandLine, out exe, out arguments);
                        commandLine = arguments;
                        BuildFsApi.ParseCommandLine(commandLine, out exe, out arguments);

                        fs.RunCached(components[1], string.Join("\\", components.Skip(2)), exe, arguments);
                    }
                    else
                    {
                        var    projname = "project";
                        var    find     = @"C:\Path\To\Project";
                        var    replace  = letter + @":\" + projname;
                        string exe;
                        string arguments;
                        folder      = folder.Replace(find, replace);
                        commandLine = commandLine.Replace(find, replace);
                        BuildFsApi.ParseCommandLine(commandLine, out exe, out arguments);

                        var realexe = Path.Combine(Path.GetDirectoryName(location), Path.GetFileNameWithoutExtension(location) + "-real.exe");
                        fs.RunCached(projname, folder, realexe, new ProcessUtils.RawCommandLineArgument(arguments));
                    }
                    Console.WriteLine("Success.");
                    return(0);
                }
                catch (ProcessException ex)
                {
                    Console.WriteLine("Failed with " + ex.ExitCode);
                    return(ex.ExitCode);
                }
            };


            //MainInternal(args, fs);


            // Example:

            //fs.AddProject(@"C:\Path\To\Project", "project");
            //fs.RunCached("project", "subdir", "nmake", "part-1");
            //fs.RunCached("project", "subdir", "nmake", "part-2");



            while (true)
            {
                Thread.Sleep(400000);
            }
        }