Sum() public static method

public static Sum ( ) : string
return string
Ejemplo n.º 1
0
        private static string PrepareToHash(MsgFile msgFile)
        {
            string hashText = msgFile.Definition.Trim('\n', '\t', '\r', ' ');

            while (hashText.Contains("  "))
            {
                hashText = hashText.Replace("  ", " ");
            }
            while (hashText.Contains("\r\n"))
            {
                hashText = hashText.Replace("\r\n", "\n");
            }
            hashText = hashText.Trim();
            string[] lines = hashText.Split('\n');

            var haves    = new Queue <string>();
            var havenots = new Queue <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string l = lines[i];
                if (l.Contains("="))
                {
                    // condense spaces on either side of =
                    string[] ls = l.Split('=');
                    haves.Enqueue(ls[0].Trim() + "=" + ls[1].Trim());
                }
                else
                {
                    havenots.Enqueue(l.Trim());
                }
            }

            hashText = "";
            while (haves.Count + havenots.Count > 0)
            {
                hashText += (haves.Count > 0 ? haves.Dequeue() : havenots.Dequeue()) + (haves.Count + havenots.Count >= 1 ? "\n" : "");
            }

            Dictionary <string, MsgFieldInfo> mfis = MessageFieldHelper.Instantiate(msgFile.Stuff);

            MsgFieldInfo[] fields = mfis.Values.ToArray();
            for (int i = 0; i < fields.Length; i++)
            {
                var field = fields[i];
                if (field.IsPrimitive)
                {
                    continue;
                }

                MsgFile ms = msgFile.Stuff[i].Definer;
                if (ms == null)
                {
                    KnownStuff.WhatItIs(msgFile, msgFile.Stuff[i]);
                    if (msgFile.Stuff[i].Type.Contains("/"))
                    {
                        msgFile.resolve(msgFile.Stuff[i]);
                    }
                    ms = msgFile.Stuff[i].Definer;
                }
                string sum = null;
                if (ms == null)
                {
                    RosMessage rosMessage = null;
                    var        packages   = MessageTypeRegistry.Default.PackageNames;
                    foreach (var package in packages)
                    {
                        try
                        {
                            var name = msgFile.Stuff[i].Type;
                            Console.WriteLine($"generate {package}/{name}");
                            rosMessage = RosMessage.Generate($"{package}/{name}");
                            sum        = rosMessage.MD5Sum();
                            break;
                        }
                        catch
                        {
                        }
                    }
                    if (rosMessage == null)
                    {
                        Logger.LogDebug("NEEDS ANOTHER PASS: "******" B/C OF " + msgFile.Stuff[i].Type);
                        return(null);
                    }
                }
                else
                {
                    sum = MD5.Sum(ms);
                }
                if (sum == null)
                {
                    Logger.LogDebug("STILL NEEDS ANOTHER PASS: "******" B/C OF " + msgFile.Stuff[i].Type);
                    return(null);
                }

                hashText = Regex.Replace(hashText, @"^(.*/)?\b" + fields[i].Type + @"\b(\s*\[\s*\])?", sum, RegexOptions.Multiline);
            }
            return(hashText);
        }
