示例#1
0
        private async void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            string fileDesc = "";

            if (txtDescription.Text != "Enter a description...")
            {
                fileDesc = txtDescription.Text;
            }

            // Actually upload the file
            connection = new Connection();

            FileInfo fi = new FileInfo(fullName);
            await connection.Connect(Settings.Default.ServerIP, Settings.Default.ServerPort);

            await connection.SendPacket(new FileUploadRequest(new NetworkFile(fi.Name, fi.Extension, fi.CreationTimeUtc, fi.Length, fileDesc)));

            progressWindow       = new ProgressWindow();
            progressWindow.Owner = this;
            progressWindow.Show();
            await progressWindow.StartUpload(connection, fi);

            DownloadID id = await connection.ReceivePacket() as DownloadID;

            //MessageBox.Show("Upload complete! Your download code is: " + id.ID, "Upload complete!");

            new UploadCompleteWindow(id.ID).ShowDialog();
        }
示例#2
0
        private static IPacket HandlePacket(dynamic jsonData)
        {
            string packetType = jsonData.packetType;

            switch (packetType)
            {
            case nameof(FileInfoResponse):
                return(FileInfoResponse.ToClass(jsonData));

            case nameof(DownloadID):
                return(DownloadID.ToClass(jsonData));

            default:
                return(null);
            }
        }
示例#3
0
    /// <summary>
    /// 取消加载 by吴江
    /// </summary>
    /// <param name="_id"></param>
    public void CancelDownload(DownloadID _id)
    {
        if (_id == null)
        {
            return;
        }

        if (processingDownloads.ContainsKey(_id.shortURL))
        {
            DownloadInfo info = processingDownloads[_id.shortURL];
            if (info.onComplete != null)
            {
                info.onComplete -= _id.onComplete;
            }
            if (_id.onProgressUpdate != null)
            {
                info.onProgressUpdate -= _id.onProgressUpdate;
            }
        }
    }
示例#4
0
    /// <summary>
    /// 加载指定类型 by吴江
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="_shortURL"></param>
    /// <param name="_name"></param>
    /// <param name="_onComplete"></param>
    /// <param name="_async"></param>
    /// <param name="_onDownloadProgressUpdate"></param>
    /// <param name="_onLoadAsyncProgressUpdate"></param>
    /// <param name="_logErrorIfFailed"></param>
    /// <returns></returns>
    public DownloadID LoadAsset <T>(string _shortURL,
                                    string _name,
                                    System.Action <T, EResult> _onComplete,
                                    bool _async = false,
                                    System.Action <float> _onDownloadProgressUpdate  = null,
                                    System.Action <float> _onLoadAsyncProgressUpdate = null,
                                    bool _logErrorIfFailed = true) where T : UnityEngine.Object
    {
#if !UNITYPRO
        _async = false;
#endif

        DownloadID id = Download(_shortURL,
                                 delegate(UnityEngine.Object _obj, EResult _result)
        {
            if (_result == EResult.Success)
            {
                if (_obj == null)
                {
                    if (_logErrorIfFailed)
                    {
                        Debug.LogError("Failed to load assetBundle from " + _shortURL);
                    }
                    _onComplete(null, EResult.Failed);
                }
                else
                {
                    if (_name == "")
                    {
                        T asset = _obj as T;
                        if (asset)
                        {
                            _onComplete(asset, EResult.Success);
                        }
                        else
                        {
                            if (_logErrorIfFailed)
                            {
                                Debug.LogError("Failed to load " + _name + " from " + _shortURL);
                            }
                            _onComplete(asset, EResult.NotFound);
                        }
                    }
                    else
                    {
                        if (_async)
                        {
                            Debug.LogError("未启用异步加载!");
                            //StartCoroutine(LoadAssetAsync<T>(_objs.assetBundle,
                            //                                    _shortURL,
                            //                                    _name,
                            //                                    _onComplete,
                            //                                    _onLoadAsyncProgressUpdate));
                        }
                        else
                        {
                            T asset = _obj as T;
                            if (asset != null)
                            {
                                _onComplete(asset, EResult.Success);
                            }
                            else
                            {
                                if (_logErrorIfFailed)
                                {
                                    Debug.LogError("Failed to load " + _name + " from " + _shortURL);
                                }
                                _onComplete(asset, EResult.NotFound);
                            }
                        }
                    }
                }
            }
            else
            {
                _onComplete(null, _result);
            }
        },
                                 _onDownloadProgressUpdate);

        return(id);
    }