Пример #1
0
        //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);
        }
Пример #2
0
        /// <summary>
        /// Creates the container.
        /// </summary>
        /// <param name="containerName">Name of the container.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task <ContainerCollection> CreateContainer(string containerName, CancellationToken cancellationToken)
        {
            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Put);
            string containerUri         = request.Endpoint.ToString();

            if (containerUri.EndsWith("/"))
            {
                containerUri += containerName;
            }
            else
            {
                containerUri += "/" + containerName;
            }

            request.Endpoint = new Uri(containerUri);

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

            return(tsk.ContinueWith <ContainerCollection>(tskOk =>
            {
                return GetContainers(cancellationToken).Result;
            }
                                                          , cancellationToken));
        }
Пример #3
0
        /// <summary>
        /// Gets the account details.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Awaitable task with result as <seealso cref="AccountDetails"/></returns>
        public Task <AccountDetails> GetAccountDetails(CancellationToken cancellationToken)
        {
            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Head);

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

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

            return(tsk.ContinueWith <AccountDetails>(tskOk => {
                return tskOk.Result.Data as AccountDetails;
            }
                                                     , cancellationToken));
        }
Пример #4
0
        /// <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));
        }
Пример #5
0
        /// <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
        /// <summary>
        /// Gets the containers.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns><see cref="ContainerCollection"/> object</returns>
        public Task <ContainerCollection> GetContainers(CancellationToken cancellationToken)
        {
            GenericDataProvider request = new GenericDataProvider(this.credentials, HttpMethod.Get);

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

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

            return(tsk.ContinueWith <ContainerCollection>(tskOk =>
            {
                ContainerCollection coll = tskOk.Result.Data as ContainerCollection;
                foreach (Container container in coll)
                {
                    string endpoint = this.credentials.Endpoint.ToString() + "/" + container.Name;
                    container.Endpoint = new Uri(endpoint);
                }
                return coll;;
            }
                                                          , cancellationToken));
        }
Пример #7
0
        /// <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));
        }
        public void CanUseGenericDataProviderForProduct()
        {
            var genericProductProvider = new GenericDataProvider<Product>(_session);

            var specificProductProvider = new ProductDataProvider(_session);

            int productId = 20;
            var productListByGeneric = genericProductProvider.GetById(productId);
            var productListBySpecific = specificProductProvider.GetProductById(productId);

            Assert.That(productListBySpecific, Is.EqualTo(productListByGeneric));
        }
        public void CanUseGenericDataProviderForOrder()
        {
            var genericOrderProvider = new GenericDataProvider<Order>(_session);
            var specificOrderProvider = new OrderDataProvider(_session);

            int orderId = 20;
            var orderListByGeneric = genericOrderProvider.GetById(orderId);
            var orderListBySpecific = specificOrderProvider.GetOrderById(orderId);

            Assert.That(orderListBySpecific, Is.EqualTo(orderListByGeneric));
        }
        public void CanUseGenericDataProviderForCustomer()
        {
            var genericCustomerProvider = new GenericDataProvider<Customer>(_session);
            var specificCustomerProvider = new CustomerDataProvider(_session);

            int customerId = 9;
            var customerListByGeneric = genericCustomerProvider.GetById(customerId);
            var customerListBySpecific = specificCustomerProvider.GetCustomerById(customerId);

            Assert.That(customerListBySpecific, Is.EqualTo(customerListByGeneric));
        }
        public void CanGetCustomerByFirstNameUsingGenericDataProvider()
        {
            var JuanHuertaCustomers =
                DetachedCriteria.For<Customer>()
                    .Add(Expression.Eq("Name.Firstname", "Juan"))
                    .Add(Expression.Eq("Name.Lastname", "Huerta"));

            var _genericProvider = new GenericDataProvider<Customer>(_session);

            var customersBySpecificProvider = _provider.GetCustomerByArbitraryCriteria(JuanHuertaCustomers);
            var customersByGenericProvider = _genericProvider.Find(JuanHuertaCustomers);

            var numberOfcustomersBySpecificProviderSerialized = customersBySpecificProvider.Count;
            var numberOfcustomersByGenericProviderSerialized = customersByGenericProvider.Count;

            Assert.That(numberOfcustomersByGenericProviderSerialized,Is.Not(0));
            Assert.That(numberOfcustomersByGenericProviderSerialized, Is.EqualTo(numberOfcustomersBySpecificProviderSerialized));
        }