Ejemplo n.º 2
0
        public static void GenerateFiles(List <MsgsFile> files, List <SrvsFile> srvfiles)
        {
            List <MsgsFile> mresolved = new List <MsgsFile>();
            List <SrvsFile> sresolved = new List <SrvsFile>();

            while (files.Except(mresolved).Any())
            {
                Debug.WriteLine("MSG: Running for " + files.Count + "/" + mresolved.Count + "\n" + files.Except(mresolved).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (MsgsFile m in files.Except(mresolved))
                {
                    string md5      = null;
                    string typename = null;;
                    md5      = MD5.Sum(m);
                    typename = m.Name;
                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        mresolved.Add(m);
                    }
                    else
                    {
                        Debug.WriteLine("Waiting for children of " + typename + " to have sums");
                    }
                }
                if (files.Except(mresolved).Any())
                {
                    Debug.WriteLine("MSG: Rerunning sums for remaining " + files.Except(mresolved).Count() + " definitions");
                }
            }
            while (srvfiles.Except(sresolved).Any())
            {
                Debug.WriteLine("SRV: Running for " + srvfiles.Count + "/" + sresolved.Count + "\n" + srvfiles.Except(sresolved).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (SrvsFile s in srvfiles.Except(sresolved))
                {
                    string md5      = null;
                    string typename = null;
                    s.Request.Stuff.ForEach(a => s.Request.resolve(s.Request, a));
                    s.Response.Stuff.ForEach(a => s.Request.resolve(s.Response, a));
                    md5      = MD5.Sum(s);
                    typename = s.Name;
                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        sresolved.Add(s);
                    }
                    else
                    {
                        Debug.WriteLine("Waiting for children of " + typename + " to have sums");
                    }
                }
                if (srvfiles.Except(sresolved).Any())
                {
                    Debug.WriteLine("SRV: Rerunning sums for remaining " + srvfiles.Except(sresolved).Count() + " definitions");
                }
            }
            foreach (MsgsFile file in files)
            {
                file.Write(outputdir);
            }
            foreach (SrvsFile file in srvfiles)
            {
                file.Write(outputdir);
            }
            File.WriteAllText(outputdir + "\\MessageTypes.cs", ToString().Replace("FauxMessages", "Messages"));
        }
Ejemplo n.º 3
0
        private static void GenerateFiles(List <MsgFile> files, List <SrvFile> srvfiles, List <ActionFile> actionFiles, string outputdir)
        {
            var resolvedMessages = new List <MsgFile>();
            var resolvedServices = new List <SrvFile>();
            var resolvedActions  = new List <ActionFile>();

            while (files.Except(resolvedMessages).Any())
            {
                Debug.WriteLine("MSG: Running for " + files.Count + "/" + resolvedMessages.Count + "\n" + files.Except(resolvedMessages).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (var m in files.Except(resolvedMessages))
                {
                    var md5      = MD5.Sum(m);
                    var typename = m.Name;

                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        resolvedMessages.Add(m);
                    }
                    else
                    {
                        Debug.WriteLine("Waiting for children of " + typename + " to have sums");
                    }
                }

                if (files.Except(resolvedMessages).Any())
                {
                    Debug.WriteLine("MSG: Rerunning sums for remaining " + files.Except(resolvedMessages).Count() + " definitions");
                }
            }

            while (srvfiles.Except(resolvedServices).Any())
            {
                Debug.WriteLine("SRV: Running for " + srvfiles.Count + "/" + resolvedServices.Count + "\n" + srvfiles.Except(resolvedServices).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (var s in srvfiles.Except(resolvedServices))
                {
                    s.Request.Stuff.ForEach(a => s.Request.resolve(a));
                    s.Response.Stuff.ForEach(a => s.Request.resolve(a));

                    var md5      = MD5.Sum(s);
                    var typename = s.Name;

                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        resolvedServices.Add(s);
                    }
                    else
                    {
                        Debug.WriteLine("Waiting for children of " + typename + " to have sums");
                    }
                }

                if (srvfiles.Except(resolvedServices).Any())
                {
                    Debug.WriteLine("SRV: Rerunning sums for remaining " + srvfiles.Except(resolvedServices).Count() + " definitions");
                }
            }

            while (actionFiles.Except(resolvedActions).Any())
            {
                Debug.WriteLine("SRV: Running for " + actionFiles.Count + "/" + resolvedActions.Count + "\n" + actionFiles.Except(resolvedActions).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (var actionFile in actionFiles.Except(resolvedActions))
                {
                    actionFile.GoalMessage.Stuff.ForEach(a => actionFile.GoalMessage.resolve(a));
                    actionFile.ResultMessage.Stuff.ForEach(a => actionFile.ResultMessage.resolve(a));
                    actionFile.FeedbackMessage.Stuff.ForEach(a => actionFile.FeedbackMessage.resolve(a));

                    var md5      = MD5.Sum(actionFile);
                    var typename = actionFile.Name;

                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        resolvedActions.Add(actionFile);
                    }
                    else
                    {
                        Logger.LogDebug("Waiting for children of " + typename + " to have sums");
                    }
                }

                if (actionFiles.Except(resolvedActions).Any())
                {
                    Logger.LogDebug("ACTION: Rerunning sums for remaining " + actionFiles.Except(resolvedActions).Count() + " definitions");
                }
            }

            foreach (var file in files)
            {
                file.Write(outputdir);
            }

            foreach (var file in srvfiles)
            {
                file.Write(outputdir);
            }

            foreach (var actionFile in actionFiles)
            {
                actionFile.Write(outputdir);
            }
        }
