Exemplo n.º 1
0
        public ErrorTypes WriteFile(string strPath, System.IO.Stream oStream, out int nReadWriteBytes)
        {
            ErrorTypes eResult = ErrorTypes.StorageWrite;

            nReadWriteBytes = (int)oStream.Length;
            try
            {
                string strFileKey = GetFilePath(strPath);
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.PutObjectRequest oRequest = new Amazon.S3.Model.PutObjectRequest();
                    oRequest.WithBucketName(m_strBucketName).WithKey(strFileKey).WithInputStream(oStream);

                    using (Amazon.S3.Model.PutObjectResponse oResponse = oS3Client.PutObject(oRequest))
                    {
                        oResponse.Dispose();
                    }
                }
            }
            catch
            {
                nReadWriteBytes = 0;
            }

            return(eResult);
        }
Exemplo n.º 2
0
        public ErrorTypes GetFileInfo(string strPath, out StorageFileInfo oStorageFileInfo)
        {
            oStorageFileInfo = null;
            ErrorTypes eError = ErrorTypes.StorageGetInfo;

            try
            {
                string strFileKey = GetFilePath(strPath);
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.GetObjectMetadataRequest oRequest = new Amazon.S3.Model.GetObjectMetadataRequest()
                                                                        .WithBucketName(m_strBucketName).WithKey(strFileKey);

                    using (Amazon.S3.Model.GetObjectMetadataResponse oResponse = oS3Client.GetObjectMetadata(oRequest))
                    {
                        oStorageFileInfo = new StorageFileInfo(oResponse.ContentLength, oResponse.LastModified);
                        eError           = ErrorTypes.NoError;
                    }
                }
            }
            catch
            {
            }
            return(eError);
        }
Exemplo n.º 3
0
        public StorageTreeNode GetTreeNode(string strPath)
        {
            StorageTreeNode oNode = null;

            try
            {
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    string strPrefix = GetDirPath(strPath);
                    Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest();
                    oRequest.WithBucketName(m_strBucketName).WithPrefix(strPrefix);

                    using (Amazon.S3.Model.ListObjectsResponse oResponse = oS3Client.ListObjects(oRequest))
                    {
                        oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true);
                        foreach (Amazon.S3.Model.S3Object entry in oResponse.S3Objects)
                        {
                            AddNodeRecursive(oNode, entry.Key.Substring(strPrefix.Length));
                        }
                    }
                }
            }
            catch
            {
            }

            return(oNode);
        }
        public void Run()
        {
            AwesomiumCore.Initialze();

            string accessKeyId = AppSettings.AmazonAccessKeyId;
            string secretAccessKeyId = AppSettings.AmazonSecretAccessKeyId;
            _amazonS3Client = AWSClientFactory.CreateAmazonS3Client(accessKeyId, secretAccessKeyId);

            _synchronizationContext = SynchronizationContext.Current;

            _pollingThread = new Thread(StartPolling);
            _pollingThread.Start();
        }
