Пример #1
0
        /// <summary>
        /// The method returns a list with all data items stored in the bucket "bucketname"
        /// </summary>
        public void ListDataItems(string bucketname, List <string> dataitems, ProgressNotify pNotify, int maxitems = 0)
        {
            try
            {
                ListObjectsResponse response;
                ListObjectsRequest  request = new ListObjectsRequest();
                request.BucketName = bucketname;

                if (maxitems == 0)
                {
                    maxitems = int.MaxValue;
                }

                bool abort = false;
                while (true)
                {
                    // Get the partial list
                    response = S3client.ListObjects(request);

                    // Process response
                    foreach (S3Object entry in response.S3Objects)
                    {
                        dataitems.Add(entry.Key);
                    }

                    // Notify
                    if (pNotify != null)
                    {
                        pNotify(dataitems.Count, out abort);
                        if (abort)
                        {
                            break;
                        }
                    }

                    // If response is truncated, set the marker to get the next set of keys
                    if (response.IsTruncated)
                    {
                        request.Marker = response.NextMarker;
                    }
                    else
                    {
                        break;
                    }

                    // Limit reached
                    if (dataitems.Count >= maxitems)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorCode    = -1;
                ErrorMessage = ex.Message;
            }
        }
Пример #2
0
 private void IncProgress(int blockCount, double elementalPart, int elemPartCeil)
 {
     if (elementalPart < 1)
     {
         ProgressNotify?.Invoke((int)(blockCount / elementalPart));
     }
     else
     {
         if (blockCount % elemPartCeil == 0)
         {
             ProgressNotify?.Invoke(blockCount / elemPartCeil);
         }
     }
 }
Пример #3
0
        public static bool Download(string[] pTsUrls, string sOutFile, ProgressNotify pFunc, HttpHelper.ProxyInfo Proxy = null)
        {
            if (pTsUrls == null || pTsUrls.Count() <= 0)
            {
                return(false);
            }

            if (System.IO.File.Exists(sOutFile))
            {
                System.IO.File.Delete(sOutFile);
            }

            int iCount = pTsUrls.Count();

            for (int i = 0; i < iCount; i++)
            {
                if (!pFunc(i, iCount))
                {
                    return(false);
                }

                bool bRet = true;
                for (int j = 0; j < 100; j++)
                {
                    bRet = (bool)DownloadFileHepler.Start(pTsUrls[i], sOutFile, bAppendFile: true, Timeout: 3 * 1000, Proxy: Proxy);
                    if (!pFunc(i, iCount))
                    {
                        return(false);
                    }
                    if (bRet)
                    {
                        break;
                    }
                }
                if (!bRet)
                {
                    return(false);
                }
            }
            pFunc(iCount, iCount);
            return(true);
        }
Пример #4
0
        public static bool Download(string[] pTsUrls, string sOutFile, ProgressNotify pFunc, ref string errmsg, HttpHelper.ProxyInfo Proxy = null)
        {
            if (pTsUrls == null || pTsUrls.Count() <= 0)
            {
                return(false);
            }

            if (System.IO.File.Exists(sOutFile))
            {
                System.IO.File.Delete(sOutFile);
            }

            int iCount = pTsUrls.Count();

            long [] fileLengths = DownloadFileHepler.GetAllFileLengths(pTsUrls);
            long    allSize     = 0;

            foreach (long item in fileLengths)
            {
                allSize += item;
                if (item <= 0)
                {
                    allSize = 0;
                    break;
                }
            }
            if (allSize <= 0)
            {
                errmsg = "Get file length failed.";
                return(false);
            }

            if (!pFunc(allSize, 0, 0, null))
            {
                return(false);
            }

            DownloadData data = new DownloadData();

            data.AllSize             = allSize;
            data.AlreadyDownloadSize = 0;
            data.Func = pFunc;

            for (int i = 0; i < iCount; i++)
            {
                bool bRet = true;
                for (int j = 0; j < 3; j++)
                {
                    bRet = (bool)DownloadFileHepler.Start(pTsUrls[i], sOutFile, data, bAppendFile: true, Timeout: 3 * 1000, Proxy: Proxy, RetryNum: 3, UpdateFunc: UpdateDownloadNotify);
                    if (!bRet)
                    {
                        continue;
                    }

                    data.AlreadyDownloadSize += fileLengths[i];
                    break;
                }
                if (!bRet)
                {
                    errmsg = "Download some part-files failed.";
                    return(false);
                }
            }
            pFunc(allSize, allSize, 0, null);
            return(true);
        }
Пример #5
0
        /// <summary>
        /// The method returns a list with all data items stored in the bucket "bucketname"
        /// </summary>
        public void ListDataItems(string bucketname, List<string> dataitems, string mask, ProgressNotify pNotify, int maxitems = 0)
        {
            try
            {
                ListObjectsResponse response;
                ListObjectsRequest request = new ListObjectsRequest();
                request.BucketName = bucketname;

                if (maxitems == 0)
                    maxitems = int.MaxValue;

                bool abort = false;
                while (true)
                {
                    // Get the partial list
                    response = S3client.ListObjects(request);

                    // Process response
                    foreach (S3Object entry in response.S3Objects)
                    {
                        if (entry.Key.IndexOf(mask, StringComparison.OrdinalIgnoreCase) > -1)
                            dataitems.Add(entry.Key);
                    }

                    // Notify
                    if (pNotify != null)
                    {
                        pNotify(dataitems.Count, out abort);
                        if (abort)
                            break;
                    }

                    // If response is truncated, set the marker to get the next set of keys
                    if (response.IsTruncated)
                        request.Marker = response.NextMarker;
                    else
                        break;

                    // Limit reached
                    if (dataitems.Count >= maxitems)
                        break;
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorMessage = ex.Message;
            }
        }