예제 #1
1
 /// <summary>
 /// Copies this file to the target directory.
 /// If the file already exists in S3 than an ArgumentException is thrown.
 /// </summary>
 /// <param name="dir">Target directory where to copy the file to.</param>
 /// <exception cref="T:System.ArgumentException">If the directory does not exist.</exception>
 /// <exception cref="T:System.IO.IOException">If the file already exists in S3.</exception>
 /// <exception cref="T:System.Net.WebException"></exception>
 /// <exception cref="T:Amazon.S3.AmazonS3Exception"></exception>
 /// <returns>S3FileInfo of the newly copied file.</returns>
 public S3FileInfo CopyTo(S3DirectoryInfo dir)
 {
     return CopyTo(dir, false);
 }
예제 #2
0
        private static void ScanDirectory(S3DirectoryInfo dir)
        {
            var files   = dir.EnumerateFiles();
            var subDirs = dir.EnumerateDirectories();

            if (subDirs.Any())
            {
                WriteLine($"\r\nProcessing {subDirs.Count()} directories in {dir.Name}...");

                foreach (S3DirectoryInfo sub in subDirs)
                {
                    ScanDirectory(sub);
                }
            }
            if (files.Any())
            {
                WriteLine($"\r\nScanning Files in {dir.Name}...");

                foreach (S3FileInfo file in files)
                {
                    try
                    {
                        ScanFile(file);
                    }
                    catch (Exception e)
                    {
                        LogError(e.Message);
                    }
                }
            }
        }
예제 #3
0
 public AWSStorageProvider(string connectionString)
 {
     // Parse the connection string to the access key and secret key
     if (string.IsNullOrEmpty(connectionString))
     {
         throw new ArgumentException("Connection string cannot be empty");
     }
     else
     {
         // Split the connection string parts (make keys lower-cased for comparison)
         var parts = connectionString.ToDictionary(KeyValueSeparator, ConnectionStringPartSeparator, makeKeysLowercased: true);
         // Check if the connection string contains all required parts
         if (parts == null || connectionStringParts.Except(parts.Keys).Count() > 0)
         {
             throw new ArgumentException("Connection string must include the access key, secret key, and bucket of your AWS account");
         }
         else
         {
             var credentials = new BasicAWSCredentials(parts["accesskey"], parts["secretkey"]);
             _client        = Amazon.AWSClientFactory.CreateAmazonS3Client(credentials);
             _rootDirectory = new S3DirectoryInfo(_client, parts["bucket"]);
             //_client = Amazon.AWSClientFactory.CreateAmazonS3Client(Amazon.RegionEndpoint.USWest2);
         }
     }
 }
