public virtual void OnReceived(byte[] data) { try { mFileGettedSize += data.Length; if (mUploadFileHandler != null) { mUploadFileHandler.OnGettingFileData(data); } SendData(MessageType.Result, mFileGettedSize, ""); if (mFileGettedSize >= mCurrentBag.FileSize) { if (mUploadFileHandler != null) { mUploadFileHandler.OnUploadFileCompleted(); } mUploadFileHandler = null; //重新接收text this.StreamType = RemotingStreamType.Text; SendData(MessageType.Result, "ok", ""); } } catch (Exception ex) { this.StreamType = RemotingStreamType.Text; var baseException = ex.GetBaseException(); SendData(MessageType.InvokeError, baseException != null ? baseException.Message : ex.Message, ""); } }
public virtual void OnDisconnected() { if (mUploadFileHandler != null) { try { mUploadFileHandler.OnUploadFileError(); } catch { } mUploadFileHandler = null; } try { if (this.GroupName.IsNullOrEmpty() == false) { if (KeepAliveHandlers.Contains(this)) { KeepAliveHandlers.Remove(this); RemotingController.MessageReceiverDisconnect(this.Session, this.GroupName); } } } catch { } }
public UploadHandler(IApplicationBuilder app, UploadHeader header, WebSocket socket) { if (MyUploadFileHandler == null) { MyUploadFileHandler = new MyUploadFileHandler(app); } _app = app; _header = header; _socket = socket; _handler = (IUploadFileHandler)app.ApplicationServices.GetService(typeof(IUploadFileHandler)); if (_handler == null) { _handler = MyUploadFileHandler; MyUploadFileHandler.start(); } }
void handleUploadFile(MessageBag msgBag) { mFileGettedSize = 0; try { string remoteName = msgBag.ClassFullName; var pageDefine = checkRemotingName(remoteName); RemotingController currentPage = (RemotingController)Activator.CreateInstance(pageDefine.ControllerType); currentPage.Session = this.Session; currentPage.RequestHeaders = new RemotingController.RequestHeaderCollection(_GetHeaderValueHandler); RemotingContext.Current.Controller = currentPage; currentPage.onLoad(); mFileGettedSize = msgBag.Offset; try { mUploadFileHandler = currentPage.OnBeginUploadFile(msgBag.FileName, msgBag.State, msgBag.FileSize, msgBag.Offset); } catch { throw; } finally { currentPage.unLoad(); } SendData(MessageType.UploadFileBegined, "ok", ""); } catch (Exception ex) { var baseException = ex.GetBaseException(); SendData(MessageType.InvokeError, baseException != null ? baseException.Message : ex.Message, ""); } }