Esempio n. 1
0
    static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.WriteLine("usage validation_addendum.exe mw-id=<middleware ID>");
            return(-1);
        }

        Config config = new Config(args);

        InitializeLogging(config);

        //o Enable Message validation.  This parameter is "false" by default.
        config.AddValue("GMSEC-MSG-CONTENT-VALIDATE", "true");

        //o Tell the API that there is an additional layer of message schema to
        // validate (The 'EXAMPLE' message definitions).  This value is set to
        // 0 (Only 'GMSEC' specification validation) by default.
        //
        // Note: These levels for validation are determined by the "LEVEL-X"
        // attributes defined in the .DIRECTORY.xml file contained in the XML
        // templates directory.  In thise case, Level-0 means GMSEC and Level-1
        // means EXAMPLE.
        //
        // Note: The GMSEC team envisions using message specifications in a
        // layered hierarchical fashion.  For example, the "GMSEC" message
        // specification would be 'layer 0', followed by an organization-level
        // message specification at 'layer 1' which builds upon the message
        // specification outlined in the GMSEC ISD.  This would be followed by
        // a mission-level message specification at 'layer 2' and so on.
        config.AddValue("GMSEC-SCHEMA-LEVEL", "1");

        //o Tell the API where to find all of the schema files.
        //
        // Note: This example only demonstrates a simple usage case of this
        // functionality.  When using this functionality, if the intent is
        // to use any of the GMSEC message definitions, then ALL of the XML
        // template files must be contained in the same directory.
        // e.g. GMSEC_API/templates/2016.00 (Or the location defined in
        // GMSEC-SCHEMA-PATH)
        config.AddValue("GMSEC-SCHEMA-PATH", "templates");

        //o Since this example relies on the 2016.00 version of the templates,
        //  we indicate such within the configuration object.
        config.AddValue("GMSEC-SPECIFICATION-VERSION", "201600");

        Log.Info("API version: " + ConnectionManager.GetAPIVersion());

        try
        {
            ConnectionManager connMgr = new ConnectionManager(config);

            Log.Info("Opening the connection to the middleware server");
            connMgr.Initialize();

            Log.Info("Middleware version: " + connMgr.GetLibraryVersion());

            FieldList definedFields = new FieldList();

            StringField missionField   = new StringField("MISSION-ID", "MY-MISSION");
            StringField satIdField     = new StringField("SAT-ID-PHYSICAL", "MY-SPACECRAFT");
            StringField facilityField  = new StringField("FACILITY", "MY-FACILITY");
            StringField componentField = new StringField("COMPONENT", "MY-COMPONENT-NAME");

            definedFields.Add(missionField);
            definedFields.Add(satIdField);
            definedFields.Add(facilityField);
            definedFields.Add(componentField);

            connMgr.SetStandardFields(definedFields);

            //o Create a Message using a subject defined in the XML template
            // outlining our example addendum message definitions
            using (MistMessage message = new MistMessage(EXAMPLE_MESSAGE_SUBJECT, "MSG.LOG", connMgr.GetSpecification()))
            {
                //o Add remaining required Fields to our message
                message.AddField(new U16Field("NUM-OF-EVENTS", (UInt16)2));
                message.SetValue("EVENT.1", AddTimeToString("AOS occurred at: "));
                message.SetValue("EVENT.2", AddTimeToString("Telemetry downlink began at: "));

                connMgr.AddStandardFields(message);

                //o Publish the message to the middleware bus
                connMgr.Publish(message);

                //o Display the XML string representation of the Message for
                // the sake of review
                Log.Info("Published message:\n" + message.ToXML());
            }

            //o Setup a new message without some of the Required Fields and
            // attempt to publish it (i.e. Trigger a validation failure)
            using (MistMessage badMessage = new MistMessage(EXAMPLE_MESSAGE_SUBJECT, "MSG.LOG", connMgr.GetSpecification()))
            {
                try
                {
                    connMgr.Publish(badMessage);
                }
                catch (GmsecException e)
                {
                    Log.Error("This error is expected:\n" + e.ToString());
                }
            }

            //o Disconnect from the middleware and clean up the Connection
            connMgr.Cleanup();
        }
        catch (GmsecException e)
        {
            Log.Error(e.ToString());
            return(-1);
        }

        return(0);
    }
