/// <summary> /// The main function in the sample. /// </summary> /// <param name="args"></param> public override void SampleCall(string[] args) { #region Parse Arguments ArgParser cmdLineParser = new ArgParser(); if (!cmdLineParser.Parse(args)) { // parse failed PrintUsage(INVALID_ARGUMENTS_ERROR); return; } #endregion #region Initialize properties from command line // Initialize the properties. ContextProperties contextProps = new ContextProperties(); SessionProperties sessionProps = SampleUtils.NewSessionPropertiesFromConfig(cmdLineParser.Config); #endregion // Define IContext. IContext context = null; try { InitContext(cmdLineParser.LogLevel); Console.WriteLine("About to create the context ..."); context = ContextFactory.Instance.CreateContext(contextProps, null); Console.WriteLine("Context successfully created. "); // We will create two sessions, and give them different msg receiver callbacks. IdPrintingReceiver recvCallback1 = new IdPrintingReceiver("Client 1"); IdPrintingReceiver recvCallback2 = new IdPrintingReceiver("Client 2"); Console.WriteLine("About to create the Sessions..."); session = context.CreateSession(sessionProps, recvCallback1.HandleMessageEvent, SampleUtils.HandleSessionEvent); session2 = context.CreateSession(sessionProps, recvCallback2.HandleMessageEvent, SampleUtils.HandleSessionEvent); Console.WriteLine("Sessions successfully created."); Console.WriteLine("About to connect the Session..."); if (session.Connect() == ReturnCode.SOLCLIENT_OK) { Console.WriteLine("Session 1 successfully connected."); Console.WriteLine(GetRouterInfo(session)); } Console.Write(String.Format("Check for capability: {0}... ", CapabilityType.SUBSCRIPTION_MANAGER)); if (!session.IsCapable(CapabilityType.SUBSCRIPTION_MANAGER)) { Console.WriteLine("Not Supported. Exiting."); return; } else { Console.WriteLine("OK"); } // Appliance supports this sample, connect 2nd session. if (session2.Connect() == ReturnCode.SOLCLIENT_OK) { Console.WriteLine("Session 2 successfully connected"); } // Create the Topic to subscribe and send messages to. ITopic serviceTopic = ContextFactory.Instance.CreateTopic(topic_str); // Once clients have been connected, their ClientNames can be extracted. ContextFactory cf = ContextFactory.Instance; string strClientName1 = (string)session.GetProperty(SessionProperties.PROPERTY.ClientName); string strClientName2 = (string)session2.GetProperty(SessionProperties.PROPERTY.ClientName); IClientName clientName1 = cf.CreateClientName(strClientName1); IClientName clientName2 = cf.CreateClientName(strClientName2); Console.WriteLine("Client '{0}' adding subscription on behalf of client '{1}'", clientName1, clientName2); session.Subscribe(clientName2, serviceTopic, SubscribeFlag.RequestConfirm | SubscribeFlag.WaitForConfirm, null); Console.WriteLine("OK. Added subscription '{0}'.", serviceTopic); IMessage messageOne = SampleUtils.CreateMessage(cmdLineParser.Config, session); messageOne.Destination = serviceTopic; Console.WriteLine("Sending a message from Client 1..."); session.Send(messageOne); Console.WriteLine("Sent."); Thread.Sleep(500); Console.WriteLine("Done."); } catch (Exception ex) { PrintException(ex); } finally { if (session != null) { session.Dispose(); } if (session2 != null) { session2.Dispose(); } if (context != null) { context.Dispose(); } // Must cleanup after. CleanupContext(); } }