Esempio n. 1
0
 public static void NameSortIndex(EntityIndex index, bool descending = false)
 {
     index.Entries.Sort(delegate(Internal.EntityIndexEntry a, Internal.EntityIndexEntry b)
     {
         int compare = string.Compare(a.Name, b.Name, true);
         if (descending)
             return compare * -1;
         else
             return compare;
     });
 }
Esempio n. 2
0
        public void UpdateIndex(string path, EntityIndex index)
        {
            var serialised = SerialiseIndex(index.Entries);
            var stream = new MemoryStream(serialised.Length);
            var writer = new StreamWriter(stream);
            writer.Write(serialised);
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            try
            {
                using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                {
                    // Check that the index has not been updated before pushing the change - reduce the risks.
                    try
                    {
                        using (var objectMetaDataResponse = client.GetObjectMetadata(new GetObjectMetadataRequest()
                        {
                            BucketName = Context.BucketName,
                            Key = path,
                            ETagToMatch = index.ETag
                        }))
                        {

                        }
                    }
                    catch (AmazonS3Exception awsEx)
                    {
                        if (awsEx.StatusCode != System.Net.HttpStatusCode.NotFound)
                            throw;
                    }

                    using (var putResponse = client.PutObject(new PutObjectRequest()
                    {
                        BucketName = Context.BucketName,
                        Key = path,
                        GenerateMD5Digest = true,
                        InputStream = stream
                    })) { }
                }
            }
            catch (AmazonS3Exception awsEx)
            {
                throw new DeploymentException("Failed loading group index", awsEx);
            }
        }
Esempio n. 3
0
 public EntityIndex LoadIndex(string path)
 {
     try
     {
         using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
         {
             using (var res = client.GetObject(new GetObjectRequest()
             {
                 BucketName = Context.BucketName,
                 Key = path,
             }))
             {
                 var index = new EntityIndex() { ETag = res.ETag };
                 using (var stream = res.ResponseStream)
                 {
                     index.Entries = ParseIndex(stream);
                 }
                 return index;
             }
         }
     }
     catch (AmazonS3Exception awsEx)
     {
         if (awsEx.StatusCode == System.Net.HttpStatusCode.NotFound)
         {
             return new EntityIndex() { Entries = new List<EntityIndexEntry>(), ETag = "" };
         }
         else
         {
             throw new DeploymentException("Failed loading group index", awsEx);
         }
     }
 }