コード例 #1
0
        private async Task CleanupUnitTest()
        {
            TestStatusMsg("Cleaning up test...");
            string basepath = txtFolderPath.Text;

            if (basepath.EndsWith("/"))
            {
                basepath.TrimEnd(new char[] { '/' });
            }
            string tfoldername = basepath + "/Cloud Elements API Test Folder";

            //check for file on disk
            string fn = System.IO.Path.Combine(WorkPath, "SFCE_test_file_1.txt");

            if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(fn)))
            {
                if (System.IO.File.Exists(fn))
                {
                    try
                    {
                        System.IO.File.Delete(fn);
                        TestStatusMsg("Downloaded test file deleted");
                    }
                    catch (System.IO.IOException ix)
                    {
                        TestStatusMsg("Downloaded test file NOT deleted - " + ix.Message);
                    }
                }
            }


            //check for folder
            try
            {
                List <Cloud_Elements_API.CloudFile> fe = await APIConnector.ListFolderContents(Cloud_Elements_API.CloudElementsConnector.FileSpecificationType.Path, tfoldername, chkWithTags.Checked);

                //if exists, delete
                try
                {
                    bool Result = await APIConnector.DeleteFolder(Cloud_Elements_API.CloudElementsConnector.FileSpecificationType.Path, tfoldername, false);

                    TestStatusMsg("Test folder deleted");
                }
                catch (Exception e)
                {
                    TestStatusMsg("Delete Folder failed: " + e.Message);
                    throw e;
                }
            }
            catch (System.Net.Http.HttpRequestException e)
            {
                TestStatusMsg("Nothing to clean: " + e.Message);
            }

            TestStatusMsg("Test cleanup complete");
        }