private static void StartTheThread(double timeout, ServiceOfferDesc desc,
                                           Thread wThread)
        {
            Thread t = new Thread(() => UseOffer(timeout, desc, wThread));

            t.Start();
        }
Ejemplo n.º 2
0
 private static string GetProperty(ServiceOfferDesc offer, string name)
 {
     foreach (ServiceProperty property in offer.properties)
     {
         if (property.name.Equals(name))
         {
             return(property.value);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
 public CallbackImpl(string loginId, ServiceOfferDesc timerOffer, Thread waitingThread)
 {
     _loginId       = loginId;
     _waitingThread = waitingThread;
     foreach (ServiceProperty serviceProperty in timerOffer.properties.Where(serviceProperty => serviceProperty.name.Equals("openbus.offer.login")))
     {
         _timerId = serviceProperty.value;
         break;
     }
     if (_timerId == null)
     {
         throw new ArgumentException();
     }
 }
        private static void UseOffer(double timeout, ServiceOfferDesc desc,
                                     Thread wThread)
        {
            Connection conn = NewLogin();

            if (!conn.Login.HasValue)
            {
                return;
            }
            OpenBusContext context = ORBInitializer.Context;

            context.SetCurrentConnection(conn);
            bool failed = true;

            try {
                MarshalByRefObject timerObj = desc.service_ref.getFacet(TimerIDLType);
                if (timerObj == null)
                {
                    Console.WriteLine(Resources.FacetNotFoundInOffer);
                    return;
                }
                Timer timer = timerObj as Timer;
                if (timer == null)
                {
                    Console.WriteLine(Resources.FacetFoundWrongType);
                    return;
                }
                Console.WriteLine(Resources.OfferFound);
                // utiliza o serviço
                timer.newTrigger(timeout,
                                 new CallbackImpl(conn.Login.Value.id, desc, wThread));
                failed = false;
            }
            catch (TRANSIENT) {
                Console.WriteLine(Resources.ServiceTransientErrorMsg);
            }
            catch (COMM_FAILURE) {
                Console.WriteLine(Resources.ServiceCommFailureErrorMsg);
            }
            catch (Exception e) {
                NO_PERMISSION npe = null;
                if (e is TargetInvocationException)
                {
                    // caso seja uma exceção lançada pelo SDK, será uma NO_PERMISSION
                    npe = e.InnerException as NO_PERMISSION;
                }
                if ((npe == null) && (!(e is NO_PERMISSION)))
                {
                    // caso não seja uma NO_PERMISSION não é uma exceção esperada então deixamos passar.
                    throw;
                }
                npe = npe ?? (NO_PERMISSION)e;
                bool   found   = false;
                string message = String.Empty;
                switch (npe.Minor)
                {
                case NoLoginCode.ConstVal:
                    message = Resources.NoLoginCodeErrorMsg;
                    found   = true;
                    break;

                case UnknownBusCode.ConstVal:
                    message = Resources.UnknownBusCodeErrorMsg;
                    found   = true;
                    break;

                case UnverifiedLoginCode.ConstVal:
                    message = Resources.UnverifiedLoginCodeErrorMsg;
                    found   = true;
                    break;

                case InvalidRemoteCode.ConstVal:
                    message = Resources.InvalidRemoteCodeErrorMsg;
                    found   = true;
                    break;
                }
                if (found)
                {
                    Console.WriteLine(message);
                }
                else
                {
                    throw;
                }
            }
            finally {
                try {
                    context.SetCurrentConnection(null);
                    conn.Logout();
                }
                catch (ServiceFailure e) {
                    Console.WriteLine(Resources.BusServiceFailureErrorMsg);
                    Console.WriteLine(e);
                }
                catch (TRANSIENT) {
                    Console.WriteLine(Resources.BusTransientErrorMsg);
                }
                catch (COMM_FAILURE) {
                    Console.WriteLine(Resources.BusCommFailureErrorMsg);
                }
                if (!failed)
                {
                    Pending++;
                }
            }
        }