Пример #1
0
        public string PostFile(string userName, FileSharingData file)
        {
            string result = null;

            try
            {
                Connect();

                var header = string.Join(",", Method.PostFile, userName, file.FileName, file.FileData.Length);
                _writer.WriteLine(header);

                Thread.Sleep(50);

                _writer.BaseStream.Write(file.FileData, 0, file.FileData.Length);
                _writer.BaseStream.Flush();

                result = _reader.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Disconnect();
            }
            return(result);
        }
Пример #2
0
        public FileSharingData GetImage(string userName, string fileName)
        {
            FileSharingData file = null;

            try
            {
                Connect();
                var header = string.Join(",", Method.GetFile, userName, fileName);
                _writer.WriteLine(header);

                var fileSize = Convert.ToInt64(_reader.ReadLine());
                var data     = ReadFileFromStream(fileSize);
                file = new FileSharingData
                {
                    FileName = fileName,
                    FileData = data
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Disconnect();
            }
            return(file);
        }