public void DeleteFolder(string path)
        {
            path = CleanPath(path);
            var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);

            dir.Delete();
        }
        /// <summary>
        /// Delete Directory from S3
        /// </summary>
        /// <param name="uploadDirectory"></param>
        /// <param name="bucket"></param>
        /// <returns></returns>
        public bool DeleteAsset(string bucket, string uploadDirectory)
        {
            try
            {
                S3DirectoryInfo directoryToDelete = new S3DirectoryInfo(_client, bucket, uploadDirectory);

                var directoryFiles = directoryToDelete.EnumerateFiles();
                foreach (S3FileInfo file in directoryFiles)
                {
                    S3FileInfo filetoDelete = new S3FileInfo(_client, bucket, file.FullName.Replace(bucket + ":\\", string.Empty));
                    if (filetoDelete.Exists)
                    {
                        filetoDelete.Delete();
                    }
                }


                if (directoryToDelete.Exists)
                {
                    directoryToDelete.Delete(false);
                    return(true);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.InnerException.Message);

                return(false);
            }
            return(false);
        }
        public void DeleteDirectory(string path)
        {
            string          key       = GetKey(path);
            S3DirectoryInfo directory = new S3DirectoryInfo(_client, _bucketName, key);

            directory.Delete(true);
        }
        public void DeleteFolder(string file_path)
        {
            EnsureBucketName();

            using (var client = Storage.GetClient())
            {
                var directoryToDelete = new S3DirectoryInfo(client, BucketName, file_path);
                directoryToDelete.Delete(true);
            }
        }
Exemplo n.º 5
0
        public static void DeleteFolder(string id, ImageService.ImageIdentity entity)
        {
            AmazonS3Config cfg = new AmazonS3Config();

            cfg.RegionEndpoint = Amazon.RegionEndpoint.EUWest1;
            AmazonS3Client  s3Client         = new AmazonS3Client(_awsAccessKey, _awsSecretKey, cfg);
            S3DirectoryInfo directoyToDelete = new S3DirectoryInfo(s3Client, _bucketName, String.Format("{0}/{1}", Enum.GetName(typeof(ImageIdentity), entity), id));

            directoyToDelete.Delete(true);//true will delete recursive all folder inside
        }
Exemplo n.º 6
0
        public void DeleteFolder(string path)
        {
            if (!IsFolderExits(path))
            {
                throw new InvalidOperationException("Directory " + path + " does not exist");
            }

            var folderInfo = new S3DirectoryInfo(_amazonS3, _bucketName, path);

            folderInfo.Delete(true);
        }
Exemplo n.º 7
0
        public void Init()
        {
            var amazonS3Client = new AmazonS3Client(RegionEndpoint.USEast1);

            _s3DirectoryInfo = new S3DirectoryInfo(amazonS3Client, _testDirectory);

            if (_s3DirectoryInfo.Exists)
            {
                _s3DirectoryInfo.Delete(true);
            }
            _s3DirectoryInfo.Create();

            _targetDirectory = new S3DirectoryObject(amazonS3Client, _testDirectory);

            _sourceObject = DirectoryHelper.CreateFullDirectory();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Implementation of the ZephyrDirectory Delete method in Amazon S3 Storage.
        /// </summary>
        /// <param name="recurse">Remove all objects in the directory as well.  If set to "false", directory must be empty or an exception will be thrown.</param>
        /// <param name="stopOnError">Stop deleting objects in the directory if an error is encountered.</param>
        /// <param name="verbose">Log each object that is deleted from the directory.</param>
        /// <param name="callbackLabel">Optional "label" to be passed into the callback method.</param>
        /// <param name="callback">Optional method that is called for logging purposes.</param>
        public override void Delete(bool recurse = true, bool stopOnError = true, bool verbose = true, string callbackLabel = null, Action <string, string> callback = null)
        {
            try
            {
                if (_client == null)
                {
                    throw new Exception($"AWSClient Not Set.");
                }

                String key = ObjectKey;
                key = key.Replace('/', '\\');
                if (key.EndsWith("\\"))
                {
                    key = key.Substring(0, key.Length - 1);
                }
                S3DirectoryInfo dirInfo = new S3DirectoryInfo(_client.Client, BucketName, key);

                if (dirInfo.Exists)
                {
                    if (!recurse)
                    {
                        int dirs  = dirInfo.GetDirectories().Length;
                        int files = dirInfo.GetFiles().Length;
                        if (dirs > 0 || files > 0)
                        {
                            throw new Exception($"Directory [{FullName}] is not empty.");
                        }
                    }

                    dirInfo.Delete(recurse);
                }

                if (verbose)
                {
                    Logger.Log($"Directory [{FullName}] Was Deleted.", callbackLabel, callback);
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, callbackLabel, callback);
                if (stopOnError)
                {
                    throw;
                }
            }
        }
Exemplo n.º 9
0
        public void Rename(string newName)
        {
            var newKey       = _key.Replace(Name, newName);
            var newDirectory = new S3DirectoryInfo(_s3Client, _bucketName, newKey);

            if (!newDirectory.Exists)
            {
                newDirectory.Create();
            }
            foreach (var s3FileInfo in _s3DirectoryInfo.GetFiles())
            {
                s3FileInfo.MoveTo(newDirectory);
            }

            _s3DirectoryInfo.Delete();
            _s3DirectoryInfo = newDirectory;
        }
Exemplo n.º 10
0
        public void RenameDirectory(string directoryName, string newDirectoryName)
        {
            S3DirectoryInfo s3DirectoryInfo = new S3DirectoryInfo(Client, Bucket, directoryName);

            if (!new S3DirectoryInfo(Client, Bucket, newDirectoryName).Exists)
            {
                CreateFolder(StorageUtils.NormalizeDirectoryName(newDirectoryName));
            }
            foreach (IS3FileSystemInfo file in s3DirectoryInfo.GetFileSystemInfos())
            {
                if (file.Type == FileSystemType.Directory)
                {
                    RenameDirectory(directoryName + "\\" + file.Name, newDirectoryName + "\\" + file.Name);
                }
                else
                {
                    Rename(directoryName.Replace("\\", StorageUtils.DELIMITER) + StorageUtils.DELIMITER + file.Name, newDirectoryName.Replace("\\", StorageUtils.DELIMITER) + StorageUtils.DELIMITER + file.Name, GxFileType.Public);
                }
            }
            s3DirectoryInfo.Delete();
        }
 public void UploadObject(Stream stream, string keyName, string folderPath)
 {
     try
     {
         S3DirectoryInfo s3DirectoryInfo = new S3DirectoryInfo(this.amazonS3Client, bucketName, folderPath);
         isValid = s3DirectoryInfo.Name.Contains(Enum.GetName(typeof(folderNames), folderNames.DefaultImage));
         if (isValid)
         {
             s3DirectoryInfo.Delete(true); // true will delete recursively in folder inside
         }
         TransferUtility fileTransferUtility = new TransferUtility(this.amazonS3Client);
         fileTransferUtility.Upload(stream, bucketName, keyName);
     }
     catch (AmazonS3Exception ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 12
0
        public OperationResponse DeleteFolder(string bucket, string key, RegionEndpoint region)
        {
            var operationResponse = new OperationResponse();

            try
            {
                this.IsValid(_awsAccessKey, _awsSecretAccessKey, bucket, key, region);
                using (var client = new AmazonS3Client(_awsAccessKey, _awsSecretAccessKey, region))
                {
                    S3DirectoryInfo folder = new S3DirectoryInfo(client, bucket, key);
                    folder.Delete(true);
                }
                operationResponse.StatusCode = System.Net.HttpStatusCode.OK;
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null &&
                    (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                     amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    operationResponse.Message    = "Please check the provided AWS Credentials. If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3";
                    operationResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                }
                else
                {
                    operationResponse.Message    = amazonS3Exception.Message;
                    operationResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                }
            }
            catch (Exception oException)
            {
                operationResponse.Message    = oException.Message;
                operationResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError;
            }
            return(operationResponse);
        }
Exemplo n.º 13
0
        public static void Cleanup()
        {
            if (Directory.Exists(_root))
            {
                Directory.Delete(_root, true);
            }

            void DeleteRootFolder()
            {
                using (var s3Client = new AmazonS3Client(_param.AwsAccessKeyId, _param.AwsSecretAccessKey,
                                                         new AmazonS3Config {
                    RegionEndpoint = Utilities.RegionSelection(_param.Region)
                }))
                {
                    var directoryToDelete = new S3DirectoryInfo(s3Client, _param.BucketName, Prefix.Replace("/", ""));
                    if (directoryToDelete.Exists)
                    {
                        directoryToDelete.Delete(true);
                    }
                }
            }

            DeleteRootFolder();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            if (checkRequiredFields())
            {
                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USWest2))
                {
                    // Creates the bucket.
                    S3DirectoryInfo rootDirectory = new S3DirectoryInfo(client, bucketName);
                    rootDirectory.Create();

                    // Creates a file at the root of the bucket.
                    S3FileInfo readme = rootDirectory.GetFile("README.txt");
                    using (StreamWriter writer = new StreamWriter(readme.OpenWrite()))
                        writer.WriteLine("This is my readme file.");

                    DirectoryInfo localRoot = new DirectoryInfo(@"C:\");
                    DirectoryInfo localCode = localRoot.CreateSubdirectory("code");

                    // Create a directory called code and write a file to it.
                    S3DirectoryInfo codeDir = rootDirectory.CreateSubdirectory("code");
                    S3FileInfo codeFile = codeDir.GetFile("Program.cs");
                    using(StreamWriter writer = new StreamWriter(codeFile.OpenWrite()))
                    {
                        writer.WriteLine("namespace S3FileSystem_Sample");
                        writer.WriteLine("{");
                        writer.WriteLine("    class Program");
                        writer.WriteLine("    {");
                        writer.WriteLine("        static void Main(string[] args)");
                        writer.WriteLine("        {");
                        writer.WriteLine("            Console.WriteLine(\"Hello World\");");
                        writer.WriteLine("        }");
                        writer.WriteLine("    }");
                        writer.WriteLine("}");
                    }


                    // Create a directory called license and write a file to it.
                    S3DirectoryInfo licensesDir = rootDirectory.CreateSubdirectory("licenses");
                    S3FileInfo licenseFile = licensesDir.GetFile("license.txt");
                    using (StreamWriter writer = new StreamWriter(licenseFile.OpenWrite()))
                        writer.WriteLine("A license to code");


                    Console.WriteLine("Write Directory Structure");
                    Console.WriteLine("------------------------------------");
                    WriteDirectoryStructure(rootDirectory, 0);


                    Console.WriteLine("\n\n");
                    foreach (var file in codeDir.GetFiles())
                    {
                        Console.WriteLine("Content of {0}", file.Name);
                        Console.WriteLine("------------------------------------");
                        using (StreamReader reader = file.OpenText())
                        {
                            Console.WriteLine(reader.ReadToEnd());
                        }
                    }

                    // Deletes all the files and then the bucket.
                    rootDirectory.Delete(true);
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
 public void DeleteFolder(string path)
 {
     path = CleanPath(path);
     var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);
     dir.Delete();
 }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            if (checkRequiredFields())
            {
                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USWest2))
                {
                    // Creates the bucket.
                    S3DirectoryInfo rootDirectory = new S3DirectoryInfo(client, bucketName);
                    rootDirectory.Create();

                    // Creates a file at the root of the bucket.
                    S3FileInfo readme = rootDirectory.GetFile("README.txt");
                    using (StreamWriter writer = new StreamWriter(readme.OpenWrite()))
                        writer.WriteLine("This is my readme file.");

                    DirectoryInfo localRoot = new DirectoryInfo(@"C:\");
                    DirectoryInfo localCode = localRoot.CreateSubdirectory("code");

                    // Create a directory called code and write a file to it.
                    S3DirectoryInfo codeDir  = rootDirectory.CreateSubdirectory("code");
                    S3FileInfo      codeFile = codeDir.GetFile("Program.cs");
                    using (StreamWriter writer = new StreamWriter(codeFile.OpenWrite()))
                    {
                        writer.WriteLine("namespace S3FileSystem_Sample");
                        writer.WriteLine("{");
                        writer.WriteLine("    class Program");
                        writer.WriteLine("    {");
                        writer.WriteLine("        static void Main(string[] args)");
                        writer.WriteLine("        {");
                        writer.WriteLine("            Console.WriteLine(\"Hello World\");");
                        writer.WriteLine("        }");
                        writer.WriteLine("    }");
                        writer.WriteLine("}");
                    }


                    // Create a directory called license and write a file to it.
                    S3DirectoryInfo licensesDir = rootDirectory.CreateSubdirectory("licenses");
                    S3FileInfo      licenseFile = licensesDir.GetFile("license.txt");
                    using (StreamWriter writer = new StreamWriter(licenseFile.OpenWrite()))
                        writer.WriteLine("A license to code");


                    Console.WriteLine("Write Directory Structure");
                    Console.WriteLine("------------------------------------");
                    WriteDirectoryStructure(rootDirectory, 0);


                    Console.WriteLine("\n\n");
                    foreach (var file in codeDir.GetFiles())
                    {
                        Console.WriteLine("Content of {0}", file.Name);
                        Console.WriteLine("------------------------------------");
                        using (StreamReader reader = file.OpenText())
                        {
                            Console.WriteLine(reader.ReadToEnd());
                        }
                    }

                    // Deletes all the files and then the bucket.
                    rootDirectory.Delete(true);
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 17
0
        private static void Main(string[] args)
        {
            if (checkRequiredFields())
            {
                using (client = new AmazonS3Client(new AmazonS3Config()
                {
                    MaxErrorRetry = 2,
                    ThrottleRetries = true
                }))
                {
                    // Creates the bucket.
                    S3DirectoryInfo rootDirectory = new S3DirectoryInfo(client, bucketName);
                    rootDirectory.Create();

                    // Creates a file at the root of the bucket.
                    S3FileInfo readme = rootDirectory.GetFile("README.txt");
                    using (StreamWriter writer = new StreamWriter(readme.OpenWrite()))
                        writer.WriteLine("This is my readme file.");

                    // Create a directory called code and write a file to it.
                    S3DirectoryInfo codeDir  = rootDirectory.CreateSubdirectory("wiki");
                    S3FileInfo      codeFile = codeDir.GetFile("Phantasmagoria.txt");
                    using (StreamWriter writer = new StreamWriter(codeFile.OpenWrite()))
                    {
                        writer.WriteLine("Phantasmagoria (About this sound American pronunciation (help·info), also fantasmagorie, fantasmagoria) was a form of horror theatre that ");
                        writer.WriteLine("(among other techniques) used one or more magic lanterns to project frightening images such as skeletons, demons, and ");
                        writer.WriteLine("ghosts onto walls, smoke, or semi-transparent screens, typically using rear projection to keep the lantern out of sight. Mobile or ");
                        writer.WriteLine("portable projectors were used, allowing the projected image to move and change size on the screen, and multiple projecting ");
                        writer.WriteLine("devices allowed for quick switching of different images. In many shows the use of spooky decoration, total darkness, sound ");
                        writer.WriteLine("effects, (auto-)suggestive verbal presentation and sound effects were also key elements. Some shows added all kinds of ");
                        writer.WriteLine("sensory stimulation, including smells and electric shocks. Even required fasting, fatigue (late shows) and drugs have been ");
                        writer.WriteLine("mentioned as methods of making sure spectators would be more convinced of what they saw. The shows started under the ");
                        writer.WriteLine("guise of actual séances in Germany in the late 18th century, and gained popularity through most of Europe (including Britain) ");
                        writer.WriteLine("throughout the 19th century.");
                    }


                    // Create a directory called license and write a file to it.
                    S3DirectoryInfo licensesDir = rootDirectory.CreateSubdirectory("licenses");
                    S3FileInfo      licenseFile = licensesDir.GetFile("license.txt");
                    using (StreamWriter writer = new StreamWriter(licenseFile.OpenWrite()))
                        writer.WriteLine("A license to code");


                    Console.WriteLine("Write Directory Structure");
                    Console.WriteLine("------------------------------------");
                    WriteDirectoryStructure(rootDirectory, 0);


                    Console.WriteLine("\n\n");
                    foreach (var file in codeDir.GetFiles())
                    {
                        Console.WriteLine("Content of {0}", file.Name);
                        Console.WriteLine("------------------------------------");
                        using (StreamReader reader = file.OpenText())
                        {
                            Console.WriteLine(reader.ReadToEnd());
                        }
                    }

                    // Deletes all the files and then the bucket.
                    if (deleteAtEnd)
                    {
                        rootDirectory.Delete(true);
                    }
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Removes directory
        /// </summary>
        /// <param name="path">Directory path.</param>
        public void DeleteDirectory(string path)
        {
            S3DirectoryInfo directory = new S3DirectoryInfo(_client, _bucketName, path);

            directory.Delete(true);
        }
Exemplo n.º 19
0
 public override void Delete()
 {
     BackingDirInfo.Delete(true);
 }
Exemplo n.º 20
0
        public void DeleteDirectory(string directoryName)
        {
            S3DirectoryInfo s3DirectoryInfo = new S3DirectoryInfo(Client, Bucket, directoryName);

            s3DirectoryInfo.Delete(true);
        }