/// <summary>
        /// 文件上传创建回调处理
        /// </summary>
        /// <param name="fileIdentity"></param>
        private void onCreated(ReturnValue <UploadFileIdentity> fileIdentity)
        {
            SynchronousState state = SynchronousState.Unknown;

            try
            {
                if (fileIdentity.Type == ReturnType.Success)
                {
                    this.fileIdentity = fileIdentity.Value;
                    if (this.fileIdentity.Tick != 0)
                    {
                        if (index != fileStream.Length)
                        {
                            read();
                            state = SynchronousState.Asynchronous;
                        }
                    }
                    else
                    {
                        state = this.fileIdentity.GetErrorState();
                    }
                }
                else
                {
                    state = SynchronousState.TcpError;
                }
            }
            catch { }
            finally { Remove(state); }
        }
Exemple #2
0
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="fileIdentity">服务端返回文件信息</param>
        /// <param name="data">文件数据</param>
        /// <param name="onUploaded">上传回调处理</param>
        public void Upload(ref UploadFileIdentity fileIdentity, ref SubArray <byte> data, Func <ReturnValue <SynchronousState>, bool> onUploaded)
        {
            SynchronousState state = SynchronousState.IdentityError;

            try
            {
                if (fileIdentity.Tick == AutoCSer.Pub.StartTime.Ticks)
                {
                    ServerFile serverFile;
                    Monitor.Enter(fileLock);
                    if (files.TryGetValue(fileIdentity.Identity, out serverFile))
                    {
                        Monitor.Exit(fileLock);
                        state = SynchronousState.ServerException;
                        new UnionType {
                            Value = serverFile
                        }.ServerUploadFile.Upload(ref data, ref onUploaded);
                    }
                    else
                    {
                        Monitor.Exit(fileLock);
                    }
                }
            }
            finally
            {
                if (onUploaded != null)
                {
                    onUploaded(state);
                }
            }
        }