Esempio n. 1
0
        public static void AsyncGetObjectProgress(string bucketName)
        {
            const string key = "AsyncGetObjectProgress";

            try
            {
                client.PutObject(bucketName, key, fileToUpload);

                var getObjectRequest = new GetObjectRequest(bucketName, key);
                getObjectRequest.StreamTransferProgress += streamProgressCallback;

                string result = "Notice user: put object finish";
                client.BeginGetObject(getObjectRequest, GetObjectCallback, result.Clone());

                _event.WaitOne();
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
        public async Task <Stream> GetFileStreamAsync(string path, CancellationToken cancellationToken = default)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            var response = await Task.Factory.FromAsync(
                (request, callback, state) => _client.BeginGetObject(request, callback, state),
                result => _client.EndGetObject(result),
                new GetObjectRequest(_bucket, NormalizePath(path)),
                null
                ).AnyContext();

            return(response.Content);
        }
Esempio n. 3
0
        public static void AsyncGetObject()
        {
            try
            {
                ossClient.PutObject(bucketName, key, fileToUpload, null);
                Console.WriteLine("PutObject done.");

                ossClient.BeginGetObject(bucketName, key, GetObjectCallback, "GetObject");
                _evnet.WaitOne();
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
Esempio n. 4
0
        public static void AsyncGetObject(string bucketName)
        {
            const string key = "AsyncGetObject";

            try
            {
                client.PutObject(bucketName, key, fileToUpload);

                string result = "Notice user: put object finish";
                client.BeginGetObject(bucketName, key, GetObjectCallback, result.Clone());

                _event.WaitOne();
            }
            catch (OssException ex)
            {
                Debug.Log("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}" +
                          ex.ErrorCode + ex.Message + ex.RequestId + ex.HostId);
            }
            catch (Exception ex)
            {
                Debug.Log("Failed with error info: {0}" + ex.Message);
            }
        }
Esempio n. 5
0
        public static void AsyncGetObject(string bucketName, string filename, string localFilename, Action <string> getCallback = null)
        {
            CreateDispatcherGameObject();

            if (System.IO.File.Exists(localFilename))
            {
                _dispatcher.Enqueue(() => {
                    if (getCallback != null)
                    {
                        getCallback(localFilename);
                    }
                });
                return;
            }

            try
            {
                var ossClient = new OssClient(endPoint, stsToken.AccessKeyId, stsToken.AccessKeySecret, stsToken.SecurityToken);

                Hashtable state = new Hashtable();
                state["client"]        = ossClient;
                state["callback"]      = getCallback;
                state["ossfilename"]   = filename;
                state["localfilename"] = localFilename;

                ossClient.BeginGetObject(bucketName, filename, GetObjectCallback, state);

//				_event.WaitOne();
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
                if (getCallback != null)
                {
                    if (ex is OssException)
                    {
                        getCallback(((OssException)ex).ErrorCode);
                    }
                    else
                    {
                        getCallback(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
                if (getCallback != null)
                {
                    if (ex is ServiceException)
                    {
                        getCallback(((ServiceException)ex).ErrorCode);
                    }
                    else
                    {
                        getCallback(ex.Message);
                    }
                }
            }
        }