Example #1
0
        public static async Task SychoniAsync(AmazonS3Client amazonS3Client, string dic, string bucketName)
        {
            // amazonS3Client.ExceptionEvent += OnAmazonS3Exception;
            var listBucketResponse = await amazonS3Client.ListBucketsAsync();

            if (listBucketResponse.Buckets.Count > 0)
            {
                var listObjectsResponse = await amazonS3Client.ListObjectsAsync(bucketName);

                DirectoryInfo TheFolder = new DirectoryInfo(dic);
                foreach (FileInfo FileLocal in TheFolder.GetFiles())
                {
                    if (Manipuler.ExistsBucket(FileLocal.Name, listObjectsResponse, amazonS3Client) == false)
                    {
                        await GestionFiles.UpLoad(bucketName, amazonS3Client, dic, FileLocal.Name);
                    }
                }


                foreach (S3Object obj in listObjectsResponse.S3Objects)
                {
                    string   pathTemps = dic + obj.Key;
                    FileInfo fi        = new FileInfo(pathTemps);

                    if (File.Exists(pathTemps))
                    {
                        CompareMd5 Md5FileLocal = new CompareMd5();
                        string     Md5Local     = Md5FileLocal.GetMD5HashFromFile(pathTemps);
                        //string Digest = ETag != null ? obj.ETag.Replace("\"", "").ToLower() : "";

                        GetObjectRequest request = new GetObjectRequest();
                        request.BucketName = bucketName;
                        request.Key        = obj.Key;
                        GetObjectResponse response = await amazonS3Client.GetObjectAsync(request);



                        CompareMd5 compareMd5 = new CompareMd5();
                        Boolean    result     = compareMd5.CompareObjFile(response, pathTemps);
                        if (result == true)
                        {
                            await GestionFiles.synchronisation(obj, bucketName, amazonS3Client, pathTemps, fi);
                        }

                        else
                        {
                            await GestionFiles.supprime(obj, bucketName, amazonS3Client);
                        }
                    }
                }
            }
        }
Example #2
0
        public async Task Gestiontasks()
        {
            var            cts            = new CancellationTokenSource();
            var            ct             = cts.Token;
            Connection     connection     = Connection.GetInstanceConnection();
            AmazonS3Client amazonS3Client = connection.GetAmazonS3Client();

            var listBucketResponse = await amazonS3Client.ListBucketsAsync();

            foreach (var bucket in listBucketResponse.Buckets)
            {
                Console.Out.WriteLine("bucket '" + bucket.BucketName + "' created at " + bucket.CreationDate);
            }

            Console.WriteLine("Input filepath exemple: D:\\\\testLocal\\\\");
            string dic = Console.ReadLine();                //"D:\\testLocal\\";

            Console.WriteLine("Input BucketName");
            string bucketName = Console.ReadLine();
            var    task1      = Manipuler.SychoniAsync(amazonS3Client, dic, bucketName);

            tasks.Add(task1);

            Console.WriteLine("Input filepath exemple: D:\\\\testLocal\\\\");
            string dic2 = Console.ReadLine();                //"D:\\testLocal\\";

            Console.WriteLine("Input BucketName");
            string bucketName2 = Console.ReadLine();
            var    task2       = Task.Run(() => Manipuler.SychoniAsync(amazonS3Client, dic2, bucketName2), ct);

            tasks.Add(task2);
            cts.Cancel();
            foreach (Task task in tasks)
            {
                Console.WriteLine("{0,10} {1,20} ", task.Id, task.Status);
            }

            Console.ReadKey();
        }