Ejemplo n.º 4
0
        private static void GenerateFiles(List <MsgFile> files, List <SrvFile> srvfiles, List <ActionFile> actionFiles, string outputdir)
        {
            List <MsgFile>    mresolved           = new List <MsgFile>();
            List <SrvFile>    sresolved           = new List <SrvFile>();
            List <ActionFile> actionFilesResolved = new List <ActionFile>();

            while (files.Except(mresolved).Any())
            {
                Debug.WriteLine("MSG: Running for " + files.Count + "/" + mresolved.Count + "\n" + files.Except(mresolved).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (MsgFile m in files.Except(mresolved))
                {
                    string md5      = null;
                    string typename = null;
                    md5      = MD5.Sum(m);
                    typename = m.Name;
                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        mresolved.Add(m);
                    }
                    else
                    {
                        Debug.WriteLine("Waiting for children of " + typename + " to have sums");
                    }
                }
                if (files.Except(mresolved).Any())
                {
                    Debug.WriteLine("MSG: Rerunning sums for remaining " + files.Except(mresolved).Count() + " definitions");
                }
            }
            while (srvfiles.Except(sresolved).Any())
            {
                Debug.WriteLine("SRV: Running for " + srvfiles.Count + "/" + sresolved.Count + "\n" + srvfiles.Except(sresolved).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (SrvFile s in srvfiles.Except(sresolved))
                {
                    string md5      = null;
                    string typename = null;
                    s.Request.Stuff.ForEach(a => s.Request.resolve(a));
                    s.Response.Stuff.ForEach(a => s.Request.resolve(a));
                    md5      = MD5.Sum(s);
                    typename = s.Name;
                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        sresolved.Add(s);
                    }
                    else
                    {
                        Debug.WriteLine("Waiting for children of " + typename + " to have sums");
                    }
                }
                if (srvfiles.Except(sresolved).Any())
                {
                    Debug.WriteLine("SRV: Rerunning sums for remaining " + srvfiles.Except(sresolved).Count() + " definitions");
                }
            }
            while (actionFiles.Except(actionFilesResolved).Any())
            {
                Debug.WriteLine("SRV: Running for " + actionFiles.Count + "/" + actionFilesResolved.Count + "\n" + actionFiles.Except(actionFilesResolved).Aggregate("\t", (o, n) => "" + o + "\n\t" + n.Name));
                foreach (ActionFile actionFile in actionFiles.Except(actionFilesResolved))
                {
                    string md5      = null;
                    string typename = null;
                    actionFile.GoalMessage.Stuff.ForEach(a => actionFile.GoalMessage.resolve(a));
                    actionFile.ResultMessage.Stuff.ForEach(a => actionFile.ResultMessage.resolve(a));
                    actionFile.FeedbackMessage.Stuff.ForEach(a => actionFile.FeedbackMessage.resolve(a));
                    md5      = MD5.Sum(actionFile);
                    typename = actionFile.Name;
                    if (md5 != null && !md5.StartsWith("$") && !md5.EndsWith("MYMD5SUM"))
                    {
                        actionFilesResolved.Add(actionFile);
                    }
                    else
                    {
                        Logger.LogDebug("Waiting for children of " + typename + " to have sums");
                    }
                }
                if (actionFiles.Except(actionFilesResolved).Any())
                {
                    Logger.LogDebug("ACTION: Rerunning sums for remaining " + actionFiles.Except(actionFilesResolved).Count() + " definitions");
                }
            }
            foreach (MsgFile file in files)
            {
                file.Write(outputdir);
            }
            foreach (SrvFile file in srvfiles)
            {
                file.Write(outputdir);
            }
            foreach (ActionFile actionFile in actionFiles)
            {
                actionFile.Write(outputdir);
            }
            File.WriteAllText(Path.Combine(outputdir, "MessageTypes.cs"), ToString().Replace("FauxMessages", "Messages"));
        }
