public NetstorageCMSv35Signer createNetStorageSigner()
        {
            var actionParams = new APIParams()
            {
                Action = "download"
            };

            return new NetstorageCMSv35Signer("GET", new Uri("http://www.example.com/foobar"), "user1", "secret1", actionParams);
        }
 internal Stream execute(string method, string path, APIParams acsParams, Stream uploadStream = null)
 {
     return new NetstorageCMSv35Signer(
         method,
         this.getNetStorageUri(path),
         this.Username,
         this.Key,
         acsParams,
         uploadStream).Execute(this.Request);
 }
        public bool Upload(string path, Stream uploadFileStream, DateTime? mTime = null, long? size = null, byte[] md5Checksum = null, byte[] sha1Checksum = null, byte[] sha256Checksum = null, bool? indexZip = null)
        {
            var acsParams = new APIParams()
            {
                Action = "upload",
                MTime = mTime,
                Size = size,
                MD5 = md5Checksum,
                SHA1 = sha1Checksum,
                SHA256 = sha256Checksum,
                IndexZip = (indexZip == true) ? indexZip : null
            };

            // sanity check to ensure that indexZip is only true if the file destination is also a zip.
            // probably should throw an exception or warning instead.
            if (acsParams.IndexZip == true && !path.EndsWith(".zip"))
                acsParams.IndexZip = null;

            // size is not supported with zip since the index-zip funtionality mutates the file thus inconsistency on which size value to use
            // probably should throw an exception or a warning
            if (acsParams.Size != null && acsParams.IndexZip == true)
                acsParams.Size = null;

            using (execute("PUT", path, acsParams, uploadFileStream)) { }
            return true;
        }
示例#4
0
 public NetstorageCMSv35Signer(string method, Uri uri, string username, string secret, APIParams apiParams, Stream uploadStream = null)
 {
     this.Method       = method;
     this.URI          = uri;
     this.Params       = apiParams;
     this.Username     = username;
     this.Secret       = secret;
     this.UploadStream = uploadStream;
     this.SignVersion  = SignType.HMACSHA256;
 }
        public void TestAPIActionParams()
        {
            var apiEvent = new APIParams()
            {
                Action = "download",
                Format = "xml",
                QuickDelete = "imreallyreallysure",
                Destination = "/foo",
                Target = "/bar",
                MTime = new DateTime(2013, 11, 11, 0, 0, 0, DateTimeKind.Utc),
                Size = 123,
                IndexZip = true
            };

            Assert.AreEqual(apiEvent.ConvertToQueryString(NetstorageCMSv35Signer.ParamsNameFormatter, NetstorageCMSv35Signer.ParamsValueFormatter),
                "version=1&action=download&format=xml&quick-delete=imreallyreallysure&destination=%2Ffoo&target=%2Fbar&mtime=1384128000&size=123&index-zip=1");

            apiEvent = new APIParams()
            {
                MD5 = "Lorem ipsum".ToByteArray(),
                SHA1 = "Lorem ipsum".ToByteArray(),
                SHA256 = "Lorem ipsum".ToByteArray()
            };
            Assert.AreEqual(apiEvent.ConvertToQueryString(NetstorageCMSv35Signer.ParamsNameFormatter, NetstorageCMSv35Signer.ParamsValueFormatter),
                "version=1&md5=4c6f72656d20697073756d&sha1=4c6f72656d20697073756d&sha256=4c6f72656d20697073756d");
        }
 public NetstorageCMSv35Signer(string method, Uri uri, string username, string secret, APIParams apiParams, Stream uploadStream = null)
 {
     this.Method = method;
     this.URI = uri;
     this.Params = apiParams;
     this.Username = username;
     this.Secret = secret;
     this.UploadStream = uploadStream;
     this.SignVersion = SignType.HMACSHA256;
 }