private List <MsgFile> InitalizeLpgFiles(bool addFullFiles)
        {
            var lpgDir = new DirectoryInfo(_settings.ServerSettings.LPGStorageDirectory);
            var files  = lpgDir.GetFiles("*.*");

            if (files.Length == 0)
            {
                throw new DistSimException("No files found");
            }

            var filteredFiles = new List <FileInfo>();

            foreach (var fi in files)
            {
                if (fi.Name.StartsWith("LPG") && fi.Name.EndsWith(".zip"))
                {
                    continue;
                }

                if (fi.Name.StartsWith("Setup") && fi.Name.EndsWith(".exe"))
                {
                    continue;
                }

                filteredFiles.Add(fi);
            }

            var lpgFiles = MsgFile.ReadMsgFiles(addFullFiles, filteredFiles, lpgDir, _logger, _threadId);

            return(lpgFiles);
        }
Beispiel #2
0
        public void ReplaceWithActualValues()
        {
            var sourceMessage   = Load("MBBSEMU.MSG");
            var outputRawStream = new MemoryStream();

            using var sourceStream = new StreamStream(sourceMessage);
            using var outputStream = new StreamStream(outputRawStream);

            MsgFile.UpdateValues(sourceStream, outputStream, new Dictionary <string, string>()
            {
                { "SOCCCR", "128" }, { "SLOWTICS", "Whatever" }, { "MAXITEM", "45" }
            });

            outputRawStream.Flush();
            outputRawStream.Seek(0, SeekOrigin.Begin);
            var result = Encoding.ASCII.GetString(outputRawStream.ToArray());

            // expected should have the mods applied
            var expected = Encoding.ASCII.GetString(Load("MBBSEMU.MSG").ToArray());

            expected = expected.Replace("SOCCCR {SoC credit consumption rate adjustment, per min: 0}", "SOCCCR {SoC credit consumption rate adjustment, per min: 128}");
            expected = expected.Replace("SLOWTICS {Slow system factor: 10000}", "SLOWTICS {Slow system factor: Whatever}");
            expected = expected.Replace("MAXITEM {Maximum number of items: 954}", "MAXITEM {Maximum number of items: 45}");

            result.Should().Be(expected);
        }
Beispiel #3
0
        public void ReplaceFileEmptyDictionary()
        {
            var fileName = Path.Combine(_modulePath, "MBBSEMU.MSG");

            Directory.CreateDirectory(_modulePath);
            File.WriteAllBytes(fileName, Load("MBBSEMU.MSG").ToArray());

            MsgFile.UpdateValues(fileName, new Dictionary <string, string>());

            File.ReadAllBytes(fileName).Should().BeEquivalentTo(Load("MBBSEMU.MSG").ToArray());
        }
Beispiel #4
0
 public static string Sum(MsgFile m)
 {
     if (!md5memo.ContainsKey(m.Name))
     {
         string hashText = PrepareToHash(m);
         if (hashText == null)
         {
             return(null);
         }
         md5memo[m.Name] = Sum(hashText);
     }
     return(md5memo[m.Name]);
 }
Beispiel #5
0
        internal static void Process(User user, MsgFile msgFile)
        {
            var currentFileName = "/tmp/" + msgFile.GetToken();

            var mode = FileMode.Append;

            if (msgFile.CreateFile)
            {
                mode = FileMode.Truncate;
            }

            var chunk = msgFile.GetChunk();
        }
Beispiel #6
0
        public void ReplaceWithEmptyDictionary()
        {
            var sourceMessage   = Load("MBBSEMU.MSG");
            var outputRawStream = new MemoryStream();

            using var sourceStream = new StreamStream(sourceMessage);
            using var outputStream = new StreamStream(outputRawStream);

            MsgFile.UpdateValues(sourceStream, outputStream, new Dictionary <string, string>());

            outputRawStream.Flush();
            outputRawStream.Seek(0, SeekOrigin.Begin);
            var result = outputRawStream.ToArray();

            sourceMessage.Seek(0, SeekOrigin.Begin);
            var expected = sourceMessage.ToArray();

            result.Should().BeEquivalentTo(expected);
        }
Beispiel #7
0
        public void SendFile(string path)
        {
            using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                var fileName = Path.GetFileName(path);
                var fileSize = fileStream.Length;

                while (fileStream.Position != fileStream.Length)
                {
                    var firstRead = fileStream.Position == 0;
                    var chunk     = ArrayPool <byte> .Shared.Rent(MsgFile.MAX_CHUNK_SIZE);

                    var readBytes = fileStream.Read(chunk, 0, chunk.Length);
                    var msgFile   = MsgFile.Create(fileName, fileSize, readBytes, chunk, firstRead);
                    Send(msgFile);
                    ArrayPool <byte> .Shared.Return(chunk);
                }
            }
        }
