Exemplo n.º 1
0
    static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.WriteLine("usage validation_custom.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");

        // TODO: Once available, replace this statement with usage of
        // ConnectionManager::getAPIVersion (See RTC 4798)
        Log.Info(Connection.GetAPIVersion());

        try
        {
            ConnectionManager connMgr = new ConnectionManager(config);

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

            Log.Info(connMgr.GetLibraryVersion());

            //o Set up the ValidationCallback and subscribe
            ValidationCallback vc = new ValidationCallback();
            connMgr.Subscribe(PROD_MESSAGE_SUBJECT, vc);

            //o Start the AutoDispatcher
            connMgr.StartAutoDispatch();

            //o Create and publish a simple Product File Message
            SetupStandardFields(connMgr);

            GMSEC.API.MIST.MESSAGE.ProductFileMessage productMessage = CreateProductFileMessage(connMgr, "//hostname/dir/filename");

            connMgr.Publish(productMessage);

            productMessage = CreateProductFileMessage(connMgr, "//badhost/dir/filename");

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

            connMgr.StopAutoDispatch();

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

        return(0);
    }
Exemplo n.º 2
0
    static GMSEC.API.MIST.MESSAGE.ProductFileMessage CreateProductFileMessage(ConnectionManager connMgr, String filePath)
    {
        ProductFile externalFile = new ProductFile("External File", "External File Description", "1.0.0", "TXT", filePath);

        GMSEC.API.MIST.MESSAGE.ProductFileMessage productMessage = new GMSEC.API.MIST.MESSAGE.ProductFileMessage(PROD_MESSAGE_SUBJECT, ResponseStatus.SUCCESSFUL_COMPLETION, Message.MessageKind.PUBLISH, "AUTO", "DM", connMgr.GetSpecification());
        productMessage.AddProductFile(externalFile);

        connMgr.AddStandardFields(productMessage);

        return(productMessage);
    }
Exemplo n.º 3
0
    public override void OnMessage(ConnectionManager connMgr, Message message)
    {
        try
        {
            //o Run the message through the GMSEC API-supplied validation
            connMgr.GetSpecification().ValidateMessage(message);

            //o In this example scenario, we are expecting to receive a
            // GMSEC PROD message containing a URI to a location on the disk
            // where a product file has been placed for retrieval.  In this
            // case, we want to validate that the location on the disk is
            // in an area which we would expect (i.e. Something that the
            // team has agreed upon prior to operational deployment).
            //
            // By validating this URI, we ensure that no malicious users
            // have infiltrated the system and somehow modified the messages
            // to cause us to retrieve a file from an unknown location.

            //o Start by checking to ensure that this is a PROD message
            if (IsProdMsg(message))
            {
                GMSEC.API.MIST.MESSAGE.ProductFileMessage prodMessage = new GMSEC.API.MIST.MESSAGE.ProductFileMessage(message.ToXML());

                //o Extract the Product File URI location(s) from the
                // message using a ProductFileIterator
                ProductFileIterator prodIter = prodMessage.GetProductFileIterator();

                while (prodIter.HasNext())
                {
                    ProductFile prodFile = prodIter.Next();

                    //o Check to ensure that the URI contains "//hostname/dir"
                    String prodUri = prodFile.GetURI();
                    if (prodUri.IndexOf("//hostname/dir") == -1)
                    {
                        String errorMsg = "Received an invalid PROD Message (bad URI):\n" + message.ToXML();
                        throw new GMSEC_Exception(StatusClass.MIST_ERROR, StatusCode.MESSAGE_FAILED_VALIDATION, errorMsg);
                    }
                }

                Log.Info("Received a valid message:\n" + message.ToXML());
            }
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
    }
Exemplo n.º 4
0
    static GMSEC.API.MIST.MESSAGE.ProductFileMessage CreateProductFileMessage(ConnectionManager connMgr, String filePath)
    {
        ProductFile externalFile = new ProductFile("External File", "External File Description", "1.0.0", "TXT", filePath);

        GMSEC.API.MIST.MESSAGE.ProductFileMessage productMessage;

        if (connMgr.GetSpecification().GetVersion() <= GMSEC_ISD.GMSEC_ISD_2016_00)
        {
            productMessage = new GMSEC.API.MIST.MESSAGE.ProductFileMessage(PROD_MESSAGE_SUBJECT, ResponseStatus.SUCCESSFUL_COMPLETION, "MSG.PROD.AUTO", connMgr.GetSpecification());
        }
        else
        {
            productMessage = new GMSEC.API.MIST.MESSAGE.ProductFileMessage(PROD_MESSAGE_SUBJECT, ResponseStatus.SUCCESSFUL_COMPLETION, "MSG.PROD", connMgr.GetSpecification());

            productMessage.AddField(new StringField("PROD-TYPE", "AUTO"));
            productMessage.AddField(new StringField("PROD-SUBTYPE", "DM"));
        }

        productMessage.AddProductFile(externalFile);

        connMgr.AddStandardFields(productMessage);

        return(productMessage);
    }
Exemplo n.º 5
0
    static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.WriteLine("usage product_message.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");

        // TODO: Once available, replace this statement with usage of
        // ConnectionManager::getAPIVersion (See RTC 4798)
        Log.Info(Connection.GetAPIVersion());

        try
        {
            ConnectionManager connManager = new ConnectionManager(config);

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

            Log.Info(connManager.GetLibraryVersion());

            //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 Create a ProductFile object with the product name,
            // description, version, file format, and the URI
            ProductFile externalFile = new ProductFile("External File", "External File Description", "1.0.0", "TXT", "//hostname/dir/filename");

            int    fSize       = 8;
            byte[] filePayload = new byte[8];
            for (byte idx = 0; idx < fSize; idx++)
            {
                filePayload[idx] = idx;
            }

            //o Create a ProductFile object with the product name,
            // description, version, format, binary array, and file size
            ProductFile binaryFile = new ProductFile("File as Binary", "Binary File Description", "1.0.0", "BIN", filePayload);

            //o Create a Product File Message with the subject,
            // RESPONSE-STATUS Field value, Message type (publish, request,
            // or reply), PROD-TYPE Field value, PROD-SUBTYPE Field value,
            // and pass it the Specification object from the Connection
            // Manager
            using (GMSEC.API.MIST.MESSAGE.ProductFileMessage productMessage = new GMSEC.API.MIST.MESSAGE.ProductFileMessage(PROD_MESSAGE_SUBJECT, ResponseStatus.SUCCESSFUL_COMPLETION, Message.MessageKind.PUBLISH, "AUTO", "DM", connManager.GetSpecification()))
            {
                productMessage.AddProductFile(externalFile);
                productMessage.AddProductFile(binaryFile);

                connManager.AddStandardFields(productMessage);

                connManager.Publish(productMessage);

                Log.Info("Published DEV message:\n" + productMessage.ToXML());
            }

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

        return(0);
    }