コード例 #1
0
        public JObject CreateEDDNMessage(JournalScan journal, ISystem system)
        {
            if (system.SystemAddress == null)
            {
                return(null);
            }

            // Reject scan if system doesn't match scan system
            if (journal.SystemAddress != null && journal.StarSystem != null && (journal.SystemAddress != system.SystemAddress || journal.StarSystem != system.Name))
            {
                return(null);
            }

            JObject msg = new JObject();

            msg["header"]     = Header();
            msg["$schemaRef"] = GetEDDNJournalSchemaRef();

            JObject message = journal.GetJsonCloned();

            if (message == null)
            {
                return(null);
            }

            message["StarSystem"] = system.Name;
            message["StarPos"]    = new JArray(new float[] { (float)system.X, (float)system.Y, (float)system.Z });

            message["SystemAddress"] = system.SystemAddress;

            if (message["Materials"] != null && message["Materials"] is JArray)
            {
                foreach (JObject mmat in message["Materials"])
                {
                    mmat.Remove("Name_Localised");
                }
            }

            string bodydesig = journal.BodyDesignation ?? journal.BodyName;

            message = RemoveCommonKeys(message);

            message = FilterJournalEvent(message, AllowedFieldsScan);

            if (!bodydesig.StartsWith(system.Name, StringComparison.InvariantCultureIgnoreCase))  // For now test if its a different name ( a few exception for like sol system with named planets)  To catch a rare out of sync bug in historylist.
            {
                if (journal.BodyDesignation != null || System.Text.RegularExpressions.Regex.IsMatch(journal.BodyName, " [A-Z][A-Z]-[A-Z] [a-h][0-9]", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                {
                    return(null);
                }

                message["IsUnknownBody"] = true;
                msg["$schemaRef"]        = GetEDDNJournalSchemaRef(true);
            }

            msg["message"] = message;
            return(msg);
        }