static void Main() { Console.WriteLine("Pressione 'enter' quando o componente Hello estiver no ar."); Console.ReadLine(); OrbServices.CreateAndRegisterIiopChannel(); String helloIorPath = Resources.IorFilename; StreamReader stream = new StreamReader(helloIorPath); String helloIor; try { helloIor = stream.ReadToEnd(); } finally { stream.Close(); } OrbServices orb = OrbServices.GetSingleton(); IComponent icomponent = orb.string_to_object(helloIor) as IComponent; Hello hello = icomponent.getFacetByName("Hello") as Hello; hello.sayHello(); Console.ReadLine(); }
public void TestSlotModifyInClientRecContextAndServer() { try { int slotId = m_testInterceptorInit.RequestIntercept.SlotId; ORB orb = OrbServices.GetSingleton(); omg.org.PortableInterceptor.Current current = (omg.org.PortableInterceptor.Current)orb.resolve_initial_references("PICurrent"); int contextEntryVal = 4; current.set_slot(slotId, contextEntryVal); System.Int32 arg = 1; System.Int32 result = m_testService.TestAddToContextData(arg); Assertion.AssertEquals(arg + contextEntryVal, result); Assertion.Assert("service context not present", m_testInterceptorInit.RequestIntercept.HasReceivedContextElement); Assertion.AssertEquals("service context content", arg + contextEntryVal, m_testInterceptorInit.RequestIntercept.ContextElement.TestEntry); current = (omg.org.PortableInterceptor.Current)orb.resolve_initial_references("PICurrent"); Assertion.AssertEquals("slot was modified", contextEntryVal, current.get_slot(slotId)); } finally { m_testInterceptorInit.RequestIntercept.ClearInvocationHistory(); } }
internal static CallChain UnmarshalCallChain(SignedData signed) { TypeCode chainTypeCode = OrbServices.GetSingleton().create_tc_for_type(typeof(CallChain)); return((CallChain)InterceptorsInitializer.Codec.decode_value(signed.encoded, chainTypeCode)); }
public static void Main(String[] args) { IOrbServices orb = OrbServices.GetSingleton(); TestInterceptorInit testInterceptorInit = new TestInterceptorInit(); orb.RegisterPortableInterceptorInitalizer(testInterceptorInit); // register the channel int port = 8087; IiopChannel chan = new IiopChannel(port); ChannelServices.RegisterChannel(chan, false); orb.CompleteInterceptorRegistration(); TestInterceptorControlService controlService = new TestInterceptorControlService(testInterceptorInit); string objectURIControlService = "interceptorControl"; RemotingServices.Marshal(controlService, objectURIControlService); TestService test = new TestService(); string objectURI = "test"; RemotingServices.Marshal(test, objectURI); Console.WriteLine("server running"); Thread.Sleep(Timeout.Infinite); }
static void Main() { log4net.Config.XmlConfigurator.Configure(); OrbServices.CreateAndRegisterIiopChannel(0); String componentModel = Resources.ComponentDesc; TextReader file = new StringReader(componentModel); XmlTextReader componentInformation = new XmlTextReader(file); XmlComponentBuilder builder = new XmlComponentBuilder(componentInformation); ComponentContext pingContext = builder.build(); //Escrevendo a IOR do IComponent no arquivo. IComponent pingComponent = pingContext.GetIComponent(); OrbServices orb = OrbServices.GetSingleton(); String ior = orb.object_to_string(pingComponent); String iorPath = Resources.IorFilename; StreamWriter stream = new StreamWriter(iorPath); try { stream.Write(ior); } finally { stream.Close(); } Console.WriteLine("Componente ping está no ar."); Console.ReadLine(); }
public void SetUp() { m_orb = OrbServices.GetSingleton(); m_channel = new IiopChannel(TEST_PORT); ChannelServices.RegisterChannel(m_channel, false); }
public void ShareDataKeys(List <byte[]> keys) { omg.org.CORBA.TypeCode byteTC = OrbServices.GetSingleton().create_octet_tc(); omg.org.CORBA.TypeCode sequenceTC = OrbServices.GetSingleton().create_sequence_tc(0, byteTC); omg.org.CORBA.TypeCode arrayTC = OrbServices.GetSingleton().create_array_tc(keys.Count, sequenceTC); Share(new Any(keys.ToArray(), arrayTC)); }
private void IntializeForInterception(IInterceptionOption[] interceptionOptions) { // flow lifetime is bound to message lifetime, GiopClientRequest is only a wrapper around message and // can be recreated during message lifetime. m_interceptionFlow = (ClientRequestInterceptionFlow)SimpleGiopMsg.GetInterceptionFlow(m_requestMessage); if (m_interceptionFlow == null) { ClientRequestInterceptor[] interceptors = OrbServices.GetSingleton().InterceptorManager.GetClientRequestInterceptors(interceptionOptions); if (interceptors.Length == 0) { m_interceptionFlow = new ClientRequestInterceptionFlow(); } else { m_interceptionFlow = new ClientRequestInterceptionFlow(interceptors); } SimpleGiopMsg.SetInterceptionFlow(m_requestMessage, m_interceptionFlow); } if (m_interceptionFlow.NeedsRequestInfo()) { // optimization: needs not be created, if non-intercepted. m_clientRequestInfo = new ClientRequestInfoImpl(this); } }
internal static core.v2_0.services.access_control.CallChain UnmarshalLegacyCallChain(SignedCallChain signed) { TypeCode chainTypeCode = OrbServices.GetSingleton().create_tc_for_type(typeof(core.v2_0.services.access_control.CallChain)); return((core.v2_0.services.access_control.CallChain)InterceptorsInitializer.Codec.decode_value(signed.encoded, chainTypeCode)); }
private void RegisterInterceptors() { IOrbServices orb = OrbServices.GetSingleton(); m_testInterceptorInit = new TestInterceptorInit(); orb.RegisterPortableInterceptorInitalizer(m_testInterceptorInit); orb.CompleteInterceptorRegistration(); }
public bool NoValueInScope() { ORB orb = OrbServices.GetSingleton(); omg.org.PortableInterceptor.Current current = (omg.org.PortableInterceptor.Current)orb.resolve_initial_references("PICurrent"); return(current.get_slot(m_slotId) == null); }
public string fetchHello(byte[] encodedChain) { OpenBusContext context = ORBInitializer.Context; CallerChain chain; try { chain = context.DecodeChain(encodedChain); } catch (InvalidEncodedStreamException e) { Console.WriteLine(e); throw new ArgumentException("Cadeia em formato inválido.", e); } context.JoinChain(chain); ServiceProperty[] properties = { new ServiceProperty("offer.domain", "Interoperability Tests"), new ServiceProperty("openbus.component.interface", Repository.GetRepositoryID(typeof(Hello))), new ServiceProperty("openbus.component.name", "RestrictedHello") }; List <ServiceOfferDesc> offers = Utils.FindOffer(ORBInitializer.Context.OfferRegistry, properties, 1, 10, 1); foreach (ServiceOfferDesc desc in offers) { try { if (OrbServices.GetSingleton().non_existent(desc.service_ref)) { continue; } } catch (TRANSIENT) { continue; } catch (COMM_FAILURE) { continue; } MarshalByRefObject helloObj = desc.service_ref.getFacet(Repository.GetRepositoryID(typeof(Hello))); if (helloObj == null) { Console.WriteLine( "Não foi possível encontrar uma faceta com esse nome."); continue; } Hello hello = helloObj as Hello; if (hello == null) { Console.WriteLine("Faceta encontrada não implementa Hello."); continue; } return(hello.sayHello()); } return(""); }
private static CredentialData UnmarshalCredential(ServiceContext serviceContext) { OrbServices orb = OrbServices.GetSingleton(); TypeCode credentialTypeCode = orb.create_tc_for_type(typeof(CredentialData)); byte[] data = serviceContext.context_data; return((CredentialData)InterceptorsInitializer.Codec.decode_value(data, credentialTypeCode)); }
/// <summary> /// Verifica se o objeto CORBA implementa a interface (repository ID). /// </summary> /// <param name="obj">O objeto CORBA.</param> /// <param name="interfaceName">A interface (repository ID).</param> /// <returns></returns> public static bool CheckInterface(MarshalByRefObject obj, string interfaceName) { OrbServices orb = OrbServices.GetSingleton(); try { return(orb.is_a(obj, interfaceName)); } catch (NullReferenceException) { return(false); } }
public object RetrieveIdlIntArrayAsAny([IdlArray(0L, 5)] int[] arg) { // test with explicit typecode-creation IOrbServices orbServices = OrbServices.GetSingleton(); omg.org.CORBA.TypeCode arrayTC = orbServices.create_array_tc(5, orbServices.create_tc_for_type(typeof(int))); Any arrayAsAny = new Any(arg, arrayTC); return(arrayAsAny); }
public void TestAnyContainer() { System.String testString = "abcd"; OrbServices orb = OrbServices.GetSingleton(); omg.org.CORBA.TypeCode wstringTc = orb.create_wstring_tc(0); Any any = new Any(testString, wstringTc); Any result = m_testService.EchoAny(any); Assertion.AssertEquals(any.Value, result.Value); }
public OpenBusContextImpl(int connectionIdSlotId, int ignoreThreadSlotId, int joinedChainSlotId, int chainSlotId) { _connections = new ConditionalWeakTable <Object, Connection>(); _connectionIdSlotId = connectionIdSlotId; _ignoreThreadSlotId = ignoreThreadSlotId; _joinedChainSlotId = joinedChainSlotId; _chainSlotId = chainSlotId; _orb = OrbServices.GetSingleton(); _lock = new ReaderWriterLockSlim(); _codec = InterceptorsInitializer.Codec; }
public System.Int32 TestAddToContextData(System.Int32 arg) { ORB orb = OrbServices.GetSingleton(); omg.org.PortableInterceptor.Current current = (omg.org.PortableInterceptor.Current)orb.resolve_initial_references("PICurrent"); int contextData = (int)current.get_slot(m_slotId); int result = contextData + arg; current.set_slot(m_slotId, result); return(result); }
public void SetUp() { m_orb = OrbServices.GetSingleton(); m_profile = new InternetIiopProfile(new GiopVersion(1, 2), "localhost", 1001, new byte[] { 1, 0, 0, 0 }); m_clientChannel = new IiopClientChannel(); ChannelServices.RegisterChannel(m_clientChannel, false); }
public object RetrieveIdlInt3DimArray2x2x3AsAny([IdlArray(0L, 2)][IdlArrayDimension(0L, 1, 2)][IdlArrayDimension(0L, 2, 3)] System.Int32[,,] arg) { // test with explicit typecode-creation IOrbServices orbServices = OrbServices.GetSingleton(); omg.org.CORBA.TypeCode arrayTC = orbServices.create_array_tc(3, orbServices.create_tc_for_type(typeof(int))); arrayTC = orbServices.create_array_tc(2, arrayTC); arrayTC = orbServices.create_array_tc(2, arrayTC); Any arrayAsAny = new Any(arg, arrayTC); return(arrayAsAny); }
/// <summary> /// Resolves a name to a service. /// </summary> /// <param name="name">name to resolve</param> /// <returns>resolved service</returns> /// <exception cref="ServiceException"> /// if a CORBA-related error occurs while resolving the service name /// </exception> public T Resolve(Name name) { try { MarshalByRefObject reference = this.DirContext.resolve(name.Components); // Touch the object to immediately fail if it is unavailable OrbServices.GetSingleton().non_existent(reference); // Jeez, C#... return((T)((object)reference)); } catch (AbstractCORBASystemException e) { throw new ServiceException("Failed to resolve service name " + name, e); } catch (TargetInvocationException e) { throw new ServiceException("Failed to resolve service name " + name, e.InnerException); } }
public void receive_request(ServerRequestInfo ri) { // modify request scope after copy to the thread scope -> must not be propagated to the thread scope. if (ri.operation == "TestReceiveReqNotChangeThreadScope") { ri.set_slot(m_slotId, 2 * (int)ri.get_slot(m_slotId)); } else if (ri.operation == "TestReceiveReqChangeThreadScope") { ORB orb = OrbServices.GetSingleton(); omg.org.PortableInterceptor.Current current = (omg.org.PortableInterceptor.Current)orb.resolve_initial_references("PICurrent"); current.set_slot(m_slotId, 3 * (int)current.get_slot(m_slotId)); } }
public void TestNilReferenceAsAny() { OrbServices orb = OrbServices.GetSingleton(); omg.org.CORBA.TypeCode nilRefTC = orb.create_tc_for_type(typeof(System.MarshalByRefObject)); Any nilRefAny = new Any(null, nilRefTC); object result = m_testService.EchoAny(nilRefAny); Assert.IsNull(result, "result not null"); Any nilRefAny2 = new Any(null, orb.create_interface_tc(String.Empty, String.Empty)); object result2 = m_testService.EchoAny(nilRefAny2); Assert.IsNull(result2, "result not null"); }
public void TestULongAsAny() { int arg = 74; int result = (int)m_testService.RetrieveULongAsAny(arg); Assert.AreEqual(arg, result, "wrong result of retrieveULongAsAny"); OrbServices orb = OrbServices.GetSingleton(); int arg2 = 89; omg.org.CORBA.TypeCode ulongTC = orb.create_ulong_tc(); Any any = new Any(arg2, ulongTC); int result2 = m_testService.ExtractFromULongAny(any); Assert.AreEqual(arg2, result2, "wrong result of ExtractFromULongAny"); }
public static List <ServiceOfferDesc> FindOffer(OfferRegistry offers, ServiceProperty[] search, int count, int tries, int interval) { OrbServices orb = OrbServices.GetSingleton(); List <ServiceOfferDesc> found = new List <ServiceOfferDesc>(); for (int i = 0; i < tries; i++) { found.Clear(); Thread.Sleep(interval * 1000); ServiceOfferDesc[] services = offers.findServices(search); if (services.Length > 0) { foreach (ServiceOfferDesc offerDesc in services) { try { if (!orb.non_existent(offerDesc.service_ref)) { found.Add(offerDesc); } } catch (Exception) { // não adiciona essa oferta } } } if (found.Count >= count) { return(found); } } StringBuilder buffer = new StringBuilder(); foreach (ServiceOfferDesc desc in found) { String name = GetProperty(desc.properties, "openbus.offer.entity"); String login = GetProperty(desc.properties, "openbus.offer.login"); buffer.AppendFormat("\n - {0} ({1})", name, login); } String msg = String .Format( "Não foi possível encontrar ofertas: found ({0}) expected({1}) tries ({2}) time ({3}){4}", found.Count, count, tries, tries * interval, buffer); throw new InvalidOperationException(msg); }
public CollaborationSession StartCollaboration() { Logger.Info("Starting collaboration"); lock (_locker) { SessionRegistry sreg = GetSessions(); try { _theSession = sreg.getSession(); Logger.Info("Session retrieved: " + OrbServices.GetSingleton().object_to_string(_theSession)); } catch (TargetInvocationException e) { if (e.InnerException is SessionDoesNotExist) { Logger.Warn("Session not found for entity " + (e.InnerException as SessionDoesNotExist).entity); } } catch (Exception e) { Logger.Error("Error trying to obtain session: " + e); throw; } if (_theSession == null) { try { CollaborationRegistry collab = GetCollabs(); _theSession = collab.createCollaborationSession(); sreg.registerSession(_theSession); } catch (Exception e) { Logger.Error("Error creating the session (it will be destroyed): " + e); if (_theSession != null) { _theSession.destroy(); } throw; } } UpdateActivation(); } return(_theSession); }
public void TestLongTypeDefAsAny() { OrbServices orb = OrbServices.GetSingleton(); int arg = 74; int result = (int)m_testService.RetrieveLongTypeDefAsAny(arg); Assert.AreEqual(arg, result, "result of RetrieveLongTypeDefAsAny"); int arg2 = 91; omg.org.CORBA.TypeCode argTC = orb.create_tc_for(arg2); omg.org.CORBA.TypeCode longTD_TC = orb.create_alias_tc("IDL:longTD:1.0", "longTD", argTC); Any any = new Any(arg2, longTD_TC); int result2 = m_testService.ExtractFromLongTypeDef(any); Assert.AreEqual(arg2, result2, "result of ExtractFromLongTypeDef"); }
public void SetupEnvironment() { if (!m_isConfigured) { OrbServices orb = OrbServices.GetSingleton(); orb.SerializerFactoryConfig.StringSerializationAllowNull = true; orb.SerializerFactoryConfig.SequenceSerializationAllowNull = true; orb.SerializerFactoryConfig.ArraySerializationAllowNull = true; m_isConfigured = true; } // register the channel m_channel = new IiopClientChannel(); ChannelServices.RegisterChannel(m_channel, false); // get the reference to the test-service m_testService = (TestService)RemotingServices.Connect(typeof(TestService), "corbaloc:iiop:1.2@localhost:8087/test"); }
public void TestSSLComponent() { IOrbServices orb = OrbServices.GetSingleton(); string iorString = orb.object_to_string(m_newTestService); Ior ior = new Ior(iorString); Assert.IsTrue(ior.Profiles.Length > 0, "nr of profiles"); IIorProfile profile = ior.Profiles[0]; omg.org.IOP.CodecFactory codecFactory = (omg.org.IOP.CodecFactory) orb.resolve_initial_references("CodecFactory"); object sslData = profile.TaggedComponents.GetComponentData(20, codecFactory.create_codec(new omg.org.IOP.Encoding(omg.org.IOP.ENCODING_CDR_ENCAPS.ConstVal, 1, 2)), SSLComponentData.TypeCode); Assert.NotNull(sslData); Assert.AreEqual((int)8087, ((SSLComponentData)sslData).GetPort()); }
public void TestPassingStringAsAny() { // explicit mapping OrbServices orb = OrbServices.GetSingleton(); string arg = "test"; omg.org.CORBA.TypeCode stringTC = orb.create_string_tc(0); Any any = new Any(arg, stringTC); string result = (string)m_testService.EchoAny(any); Assert.AreEqual(arg, result); // check extraction on server side with explicit mapping string result3 = m_testService.ExtractFromStringAny(any); Assert.AreEqual(arg, result3); }