예제 #1
0
파일: Transfer.cs 프로젝트: lonelyong/NgNet
 /// <summary>
 /// (无try)当一块文件传输完成后发生
 /// </summary>
 /// <param name="BlockIndex"></param>
 protected virtual void OnBlockFinished(int BlockIndex)
 {
     if (!_FinishedBlock.Exists(a => a == BlockIndex))
     {
         _FinishedBlock.Add(BlockIndex);
     }
     if (BlockIndex == _TotalBlockCount - 1)
     {
         ByteSpeed = _LastBlockSize / (DateTime.Now - _priorBlockTime).TotalSeconds;
     }
     else
     {
         ByteSpeed = Consts.BlockSize / (DateTime.Now - _priorBlockTime).TotalSeconds;
     }
     _priorBlockTime = DateTime.Now;
     BlockFinished?.Invoke(this, new BlockFinishedEventArgs(BlockIndex));
 }
        /// <summary>
        ///     Handles ScanRMDEvent. Invokes FlashSessionStarted, DownloadStarted, BlockFinished, DownloadEnded,
        ///     FlashSessionEnded, or FirmwareStatusOrErrorReceived.
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="prmdData"></param>
        private void OnScanRmdEvent(short eventType, ref string prmdData)
        {
            var xdoc      = XDocument.Parse(prmdData);
            var status    = (StatusCode)ParseStatus(xdoc);
            var scannerId = ParseScannerId(xdoc);

            switch ((RmdEventType)eventType)
            {
            case RmdEventType.SessionStarted:
            {
                FlashSessionStarted?.Invoke(this, new FlashStartEventArgs(scannerId, status, ParseTotalRecords(xdoc)));
                break;
            }

            case RmdEventType.DownloadStarted:
            {
                DownloadStarted?.Invoke(this, new DownloadEventArgs(scannerId, status, ParseComponent(xdoc)));
                break;
            }

            case RmdEventType.BlockFinished:
            {
                BlockFinished?.Invoke(this, new DownloadEventArgs(scannerId, status, ParseComponent(xdoc), ParseProgress(xdoc)));
                break;
            }

            case RmdEventType.DownloadEnded:
            {
                DownloadEnded?.Invoke(this, new DownloadEventArgs(scannerId, status, ParseComponent(xdoc)));
                break;
            }

            case RmdEventType.SessionEnded:
            {
                FlashSessionEnded?.Invoke(this, new FirmwareEventArgs(scannerId, status));
                break;
            }

            case RmdEventType.ErrorOrStatus:
            {
                FirmwareStatusOrErrorReceived?.Invoke(this, new FirmwareEventArgs(scannerId, status));
                break;
            }
            }
        }