Beispiel #8
0
        public async ValueTask SendFile(string path, int tokenId)
        {
            var token = Tokens[tokenId];

            using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                var fileSize = fileStream.Length;
                var chunk    = new byte[MsgFile.MAX_CHUNK_SIZE];

                while (fileStream.Position != fileStream.Length)
                {
                    var firstRead = fileStream.Position == 0;
                    var readBytes = await fileStream.ReadAsync(chunk, 0, MsgFile.MAX_CHUNK_SIZE);

                    var msgFile = MsgFile.Create(token, fileSize, readBytes, chunk, firstRead);
                    Send(msgFile);
                }
            }

            Tokens.TryRemove(tokenId, out _);
        }
Beispiel #9
0
        public void ReplaceFileWithActualValues()
        {
            var fileName = Path.Combine(_modulePath, "MBBSEMU.MSG");

            Directory.CreateDirectory(_modulePath);
            File.WriteAllBytes(fileName, Load("MBBSEMU.MSG").ToArray());

            MsgFile.UpdateValues(fileName, new Dictionary <string, string>()
            {
                { "SOCCCR", "128" }, { "SLOWTICS", "Whatever" }, { "MAXITEM", "45" }
            });

            // expected should have the mods applied
            var expected = Encoding.ASCII.GetString(Load("MBBSEMU.MSG").ToArray());

            expected = expected.Replace("SOCCCR {SoC credit consumption rate adjustment, per min: 0}", "SOCCCR {SoC credit consumption rate adjustment, per min: 128}");
            expected = expected.Replace("SLOWTICS {Slow system factor: 10000}", "SLOWTICS {Slow system factor: Whatever}");
            expected = expected.Replace("MAXITEM {Maximum number of items: 954}", "MAXITEM {Maximum number of items: 45}");

            File.ReadAllBytes(fileName).Should().BeEquivalentTo(Encoding.ASCII.GetBytes(expected));
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public StaticResolverFixture()
        {
            // Add stubs of standard messages to resolver
            var msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\std_msgs\msg\Header.msg", "."),
                                       new List <string> {
                "uint32 seq", "time stamp", "string frame_id"
            }, "");

            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\std_msgs\msg\String.msg", "."),
                                   new List <string> {
                "string data"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\std_msgs\msg\Duration.msg", "."),
                                   new List <string> {
                "duration data"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\trajectory_msgs\msg\JointTrajectoryPoint.msg", "."),
                                   new List <string> {
                "float64[] positions", "float64[] velocities", "float64[] accelerations", "float64[] effort",
                "duration time_from_start"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\trajectory_msgs\msg\JointTrajectory.msg", "."),
                                   new List <string> {
                "std_msgs/Header header", "string[] joint_names", "JointTrajectoryPoint[] points"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\control_msgs\msg\JointTolerance.msg", "."),
                                   new List <string> {
                "string name", "float64 position", "float64 velocity", "float64 acceleration"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\actionlib_msgs\GoalID.msg", "."),
                                   new List <string> {
                "time stamp", "string id"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\actionlib_msgs\GoalStatus.msg", "."),
                                   new List <string> {
                "uint8 PENDING         = 0", "uint8 ACTIVE          = 1",
                "uint8 PREEMPTED       = 2", "uint8 SUCCEEDED       = 3", "uint8 ABORTED         = 4 ",
                "uint8 REJECTED        = 5", "uint8 PREEMPTING      = 6 ", "uint8 RECALLING       = 7 ",
                "uint8 RECALLED        = 8", "uint8 LOST            = 9", "GoalID goal_id", "uint8 status", "string text"
            }, "");
            msgsStub.ParseAndResolveTypes();

            msgsStub = new MsgFile(new MsgFileLocation(@"common_msgs\actionlib_msgs\GoalStatusArray.msg", "."),
                                   new List <string> {
                "Header header", "GoalStatus[] status_list"
            }, "");
            msgsStub.ParseAndResolveTypes();
        }
Beispiel #12
0
 public MSGTest()
 {
     _msgFile = new MsgFile();
     _msgFile.Load(@"TestFiles\TestMessage-ansi.msg");
 }
Beispiel #13
0
 public MSGTest()
 {
     _msgFile = new MsgFile();
     _msgFile.Load(@"TestFiles\TestMessage-ansi.msg");
 }