Last active
September 2, 2019 09:06
-
-
Save ivanbuzyka/265de65c491e3c6d4933 to your computer and use it in GitHub Desktop.
[ProjectReview]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[WebMethod] | |
public static object CyclicallyInheritedTemplates() | |
{ | |
using (new SecurityDisabler()) | |
{ | |
var templates = GetMasterTemplates(); | |
var resultPairs = new List<Pair<string, string>>(); | |
foreach (var template in templates) | |
{ | |
resultPairs = CheckInBaseTemplates(resultPairs, template.ID.ToString(), template.ID.ToString(), string.Empty); | |
} | |
return resultPairs.Select(x => new { TemplatePath = x.Part1, InheritanceChain = x.Part2 }).ToList(); | |
} | |
} | |
private static List<Pair<string, string>> CheckInBaseTemplates(List<Pair<string, string>> result, | |
string currentTemplatePath, string templateInitiator, string inheritanceChain) | |
{ | |
var templateItem = PrtExtensions.MasterDatabase.GetTemplate(currentTemplatePath); | |
var templateInitiatorItem = PrtExtensions.MasterDatabase.GetTemplate(templateInitiator); | |
if (templateItem != null) | |
{ | |
var inheritanceChainUpdated = string.Format("{0} <-- {1}", inheritanceChain, templateItem.Name); | |
var foundMatches = templateItem.BaseTemplates.Where(t => t.ID.ToString().Equals(templateInitiator, StringComparison.InvariantCultureIgnoreCase)) | |
.Select(t => new Pair<string, string>(templateInitiatorItem.InnerItem.Paths.Path, string.Format("{0} <-- {1}", inheritanceChainUpdated, templateInitiatorItem.Name))); | |
if (foundMatches.Any()) | |
{ | |
result.Add(foundMatches.FirstOrDefault()); | |
} | |
foreach (var baseTemplate in templateItem.BaseTemplates) | |
{ | |
// Check in order to get rid of infinity recursion | |
if (baseTemplate.ID.ToString().Equals(templateInitiator)) | |
{ | |
continue; | |
} | |
result = CheckInBaseTemplates(result, baseTemplate.ID.ToString(), templateInitiator, inheritanceChainUpdated); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment