Ejemplo n.º 1
0
    public async UniTask <bool> UploadDataAsync()
    {
        var success = true;

        for (int i = 0; i < uploadFiles.Count; i++)
        {
            UploadProgress = i / (float)uploadFiles.Count;
            OnUploadProgress?.Invoke(UploadProgress);

            var uploadFile = uploadFiles[i];
            var googleFile = new UnityGoogleDrive.Data.File {
                Content = uploadFile.ByteContent
            };
            var fileId = await Helpers.CreateOrUpdateFileAtPathAsync(googleFile, uploadFile.Path, uploadMimeType : "text/plain");

            if (string.IsNullOrEmpty(fileId))
            {
                success = false; break;
            }
        }

        OnUploadProgress?.Invoke(1f);
        UploadProgress = 0f;
        return(success);
    }
Ejemplo n.º 2
0
        private void DoRequest()
        {
            Exception exception = null;

            try {
                foreach (IPAddress addr in Addresses)
                {
                    int        tries    = 0;
                    IPEndPoint endPoint = new IPEndPoint(addr, Request.Port);

                    exception  = null;
                    Connection = Connections.GetConnection(Request.Host, endPoint, Request.IsSecure);

retry:
                    ++tries;
                    try {
                        Request.WriteTo(Connection.Stream, (p, t) => OnUploadProgress?.Invoke(this, p, t));
                        break;
                    } catch (IOException ex) {
                        Connection.Dispose();
                        Connection = Connections.GetConnection(Request.Host, endPoint, Request.IsSecure);

                        if (tries < 2)
                        {
                            goto retry;
                        }

                        exception = ex;
                        continue;
                    } finally {
                        Connection.MarkUsed();
                    }
                }
            } catch (Exception ex) {
                Error(ex);
            }

            if (exception != null)
            {
                Error(exception);
            }
            else if (Connection == null)
            {
                Error(new HttpTaskNoConnectionException());
            }
        }