Пример #1
0
        private void buttonCreateParticipant_Click(object sender, EventArgs e)
        {
            if (myParticipant == null)
            {
                try
                {
                    myParticipant    = Participant.GetInstance("PizzaDomain", "partId", "ops_config.xml");
                    OtherParticipant = Participant.GetInstance("OtherPizzaDomain", "partId", "ops_config.xml");
                    if (myParticipant == null)
                    {
                        myParticipant    = Participant.GetInstance("PizzaDomain", "partId", "..\\..\\ops_config.xml");
                        OtherParticipant = Participant.GetInstance("OtherPizzaDomain", "partId", "..\\..\\ops_config.xml");
                    }
                    if (myParticipant == null)
                    {
                        Log("Failed to create Participant!");
                        return;
                    }
                    myParticipant.AddTypeSupport(new PizzaProject.PizzaProjectTypeFactory());
                    OtherParticipant.AddTypeSupport(new PizzaProject.PizzaProjectTypeFactory());

                    // Setup the correct participant for each topic in our helper list
                    foreach (MyTopicInfo info in MyTopicInfoList)
                    {
                        if (info.DomainName == "PizzaDomain")
                        {
                            info.Part = myParticipant;
                        }
                        if (info.DomainName == "OtherPizzaDomain")
                        {
                            info.Part = OtherParticipant;
                        }
                    }

                    //TEST partInfoHelper = new COpsHelperPartInfoData(this);
                    // partInfoHelper.CreateSubscriber(myParticipant);
                }
                catch (Exception ex)
                {
                    Logger.ExceptionLogger.LogException(ex);
                }
            }
            else
            {
                Log("Participant is already created!");
            }
        }
Пример #2
0
        public void DoTest()
        {
            // ===========================================
            cd1 = new ChildData();
            ChildData cd2 = new ChildData();
            ChildData cd3 = new ChildData();

            // ==============================================================
            LogNL("Test initial state...");
            CheckEmpty(cd1);
            CheckEmpty(cd2);
            CheckEmpty(cd3);

            CheckObjects(cd1, cd2);
            LogNL("Finished ");

            LogNL("Test cloning...");
            FillChildData(cd1);
            cd1.FillClone(cd2);
            CheckObjects(cd1, cd2);

            LogNL("Finished ");

            // ==============================================================
            LogNL("Serialize filled object");
            byte[]          bytes = new byte[Globals.MAX_SEGMENT_SIZE];
            WriteByteBuffer buf   = new WriteByteBuffer(bytes, Globals.MAX_SEGMENT_SIZE, true);
            OPSArchiverOut  ao    = new OPSArchiverOut(buf, false);

            LogNL("  Position()= " + buf.Position());
            ao.Inout <ChildData>("data", cd1);
            LogNL("  optNonVirt = false, Position()= " + buf.Position());
            AssertEQ(buf.Position(), 3150, "Serialized size error");

            buf = new WriteByteBuffer(bytes, Globals.MAX_SEGMENT_SIZE, true);
            ao  = new OPSArchiverOut(buf, true);
            LogNL("  Position()= " + buf.Position());
            ao.Inout <ChildData>("data", cd1);
            LogNL("  optNonVirt = true,  Position()= " + buf.Position());
            AssertEQ(buf.Position(), 2591, "Serialized size error");
            LogNL("Serialize finished");

            // Create a new stream to write to the file
            //BinaryWriter Writer = new BinaryWriter(File.OpenWrite(@"csharp-dump-opt.bin"));
            //Writer.Write(bytes, 0, buf.Position());
            //Writer.Flush();
            //Writer.Close();

            // ==============================================================
            LogNL("Test publish/subscribe");

            Logger.ExceptionLogger.AddLogger(logger);

            if (File.Exists("ops_config.xml"))
            {
                LogNL("Using config file in CWD");
            }
            else
            {
                string cwd = Environment.CurrentDirectory;
                int    pos = cwd.IndexOf("Example");
                if (pos > 0)
                {
                    cwd = cwd.Substring(0, pos) + "Examples/OPSIdls/TestAll/ops_config.xml";
                    LogNL("Using config file: " + cwd);
                    OPSConfigRepository.Add(cwd);
                }
            }

            participant = Participant.GetInstance("TestAllDomain");
            if (participant == null)
            {
                LogNL("Create participant failed. do you have ops_config.xml on your rundirectory?");
                return;
            }
            participant.AddTypeSupport(new TestAllTypeFactory());

            {
                // Setup & start subscriber w polling
                Topic topic = participant.CreateTopic("ChildTopic");
                sub = new ChildDataSubscriber(topic);
                sub.Start();

                // Setup & start publisher
                pub = new ChildDataPublisher(topic);
                pub.SetName("C#");
                pub.Start();

                Thread.Sleep(100);

                // Publish data
                pub.Write(cd1);

                // Check that sent data isn't affected by publish
                CheckObjects(cd1, cd2);

                // Check received values against sent values
                sub.WaitForNextData(500);
                OPSMessage msg = sub.GetMessage();
                if (msg != null)
                {
                    cd3 = (ChildData)msg.GetData();
                }
                AssertTRUE((msg != null) && (cd3 != null), "No received data");

                if ((msg != null) && (cd3 != null))
                {
                    CheckObjects(cd1, cd3);
                }

                LogNL("Finished ");

                sub.newData += new ChildDataEventHandler(SubscriberNewData);

                // Create a timer with a 5 second interval.
                aTimer = new System.Timers.Timer(5000);
                // Hook up the Elapsed event for the timer.
                aTimer.Elapsed  += OnTimedEvent;
                aTimer.AutoReset = true;
                aTimer.Enabled   = true;
            }
        }