예제 #4
0
        public S3Storage()
        {
            const string filename = "keyxml.pk";
            var path = WebServerPathUtils.GetPathTo(Path.Combine("bin", filename));
            var f = new FileInfo(path);

            if (f.Exists)
            {
                using (var file = f.OpenRead())
                {
                    var keyString = new StreamReader(file).ReadToEnd();
                    _algorithm = RSA.Create();
                    _algorithm.FromXmlString(keyString);

                    var encryptionMaterials = new EncryptionMaterials(_algorithm);
                    try
                    {
                        _client = new AmazonS3EncryptionClient(encryptionMaterials);

                        var bucket = new S3DirectoryInfo(_client, PdfDocumentsBucketName);
                        if (!bucket.Exists)
                        {
                            bucket.Create();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Unable to initialize S3 client\n" + ex);
                    }
                }
            }
        }
        static public void printLevelWaveletNorm(List <GeoWave> decisionGeoWaveArr, string filename)
        {
            StreamWriter sw;

            if (Form1.UseS3)
            {
                string dir_name  = Path.GetDirectoryName(filename);
                string file_name = Path.GetFileName(filename);

                S3DirectoryInfo s3dir   = new S3DirectoryInfo(Form1.S3client, Form1.bucketName, dir_name);
                S3FileInfo      artFile = s3dir.GetFile(file_name);
                sw = new StreamWriter(artFile.OpenWrite());
            }
            else
            {
                sw = new StreamWriter(filename, false);
            }

            /*  int dataDim = decisionGeoWaveArr[0].rc.dim;
             * int labelDim = decisionGeoWaveArr[0].MeanValue.Count();*/

            foreach (GeoWave t in decisionGeoWaveArr)
            {
                sw.WriteLine(t.level + ", " + t.norm);
            }

            sw.Close();
        }
예제 #6
0
        public static void Move(string oldFileKey, string newFileKey, string folderName, bool overWrite = false)
        {
            if (!IsUseS3)
            {
                return;
            }

            if (string.IsNullOrEmpty(oldFileKey))
            {
                return;
            }

            if (overWrite)
            {
                Delete(newFileKey);
            }

            using (IAmazonS3 client = new AmazonS3Client(Region))
            {
                S3FileInfo      currentObject = new S3FileInfo(client, Bucket, oldFileKey);
                S3DirectoryInfo destination   = new S3DirectoryInfo(client, Bucket, folderName);
                if (!destination.Exists)
                {
                    destination.Create();
                }
                S3FileInfo movedObject = currentObject.MoveTo(Bucket, newFileKey);
            }
            MakePublic(newFileKey);
        }
        public void DeleteDirectory(string path)
        {
            string          key       = GetKey(path);
            S3DirectoryInfo directory = new S3DirectoryInfo(_client, _bucketName, key);

            directory.Delete(true);
        }
        public IEnumerable <IStorageFile> ListFiles(string path)
        {
            path = CleanPath(path);
            var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);

            return(dir.GetFiles().Where(x => !x.Name.EndsWith("_$folder$")).Select(x => new AmazonS3StorageFile(x, this)).ToList());
        }
        static public AWSStorageDirectory ToStorageDirectory(this S3DirectoryInfo directoryInfo)
        {
            AWSStorageDirectory targetDirectory = new AWSStorageDirectory(directoryInfo);

            // Copy properties
            return(targetDirectory);
        }
