public async Task DeleteFileAsync()
        {
            var file = SelectedFile;

            if (file == null)
            {
                Log($"No file selected");
                return;
            }

            var c = new SwiftClient();

            if (!await AuthenticateIfNeededAsync())
            {
                Log($"Could not authenticated: could not retreive a valid token");
                return;
            }
            c.InitToken(Token);


            var resp = await c.ObjectDeleteAsync(ObjectStoreUrl, Container, file.Name);

            Log($"File '{file.Name}' {(resp.IsSuccess ? "" : "not ")}deleted successfully");

            await ContainerInfoAsync();
        }
        public async Task ContainerInfoAsync()
        {
            var c = new SwiftClient();

            if (!await AuthenticateIfNeededAsync())
            {
                Log($"Could not authenticated: could not retreive a valid token");
                return;
            }
            c.InitToken(Token);
            var resp = await c.ContainerGetAsync(ObjectStoreUrl, Container);

            Log($"Container '{Container}' infos received {(resp.IsSuccess ? "" : "not ")}successfully");
            if (resp.IsSuccess)
            {
                Log($"{resp.ContentObject.Count} file(s)");
                Files.Clear();

                foreach (var file in resp.ContentObject)
                {
                    Log($"file: {file.Name} ({file.Bytes} bytes, last modified {file.Last_modified}, content type: '{file.Content_type}')");
                    Files.Add(file);
                }
            }
        }
        public async Task SendFileAsync()
        {
            var c = new SwiftClient();

            if (!await AuthenticateIfNeededAsync())
            {
                Log($"Could not authenticated: could not retreive a valid token");
                return;
            }
            c.InitToken(Token);

            var file = System.IO.File.OpenRead(NewFileSource);

            string contentType = "application/octet-stream";

            contentType = MimeTypeMap.GetMimeType(System.IO.Path.GetExtension(NewFileSource));

            var resp = await c.ObjectPutAsync(ObjectStoreUrl, Container, NewFileName, file, contentType);

            Log($"File '{NewFileName}' {(resp.IsSuccess ? "" : "not ")}sent successfully");
            //if (resp.IsSuccess)
            //{
            //    Log($"{resp.ContentObject.Count} file(s)");
            //    Files.Clear();

            //    foreach (var file in resp.ContentObject)
            //    {
            //        Log($"file: {file.Name} ({file.Bytes} bytes, last modified {file.LastModified}, content type: '{file.Content_type}')");
            //        Files.Add(file);
            //    }
            //    if (resp.ContentObject.Count > 0)
            //        Container = resp.ContentObject.First().Name;
            //}
            await ContainerInfoAsync();
        }
        public async Task ListContainersAsync()
        {
            var c = new SwiftClient();

            if (!await AuthenticateIfNeededAsync())
            {
                Log($"Could not authenticated: could not retreive a valid token");
                return;
            }
            c.InitToken(Token);
            var resp = await c.AccountListContainersAsync(ObjectStoreUrl);

            Log($"Containers listing {(resp.IsSuccess ? "" : "not ")}successful");
            if (resp.IsSuccess)
            {
                Log($"{resp.ContentObject.Count} containers");
                foreach (var cont in resp.ContentObject)
                {
                    Log($"Container: {cont.Name} ({cont.Bytes} bytes, last modified {cont.Last_modified})");
                }
                if (resp.ContentObject.Count > 0)
                {
                    Container = resp.ContentObject.First().Name;
                }
            }
        }
Esempio n. 5
0
 // build Swift client using the authentication
 // information in the configuration file
 private void BuildClient()
 {
     if (client == null)
     {
         client = new SwiftClient(cfg);
     }
 }
Esempio n. 6
0
 public static void BuildClient()
 {
     if (client == null || !client.IsAuthenticated())
     {
         client = new SwiftClient(cfg);
     }
 }
Esempio n. 7
0
        public void setup()
        {
            created_containers = new List <string>();
            created_objects    = new List <Dictionary <string, string> >();
            client             = new SwiftClient();
            var res = client.GetAuth(auth_url, user_name, api_key, new Dictionary <string, string>(), new Dictionary <string, string>(), false);

            auth_token  = res.Headers["x-auth-token"];
            storage_url = res.Headers["x-storage-url"];
        }
        public async Task AuthenticateAsync()
        {
            var c = new SwiftClient()
            {
            };
            var resp = await c.AuthenticateAsync(AuthUrl, AuthName, AuthPassword, AuthDomain);

            Log($"Authentication {(resp.IsSuccess ? "" : " not ")} successful");
            if (resp.IsSuccess)
            {
                Log($"Token: {resp.Token}");
                Token = resp.Token;
            }
        }
Esempio n. 9
0
 public void setup()
 {
     created_containers = new List<string>();
     created_objects = new List<Dictionary<string, string>>();
     client = new SwiftClient();
     var res = client.GetAuth(auth_url, user_name, api_key, new Dictionary<string, string>(), new Dictionary<string, string>(), false);
     auth_token = res.Headers["x-auth-token"];
     storage_url = res.Headers["x-storage-url"];
 }