Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Bridge result?");
            string bridgeResult = File.ReadAllText(args.Length == 2 ? args[0] : RQuotes(Console.ReadLine()));

            Console.WriteLine(".NET result?");
            string      netResult       = File.ReadAllText(args.Length == 2 ? args[1] : RQuotes(Console.ReadLine()));
            CSNamespace bridgeNamespace = CSNamespace.FromText(bridgeResult);
            CSNamespace netNamespace    = CSNamespace.FromText(netResult);

            bridgeNamespace.SortAll();
            netNamespace.SortAll();
            using (writer = new StreamWriter("result.html"))
            {
                #region Start
                writer.Write(@"<!DOCTYPE html>
<html>
<head>
  <meta charset=""utf-8"">
  <title>Comparison of Bridge and .NET</title>
  <!-- 2 load the theme CSS file -->
  <link rel=""stylesheet"" href=""dist/themes/default/style.min.css"" />
</head>
<body><div id=""main"">");
                #endregion
                DiffNamespaces(bridgeNamespace, netNamespace);
                #region End
                writer.Write(@"</div>
<!-- 4 include the jQuery library -->
  <script src=""dist/libs/jquery.min.js""></script>
  <script src = ""dist/jstree.min.js"" ></script>
<script>
$(function(){
$('#main').jstree();
});
</script>
</body>
</html>");
                #endregion
            }
        }
Example #2
0
        public static CSNamespace FromText(string text)
        {
            CSNamespace    result  = new CSNamespace();
            bool           newType = true;
            CSMemberedType last    = null;

            foreach (var _line in text.Split('\n'))
            {
                var line = _line.Replace("\r", "");
                if (string.IsNullOrEmpty(line))
                {
                    newType = true;
                    continue;
                }
                if (newType)
                {
                    newType = false;
                    int        minusIndex       = line.IndexOf('-');
                    string     typeName         = line.Substring(0, minusIndex);
                    Attributes attributes       = (Attributes)uint.Parse(line.Substring(minusIndex + 1));
                    string[]   dotSplitTypeName = typeName.Split('.');
                    var        cNamespace       = result;
                    for (int n = 0; n < dotSplitTypeName.Length; n++)
                    {
                        var item = dotSplitTypeName[n];
                        if (n == dotSplitTypeName.Length - 1)
                        {
                            cNamespace.NestedClasses.Add(last = new CSMemberedType
                            {
                                Name       = item,
                                Attributes = attributes
                            });
                            break;
                        }
                        var firstOrDefault = cNamespace.NestedNamespaces.FirstOrDefault(v => v.name == item);
                        if (firstOrDefault != null)
                        {
                            cNamespace = firstOrDefault;
                        }
                        else
                        {
                            var oldN = cNamespace;
                            oldN.NestedNamespaces.Add(cNamespace = new CSNamespace
                            {
                                name = item
                            });
                        }
                    }
                }
                else
                {
                    newType = false;
                    int           pIndex     = line.IndexOf('(');
                    int           attIndex   = line.IndexOf('-');
                    Attributes    attributes = (Attributes)uint.Parse(line.Substring(attIndex + 1));
                    CSTypedMember member;
                    if (attributes.HasFlag(Attributes.Field) || attributes.HasFlag(Attributes.Property))
                    {
                        member = new CSField();
                    }
                    else if (attributes.HasFlag(Attributes.Method))
                    {
                        member = new CSMethod();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    member.Attributes = attributes;
                    string        name;
                    CSParameter[] parameters;
                    if (pIndex != -1)
                    {
                        name = line.Substring(0, pIndex);
                        var        cPindex   = line.IndexOf(')');
                        string     args      = line.Substring(pIndex + 1, cPindex - pIndex - 1);
                        string[][] argsSplit = Array.ConvertAll(args.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries), v => v.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                        ((CSMethod)member).Parameters = (parameters = Array.ConvertAll(argsSplit, v => new CSParameter
                        {
                            Name = v[1],
                            Type = v[0]
                        })).ToList();
                    }
                    else
                    {
                        name = line.Split(' ')[0];
                    }
                    member.Name = name;
                    int tIndex = line.IndexOf("=>");
                    if (tIndex != -1)
                    {
                        member.Type = line.Substring(tIndex + 3);
                    }
                    last.Members.Add(member);
                }
            }
            return(result);
        }
Example #3
0
        static void DiffNamespaces(CSNamespace bridgeNamespace, CSNamespace netNamespace)
        {
            writer.Write("<ul>");
            HashSet <string> combinedTypeStrings      = new HashSet <string>();
            HashSet <string> combinedNamespaceStrings = new HashSet <string>();

            (Dictionary <string, CSType> classes, Dictionary <string, CSNamespace> namespaces) CreateFrom(CSNamespace @namespace)
            {
                Dictionary <string, CSType>      classes    = new Dictionary <string, CSType>();
                Dictionary <string, CSNamespace> namespaces = new Dictionary <string, CSNamespace>();

                foreach (var @class in @namespace.NestedClasses)
                {
                    combinedTypeStrings.Add(@class.Name);
                    classes.Add(@class.Name, @class);
                }
                foreach (var nestedNamespace in @namespace.NestedNamespaces)
                {
                    namespaces.Add(nestedNamespace.name, nestedNamespace);
                    combinedNamespaceStrings.Add(nestedNamespace.name);
                }
                return(classes, namespaces);
            }

            (Dictionary <string, CSType> bridgeTypes, Dictionary <string, CSNamespace> bridgeNamespaces) = CreateFrom(bridgeNamespace);
            (Dictionary <string, CSType> netTypes, Dictionary <string, CSNamespace> netNamespaces)       = CreateFrom(netNamespace);
            foreach (var @string in combinedNamespaceStrings.OrderBy(v => v))
            {
                bool inBridge = bridgeNamespaces.ContainsKey(@string);
                bool inNet    = netNamespaces.ContainsKey(@string);
                writer.Write($"<li data-jstree='{"{"}\"icon\":\"dist/images/namespace.png\"{"}"}'><span style=\"color:");
                CompareSupport(inBridge, inNet);
                writer.Write($"\">{@string}</span>");
                if (inBridge && inNet)
                {
                    DiffNamespaces(bridgeNamespaces[@string], netNamespaces[@string]);
                }
                writer.Write("</li>");
                // TODO: Add to tree.
            }
            foreach (var @string in combinedTypeStrings.OrderBy(v => v))
            {
                bool inBridge = bridgeTypes.ContainsKey(@string);
                bool inNet    = netTypes.ContainsKey(@string);
                writer.Write("<li data-jstree='{\"icon\":\"dist/images/class.png\"}'><span style=\"color:");
                CompareSupport(inBridge, inNet);
                writer.Write("\">");
                writer.Write(@string);
                writer.Write("</span>");
                if (inBridge && inNet)
                {
                    var bridgeType = bridgeTypes[@string];
                    var netType    = netTypes[@string];
                    CompareAttributes(bridgeType.Attributes, netType.Attributes);
                    DiffTypes(bridgeType as CSMemberedType, netType as CSMemberedType);
                }
                writer.Write("</li>");
                // TODO: Add to tree.
            }
            writer.Write("</ul>");
        }