コード例 #1
0
ファイル: FileSession.cs プロジェクト: xlg210/Mina.NET
 /// <summary>
 ///     读取路径中的文件
 /// </summary>
 private void ReadPath()
 {
     while (Reading)
     {
         var round = GetAttribute(FieldRound, 0);
         SetAttribute(FieldRound, ++round);
         var endPoint = (FileEndPoint)RemoteEndPoint;
         if (endPoint.PathType == PathType.Directory)
         {
             ReadDirectory(endPoint.Path);
         }
         else if (endPoint.PathType == PathType.File)
         {
             ReadSingleFile(endPoint.Path);
         }
         else
         {
             FilterChain.FireExceptionCaught(
                 new FileNotFoundException($"Can not find file or directory {endPoint.Path}"));
         }
         if (!Config.CycleRead)
         {
             break;
         }
     }
 }
コード例 #2
0
ファイル: FileSession.cs プロジェクト: xlg210/Mina.NET
        /// <summary>
        ///     读取目录所有文件
        /// </summary>
        private void ReadDirectory(string directory)
        {
            var files = Directory.GetFiles(directory);

            try
            {
                foreach (var file in files)
                {
                    using (fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        while (Reading & fileStream.CanRead)
                        {
                            if (ReadSuspended)
                            {
                                //暂停读取
                                Thread.Sleep(Math.Min(100, Config.ReadSpan));
                                continue;
                            }
                            var data      = new byte[1024];
                            var begin     = DateTime.Now;
                            var readBytes = fileStream.Read(data, 0, 1024);
                            if (readBytes == 0)
                            {
                                break;
                            }
                            try
                            {
                                FilterChain.FireMessageReceived(IoBuffer.Wrap(data, 0, readBytes));
                            }
                            catch (Exception ex)
                            {
                                FilterChain.FireExceptionCaught(ex);
                            }
                            var used  = DateTime.Now - begin;
                            var sleep = Config.ReadSpan > used.Milliseconds ? Config.ReadSpan - used.Milliseconds : 0;
                            Thread.Sleep(sleep);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                FilterChain.FireExceptionCaught(e);
            }
        }
コード例 #3
0
        /// <inheritdoc/>
        public ICloseFuture CloseNow()
        {
            lock (_syncRoot)
            {
                if (Closing)
                {
                    return(_closeFuture);
                }

                _closing = true;

                try
                {
                    Destroy();
                }
                catch (Exception e)
                {
                    FilterChain.FireExceptionCaught(e);
                }
            }
            FilterChain.FireFilterClose();
            return(_closeFuture);
        }