コード例 #1
0
        public async Task <int> RunAsync(DeployOptions options)
        {
            log("runnning");

            branch           = options.Branch;
            modelstorePath   = options.ModelstorePath;
            workingDirectory = options.WorkingDirectory;
            workspaceName    = options.WorkspaceName;

            log(String.Format("RemoteHost: '{0}'", options.RemoteHost));

            if (options.RemoteHost != null && options.RemoteHost.Trim() != String.Empty)
            {
                log("remote");
                await Task.Run(() => this.DoRemoteDeploy(options));
            }
            else
            {
                log("local");
                await Task.Run(() => this.DoDeploy());
            }

            return(0);
        }
コード例 #2
0
        void DoRemoteDeploy(DeployOptions options)
        {
            TcpClient client = new TcpClient();

            log("connecting");

            client.Connect(options.RemoteHost, 35777);

            log("connected");

            NetworkStream stream = client.GetStream();

            string text;

            text = String.Format("deploy --branch {0} --workspace {1} --workdir {2} --modelstorepath {3}",
                                 options.Branch,
                                 options.WorkspaceName,
                                 options.WorkingDirectory,
                                 options.ModelstorePath
                                 );

            int size = text.Length;

            byte[] intBuff = new byte[4];
            intBuff = BitConverter.GetBytes(size);
            stream.Write(intBuff, 0, intBuff.Length);

            byte[] dataSend = Encoding.UTF8.GetBytes(text);
            stream.Write(dataSend, 0, dataSend.Length);

            while (client != null && client.Connected)
            {
                int read = 0;

                byte[] Buffer = new byte[4];

                read = stream.Read(Buffer, 0, Buffer.Length);

                if (read == 0)
                {
                    Thread.Sleep(1000);

                    continue;
                }

                int length = BitConverter.ToInt32(Buffer, 0);

                if (length == 0)
                {
                    log("close command received");

                    client.Close();

                    break;
                }

                byte[] buffer = new byte[1024];

                Stream Message = new MemoryStream();

                while (length > 0)
                {
                    read = stream.Read(buffer, 0, Math.Min(buffer.Length, length));
                    Message.Write(buffer, 0, read);
                    length -= read;
                }

                Message.Position = 0;
                StreamReader streamReader = new StreamReader(Message);
                string       recvtext     = streamReader.ReadToEnd();

                log("received:");
                log(recvtext);
            }

            log("finished");
        }