/// <summary>Appends text to Amazon S3 storage object.</summary>
 /// <param name="obj">Object info.</param>
 /// <param name="content">Content to append.</param>
 public void AppendTextToObject(IS3ObjectInfo obj, string content)
 {
     if (this.ObjectExists(obj))
     {
         if (obj.IsLocked)
         {
             throw new Exception($"[IS3ObjectInfoProvider.AppendTextToObject]: Couldn't upload object {obj.Key} because it is used by another process.");
         }
         obj.Lock();
         System.IO.Stream objectContent = this.GetObjectContent(obj, System.IO.FileMode.Open,
                                                                System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite, 4096);
         string str = null;
         using (CMS.IO.StreamReader streamReader = CMS.IO.StreamReader.New(objectContent))
         {
             str = streamReader.ReadToEnd();
         }
         PutObjectRequest putRequest = CreatePutRequest(obj.Key, obj.BucketName);
         putRequest.ContentBody = str + content;
         PutObjectResponse response = this.S3Client.PutObject(putRequest);
         this.SetS3ObjectMetadaFromResponse(obj, response, 0L);
         FileDebug.LogFileOperation(PathHelper.GetPathFromObjectKey(obj.Key, true), nameof(AppendTextToObject), "Custom Amazon");
         obj.UnLock();
         RemoveRequestCache(obj.Key);
     }
     else
     {
         this.PutTextToObject(obj, content);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Opens a text file, reads all lines of the file, and then closes the file.
        /// </summary>
        /// <param name="path">Path to file.</param>
        public override string ReadAllText(string path)
        {
            if (!this.Exists(path))
            {
                throw GetFileNotFoundException(path);
            }
            IS3ObjectInfo info = S3ObjectFactory.GetInfo(path);

            if (!Provider.ObjectExists(info))
            {
                return(System.IO.File.ReadAllText(path));
            }
            using (CMS.IO.StreamReader streamReader =
                       CMS.IO.StreamReader.New(Provider
                                               .GetObjectContent(info, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 4096)
                                               ))
            {
                return(streamReader.ReadToEnd());
            }
        }