/// <summary>
        /// Send a text file to the cvs server.
        /// </summary>
        /// <param name="outStream"></param>
        /// <param name="fileName"></param>
        public virtual void SendTextFile(CvsStream outStream, string fileName) {
            // convert operating system linefeeds (\r\n) to UNIX style
            // linefeeds (\n)
            string tmpFileName = Path.GetTempFileName();
            FileStream tmpFile = File.Create(tmpFileName);

            StreamReader fs = File.OpenText(fileName);
            LOGGER.Debug(fileName);
            while (true) {
                string line = fs.ReadLine();
//                if (line == null || line.Length == 0 || String.Empty == line) {
                if (line == null) {
                    break;
                }

                byte[] buf = new byte[line.Length];
                SharpCvsLibConfig.Encoding.GetBytes(line.ToCharArray(), 0, line.Length, buf, 0);
                tmpFile.Write(buf, 0, buf.Length);
                tmpFile.WriteByte((byte)'\n');
            }
            tmpFile.Close();
            fs.Close();

            // send converted file like a binary file
            SendBinaryFile(outStream, tmpFileName);

            // delete temp file
            File.Delete(tmpFileName);
        }
        /// <summary>
        /// Send a binary file to the cvs server.
        /// </summary>
        /// <param name="outStream"></param>
        /// <param name="fileName"></param>
        public override void SendBinaryFile(CvsStream outStream, string fileName) {
            FileStream fs = File.OpenRead(fileName);
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();

            Stream oldStream  = outStream.BaseStream;
            outStream.BaseStream = new GZipOutputStream(outStream.BaseStream);

            outStream.SendString("z" + data.Length.ToString() + "\n");
            outStream.Write(data);
            outStream.BaseStream = oldStream;
        }
        /// <summary>
        /// Authentication for the repository.
        /// </summary>
        /// <param name="password"></param>
        public void Authentication(string password) {
            this.protocol = 
                ProtocolFactory.Instance.GetProtocol(repository.CvsRoot.Protocol);

            this.protocol.Repository = this.Repository;
            this.protocol.Password = password;

            protocol.Connect();
            this.inputStream = protocol.InputStream;
            this.outputStream = protocol.OutputStream;


            // TODO: Move these into an abstract request class
            SubmitRequest(new ValidResponsesRequest());
            SubmitRequest(new ValidRequestsRequest());

            SubmitRequest(new UseUnchangedRequest());
            SubmitRequest(new RootRequest(repository.CvsRoot.CvsRepository));

            SubmitRequest(new GlobalOptionRequest(GlobalOptionRequest.Options.QUIET));
        }
        private void Init () {
            inputStream  = new CvsStream (new MemoryStream());
            outputStream = new CvsStream (new MemoryStream());

            this.config = SharpCvsLibConfig.GetInstance();
            try {
                if (config.Log.DebugLog.Enabled) {
                    requestLog = new RequestLog ();
                    responseLog = new ResponseLog ();

                    this.InputStream.RequestMessage.MessageEvent +=
                        new EncodedMessage.MessageHandler (requestLog.Log);
                    this.OutputStream.ResponseMessage.MessageEvent +=
                        new EncodedMessage.MessageHandler (responseLog.Log);
                }
            } catch (Exception e) {
                LOGGER.Error (e);
            }

            if (null == config) {
                config = new SharpCvsLibConfig ();
            }
            LOGGER.Debug("Config=["  + config.ToString() + "]");

            if (this.repository == null) {
                this.repository = DeriveWorkingDirectory();
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Set the cvs stream and then delegate processing to the parameterless process command.
 /// </summary>
 /// <param name="cvsStream"></param>
 /// <param name="services"></param>
 public void Process(CvsStream cvsStream, IResponseServices services) {
     this.stream = cvsStream;
     this.services = services;
     this.Process();
 }
Exemplo n.º 6
0
 public void SetUp()
 {
     cvsStream            = new CvsStream(this);
     cvsStream.BaseStream = this;
 }
        /// <summary>
        /// Receive a text file from the cvs server.
        /// </summary>
        /// <param name="inputStream">Input stream from the cvs server.</param>
        /// <param name="fileName">The name of the file to be created.</param>
        /// <param name="length">The number of bytes the file contains.</param>
        public virtual void ReceiveTextFile(CvsStream inputStream, 
            string fileName, int length) {

            byte[] buffer = new byte[length];

            inputStream.ReadBlock(buffer, length);

            // Take care to preserve none printable or other culture token
            // encodings
            using (MemoryStream ms = new MemoryStream(buffer, 0, length)) {
                StreamReader sr = new StreamReader(ms, Encoding.Default);
                StreamWriter sw = new StreamWriter(fileName, false, Encoding.Default);
                while (sr.Peek() >= 0) {
                    sw.WriteLine(sr.ReadLine());
                }
                sw.Close();
                sr.Close();
            }
        }
        /// <summary>
        /// Receive a binary file from the cvs server.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="fileName"></param>
        /// <param name="length"></param>
        public virtual void ReceiveBinaryFile(CvsStream inputStream, 
            String fileName, int length) {
            byte[] buffer = new byte[length];

            inputStream.ReadBlock(buffer, length);

            FileStream fs = System.IO.File.Create(fileName);
            fs.Write(buffer, 0, length);
            fs.Close();
        }
        /// <summary>
        /// Send a binary file to the cvs server.
        /// </summary>
        /// <param name="outStream">Writable stream to the cvs server.</param>
        /// <param name="fileName">The name of the file to stream across.</param>
        public virtual void SendBinaryFile(CvsStream outStream, string fileName) {
            FileStream fs = File.OpenRead(fileName);
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();

            outStream.SendString(data.Length.ToString() + "\n");
            outStream.Write(data);
        }
 /// <summary>
 /// Receive a binary file from the cvs server.
 /// </summary>
 /// <param name="inputStream"></param>
 /// <param name="fileName"></param>
 /// <param name="length"></param>
 public override void ReceiveBinaryFile(CvsStream inputStream, 
     string fileName, int length) {
     Stream oldStream  = inputStream.BaseStream;
     inputStream.BaseStream = new GZipInputStream(inputStream.BaseStream);
     base.ReceiveBinaryFile(inputStream, fileName, length);
     inputStream.BaseStream = oldStream;
 }
 /// <summary>
 /// Upload a text file to the cvs server.
 /// </summary>
 /// <param name="outStream"></param>
 /// <param name="fileName"></param>
 public override void SendTextFile(CvsStream outStream, string fileName) {
     base.SendTextFile(outStream, fileName); // because it depends ond SendBinaryFile this is OK
 }
Exemplo n.º 12
0
 /// <summary>
 /// Set the internal copy of the input stream.
 /// </summary>
 /// <param name="stream"></param>
 protected void SetOutputStream (CvsStream stream) {
     this.outputStream = stream;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Set the internal copy of the input stream.
 /// </summary>
 /// <param name="stream"></param>
 protected void SetInputStream (CvsStream stream) {
     this.inputStream = stream;
 }