Exemplo n.º 5
0
        public ErrorTypes ReadFile(string strPath, System.IO.Stream oStream, out int nReadWriteBytes)
        {
            ErrorTypes eResult = ErrorTypes.StorageRead;

            nReadWriteBytes = 0;
            try
            {
                string strFileKey = GetFilePath(strPath);
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.GetObjectRequest oRequest = new Amazon.S3.Model.GetObjectRequest()
                                                                .WithBucketName(m_strBucketName).WithKey(strFileKey);
                    using (Amazon.S3.Model.GetObjectResponse oResponse = oS3Client.GetObject(oRequest))
                    {
                        using (Stream oResponseStream = oResponse.ResponseStream)
                        {
                            int nNeedReadBytes = (int)oResponse.ContentLength;

                            int          nMemoryStreamSize   = Math.Min(c_nMaxReadBufferSize, nNeedReadBytes);
                            MemoryStream oMemoryStreamOutput = new MemoryStream(nMemoryStreamSize);

                            while (nNeedReadBytes > 0)
                            {
                                int nReadBytesPos             = 0;
                                int nReadBytesCount           = nMemoryStreamSize;
                                int nReadBytesFromStreamCount = 0;
                                while (nReadBytesCount > 0 &&
                                       (nReadBytesFromStreamCount = oResponseStream.Read(oMemoryStreamOutput.GetBuffer(), nReadBytesPos, nReadBytesCount)) > 0)
                                {
                                    nReadBytesPos   += nReadBytesFromStreamCount;
                                    nReadBytesCount -= nReadBytesFromStreamCount;
                                }

                                oStream.Write(oMemoryStreamOutput.GetBuffer(), 0, nReadBytesPos);
                                nReadWriteBytes += nReadBytesPos;
                                nNeedReadBytes  -= nReadBytesPos;
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(eResult);
        }
Exemplo n.º 6
0
        public ErrorTypes RemovePath(string strPath)
        {
            ErrorTypes eResult = ErrorTypes.StorageRemoveDir;

            try
            {
                string strDirKey = GetDirPath(strPath);

                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.ListObjectsRequest oListObjectsRequest = new Amazon.S3.Model.ListObjectsRequest();
                    oListObjectsRequest.WithBucketName(m_strBucketName).WithPrefix(strDirKey);

                    using (Amazon.S3.Model.ListObjectsResponse oListObjectsResponse = oS3Client.ListObjects(oListObjectsRequest))
                    {
                        int nDeletedObjectCount   = 0;
                        int nObjectsToDeleteCount = oListObjectsResponse.S3Objects.Count;
                        if (nObjectsToDeleteCount > 0)
                        {
                            Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest();
                            oDeleteObjectsRequest.WithBucketName(m_strBucketName);

                            foreach (Amazon.S3.Model.S3Object oS3Obj in oListObjectsResponse.S3Objects)
                            {
                                oDeleteObjectsRequest.AddKey(oS3Obj.Key);
                            }

                            using (Amazon.S3.Model.DeleteObjectsResponse oDeleteObjectsResponse = oS3Client.DeleteObjects(oDeleteObjectsRequest))
                            {
                                nDeletedObjectCount = oDeleteObjectsResponse.DeletedObjects.Count;
                            }
                        }

                        if (nObjectsToDeleteCount == nDeletedObjectCount)
                        {
                            eResult = ErrorTypes.NoError;
                        }
                    }
                }
            }
            catch
            {
            }

            return(eResult);
        }
Exemplo n.º 7
0
        public ErrorTypes CreateDirectory(string strPath)
        {
            ErrorTypes eResult = ErrorTypes.StorageCreateDir;

            try
            {
                string strDirKey = GetDirPath(strPath);
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.PutObjectRequest oRequest = new Amazon.S3.Model.PutObjectRequest();
                    oRequest.WithBucketName(m_strBucketName).WithKey(strDirKey).WithContentBody(string.Empty);

                    using (Amazon.S3.Model.PutObjectResponse oResponse = oS3Client.PutObject(oRequest))
                    {
                        eResult = ErrorTypes.NoError;
                    }
                }
            }
            catch
            {
            }
            return(eResult);
        }
Exemplo n.º 8
0
            public override void Close()
            {
                try
                {
                    if (null != m_oStreamOutput)
                    {
                        m_oStreamOutput = null;
                    }
                    if (null != m_oS3Client)
                    {
                        m_oS3Client.Dispose();
                        m_oS3Client = null;
                    }

                    if (null != m_oGetObjectResponse)
                    {
                        m_oGetObjectResponse.Dispose();
                        m_oGetObjectResponse = null;
                    }

                    if (null != m_oListObjectsResponse)
                    {
                        m_oListObjectsResponse.Dispose();
                        m_oListObjectsResponse = null;
                    }

                    if (null != m_oDeleteObjectResponse)
                    {
                        m_oDeleteObjectResponse.Dispose();
                        m_oDeleteObjectResponse = null;
                    }
                }
                catch
                {
                }
            }
Exemplo n.º 9
0
            public override void Close()
            {
                try
                {
                    if (null != m_oStreamOutput)
                    {

                       m_oStreamOutput = null;
                    }
                    if (null != m_oS3Client)
                    {
                        m_oS3Client.Dispose();
                        m_oS3Client = null;
                    }

                    if (null != m_oGetObjectResponse)
                    {
                        m_oGetObjectResponse.Dispose();
                        m_oGetObjectResponse = null;
                    }

                    if (null != m_oListObjectsResponse)
                    {
                        m_oListObjectsResponse.Dispose();
                        m_oListObjectsResponse = null;
                    }

                    if (null != m_oDeleteObjectResponse)
                    {
                        m_oDeleteObjectResponse.Dispose();
                        m_oDeleteObjectResponse = null;
                    }
                }
                catch
                {
                }
            }
Exemplo n.º 10
0
 public AmazonS3Repository(string accessKey, string secretKey, string bucketName)
 {
     this._client = AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey);
     this._bucketName = bucketName;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new archive instance
 /// </summary>
 /// <param name="s3">
 /// The connected AWS S3 client
 /// </param>
 /// <param name="glacier">
 /// The connected AWS Glacier client
 /// </param>
 /// <param name="vault">
 /// The name of the Glacier vault for the archive
 /// </param>
 /// <param name="bucket">
 /// The name of the S3 bucket containing the backup index
 /// </param>
 /// <param name="name">
 /// The name of the archive
 /// </param>
 public GlacierArchive(
     Amazon.S3.AmazonS3 s3,
     Amazon.Glacier.AmazonGlacierClient glacier,
     String vault,
     String bucket,
     String name)
 {
     this.s3 = s3;
      this.glacier = glacier;
      this.vault = vault;
      this.bucket = bucket;
      this.name = name;
      // connect to the restore index
      var restoreIndexPath = new IO.Path(
     Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
     "SkyFloe",
     "AwsGlacier",
     name,
     "restore.db"
      );
      IO.FileSystem.CreateDirectory(restoreIndexPath.Parent);
      this.restoreIndex = (IO.FileSystem.GetMetadata(restoreIndexPath).Exists) ?
     Sqlite.RestoreIndex.Open(restoreIndexPath) :
     Sqlite.RestoreIndex.Create(restoreIndexPath, new Restore.Header());
      this.copier = new IO.StreamCopier();
 }