Example #1
0
 private Boolean RecalculateFileChecksum(string path, string fileName)
 {
     try
     {
         Hashtable row = new Hashtable();
         row = db.SelectRow(fileName);
         int    ID   = int.Parse(row["ID"].ToString());
         string hash = string.Empty;
         Dictionary <string, byte[]> Packets = new Dictionary <string, byte[]>();
         Packets = GetPackets(Path.Combine(path, fileName));
         foreach (KeyValuePair <string, byte[]> item in Packets)
         {
             hash = GetChecksumBufferedFromByteArray(item.Value);
             db.UpInsertChecksum("checksums", ID, hash, item.Key);
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Example #2
0
        private void HandleClientComm(object obj)
        {
            //NetworkStream clientStream = tcpClient.GetStream();
            progress.Report("client connected\n");
            FileStream                  fileStream3;
            ClsFileInformation          objFileInfo = new ClsFileInformation();
            Dictionary <string, byte[]> Packets     = new Dictionary <string, byte[]>();
            string hash = "";
            // retrieve client from parameter passed to thread
            TcpClient client = (TcpClient)obj;
            // sets two streams
            //StreamWriter sWriter = new StreamWriter(client.GetStream(), Encoding.ASCII);
            //StreamReader sReader = new StreamReader(client.GetStream(), Encoding.ASCII);
            NetworkStream ns = client.GetStream();
            // Get file info
            long   fileLength;
            string fileName;
            string fileSize;

            {
                byte[] fileNameBytes;
                byte[] fileNameLengthBytes = new byte[4]; //int32
                byte[] fileLengthBytes     = new byte[8]; //int64

                ns.Read(fileLengthBytes, 0, 8);           // int64
                ns.Read(fileNameLengthBytes, 0, 4);       // int32
                fileNameBytes = new byte[BitConverter.ToInt32(fileNameLengthBytes, 0)];
                ns.Read(fileNameBytes, 0, fileNameBytes.Length);

                fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
                fileName   = ASCIIEncoding.ASCII.GetString(fileNameBytes);
            }
            Thread.Sleep(1000);
            FileStream fileStream = File.Open(Path.Combine(ConfigurationManager.AppSettings["sourcePath"], fileName), FileMode.Create, FileAccess.ReadWrite);
            int        read;
            int        totalRead = 0;

            byte[] buffer = new byte[32 * 1024]; // 32k chunks
            while ((read = ns.Read(buffer, 0, buffer.Length)) > 0)
            {
                fileStream.Write(buffer, 0, read);
                totalRead += read;
                //progressBar1.Value = (int)((100d * totalRead) / fileLength);
            }

            fileStream.Dispose();
            db.UpInsert("Files", fileName);

            Hashtable row = new Hashtable();

            row = db.SelectRow(fileName);
            int          ID = int.Parse(row["ID"].ToString());
            FileSplitter fs = new FileSplitter();

            Packets = fs.SplitFile(Path.Combine(ConfigurationManager.AppSettings["sourcePath"], fileName), 4);
            foreach (KeyValuePair <string, byte[]> item in Packets)
            {
                hash = GetChecksumBufferedFromByteArray(item.Value);
                db.UpInsertChecksum("checksums", ID, hash, item.Key);
                //fManager.DeleteFile(Path.Combine(ConfigurationManager.AppSettings["sourcePath"], packet));
            }
            //client.Close();
        }