예제 #10
0
        public S3Storage()
        {
            const string filename = "keyxml.pk";
            var          path     = WebServerPathUtils.GetPathTo(Path.Combine("bin", filename));
            var          f        = new FileInfo(path);

            if (f.Exists)
            {
                using (var file = f.OpenRead())
                {
                    var keyString = new StreamReader(file).ReadToEnd();
                    _algorithm = RSA.Create();
                    _algorithm.FromXmlString(keyString);

                    var encryptionMaterials = new EncryptionMaterials(_algorithm);
                    try
                    {
                        _client = new AmazonS3EncryptionClient(encryptionMaterials);

                        var bucket = new S3DirectoryInfo(_client, PdfDocumentsBucketName);
                        if (!bucket.Exists)
                        {
                            bucket.Create();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Unable to initialize S3 client\n" + ex);
                    }
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Implementation of the ZephyrDirectory Create method in Amazon S3 Storage.
        /// </summary>
        /// <param name="failIfExists">Throws an error if the directory already exists.</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>
        /// <returns>An AmazonS3ZephyrDictionary Instance.</returns>
        public override ZephyrDirectory Create(bool failIfExists = false, bool verbose = true, string callbackLabel = null, Action <string, string> callback = null)
        {
            if (_client == null)
            {
                throw new Exception($"AWSClient Not Set.");
            }

            if (this.Exists && failIfExists)
            {
                throw new Exception($"Directory [{FullName}] Already Exists.");
            }

            String key = ObjectKey;

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

            dirInfo.Create();
            if (verbose)
            {
                Logger.Log($"Directory [{FullName}] Was Created.", callbackLabel, callback);
            }
            return(this);
        }
        /// <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);
        }
예제 #13
0
        private List <string> Get(string directoryName, FileSystemType type, string filter = "*")
        {
            filter = (string.IsNullOrEmpty(filter)) ? "*" : filter;
            List <string>   files                    = new List <string>();
            S3DirectoryInfo s3DirectoryInfo          = GetDirectoryInfo(directoryName);
            IEnumerable <IS3FileSystemInfo> elements = null;

            switch (type)
            {
            case FileSystemType.Directory:
                elements = s3DirectoryInfo.EnumerateDirectories(filter, SearchOption.TopDirectoryOnly);
                break;

            case FileSystemType.File:
                elements = s3DirectoryInfo.EnumerateFiles(filter, SearchOption.TopDirectoryOnly);
                break;

            default:
                throw new NotImplementedException(type.ToString());
            }
            foreach (IS3FileSystemInfo file in elements)
            {
                files.Add(directoryName + StorageUtils.DELIMITER + file.Name);
            }
            return(files);
        }
//************************************** PRINT FUNCTIONS WITH OUT REFERENCES ****************************************************
        public static void printErrorsToFile(string filename, double l2, double l1, double l0, double testSize)
        {
            StreamWriter writer;

            if (Form1.UseS3)
            {
                string dir_name  = Path.GetDirectoryName(filename);
                string file_name = Path.GetFileName(filename);

                S3DirectoryInfo s3dir   = new S3DirectoryInfo(Form1.S3client, Form1.bucketName, dir_name);
                S3FileInfo      artFile = s3dir.GetFile(file_name);
                writer = new StreamWriter(artFile.OpenWrite());
            }
            else
            {
                writer = new StreamWriter(filename, false);
            }

            //WRITE
            writer.WriteLine("l2 estimation error: " + l2.ToString(CultureInfo.InvariantCulture));
            writer.WriteLine("l1 estimation error: " + l1.ToString(CultureInfo.InvariantCulture));
            writer.WriteLine("num of miss labels: " + l0.ToString(CultureInfo.InvariantCulture));
            writer.WriteLine("num of tests: " + testSize.ToString(CultureInfo.InvariantCulture));
            writer.WriteLine("sucess rate : " + (1 - (l0 / testSize)).ToString(CultureInfo.InvariantCulture));
            writer.Close();
        }
        public static void printtable(List <int>[] table, string filename)
        {
            StreamWriter sw;

            if (Form1.UseS3)
            {
                string dir_name  = Path.GetDirectoryName(filename);
                string file_name = Path.GetFileName(filename);

                S3DirectoryInfo s3dir   = new S3DirectoryInfo(Form1.S3client, Form1.bucketName, dir_name);
                S3FileInfo      artFile = s3dir.GetFile(file_name);
                sw = new StreamWriter(artFile.OpenWrite());
            }
            else
            {
                sw = new StreamWriter(filename, false);
            }

            for (int i = 0; i < table.Count(); i++)
            {
                var line = "";
                for (int j = 0; j < table[i].Count(); j++)
                {
                    line += table[i][j].ToString() + " ";
                }
                sw.WriteLine(line);
            }

            sw.Close();
        }
        public static void printList(List <double> lst, string filename)
        {
            StreamWriter sw;

            if (Form1.UseS3)
            {
                string dir_name  = Path.GetDirectoryName(filename);
                string file_name = Path.GetFileName(filename);

                S3DirectoryInfo s3dir   = new S3DirectoryInfo(Form1.S3client, Form1.bucketName, dir_name);
                S3FileInfo      artFile = s3dir.GetFile(file_name);
                sw = new StreamWriter(artFile.OpenWrite());
            }
            else
            {
                sw = new StreamWriter(filename, false);
            }

            for (int i = 0; i < lst.Count(); i++)
            {
                sw.WriteLine(lst[i]);
            }

            sw.Close();
        }
        public bool FolderExists(string path)
        {
            path = CleanPath(path);
            var dir = new S3DirectoryInfo(_client, path);

            return(dir.Exists);
        }
        public IEnumerable <IStorageFolder> ListFolders(string path)
        {
            path = CleanPath(path);
            var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);

            return(dir.GetDirectories("*", SearchOption.TopDirectoryOnly).Select(x => new AmazonS3StorageFolder(x)).ToList());
        }
        public void DeleteFolder(string path)
        {
            path = CleanPath(path);
            var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);

            dir.Delete();
        }
예제 #20
0
        private static long GetDirectorySize(S3DirectoryInfo directoryInfo)
        {
            var fileInfos      = directoryInfo.GetFiles();
            var size           = fileInfos.Sum(fileInfo => fileInfo.Length);
            var directoryInfos = directoryInfo.GetDirectories();

            size += directoryInfos.Sum(dInfo => GetDirectorySize(dInfo));
            return(size);
        }
예제 #21
0
        public AWSStorageClient(string specificFolder)
        {
            _storageClient = AWSClientFactory.CreateAmazonS3Client();
            S3DirectoryInfo rootDirectory = new S3DirectoryInfo(_storageClient, BucketName);

            rootDirectory.Create();

            _subDirectory = rootDirectory.CreateSubdirectory(specificFolder);
        }
        public void RenameFolder(string oldPath, string newPath)
        {
            oldPath = CleanPath(oldPath);
            newPath = CleanPath(newPath);
            var oldDir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, oldPath);
            var newDir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, newPath);

            oldDir.MoveToLocal(newPath);
        }
        public void DeleteFolder(string file_path)
        {
            EnsureBucketName();

            using (var client = Storage.GetClient())
            {
                var directoryToDelete = new S3DirectoryInfo(client, BucketName, file_path);
                directoryToDelete.Delete(true);
            }
        }
