Ejemplo n.º 1
0
        /*----< uploads file to Receiver instance >--------------------*/

        public bool postFile(string fromDir, string toDir, string fileName)
        {
            FileStream fs = null;
            long       bytesRemaining;

            try
            {
                string path = Path.Combine(fromDir, fileName);
                fs             = File.OpenRead(path);
                bytesRemaining = fs.Length;
                channel.openFileForWrite(toDir, fileName);
                while (true)
                {
                    long   bytesToRead  = Math.Min(ServiceClientEnvironment.blockSize, bytesRemaining);
                    byte[] blk          = new byte[bytesToRead];
                    long   numBytesRead = fs.Read(blk, 0, (int)bytesToRead);
                    bytesRemaining -= numBytesRead;

                    channel.writeFileBlock(blk);
                    if (bytesRemaining <= 0)
                    {
                        break;
                    }
                }
                channel.closeFile();
                fs.Close();
            }
            catch (Exception ex)
            {
                lastError = ex.Message;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /*----< uploads file to Receiver instance >--------------------*/

        /*
         *  expects fully qualified file name for file being sent
         */
        public bool postFile(string fileSpec, string owner, bool toServer)
        {
            FileStream fs = null;
            long       bytesRemaining;

            try
            {
                if (toServer)
                {
                    if (Path.GetFileName(fileSpec) == "")
                    {
                        return(false);
                    }

                    //System.IO.Directory.CreateDirectory("../../Repo/");
                    //System.IO.Directory.CreateDirectory("../../Repo/" + owner);
                    //string fileRef = "../../Repo/" + owner + "/" + Path.GetFileName(fileSpec);
                    string fileRef = owner + "/" + Path.GetFileName(fileSpec);

                    Console.WriteLine("postfile: {0}", fileSpec);


                    fs             = File.OpenRead(fileSpec);
                    bytesRemaining = fs.Length;
                    channel.openFileForWrite(fileRef);
                }
                else
                {
                    if (Path.GetFileName(fileSpec) == "")
                    {
                        return(false);
                    }

                    //System.IO.Directory.CreateDirectory("../../Repo/");
                    //System.IO.Directory.CreateDirectory("../../Repo/" + owner);
                    //string fileRef = "../../Repo/" + owner + "/" + Path.GetFileName(fileSpec);
                    string fileRef = "../../Storage/" + owner + "/" + Path.GetFileName(fileSpec);

                    Console.WriteLine("postfile: {0}", fileSpec);


                    fs             = File.OpenRead(fileRef);
                    bytesRemaining = fs.Length;
                    channel.openFileForWrite(fileSpec);
                }



                while (true)
                {
                    long   bytesToRead  = Math.Min(ServiceClientEnvironment.blockSize, bytesRemaining);
                    byte[] blk          = new byte[bytesToRead];
                    long   numBytesRead = fs.Read(blk, 0, (int)bytesToRead);
                    bytesRemaining -= numBytesRead;

                    channel.writeFileBlock(blk);
                    if (bytesRemaining <= 0)
                    {
                        break;
                    }
                }
                channel.closeFile();
                fs.Close();
            }
            catch (Exception ex)
            {
                lastError = ex.Message;
                return(false);
            }
            return(true);
        }