Пример #1
0
        public string ReadTextFile(string fullPath)
        {
            var FileContents = string.Empty;

            ConsoleWrite.Print("Reading file: " + fullPath);
            lock (SDCardLock)
            {
                if (File.Exists(fullPath))
                {
                    using (StreamReader objStreamReader = new StreamReader(fullPath))
                        FileContents = objStreamReader.ReadToEnd();
                }
                else
                {
                    throw new IOException("File Not Found!");
                }
            }
            return(FileContents);
        }
Пример #2
0
        public void SendFile(string fullPath, Socket socket)
        {
            ConsoleWrite.Print("Reading file: " + fullPath);
            bool chunkHasBeenRead = false;
            int  totalBytesRead   = 0;

            lock (SDCardLock)
            {
                if (File.Exists(fullPath))
                {
                    using (FileStream inputStream = new FileStream(fullPath, FileMode.Open))
                    {
                        byte[] readBuffer = new byte[READ_CHUNK_SIZE];
                        while (true)
                        {
                            // Send the file a few bytes at a time
                            int bytesRead = inputStream.Read(readBuffer, 0, readBuffer.Length);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            socket.Send(readBuffer, 0, bytesRead, SocketFlags.None);
                            //sendDataCallback(readBuffer);
                            totalBytesRead += bytesRead;
                        }
                    }
                    chunkHasBeenRead = true;
                }
                else
                {
                    chunkHasBeenRead = false;
                }
            }
            if (chunkHasBeenRead == true)
            {
                ConsoleWrite.Print("Sending " + totalBytesRead.ToString() + " bytes...");
            }
            else
            {
                ConsoleWrite.Print("Failed to read chunk, full path: " + fullPath);
            }
        }