Ejemplo n.º 5
0
        private static string PrepareToHash(MsgsFile irm)
        {
            string hashme = irm.Definition.Trim('\n', '\t', '\r', ' ');

            while (hashme.Contains("  "))
            {
                hashme = hashme.Replace("  ", " ");
            }
            while (hashme.Contains("\r\n"))
            {
                hashme = hashme.Replace("\r\n", "\n");
            }
            hashme = hashme.Trim();
            string[] lines = hashme.Split('\n');

            Queue <string> haves = new Queue <string>(), havenots = new Queue <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string l = lines[i];
                if (l.Contains("="))
                {
                    //condense spaces on either side of =
                    string[] ls = l.Split('=');
                    haves.Enqueue(ls[0].Trim() + "=" + ls[1].Trim());
                }
                else
                {
                    havenots.Enqueue(l.Trim());
                }
            }
            hashme = "";
            while (haves.Count + havenots.Count > 0)
            {
                hashme += (haves.Count > 0 ? haves.Dequeue() : havenots.Dequeue()) + (haves.Count + havenots.Count >= 1 ? "\n" : "");
            }
            Dictionary <string, MsgFieldInfo> mfis = MessageFieldHelper.Instantiate(irm.Stuff);

            MsgFieldInfo[] fields = mfis.Values.ToArray();
            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i].IsLiteral)
                {
                    continue;
                }
                MsgsFile ms = irm.Stuff[i].Definer;
                if (ms == null)
                {
                    KnownStuff.WhatItIs(irm, irm.Stuff[i]);
                    if (irm.Stuff[i].Type.Contains("/"))
                    {
                        irm.resolve(irm, irm.Stuff[i]);
                    }
                    ms = irm.Stuff[i].Definer;
                }
                if (ms == null)
                {
                    Debug.WriteLine("NEEDS ANOTHER PASS: "******" B/C OF " + irm.Stuff[i].Type);
                    return(null);
                }
                string sum = MD5.Sum(ms);
                if (sum == null)
                {
                    Debug.WriteLine("STILL NEEDS ANOTHER PASS: "******" B/C OF " + irm.Stuff[i].Type);
                    return(null);
                }
                Regex    findCurrentFieldType = new Regex("\\b" + fields[i].Type + "\\b");
                string[] BLADAMN = findCurrentFieldType.Replace(hashme, sum).Split('\n');
                hashme = "";
                for (int x = 0; x < BLADAMN.Length; x++)
                {
                    if (BLADAMN[x].Contains(fields[i].Name.Replace("@", "")))
                    {
                        if (BLADAMN[x].Contains("/"))
                        {
                            BLADAMN[x] = BLADAMN[x].Split('/')[1];
                        }

                        if (BLADAMN[x].Contains("[]") && !fields[i].IsLiteral)
                        {
                            BLADAMN[x] = BLADAMN[x].Replace("[]", "");
                        }
                    }
                    hashme += BLADAMN[x];
                    if (x < BLADAMN.Length - 1)
                    {
                        hashme += "\n";
                    }
                }
            }
            return(hashme);
        }