예제 #24
0
        public AWSStorageClientClient(string directory)
        {
            _storageClient = AWSClientFactory.CreateAmazonS3Client();
            S3DirectoryInfo rootDirectory = new S3DirectoryInfo(_storageClient, BucketName);

            rootDirectory.Create();

            _mainDirectory   = rootDirectory.CreateSubdirectory(directory);
            _outputDirectory = rootDirectory.CreateSubdirectory("AnalysisOutput");
        }
예제 #25
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
        }
예제 #26
0
        public void CopyObjectToLocal(string bucketName, string objectKey, string destination, string copyFrom = null, Action <string, string> logger = null)
        {
            FileSystemType type = FileSystemType.File;

            if (objectKey.EndsWith("/"))
            {
                type = FileSystemType.Directory;
            }

            if (type == FileSystemType.File)
            {
                S3FileInfo file      = new S3FileInfo(client, bucketName, objectKey);
                String     localFile = fs.Path.Combine(destination, objectKey);
                if (copyFrom != null)
                {
                    if (!copyFrom.EndsWith("/"))
                    {
                        copyFrom += "/";
                    }
                    localFile = localFile.Replace(copyFrom, "");
                }

                if (fs.File.Exists(localFile))
                {
                    fs.File.Delete(localFile);
                }
                //file.CopyToLocal( localFile );
                CopyS3ToLocal(file, localFile);
                if (logger != null)
                {
                    logger(bucketName, $"Copied [s3://{bucketName}/{objectKey}] To [{localFile}].");
                }
            }
            else if (type == FileSystemType.Directory)
            {
                S3DirectoryInfo dir      = new S3DirectoryInfo(client, bucketName, objectKey);
                String          localDir = fs.Path.Combine(destination, objectKey);
                if (copyFrom != null)
                {
                    if (!copyFrom.EndsWith("/"))
                    {
                        copyFrom += "/";
                    }
                    localDir = localDir.Replace(copyFrom, "");
                }
                if (!fs.Directory.Exists(localDir))
                {
                    fs.Directory.CreateDirectory(localDir);
                    if (logger != null)
                    {
                        logger(bucketName, $" Copied [s3://{bucketName}/{objectKey}] To [{localDir}].");
                    }
                }
            }
        }
예제 #27
0
        private static void ProcessDirectory(S3DirectoryInfo dir)
        {
            sdd = new ScannedDirectoryData(dir.FullName);

            WriteLine($"\r\nProcessing directory: {dir.FullName}");

            ScanDirectory(dir);
            SubmitBatch();
            DisplayResults();
            processedDirectories.Add(sdd);
        }
예제 #28
0
        public override string GetFolderPath(NonSecureFileModel filemodel)
        {
            string          folder  = CreateAbsoultePath(filemodel.FileDocType);
            S3DirectoryInfo dirInfo = new S3DirectoryInfo(s3Client, bucketName, folder);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
            return(folder);
        }
