Example #1
0
        private static void WriteBytesToFile(FileFrag frag, DataChannel channel)
        {
            //
            SendFileInfo <string> data = new SendFileInfo <string>
            {
                Data         = frag.fileGuid,
                SendFileType = SendFileType.ReciveFileFragSuccess
            };

            channel.SendChannelData(JsonConvert.SerializeObject(data));

            var fileInfo = caches_recive_files.FirstOrDefault(o => o.fileGuid == frag.fileGuid);

            fileInfo.currentFragIndex = frag.currentFragIndex;
            onFragChanged?.Invoke(fileInfo, fileInfo);
            //
            var filepath = localDirectory + frag.fileGuid;

            try
            {
                using (var filestream = File.OpenWrite(filepath))
                {
                    filestream.Seek(frag.currentFragIndex * Params.flagSize, SeekOrigin.Begin);
                    filestream.Write(frag.bytes, 0, frag.bytesLength);
                    filestream.Seek(0, SeekOrigin.Begin);
                }
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        public static void readFragError(DataChannel channel, FileFragHelper_Read filereader)
        {
            removeFileReaderByGuid(channel, filereader.CurrentFileInfo.fileGuid);
            SendFileInfo <FileFragInfo> data = new SendFileInfo <FileFragInfo>
            {
                Data         = filereader.CurrentFileInfo,
                SendFileType = SendFileType.SendFileError
            };

            channel.SendChannelData(JsonConvert.SerializeObject(data));
        }
Example #3
0
        public static void sendFileFrag(DataChannel channel, FileFragHelper_Read filereader)
        {
            var find = findFileReaderByGuid(filereader.CurrentFileInfo.fileGuid);

            if (find != null)
            {
                SendFileInfo <FileFrag> data = new SendFileInfo <FileFrag>
                {
                    Data         = filereader.CurrentFrag,
                    SendFileType = SendFileType.SendFileFrag
                };
                find.CurrentFileInfo.currentFragIndex = filereader.CurrentFrag.currentFragIndex;
                onFragChanged?.Invoke(find.CurrentFileInfo, find.CurrentFileInfo);
                channel.SendChannelData(JsonConvert.SerializeObject(data));
            }
        }
Example #4
0
        public static void startSendFile(DataChannel channel, FileFragHelper_Read filereader)
        {
            var find = findFileReaderByGuid(filereader.CurrentFileInfo.fileGuid);

            if (find == null)
            {
                caches.FirstOrDefault(o => o.Key == channel).Value.Add(filereader);
            }
            onFileCountChanged?.Invoke(channel, cuteFileCount(channel));
            SendFileInfo <FileFragInfo> data = new SendFileInfo <FileFragInfo>
            {
                Data         = filereader.CurrentFileInfo,
                SendFileType = SendFileType.StartSendFile
            };

            channel.SendChannelData(JsonConvert.SerializeObject(data));
        }