Example #1
0
        static void Main(string[] args)
        {
            // This example uses the Everest File Connector to listen to a directory and validate messages that appear there
            // It can be used as a standalone application as a way of validating instance messages from other sources

            // copied the below code from the example in the dev guide page 50
            Assembly.Load(new AssemblyName("MARC.Everest.RMIM.CA.R020401"));

            XmlIts1Formatter its1Formatter = new XmlIts1Formatter();

            its1Formatter.GraphAides.Add(
                new DatatypeFormatter()
                );

            // Select a folder
            string directory = String.Empty;

            while (String.IsNullOrEmpty(directory) || !Directory.Exists(directory))
            {
                Console.Write("Enter directory to listen to:");
                directory = Console.ReadLine();
            }

            // We can use a connection string builder to make creating the connection string easier
            FileConnectionStringBuilder connStringBuilder = new FileConnectionStringBuilder();

            connStringBuilder.Directory = directory;
            connStringBuilder.KeepFiles = true;
            connStringBuilder.Pattern   = "*.xml";

            // Create an instance of the connector
            FileListenConnector connector = new FileListenConnector(connStringBuilder.GenerateConnectionString());

            connector.Formatter = its1Formatter;
            connector.Open();

            // Assign message available event
            connector.MessageAvailable += new EventHandler <UnsolicitedDataEventArgs>(connector_MessageAvailable);

            connector.Start(); // Start watching the directory

            // Exit condition
            Console.Write("Press any key to quit...\n");
            Console.ReadKey();

            // Close connector
            connector.Close();
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                // Ask the user what directory they want to listen to
                Console.Write("Enter directory to listen on (example: C:\\temp):");
                var directory = Console.ReadLine();

                // Create the directory if it doesn't exist
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                // Setup the listener
                FileListenConnector flc = new FileListenConnector(String.Format("Directory={0};Pattern=*.xml", directory));

                // Create the formatter that will interpret CDAr2 (XML ITS 1.0 and Datatypes R1)
                MARC.Everest.Formatters.XML.ITS1.Formatter fmtr = new MARC.Everest.Formatters.XML.ITS1.Formatter();
                fmtr.ValidateConformance = true;
                fmtr.GraphAides.Add(new DatatypeFormatter());
                flc.Formatter = fmtr;

                // Subscribe to the message available event
                flc.MessageAvailable += new EventHandler <MARC.Everest.Connectors.UnsolicitedDataEventArgs>(flc_MessageAvailable);

                // Start the connector
                try
                {
                    flc.Open();
                    flc.Start();
                    Console.WriteLine("Waiting for messages in {0}, press any key to stop listening...", directory);
                    Console.ReadKey();
                }
                finally
                {
                    flc.Stop();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error in the execution of the example {0}", e);
            }
        }