Exemple #1
0
        public void TestCopyObjectAsync()
        {
            var    client     = new S3Service();
            String bucketName = Environment.GetEnvironmentVariable("SCREEN3_S3_BUCKET");

            client.CopyObject(bucketName, @"source/1997-2006.zip", bucketName, @"archive/1997-2006.zip").Wait();
        }
Exemple #2
0
        public override FileOperationResult CopyTo(S3CommanderFile dest, bool overwrite, bool move, RemoteInfo info)
        {
            var entry = dest as Entry;

            if (entry == null)
            {
                return(FileOperationResult.NotSupported);
            }

            try
            {
                if (!overwrite && S3Service.ObjectExists(entry.bucketName, entry.key))
                {
                    return(FileOperationResult.Exists);
                }

                var source = bucketName + "/" + key;
                var target = entry.bucketName + "/" + entry.key;

                if (SetProgress(source, target, 0, 100) == false)
                {
                    return(FileOperationResult.UserAbort);
                }
                S3Service.CopyObject(bucketName, key, entry.bucketName, entry.key);

                if (move)
                {
                    if (SetProgress(source, target, 50, 100) == false)
                    {
                        return(FileOperationResult.UserAbort);
                    }
                    DeleteFile();
                }
                if (SetProgress(source, target, 100, 100) == false)
                {
                    return(FileOperationResult.UserAbort);
                }

                return(FileOperationResult.OK);
            }
            catch (Exception ex)
            {
                Context.Log.Error(ex);
                return(FileOperationResult.WriteError);
            }
        }
Exemple #3
0
        public async Task ProcessSourceFile(S3Object fileInfo)
        {
            LambdaLogger.Log($"About to download file, {fileInfo.Key}\n");
            String resultFileName = await this.DownloadFileAsync(fileInfo.BucketName, fileInfo.Key, this.Temp_Folder + "originSourceFiles/");

            string dailyTargetFolder = this.Temp_Folder + $"originExtractedFiles/{fileInfo.Key}/";

            LambdaLogger.Log($"Download file, {fileInfo.Key}, about to extract to {dailyTargetFolder}.\n");
            List <String> dailyFileList = this.ExtractIntoDayData(resultFileName, dailyTargetFolder);

            LambdaLogger.Log($"Extracted files done. items {dailyFileList.Count} \n");

            foreach (string path in dailyFileList)
            {
                this.AddDailyFileIntoStockDict(path);
            }

            TickerBLL bll = new TickerBLL(this.S3_Bucket_Name, this.Temp_Folder);

            // save tickers into S3
            foreach (KeyValuePair <string, List <TickerEntity> > tickerGroup in this.stockDict)
            {
                await bll.SaveTickersToS3(tickerGroup.Key, tickerGroup.Value, true);

                LambdaLogger.Log($"Save to S3 for {tickerGroup.Key} with items {tickerGroup.Value.Count} \n");
            }

            // move file to archive
            S3Service service    = new S3Service();
            string    archiveKey = fileInfo.Key.Replace("source", "archive");
            await service.CopyObject(this.S3_Bucket_Name, fileInfo.Key, this.S3_Bucket_Name, archiveKey);

            await service.DeleteObject(this.S3_Bucket_Name, fileInfo.Key);

            // about to clean things
            File.Delete(resultFileName);
            FileHelper.ClearDirectory(this.Temp_Folder + $"originExtractedFiles/", true);

            this.stockDict = new Dictionary <string, List <TickerEntity> >();

            LambdaLogger.Log("Temp folder cleared");
        }
Exemple #4
0
 public void CopyObject(string sourceBucketName, string sourceKey, string destBucketName, string destKey)
 {
     client.CopyObject(sourceBucketName, sourceKey, destBucketName, destKey);
 }