public async Task Clean() { if (this.spark == null) { return; } var r = await spark.ListSpacesAsync(sortBy : SpaceSortBy.Created, max : 50); while (true) { if (r.IsSuccessStatus && r.Data.HasItems) { foreach (var item in r.Data.Items) { if (item.Title.Contains(UNIT_TEST_CREATED_PREFIX)) { await spark.DeleteSpaceAsync(item); } } } if (unitTestSpace == null && r.HasNext) { r = await r.ListNextAsync(); } else { break; } } }
public async Task Init() { string userDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var dirInfo = new DirectoryInfo(String.Format("{0}{1}.thrzn41{1}unittest{1}spark", userDir, Path.DirectorySeparatorChar)); byte[] encryptedToken; byte[] entropy; using (var stream = new FileStream(String.Format("{0}{1}sparktoken.dat", dirInfo.FullName, Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read, FileShare.Read)) using (var memory = new MemoryStream()) { stream.CopyTo(memory); encryptedToken = memory.ToArray(); } using (var stream = new FileStream(String.Format("{0}{1}tokenentropy.dat", dirInfo.FullName, Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read, FileShare.Read)) using (var memory = new MemoryStream()) { stream.CopyTo(memory); entropy = memory.ToArray(); } spark = SparkAPI.CreateVersion1Client(LocalProtectedString.FromEncryptedData(encryptedToken, entropy)); var r = await spark.ListSpacesAsync(sortBy : SpaceSortBy.Created, max : 50); while (true) { if (r.IsSuccessStatus && r.Data.HasItems) { foreach (var item in r.Data.Items) { if (item.Title.Contains(UNIT_TEST_SPACE_TAG)) { unitTestSpace = item; break; } } } if (unitTestSpace == null && r.HasNext) { r = await r.ListNextAsync(); } else { break; } } checkSparkAPIClient(); checkUnitTestSpace(); }