Esempio n. 2
0
    static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.WriteLine("usage log_message.exe mw-id=<middleware ID>");
            return(-1);
        }

        Config config = new Config(args);

        InitializeLogging(config);

        //o Set the GMSEC message specification version to be used to determine
        // what the structure of messages is for verification and the
        // construction of MistMessages
        config.AddValue("GMSEC-SPECIFICATION-VERSION", GMSEC_SPEC_VERSION);

        Log.Info(ConnectionManager.GetAPIVersion());

        try
        {
            ConnectionManager connManager = new ConnectionManager(config);

            Log.Info("Opening the connection to the middleware server");
            connManager.Initialize();

            Log.Info(connManager.GetLibraryVersion());


            //o Begin the steps necessary to create a GMSEC-compliant LOG
            // message using the ConnectionManager

            //o Create all of the GMSEC Message header Fields which will
            // be used by all GMSEC Messages
            //
            // Note: Since these Fields contain variable values which are
            // based on the context in which they are used, they cannot be
            // automatically populated using MistMessage.
            List <Field> definedFields = new List <Field>();

            StringField missionField = new StringField("MISSION-ID", "MISSION");
            // Note: SAT-ID-PHYSICAL is an optional header Field, according
            // to the GMSEC ISD.
            StringField satIdField     = new StringField("SAT-ID-PHYSICAL", "SPACECRAFT");
            StringField facilityField  = new StringField("FACILITY", "GMSEC Lab");
            StringField componentField = new StringField("COMPONENT", "device_message");

            definedFields.Add(missionField);
            definedFields.Add(satIdField);
            definedFields.Add(facilityField);
            definedFields.Add(componentField);

            //o Use setStandardFields to define a set of header fields for
            // all messages which are created or published on the
            // ConnectionManager using the following functions:
            // createLogMessage, publishLog, createHeartbeatMessage,
            // startHeartbeatService, createResourceMessage,
            // publishResourceMessage, or startResourceMessageService
            connManager.SetStandardFields(definedFields);

            //o Determine which version of the GMSEC message specification
            // the ConnectionManager was initialized with
            uint   version          = connManager.GetSpecification().GetVersion();
            String gmsecSpecVersion = "";
            if (version == 201600)
            {
                gmsecSpecVersion = "2016.00";
            }
            else if (version == 201400)
            {
                gmsecSpecVersion = "2014.00";
            }

            String msgId = gmsecSpecVersion + ".GMSEC.MSG.LOG";

            //o Use MistMessage to construct a GMSEC LOG message based off
            // of the latest XML templates provided with the GMSEC API.
            // This will automatically populate the Message with all of the
            // Fields which have specific values defined for them in the XML
            // template files.  For more information on which Fields have
            // values defined for them, please review the XML template files
            // located in GMSEC_API/templates.
            //
            // Note: The second parameter is an identifier for the type of
            // GMSEC-compliant message to construct.  This parameter varies
            // depending on the version of the GMSEC ISD that the messages
            // are based off of.  This example shows how to handle a varying
            // case.
            using (MistMessage logMsg = new MistMessage(LOG_MESSAGE_SUBJECT, msgId, connManager.GetSpecification()))
            {
                //o Add the LOG-specific fields to the LOG message
                //
                // Note: Since these Fields contain variable values which are
                // based on the context in which they are used, they cannot be
                // automatically populated using MistMessage.
                String eventTime = TimeUtil.FormatTime(TimeUtil.GetCurrentTime());

                logMsg.AddField(new I16Field("SEVERITY", (short)1));
                logMsg.SetValue("MSG-TEXT", "Creating an example GMSEC LOG Message");
                logMsg.SetValue("OCCURRENCE-TYPE", "SYS");
                logMsg.SetValue("SUBCLASS", "AST");
                logMsg.SetValue("EVENT-TIME", eventTime);

                //o Add the standard fields to the LOG message
                connManager.AddStandardFields(logMsg);

                connManager.Publish(logMsg);

                Log.Info("Published LOG message:\n" + logMsg.ToXML());
            }

            connManager.Cleanup();
        }
        catch (GMSEC_Exception e)
        {
            Log.Error(e.ToString());
            return(-1);
        }

        return(0);
    }
Esempio n. 3
0
 /// <summary>Copy constructor - initializes the message instance using the other given MistMessage</summary>
 ///
 /// <param name="other">The message to be copied.</param>
 ///
 /// <exception cref="GmsecException">Thrown if the given MistMessage is null.</exception>
 public MistMessage(MistMessage other)
 {
 }