コード例 #1
0
        [PropertyData("RandomFileAtAllContainers")]        //[PropertyData("FixedFileName")]
        public void Upload_object(string fileName, Container container)
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            System.Diagnostics.Trace.WriteLine("File: " + fileName + " gonna be uploaded to container: " + container.Name);

            Assert.DoesNotThrow(() => {
                var tsk2 = swiftclient.UploadObject(fileName, container, tokenSource.Token);
                tsk2.Wait();
            });
        }
コード例 #2
0
        public void Bring_all_objects(Container targetContainer)
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            SwiftObjectsCollection swiftObjectCollection = null;

            Assert.DoesNotThrow(() => {
                var tsk = swiftclient.GetObjects(targetContainer, tokenSource.Token);
                swiftObjectCollection = tsk.Result;
            });

            //
            // Even if they are not objects the 'data' could not be null
            Assert.NotNull(swiftObjectCollection);

            System.Diagnostics.Trace.WriteLine("Container: " + targetContainer.Name + " has " + swiftObjectCollection.Count.ToString() + " objects inside it");
            swiftObjectCollection.AsParallel().ForAll(obj => System.Diagnostics.Trace.WriteLine("Swift object name: " + obj.Name + " Hash: " + obj.MD5Hash + " length: " + obj.Length + " Endpoint: " + obj.Endpoint.ToString()));
        }
コード例 #3
0
ファイル: Swift.cs プロジェクト: jasper22/Swift.Sharp
        //public Task<SwiftObject> DownloadObject(Container container, SwiftObject targetObject, CancellationToken cancellationToken)
        //{
        //    GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get);

        //    request.QueryParams.Add("container", container.Name);
        //    request.QueryParams.Add("object", targetObject.Name);

        //    request.Endpoint = targetObject.Endpoint;


        //}

        /// <summary>
        /// Deletes the object/file from SWIFT
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="targetObject">The target object.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>New collection of object for this container after deletion</returns>
        public Task<SwiftObjectsCollection> DeleteObject(Container container, SwiftObject targetObject, CancellationToken cancellationToken)
        {
            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Delete);

            if (targetObject.Endpoint != null)
            {
                request.Endpoint = targetObject.Endpoint;
            }
            else
            {
                request.Endpoint = new Uri(container.Endpoint.ToString() + "/" + Uri.EscapeDataString(FileUtils.NormalizeFileName(targetObject.Name)));
            }

            RestClient<GenericDataProvider, NullableParser> client = new RestClient<GenericDataProvider, NullableParser>();

            var tsk = client.Execute(request, cancellationToken);

            return tsk.ContinueWith<SwiftObjectsCollection>(tskOk => {

                if (tsk.Status == TaskStatus.Faulted)
                {
                    throw tsk.Exception;
                }

                return GetObjects(container, cancellationToken).Result;
            }); //,  cancellationToken, TaskContinuationOptions.NotOnFaulted, TaskScheduler.Current);
        }
コード例 #4
0
ファイル: Swift.cs プロジェクト: jasper22/Swift.Sharp
        /// <summary>
        /// Uploads the object/file to SWFIT server
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="container">The container.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Awaitable task to wait for uploading to finish</returns>
        public Task UploadObject(string fileName, Container container, CancellationToken cancellationToken)
        {
            //request.QueryParams.Add("object", Uri.EscapeDataString(System.IO.Path.GetFileName(fileName)));
            //request.HeaderParams.Add("object", System.IO.Path.GetFileName(fileName));
            //request.HeaderParams.Add("ETag", FileUtils.GenerateMD5Hash(fileName));
            //request.HeaderParams.Add("Content-Encoding", "BASE64");
            //request.HeaderParams.Add("Content-Length", new System.IO.FileInfo(fileName).Length.ToString());

            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Put);

            request.Endpoint = new Uri(container.Endpoint + "/" + Uri.EscapeDataString(FileUtils.NormalizeFileName(fileName)));

            //
            // Real file name
            request.HeaderParams.Add("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(fileName));

            request.Content = FileUtils.FileContent(fileName);

            RestClient<GenericDataProvider, NullableParser> client = new RestClient<GenericDataProvider, NullableParser>();

            return client.Execute(request, cancellationToken);
        } 
コード例 #5
0
ファイル: Swift.cs プロジェクト: jasper22/Swift.Sharp
        /// <summary>
        /// Gets the objects for container
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns><see cref="SwiftObjectsCollection"/> object</returns>
        public Task<SwiftObjectsCollection> GetObjects(Container container, CancellationToken cancellationToken)
        {
            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get);

            request.Endpoint = container.Endpoint;

            request.QueryParams.Add("format", "json");

            RestClient<GenericDataProvider, SwiftObjectsCollectionParser> client = new RestClient<GenericDataProvider, SwiftObjectsCollectionParser>();

            var tsk = client.Execute(request, cancellationToken);

            return tsk.ContinueWith<SwiftObjectsCollection>(tskOk => {
                
                SwiftObjectsCollection coll = tskOk.Result.Data;

                coll.ForEach(obj => obj.Endpoint = new Uri(container.Endpoint.ToString() + "/" + obj.Name));

                return coll;
            });
        }
コード例 #6
0
ファイル: Swift.cs プロジェクト: jasper22/Swift.Sharp
        /// <summary>
        /// Deletes the container.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task<ContainerCollection> DeleteContainer(Container container, CancellationToken cancellationToken)
        {
            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Delete);

            request.Endpoint = container.Endpoint;

            RestClient<GenericDataProvider, ContainerCollectionParser> client = new RestClient<GenericDataProvider, ContainerCollectionParser>();
            var tsk = client.Execute(request, cancellationToken);

            return tsk.ContinueWith<ContainerCollection>(tskOk =>
            {
                //return tskOk.Result.Data as ContainerCollection;

                return GetContainers(cancellationToken).Result;
            }
            , cancellationToken);
        }
コード例 #7
0
        public void Delete_unknown_container_should_fail()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containersCollection = null;

            Assert.DoesNotThrow(()=>{
                var tsk = swiftclient.GetContainers(tokenSource.Token);
                containersCollection = tsk.Result;
            });

            Assert.NotNull(containersCollection);
            string validUri = containersCollection.First().Endpoint.ToString();
            validUri = validUri.Substring(0, validUri.LastIndexOf("/"));

            Container badContainer = new Container(){
                Endpoint = new Uri(validUri + "/" + "##I_am_super_bad##")
            };


            Assert.Throws(typeof(AggregateException), () => {
                var tsk = swiftclient.DeleteContainer(badContainer, tokenSource.Token);
                var coll = tsk.Result;
                Assert.Null(coll);
            });
        }