Пример #3
0
        private void buttonCreateParticipant_Click(object sender, EventArgs e)
        {
            if (myParticipant == null)
            {
                try
                {
                    if (File.Exists("ops_config.xml"))
                    {
                        Log("Using config file in CWD");
                    }
                    else
                    {
                        string cwd = Environment.CurrentDirectory;
                        int    pos = cwd.IndexOf("Example");
                        if (pos > 0)
                        {
                            cwd = cwd.Substring(0, pos) + "Examples/OPSIdls/PizzaProject/ops_config.xml";
                            Log("Using config file: " + cwd);
                            OPSConfigRepository.Add(cwd);
                        }
                    }

                    myParticipant    = Participant.GetInstance("PizzaDomain", "partId");
                    OtherParticipant = Participant.GetInstance("OtherPizzaDomain", "partId");
                    if (myParticipant == null)
                    {
                        Log("Failed to create Participant!");
                        return;
                    }
                    myParticipant.AddTypeSupport(new PizzaProject.PizzaProjectTypeFactory());
                    OtherParticipant.AddTypeSupport(new PizzaProject.PizzaProjectTypeFactory());

                    Log("");
                    Log("DomainID : " + myParticipant.getDomain().GetDomainID());
                    Log("DomainAddress: " + myParticipant.getDomain().GetDomainAddress());
                    Log("InSocketBufferSize: " + myParticipant.getDomain().GetInSocketBufferSize());
                    Log("OutSocketBufferSize: " + myParticipant.getDomain().GetOutSocketBufferSize());
                    Log("MetaDataMcPort: " + myParticipant.getDomain().GetMetaDataMcPort());
                    Log("LocalInterface: " + myParticipant.getDomain().GetLocalInterface());
                    Log("TimeToLive: " + myParticipant.getDomain().getTimeToLive());

                    Log("");
                    Log("DomainID : " + OtherParticipant.getDomain().GetDomainID());
                    Log("DomainAddress: " + OtherParticipant.getDomain().GetDomainAddress());
                    Log("InSocketBufferSize: " + OtherParticipant.getDomain().GetInSocketBufferSize());
                    Log("OutSocketBufferSize: " + OtherParticipant.getDomain().GetOutSocketBufferSize());
                    Log("MetaDataMcPort: " + OtherParticipant.getDomain().GetMetaDataMcPort());
                    Log("LocalInterface: " + OtherParticipant.getDomain().GetLocalInterface());
                    Log("TimeToLive: " + OtherParticipant.getDomain().getTimeToLive());

                    // Setup the correct participant for each topic in our helper list
                    foreach (MyTopicInfo info in MyTopicInfoList)
                    {
                        if (info.DomainName == "PizzaDomain")
                        {
                            info.Part = myParticipant;
                        }
                        if (info.DomainName == "OtherPizzaDomain")
                        {
                            info.Part = OtherParticipant;
                        }
                    }

                    //TEST partInfoHelper = new COpsHelperPartInfoData(this);
                    // partInfoHelper.CreateSubscriber(myParticipant);
                }
                catch (Exception ex)
                {
                    Logger.ExceptionLogger.LogException(ex);
                }
            }
            else
            {
                Log("Participant is already created!");
            }
        }