1

我正在尝试使用 C# 运行 SVN 更新。我知道几种方法可以做到这一点,但我不知道哪种方法最好。

现在,我将从定义最佳开始:我正在寻找一种不关心 CPU 使用率、带宽或 RAM 使用率的方法(我将在 VPS 上运行它,所以这些通常都很关键,但在这种情况下,我将在我的游戏服务器关闭时运行该操作)。我基本上是在寻找最快的方法。IE 从开始到结束花费的时间最少。

我知道的方法是:

从我的控制台应用程序运行 .bat 文件作为进程。使用 StartParameters 运行命令以更改目录并更新存储库。创建或下载允许我在应用程序内部运行 SVN 查询的库。

现在,我不知道做第三个有多容易,而且我不是 C# 专家,只是一个有一点空闲时间的爱好者。到目前为止,我的代码如下所示:

class ServerLoader
{
    public static Process TFS = new Process();
    static void Main(string[] args)
    {
        Console.WriteLine("Welcome to XtrmJosh's control centre for TFS Console.");
        // Function generate processes
        Init();

        // Function begin process
        RunServer();

        string userInput = Console.ReadLine();
        if (userInput == "r,0")
        {
            StopServer();
            Init();
            RunServer();
        }
        else if (userInput == "s,0")
        {
            StopServer();
        }
        else if (userInput == "st,0")
        {
            Init();
            RunServer();
        }
        else if (userInput == "u,0")
        {
            StopServer();
            UpdateSVN();
            RunServer();
        }

    }

    static void UpdateSVN()
    {

    }

    static void Init()
    {
        //Initialise the TFS process
        Console.WriteLine("Initialising Process");
        TFS.StartInfo.FileName = "tfs.exe";
        Console.WriteLine("Preventing window creation");
        TFS.StartInfo.CreateNoWindow = true;
        Console.WriteLine("Redirecting Output");
        TFS.StartInfo.RedirectStandardOutput = true;
        Console.WriteLine("Stopping shell execution");
        TFS.StartInfo.UseShellExecute = false;
    }

    static void RunServer()
    {
        Console.WriteLine("Running Server");
        TFS.Start();
    }

    static void StopServer()
    {
        Console.WriteLine("Closing Process");
        TFS.Close();
        Console.WriteLine("Releasing Resources");
        TFS.Dispose();
    }
}

再往下看,我认为很明显我打算在这段代码中添加一个 TCP 服务器,它将监听列出的命令并对其进行操作。我有很多编写 TCP 服务器应用程序的练习,所以我不应该为此而苦恼,但这确实引发了如何处理某些事情的问题,当然知道我无论如何都会联网可能很有用,所以如果我正在联网,则仅使用库来更新存储库可能会更简单。

我也会把它放在那里,你认为哪个 SVN 客户端对于这种工作最稳定,如果它们都同样稳定,那么哪个会最快地完成这个动作?仅供参考,我只更新 3 个文件,2 个是小型 XML 文档,1 个是基于图形的大型文档,大小约为 3MB,很快就会增长到 10MB 以上,所以速度有点关键,尤其是我运行游戏服务器,我希望尽可能减少停机时间......

谢谢

4

0 回答 0