コード例 #1
0
ファイル: Program.cs プロジェクト: jinhang2008/FxSsh
        static void service_CommandOpened(object sender, SessionRequestedArgs e)
        {
            Console.WriteLine("Channel {0} runs command: \"{1}\".", e.Channel.ServerChannelId, e.CommandText);

            var allow = true; // func(e.CommandText, e.AttachedUserauthArgs);

            if (!allow)
                return;

            var parser = new Regex(@"(?<cmd>git-receive-pack|git-upload-pack|git-upload-archive) \'/?(?<proj>.+)\.git\'");
            var match = parser.Match(e.CommandText);
            var command = match.Groups["cmd"].Value;
            var project = match.Groups["proj"].Value;

            var git = new GitService(command, project);

            e.Channel.DataReceived += (ss, ee) => git.OnData(ee);
            e.Channel.CloseReceived += (ss, ee) => git.OnClose();
            git.DataReceived += (ss, ee) => e.Channel.SendData(ee);
            git.CloseReceived += (ss, ee) => e.Channel.SendClose(ee);

            git.Start();
        }