예제 #29
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);
        }
예제 #30
0
        public void CreateFolder(string path)
        {
            if (IsFolderExits(path))
            {
                throw new InvalidOperationException("Directory " + path + " already exists");
            }

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

            di.Create();
        }
예제 #31
0
        public bool TryCreateFolder(string path)
        {
            if (IsFolderExits(path))
            {
                return(false);
            }

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

            di.Create();
            return(true);
        }
예제 #32
0
        public string GetDirectory(string directoryName)
        {
            S3DirectoryInfo directory = new S3DirectoryInfo(Client, Bucket, directoryName);

            if (directory.Exists)
            {
                return(StorageUtils.NormalizeDirectoryName(directory.FullName));
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #33
0
 public bool CheckBucketIsExist(string userid)
 {
     bool retval = false;
     using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.APSoutheast1))
     {
         try
         {
             S3DirectoryInfo bucket = new S3DirectoryInfo(client, userid);
             retval = bucket.Exists;
         }
         catch (AmazonS3Exception amazonS3Exception)
         {
             throw amazonS3Exception;
         }
     }
     return retval;
 }
예제 #34
0
 public AWSStorageProvider(string connectionString)
 {
     // Parse the connection string to the access key and secret key
     if (string.IsNullOrEmpty(connectionString))
         throw new ArgumentException("Connection string cannot be empty");
     else
     {
         // Split the connection string parts (make keys lower-cased for comparison)
         var parts = connectionString.ToDictionary(KeyValueSeparator, ConnectionStringPartSeparator, makeKeysLowercased: true);
         // Check if the connection string contains all required parts
         if (parts == null || connectionStringParts.Except(parts.Keys).Count() > 0)
         {
             throw new ArgumentException("Connection string must include the access key, secret key, and bucket of your AWS account");
         }
         else
         {
             var credentials = new BasicAWSCredentials(parts["accesskey"], parts["secretkey"]);
             _client = Amazon.AWSClientFactory.CreateAmazonS3Client(credentials);
             _rootDirectory = new S3DirectoryInfo(_client, parts["bucket"]);
             //_client = Amazon.AWSClientFactory.CreateAmazonS3Client(Amazon.RegionEndpoint.USWest2);
         }
     }
 }
예제 #35
0
        /// <summary>
        /// Copies this file to the target directory.
        /// If the file already exists in S3 and overwrite is set to false than an ArgumentException is thrown.
        /// </summary>
        /// <param name="dir">Target directory where to copy the file to.</param>
        /// <param name="overwrite">Determines whether the file can be overwritten.</param>
        /// <exception cref="T:System.ArgumentException">If the directory does not exist.</exception>
        /// <exception cref="T:System.IO.IOException">If the file already exists in S3 and overwrite is set to false.</exception>
        /// <exception cref="T:System.Net.WebException"></exception>
        /// <exception cref="T:Amazon.S3.AmazonS3Exception"></exception>
        /// <returns>S3FileInfo of the newly copied file.</returns>
        public S3FileInfo CopyTo(S3DirectoryInfo dir, bool overwrite)
        {
            if (!dir.Exists)
            {
                throw new ArgumentException("directory does not exist", "dir");
            }

            S3FileInfo ret = CopyTo(new S3FileInfo(dir.S3Client, dir.BucketName, string.Format(CultureInfo.InvariantCulture, "{0}{1}", dir.ObjectKey, Name)),overwrite);
            return ret;
        }
 public IEnumerable<IStorageFile> ListFiles(string path)
 {
     path = CleanPath(path);
     var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);
     return dir.GetFiles().Where(x => !x.Name.EndsWith("_$folder$")).Select(x => new AmazonS3StorageFile(x, this)).ToList();
 }
