private void CreateRelationHasA(CodeElement objA, CodeElement objB, CodeRelation.ReletionType relationType, CodeRelation.ReletionMultiplicity relationMultiplicity) { CodeRelation codeRelation = null; if (objA.Properties == null) { objA.Properties = new List<CodeRelation>(); } if (null == (codeRelation = objA.Properties.FirstOrDefault(p => p.RelationType == (int)relationType))) { codeRelation = new CodeRelation(relationType); //codeRelation.Childs = new List<Multiplicity>(); objA.Properties.Add(codeRelation); } if (codeRelation.Childs.FirstOrDefault(p => p.CodeElement.Name == objB.Name) == null) { Arrow multiplicity = new Arrow(); multiplicity.CodeElement = objB; multiplicity.Multiplicity = (int)relationMultiplicity; codeRelation.Childs.Add(multiplicity); } }
private string ConvertToNaturalLanguage(CodeElement codeSection) { StringBuilder stringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(codeSection.Name)) // && codeSection.modifiers.Contains("public")) { if (codeSection.ReturnType != null && codeSection.ReturnType.Equals("class")) { //Console.WriteLine("\t The " + codeSection.ReturnType + " " + codeSection.identifier + " "); stringBuilder.AppendLine("\t" + " a " + codeSection.Name); } if (codeSection.ReturnType != null && codeSection.ReturnType.Equals("namespace")) { //Console.WriteLine("In " + codeSection.ReturnType + " " + codeSection.identifier + " "); stringBuilder.AppendLine(" In " + codeSection.Name); } } if (codeSection.Childs!=null) foreach (CodeElement codeSectionChild in codeSection.Childs) { if (!string.IsNullOrEmpty(codeSectionChild.Name)) { // Only public methods if (!codeSectionChild.Modifiers.Contains("public")) { // Console.WriteLine(); stringBuilder.AppendLine(ConvertToNaturalLanguage(codeSectionChild)); continue; } if (codeSectionChild.ReturnType.Equals("eventHandler")) { stringBuilder.AppendLine("\t\t => " + "React to: " + codeSectionChild.Name); } else if (codeSectionChild.ReturnType.Equals("method")) { stringBuilder.AppendLine("\t\t => " + "Can: " + codeSectionChild.Name); } else { if (codeSectionChild.ReturnType != null && (codeSectionChild.ReturnType.Equals("namespace") || codeSectionChild.ReturnType.Equals("class"))) { stringBuilder.AppendLine(); stringBuilder.AppendLine(ConvertToNaturalLanguage(codeSectionChild)); continue; } stringBuilder.AppendLine("\t\t => " + " " + codeSectionChild.Name); } if (codeSectionChild.ReturnType != null && !codeSectionChild.ReturnType.Equals("void")) { stringBuilder.Append(" as a " + codeSectionChild.ReturnType); } string parameters =""; if (codeSectionChild.Parameters != null) { parameters += codeSectionChild.Parameters.Aggregate("", (current, parameter) => current + parameter); } // has parameters but is not an event if (!string.IsNullOrEmpty(parameters) && !codeSectionChild.ReturnType.Equals("eventHandler")) { stringBuilder.Append(" based on " + codeSectionChild.Parameters); } stringBuilder.AppendLine(); } stringBuilder.AppendLine(ConvertToNaturalLanguage(codeSectionChild)); } return stringBuilder.ToString(); }
private void CreateRelationIsA(CodeElement objA, CodeElement objB) { //objA; }
private string CreateDiagramSource(CodeElement codeElement) { StringBuilder stringBuilder = new StringBuilder(); if (codeElement.Childs != null) foreach (CodeElement codeSectionChild in codeElement.Childs) { if (!string.IsNullOrEmpty(codeElement.Name.Trim()) && !string.IsNullOrEmpty(codeSectionChild.Name.Trim())) { string shape = "elipse"; switch (codeSectionChild.Visibility) { case 1: shape = "diamond"; break; case 2: shape = "diamond"; break; case 3: shape = "diamond"; break; case 4: shape = "diamond"; break; default: shape = "elipse"; break; } string color = "white"; double complexity = (codeSectionChild.Childs.Count); switch ((int) Math.Round(complexity)) { case 0: color = "yellow"; break; case 1: color = "yellow"; break; case 2: color = "orange"; break; case 3: color = "green"; break; case 4: color = "gray"; break; case 5: color = "magenta"; break; default: color = "red"; break; } string codeSectionChildIdentifier = codeSectionChild.Name.Replace('.', '_'); if (codeSectionChildIdentifier.Contains("[")) stringBuilder.ToString(); if (codeElement.Name.Contains("[")) stringBuilder.ToString(); if (codeSectionChildIdentifier.Contains("+")) stringBuilder.ToString(); if (codeElement.Name.Contains("+")) stringBuilder.ToString(); if (codeSectionChildIdentifier.Contains("~")) stringBuilder.ToString(); if (codeElement.Name.Contains("~")) stringBuilder.ToString(); if (string.IsNullOrEmpty(codeElement.Name.Trim())) { stringBuilder.ToString(); } if (!codeSectionChildIdentifier.Contains("[") && !codeElement.Name.Contains("[")) { if (!codeSectionChildIdentifier.Contains("~") && !codeElement.Name.Contains("~")) { if (!codeSectionChildIdentifier.Contains("+") && !codeElement.Name.Contains("+")) { if (!codeSectionChildIdentifier.Contains("=") && !codeElement.Name.Contains("=")) { stringBuilder.AppendLine(codeSectionChildIdentifier + "[fillcolor=" + color + ", style=\"rounded,filled\", shape=" + shape + "];"); stringBuilder.AppendLine(codeElement.Name.Replace('.', '_') + " -> " + codeSectionChildIdentifier + ";"); } } } } } stringBuilder.Append(CreateDiagramSource(codeSectionChild)); } //foreach (CodeElement codeElementChild in codeElement.Childs) { } return stringBuilder.ToString(); }