public void TestCollectionsExtrasAll() { CollectionMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Collection item = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection, combinedEnum).Result; TestMethodsHelper.TestAllNotNull(_methods, item); }
public Collection GetCollection(int collectionId, string language, CollectionMethods extraMethods = CollectionMethods.Undefined) { RestRequest req = new RestRequest("collection/{collectionId}"); req.AddUrlSegment("collectionId", collectionId.ToString()); language = language ?? DefaultLanguage; if (!String.IsNullOrWhiteSpace(language)) { req.AddParameter("language", language); } string appends = string.Join(",", Enum.GetValues(typeof(CollectionMethods)) .OfType <CollectionMethods>() .Except(new[] { CollectionMethods.Undefined }) .Where(s => extraMethods.HasFlag(s)) .Select(s => s.GetDescription())); if (appends != string.Empty) { req.AddParameter("append_to_response", appends); } req.DateFormat = "yyyy-MM-dd"; IRestResponse <Collection> resp = _client.Get <Collection>(req); return(resp.Data); }
public void GetProductVendorByProductNameTest() { using (CollectionMethods cm = new CollectionMethods()) { string productVendorByProductName = cm.GetProductVendorByProductName("Chainring"); Assert.AreEqual("Training Systems", productVendorByProductName); } }
public void GetProductsByNameTest() { using (CollectionMethods cm = new CollectionMethods()) { List <Product> productsByName = cm.GetProductsByName("Blade"); Assert.AreEqual(1, productsByName.Count); Assert.AreEqual("Blade", productsByName[0].Name); } }
public void TestCollectionsExtrasAll() { // Ignore missing json IgnoreMissingJson("parts[array] / media_type"); CollectionMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Collection item = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection, combinedEnum).Result; TestMethodsHelper.TestAllNotNull(_methods, item); }
public void GetTotalStandardCostByCategoryTest() { using (CollectionMethods cm = new CollectionMethods()) { ProductionDataContext db = new ProductionDataContext(); ProductCategory productCategory = db.ProductCategories.ToList().First(); int totalCost = cm.GetTotalStandardCostByCategory(productCategory); Assert.AreEqual(92092, totalCost); } }
public void GetProductsWithNRecentReviewsTest() { using (CollectionMethods cm = new CollectionMethods()) { List <Product> productsWithRecentReviews = cm.GetProductsWithNRecentReviews(3); Assert.AreEqual(2, productsWithRecentReviews.Count); Assert.AreEqual(709, productsWithRecentReviews[0].ProductID); Assert.AreEqual(937, productsWithRecentReviews[1].ProductID); } }
public void GetProductsByVendorNameTest() { using (CollectionMethods cm = new CollectionMethods()) { List <Product> productsByVendorName = cm.GetProductsByVendorName("Training Systems"); Assert.AreEqual(3, productsByVendorName.Count); Assert.AreEqual(320, productsByVendorName[0].ProductID); Assert.AreEqual(321, productsByVendorName[1].ProductID); Assert.AreEqual(322, productsByVendorName[2].ProductID); } }
public void GetNProductsFromCategoryTest() { using (CollectionMethods cm = new CollectionMethods()) { List <Product> productsFromCategory = cm.GetNProductsFromCategory("Bikes", 4); Assert.AreEqual(4, productsFromCategory.Count); Assert.AreEqual(771, productsFromCategory[0].ProductID); Assert.AreEqual(772, productsFromCategory[1].ProductID); Assert.AreEqual(773, productsFromCategory[2].ProductID); } }
public void GetNRecentlyReviewedProductsTest() { using (CollectionMethods cm = new CollectionMethods()) { List <Product> recentlyReviewedProducts = cm.GetNRecentlyReviewedProducts(3); Assert.AreEqual(3, recentlyReviewedProducts.Count); Assert.AreEqual(709, recentlyReviewedProducts[0].ProductID); Assert.AreEqual(937, recentlyReviewedProducts[1].ProductID); Assert.AreEqual(937, recentlyReviewedProducts[2].ProductID); } }
public void GetProductNamesByVendorNameTest() { using (CollectionMethods cm = new CollectionMethods()) { List <string> productNamesByVendorName = cm.GetProductNamesByVendorName("Training Systems"); Assert.AreEqual(3, productNamesByVendorName.Count); Assert.AreEqual("Chainring Bolts", productNamesByVendorName[0]); Assert.AreEqual("Chainring Nut", productNamesByVendorName[1]); Assert.AreEqual("Chainring", productNamesByVendorName[2]); } }
public static bool AreEquivalent(ICollection expected, ICollection actual) { //We can do a few quick tests we can do to get a easy true or easy false. //Is one collection null and one not? if (Object.ReferenceEquals(expected, null) != Object.ReferenceEquals(actual, null)) { return(false); } //Do they both point at the same object? if (Object.ReferenceEquals(expected, actual)) { return(true); } //Do they have diffrent counts? if (expected.Count != actual.Count) { return(false); } //Do we have two empty collections? if (expected.Count == 0) { return(true); } //Ran out of easy tests, now have to do the slow work. int nullCount1; Dictionary <object, int> elementCounts1 = CollectionMethods.GetElementCounts(expected, out nullCount1); int nullCount2; Dictionary <object, int> elementCounts2 = CollectionMethods.GetElementCounts(actual, out nullCount2); //One last quick check, do the two collections have the same number of null elements? if (nullCount2 != nullCount1) { return(false); } //Check for each element and see if we see them the same number of times in both collections. foreach (object key in elementCounts1.Keys) { int expectedCount; elementCounts1.TryGetValue(key, out expectedCount); int actualCount; elementCounts2.TryGetValue(key, out actualCount); if (expectedCount != actualCount) { return(false); } } return(true); }
private async Task <T> GetCollectionMethod <T>(int collectionId, CollectionMethods collectionMethod, string language = null) where T : new() { RestRequest req = new RestRequest("collection/{collectionId}/{method}"); req.AddUrlSegment("collectionId", collectionId.ToString()); req.AddUrlSegment("method", collectionMethod.GetDescription()); if (language != null) { req.AddParameter("language", language); } IRestResponse <T> resp = await _client.ExecuteGetTaskAsync <T>(req).ConfigureAwait(false); return(resp.Data); }
private T GetCollectionMethod <T>(int collectionId, CollectionMethods collectionMethod, string language = null) where T : new() { RestRequest req = new RestRequest("collection/{collectionId}/{method}"); req.AddUrlSegment("collectionId", collectionId.ToString()); req.AddUrlSegment("method", collectionMethod.GetDescription()); if (language != null) { req.AddParameter("language", language); } IRestResponse <T> resp = _client.Get <T>(req); return(resp.Data); }
private async Task <T> GetCollectionMethod <T>(int collectionId, CollectionMethods collectionMethod, string language = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("collection/{collectionId}/{method}"); req.AddUrlSegment("collectionId", collectionId.ToString()); req.AddUrlSegment("method", collectionMethod.GetDescription()); if (language != null) { req.AddParameter("language", language); } RestResponse <T> resp = await req.ExecuteGet <T>(cancellationToken).ConfigureAwait(false); return(resp); }
public void TestGenericPagingList() { List <testObj> objList = Common.GenerateSampleList(23); Trace.WriteLine($"List Generation is Completed for sample {objList.Count} Records"); foreach (var item in objList) { Trace.WriteLine(item.Id + " - " + item.Name); } CollectionMethods.ProcessListViaPaging(objList, 10, (currentPageList) => { Trace.WriteLine("\nNow Looping through currentPageList"); foreach (var item in currentPageList) { Trace.WriteLine($"{item.Id} - {item.Name}"); } }); //Alternative Method //CollectionMethods.ProcessListViaPaging(objList, 10, processEachList ); }
public void TestPagingList() { List <testObj> objList = Common.GenerateSampleList(23); Trace.WriteLine("List Generation is Completed for sample 23 Records"); foreach (var item in objList) { Trace.WriteLine(item.Id + " - " + item.Name); } int pageSize = 11; int totalPages = objList.Count / pageSize; Trace.WriteLine($"Total pages are {totalPages} with total count of {objList.Count} and pageSize of {pageSize}"); //var NewList = HelperUtilities.Collections.CollectionMethods.GetPage<testObj>(objList, totalPages, pageSize); //Trace.WriteLine("Now Paging through last list"); //foreach (var item in NewList) //{ // Trace.WriteLine(item.Id + " -- " + item.Name); //} //NewList = CollectionMethods.GetPage(objList, 0, pageSize); //Trace.WriteLine("Now Page through FIRST page of list"); //foreach (var item in NewList) //{ // Trace.WriteLine(item.Id + " -- " + item.Name); //} Trace.WriteLine("Now Looping through all pages one by one"); for (int i = 0; i <= totalPages; i++) { Trace.WriteLine($"Page No. {i}\n starts"); var list = CollectionMethods.GetPage(objList, i, pageSize); foreach (var item in list) { Trace.WriteLine($"{item.Id} - {item.Name}"); } Trace.WriteLine($"Page No. {i} ends"); } }
private void SolveFirstCross() { // Step 1: Get the edges with target position on the bottom layer IEnumerable <Cube> bottomEdges = Rubik.Cubes.Where(c => c.IsEdge && GetTargetFlags(c).HasFlag(CubeFlag.BottomLayer)); // Step 2: Rotate a correct orientated edge of the bottom layer to target position IEnumerable <Cube> solvedBottomEdges = bottomEdges.Where(bE => bE.Position.Flags == GetTargetFlags(bE) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom); if (bottomEdges.Count(bE => bE.Position.HasFlag(CubeFlag.BottomLayer) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom) > 0) { while (solvedBottomEdges.Count() < 1) { SolverMove(CubeFlag.BottomLayer, true); solvedBottomEdges = bottomEdges.Where(bE => bE.Position.Flags == GetTargetFlags(bE) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom); } } // Step 3: Solve incorrect edges of the bottom layer while (solvedBottomEdges.Count() < 4) { IEnumerable <Cube> unsolvedBottomEdges = bottomEdges.Except(solvedBottomEdges); Cube e = (unsolvedBottomEdges.FirstOrDefault(c => c.Position.HasFlag(CubeFlag.TopLayer)) != null) ? unsolvedBottomEdges.FirstOrDefault(c => c.Position.HasFlag(CubeFlag.TopLayer)) : unsolvedBottomEdges.First(); Color secondColor = e.Colors.First(co => co != Rubik.BottomColor && co != Color.Black); if (e.Position.Flags != GetTargetFlags(e)) { // Rotate to top layer CubeFlag layer = CubeFlagService.FromFacePosition(e.Faces.First(f => (f.Color == Rubik.BottomColor || f.Color == secondColor) && f.Position != FacePosition.Top && f.Position != FacePosition.Bottom).Position); CubeFlag targetLayer = CubeFlagService.FromFacePosition(StandardCube.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, e.Colors)) .Faces.First(f => f.Color == secondColor).Position); if (e.Position.HasFlag(CubeFlag.MiddleLayer)) { if (layer == targetLayer) { while (!e.Position.HasFlag(CubeFlag.BottomLayer)) { SolverMove(layer, true); } } else { SolverMove(layer, true); if (e.Position.HasFlag(CubeFlag.TopLayer)) { SolverMove(CubeFlag.TopLayer, true); SolverMove(layer, false); } else { for (int i = 0; i < 2; i++) { SolverMove(layer, true); } SolverMove(CubeFlag.TopLayer, true); SolverMove(layer, true); } } } if (e.Position.HasFlag(CubeFlag.BottomLayer)) { for (int i = 0; i < 2; i++) { SolverMove(layer, true); } } // Rotate over target position while (!e.Position.HasFlag(targetLayer)) { SolverMove(CubeFlag.TopLayer, true); } //Rotate to target position for (int i = 0; i < 2; i++) { SolverMove(targetLayer, true); } CubeFlag targetPos = GetTargetFlags(e); } // Flip the incorrect orientated edges with the algorithm: Fi D Ri Di if (Solvability.GetOrientation(Rubik, e) != 0) { CubeFlag frontSlice = CubeFlagService.FromFacePosition(e.Faces.First(f => f.Color == Rubik.BottomColor).Position); SolverMove(frontSlice, false); SolverMove(CubeFlag.BottomLayer, true); CubeFlag rightSlice = CubeFlagService.FromFacePosition(e.Faces.First(f => f.Color == secondColor).Position); SolverMove(rightSlice, false); SolverMove(CubeFlag.BottomLayer, false); } List <Face> faces = e.Faces.ToList(); solvedBottomEdges = bottomEdges.Where(bE => bE.Position.Flags == GetTargetFlags(bE) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom); } }
private void SolveFirstCross() { // Step 1: Get the edges with target position on the bottom layer IEnumerable <Cube> bottomEdges = Rubik.Cubes.Where(c => c.IsEdge // target position on bottom layer && GetTargetFlags(c).HasFlag(CubeFlag.BottomLayer) ); // Step 2: Rotate a correct orientated edge of the bottom layer to target position IEnumerable <Cube> bottomEdgesInBottomLayerCorrectlyOriented = bottomEdges.Where(bottomEdge => // is in bottom layer bottomEdge.Position.Flags == GetTargetFlags(bottomEdge) // is oriented correctly && bottomEdge.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom ); var anyEdgesAreSolvableWithDMoves = bottomEdges.Count(bE => bE.Position.HasFlag(CubeFlag.BottomLayer) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom ) > 0; if (anyEdgesAreSolvableWithDMoves) { while (!bottomEdgesInBottomLayerCorrectlyOriented.Any()) { // turn the bottom layer until at least one is SolverMove(CubeFlag.BottomLayer, true); bottomEdgesInBottomLayerCorrectlyOriented = bottomEdges.Where(bE => bE.Position.Flags == GetTargetFlags(bE) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom ); } } // Step 3: Solve incorrect edges of the bottom layer while (bottomEdgesInBottomLayerCorrectlyOriented.Count() < 4) { IEnumerable <Cube> unsolvedBottomEdges = bottomEdges.Except(bottomEdgesInBottomLayerCorrectlyOriented); Cube e = unsolvedBottomEdges.FirstOrDefault(c => c.Position.HasFlag(CubeFlag.TopLayer)) ?? unsolvedBottomEdges.First(); Color secondColor = e.Colors.First(co => co != Rubik.BottomColor && co != Color.Black ); if (e.Position.Flags != GetTargetFlags(e)) { // Rotate to top layer CubeFlag layer = CubeFlagService.FromFacePosition( e.Faces.First(f => (f.Color == Rubik.BottomColor || f.Color == secondColor) && f.Position != FacePosition.Top && f.Position != FacePosition.Bottom ).Position ); CubeFlag targetLayer = CubeFlagService.FromFacePosition( StandardCube.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, e.Colors) ) .Faces .First(f => f.Color == secondColor) .Position ); if (e.Position.HasFlag(CubeFlag.MiddleLayer)) { if (layer == targetLayer) { while (!e.Position.HasFlag(CubeFlag.BottomLayer)) { SolverMove(layer, true); } } else { SolverMove(layer, true); if (e.Position.HasFlag(CubeFlag.TopLayer)) { SolverMove(CubeFlag.TopLayer, true); SolverMove(layer, false); } else { for (int i = 0; i < 2; i++) { SolverMove(layer, true); } SolverMove(CubeFlag.TopLayer, true); SolverMove(layer, true); } } } if (e.Position.HasFlag(CubeFlag.BottomLayer)) { for (int i = 0; i < 2; i++) { SolverMove(layer, true); } } // Rotate over target position while (!e.Position.HasFlag(targetLayer)) { SolverMove(CubeFlag.TopLayer, true); } //Rotate to target position for (int i = 0; i < 2; i++) { SolverMove(targetLayer, true); } } // Flip the incorrect orientated edges with the algorithm: F' D R' D' if (Solvability.GetOrientation(Rubik, e) != 0) { CubeFlag frontSlice = CubeFlagService.FromFacePosition(e.Faces.First(f => f.Color == Rubik.BottomColor).Position); SolverMove(frontSlice, false); SolverMove(CubeFlag.BottomLayer, true); CubeFlag rightSlice = CubeFlagService.FromFacePosition(e.Faces.First(f => f.Color == secondColor).Position); SolverMove(rightSlice, false); SolverMove(CubeFlag.BottomLayer, false); } bottomEdgesInBottomLayerCorrectlyOriented = bottomEdges.Where(bE => bE.Position.Flags == GetTargetFlags(bE) && bE.Faces.First(f => f.Color == Rubik.BottomColor).Position == FacePosition.Bottom ); } }
public Collection GetCollection(int collectionId, CollectionMethods extraMethods = CollectionMethods.Undefined) { return(GetCollection(collectionId, DefaultLanguage, extraMethods)); }
public async Task <Collection> GetCollectionAsync(int collectionId, string language, CollectionMethods extraMethods = CollectionMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("collection/{collectionId}"); req.AddUrlSegment("collectionId", collectionId.ToString()); language = language ?? DefaultLanguage; if (!string.IsNullOrWhiteSpace(language)) { req.AddParameter("language", language); } string appends = string.Join(",", Enum.GetValues(typeof(CollectionMethods)) .OfType <CollectionMethods>() .Except(new[] { CollectionMethods.Undefined }) .Where(s => extraMethods.HasFlag(s)) .Select(s => s.GetDescription())); if (appends != string.Empty) { req.AddParameter("append_to_response", appends); } //req.DateFormat = "yyyy-MM-dd"; RestResponse <Collection> response = await req.ExecuteGet <Collection>(cancellationToken).ConfigureAwait(false); if (!response.IsValid) { return(null); } Collection item = await response.GetDataObject().ConfigureAwait(false); if (item != null) { item.Overview = WebUtility.HtmlDecode(item.Overview); } return(item); }
public async Task <Collection> GetCollectionAsync(int collectionId, CollectionMethods extraMethods = CollectionMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { return(await GetCollectionAsync(collectionId, DefaultLanguage, extraMethods, cancellationToken).ConfigureAwait(false)); }
internal bool ResolveCollectionMethods() { // If the length is 1, either we only got 1 collection method, or we got this value from the powershell script and we need to split var collMethodArray = CollectionMethods.ToArray(); if (collMethodArray.Length == 1) { collMethodArray = collMethodArray[0].Split(','); } var resolved = CollectionMethodResolved.None; foreach (var baseString in collMethodArray) { var option = CollectionMethodOptions.None; try { option = (CollectionMethodOptions)Enum.Parse(typeof(CollectionMethodOptions), baseString, true); } catch { Console.WriteLine($"Failed to parse Collection Method {baseString}."); return(false); } switch (option) { case CollectionMethodOptions.All: resolved = resolved | CollectionMethodResolved.ACL | CollectionMethodResolved.Container | CollectionMethodResolved.Group | CollectionMethodResolved.LocalGroups | CollectionMethodResolved.ObjectProps | CollectionMethodResolved.Sessions | CollectionMethodResolved.Trusts | CollectionMethodResolved.LoggedOn | CollectionMethodResolved.SPNTargets; break; case CollectionMethodOptions.DCOnly: resolved = resolved | CollectionMethodResolved.ACL | CollectionMethodResolved.Container | CollectionMethodResolved.Group | CollectionMethodResolved.ObjectProps | CollectionMethodResolved.Trusts | CollectionMethodResolved.DCOnly | CollectionMethodResolved.GPOLocalGroup; break; case CollectionMethodOptions.Group: resolved |= CollectionMethodResolved.Group; break; case CollectionMethodOptions.Session: resolved |= CollectionMethodResolved.Sessions; break; case CollectionMethodOptions.LoggedOn: resolved |= CollectionMethodResolved.LoggedOn; break; case CollectionMethodOptions.Trusts: resolved |= CollectionMethodResolved.Trusts; break; case CollectionMethodOptions.ACL: resolved |= CollectionMethodResolved.ACL; break; case CollectionMethodOptions.ObjectProps: resolved |= CollectionMethodResolved.ObjectProps; break; case CollectionMethodOptions.RDP: resolved |= CollectionMethodResolved.RDP; break; case CollectionMethodOptions.DCOM: resolved |= CollectionMethodResolved.DCOM; break; case CollectionMethodOptions.LocalAdmin: resolved |= CollectionMethodResolved.LocalAdmin; break; case CollectionMethodOptions.PSRemote: resolved |= CollectionMethodResolved.PSRemote; break; case CollectionMethodOptions.SPNTargets: resolved |= CollectionMethodResolved.SPNTargets; break; case CollectionMethodOptions.Container: resolved |= CollectionMethodResolved.Container; break; case CollectionMethodOptions.GPOLocalGroup: resolved |= CollectionMethodResolved.GPOLocalGroup; break; case CollectionMethodOptions.LocalGroup: resolved |= CollectionMethodResolved.LocalGroups; break; case CollectionMethodOptions.Default: resolved = resolved | CollectionMethodResolved.ACL | CollectionMethodResolved.Container | CollectionMethodResolved.Group | CollectionMethodResolved.LocalGroups | CollectionMethodResolved.ObjectProps | CollectionMethodResolved.Sessions | CollectionMethodResolved.Trusts | CollectionMethodResolved.SPNTargets; break; case CollectionMethodOptions.ComputerOnly: resolved = resolved | CollectionMethodResolved.LocalGroups | CollectionMethodResolved.Sessions; break; default: throw new ArgumentOutOfRangeException(); } } if (Stealth) { var updates = new List <string>(); if ((resolved & CollectionMethodResolved.LoggedOn) != 0) { resolved ^= CollectionMethodResolved.LoggedOn; updates.Add("[-] Removed LoggedOn Collection"); } var localGroupRemoved = false; if ((resolved & CollectionMethodResolved.RDP) != 0) { localGroupRemoved = true; resolved ^= CollectionMethodResolved.RDP; updates.Add("[-] Removed RDP Collection"); } if ((resolved & CollectionMethodResolved.DCOM) != 0) { localGroupRemoved = true; resolved ^= CollectionMethodResolved.DCOM; updates.Add("[-] Removed DCOM Collection"); } if ((resolved & CollectionMethodResolved.PSRemote) != 0) { localGroupRemoved = true; resolved ^= CollectionMethodResolved.PSRemote; updates.Add("[-] Removed PSRemote Collection"); } if ((resolved & CollectionMethodResolved.LocalAdmin) != 0) { localGroupRemoved = true; resolved ^= CollectionMethodResolved.LocalAdmin; updates.Add("[-] Removed LocalAdmin Collection"); } if (localGroupRemoved) { resolved |= CollectionMethodResolved.GPOLocalGroup; updates.Add("[+] Added GPOLocalGroup"); } if (updates.Count > 0) { Console.WriteLine("Updated Collection Methods to Reflect Stealth Options"); foreach (var update in updates) { Console.WriteLine(update); } Console.WriteLine(); } } Console.WriteLine($"Resolved Collection Methods: {resolved}"); Console.WriteLine(); ResolvedCollectionMethods = resolved; return(true); }
private Cube RefreshCube(Cube c) { return(Rubik.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, c.Colors))); }
public Collection GetCollection(int collectionId, CollectionMethods extraMethods = CollectionMethods.Undefined) { return(GetCollection(collectionId, null, extraMethods)); }
public async Task <Collection> GetCollectionAsync(int collectionId, CollectionMethods extraMethods = CollectionMethods.Undefined) { return(await GetCollectionAsync(collectionId, DefaultLanguage, extraMethods).ConfigureAwait(false)); }
/// <summary> /// True, if this pattern has exactly the same pattern elemnts as the other pattern /// </summary> /// <param name="pattern">Pattern to compare</param> public bool Equals(Pattern pattern) { return(CollectionMethods.ScrambledEquals(pattern.Items, Items)); }
public static bool CorrectColors(Rubik r) { return(r.GenStandardCube().Cubes.Count(sc => r.Cubes .Where(c => CollectionMethods.ScrambledEquals(c.Colors, sc.Colors)).Count() == 1) == r.Cubes.Count()); }
/// <summary> /// Returns the position of given cube where it has to be when the Rubik is solved /// </summary> /// <param name="cube">Defines the cube to be analyzed</param> /// <returns></returns> protected CubeFlag GetTargetFlags(Cube cube) { return(StandardCube.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, cube.Colors)).Position.Flags); }
internal bool ResolveCollectionMethods(ILogger logger, out ResolvedCollectionMethod resolved, out bool dconly) { var arr = CollectionMethods.Count() == 1 ? CollectionMethods.First().Split(',') : CollectionMethods.ToArray(); resolved = ResolvedCollectionMethod.None; dconly = false; foreach (var baseMethod in arr) { CollectionMethodOptions option; try { option = (CollectionMethodOptions)Enum.Parse(typeof(CollectionMethodOptions), baseMethod, true); } catch { logger.LogCritical("Failed to parse collection method {baseMethod}", baseMethod); return(false); } resolved |= option switch { CollectionMethodOptions.Group => ResolvedCollectionMethod.Group, CollectionMethodOptions.Session => ResolvedCollectionMethod.Session, CollectionMethodOptions.LoggedOn => ResolvedCollectionMethod.LoggedOn, CollectionMethodOptions.Trusts => ResolvedCollectionMethod.Trusts, CollectionMethodOptions.ACL => ResolvedCollectionMethod.ACL, CollectionMethodOptions.ObjectProps => ResolvedCollectionMethod.ObjectProps, CollectionMethodOptions.RDP => ResolvedCollectionMethod.RDP, CollectionMethodOptions.DCOM => ResolvedCollectionMethod.DCOM, CollectionMethodOptions.LocalAdmin => ResolvedCollectionMethod.LocalAdmin, CollectionMethodOptions.PSRemote => ResolvedCollectionMethod.PSRemote, CollectionMethodOptions.SPNTargets => ResolvedCollectionMethod.SPNTargets, CollectionMethodOptions.Container => ResolvedCollectionMethod.Container, CollectionMethodOptions.GPOLocalGroup => ResolvedCollectionMethod.GPOLocalGroup, CollectionMethodOptions.LocalGroup => ResolvedCollectionMethod.LocalGroups, CollectionMethodOptions.Default => ResolvedCollectionMethod.Default, CollectionMethodOptions.DCOnly => ResolvedCollectionMethod.DCOnly, CollectionMethodOptions.ComputerOnly => ResolvedCollectionMethod.ComputerOnly, CollectionMethodOptions.All => ResolvedCollectionMethod.All, CollectionMethodOptions.None => ResolvedCollectionMethod.None, _ => throw new ArgumentOutOfRangeException() }; if (option == CollectionMethodOptions.DCOnly) { dconly = true; } } if (Stealth) { var updates = new List <string>(); if ((resolved & ResolvedCollectionMethod.LoggedOn) != 0) { resolved ^= ResolvedCollectionMethod.LoggedOn; updates.Add("[-] Removed LoggedOn"); } var localGroupRemoved = false; if ((resolved & ResolvedCollectionMethod.RDP) != 0) { localGroupRemoved = true; resolved ^= ResolvedCollectionMethod.RDP; updates.Add("[-] Removed RDP Collection"); } if ((resolved & ResolvedCollectionMethod.DCOM) != 0) { localGroupRemoved = true; resolved ^= ResolvedCollectionMethod.DCOM; updates.Add("[-] Removed DCOM Collection"); } if ((resolved & ResolvedCollectionMethod.PSRemote) != 0) { localGroupRemoved = true; resolved ^= ResolvedCollectionMethod.PSRemote; updates.Add("[-] Removed PSRemote Collection"); } if ((resolved & ResolvedCollectionMethod.LocalAdmin) != 0) { localGroupRemoved = true; resolved ^= ResolvedCollectionMethod.LocalAdmin; updates.Add("[-] Removed LocalAdmin Collection"); } if (localGroupRemoved) { resolved |= ResolvedCollectionMethod.GPOLocalGroup; updates.Add("[+] Added GPOLocalGroup"); } if (updates.Count > 0) { var updateString = new StringBuilder(); updateString.AppendLine("Updated Collection Methods to Reflect Stealth Options"); foreach (var update in updates) { updateString.AppendLine(update); } logger.LogInformation("{Update}", updateString.ToString()); } } logger.LogInformation("Resolved Collection Methods: {resolved}", resolved.GetIndividualFlags()); return(true); } }