예제 #37
0
 public AWSStorageDirectory(S3DirectoryInfo directoryInfo)
 {
     DirectoryInfo = directoryInfo;
     this.Uri = new Uri(directoryInfo.GetDirectoryPath(), UriKind.Relative);
 }
 public bool FolderExists(string path)
 {
     path = CleanPath(path);
     var dir = new S3DirectoryInfo(_client, path);
     return dir.Exists;
 }
 public IEnumerable<IStorageFolder> ListFolders(string path)
 {
     path = CleanPath(path);
     var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);
     return dir.GetDirectories("*", SearchOption.TopDirectoryOnly).Select(x => new AmazonS3StorageFolder(x)).ToList();
 }
 public bool TryCreateFolder(string path)
 {
     try
     {
         path = CleanPath(path);
         var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);
         dir.Create();
     }
     catch 
     {
         return false;
     }
     return true;
 }
 public void RenameFolder(string oldPath, string newPath)
 {
     oldPath = CleanPath(oldPath);
     newPath = CleanPath(newPath);
     var oldDir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, oldPath);
     var newDir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, newPath);
     oldDir.MoveToLocal(newPath);
 }
 public AmazonS3StorageFolder(S3DirectoryInfo s3DirectoryInfo)
 {
     _s3DirectoryInfo = s3DirectoryInfo;
 }
예제 #43
0
        static void WriteDirectoryStructure(S3DirectoryInfo directory, int level)
        {
            StringBuilder indentation = new StringBuilder();
            for (int i = 0; i < level; i++)
                indentation.Append("\t");

            Console.WriteLine("{0}{1}", indentation, directory.Name);
            foreach (var file in directory.GetFiles())
                Console.WriteLine("\t{0}{1}", indentation, file.Name);

            foreach (var subDirectory in directory.GetDirectories())
            {
                WriteDirectoryStructure(subDirectory, level + 1);
            }
        }
예제 #44
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();
        }
예제 #45
0
 /// <summary>
 /// Moves the file to a a new location in S3.
 /// </summary>
 /// <param name="path">The target directory to copy to.</param>
 /// <exception cref="T:System.IO.IOException">If the file already exists in S3.</exception>
 /// <exception cref="T:System.ArgumentException"></exception>
 /// <exception cref="T:System.Net.WebException"></exception>
 /// <exception cref="T:Amazon.S3.AmazonS3Exception"></exception>
 /// <returns>S3FileInfo for the target location.</returns>
 public S3FileInfo MoveTo(S3DirectoryInfo path)
 {
     S3FileInfo ret = CopyTo(path, false);
     Delete();
     return ret;
 }
 public void DeleteFolder(string path)
 {
     path = CleanPath(path);
     var dir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);
     dir.Delete();
 }
예제 #47
0
 /// <summary>
 /// Replaces the destination file with the content of this file and then deletes the orignial file.  If a backupDir is specifed then the content of destination file is 
 /// backup to it.
 /// </summary>
 /// <param name="destDir">Where the contents of this file will be copy to.</param>
 /// <param name="backupDir">If specified the destFile is backup to it.</param>
 /// <exception cref="T:System.ArgumentException"></exception>
 /// <exception cref="T:System.IO.IOException"></exception>
 /// <exception cref="T:System.Net.WebException"></exception>
 /// <exception cref="T:Amazon.S3.AmazonS3Exception"></exception>
 /// <returns>S3FileInfo of the destination file.</returns>
 public S3FileInfo Replace(S3DirectoryInfo destDir, S3DirectoryInfo backupDir)
 {
     S3FileInfo ret = Replace(
         new S3FileInfo(destDir.S3Client, destDir.BucketName, string.Format(CultureInfo.InvariantCulture, "{0}{1}", destDir.ObjectKey, Name)),
         backupDir == null ? null : new S3FileInfo(backupDir.S3Client, backupDir.BucketName, string.Format(CultureInfo.InvariantCulture, "{0}{1}", backupDir.ObjectKey, Name)));
     return ret;
 }
예제 #48
0
 public S3VirtualDirectory(S3VirtualPathProvider owningProvider, IVirtualDirectory parentDirectory, S3DirectoryInfo dInfo)
     : base(owningProvider, parentDirectory)
 {
     Provider = owningProvider;
     this.BackingDirInfo = dInfo;
 }