Пример #1
0
        public static Correo operator +(Correo c, Paquete p)
        {
            bool flag = false;

            if (p != null)
            {
                foreach (Paquete item in c.Paquetes)
                {
                    if (item == p)
                    {
                        flag = true;
                        TrackingIdRepetidoException e = new TrackingIdRepetidoException("El tracking ID " + p.TrackingID + " ya figura en la lista de envios.");
                        throw e;
                        //break;
                    }
                }
                if (flag == false)
                {
                    c._paquetes.Add(p);
                    try
                    {
                        Thread hiloPaquete = new Thread(p.MockCicloDeVida);
                        c._mockPaquetes.Add(hiloPaquete);
                        hiloPaquete.Start();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            return(c);
        }
Пример #2
0
        /// <summary>
        /// Operador que añade un paquete a la lista paquetes
        /// </summary>
        /// <param name="c">Instancia Correo</param>
        /// <param name="p">Paquete que se quiere añadir</param>
        /// <returns>
        /// Dependiendo si "p" se encuentra en la lista, va a devolver una correo con un paquete añadido(o no)
        /// </returns>
        public static Correo operator +(Correo c, Paquete p)
        {
            foreach (Paquete paquete in c.paquetes)
            {
                if (p == paquete)
                {
                    TrackingIdRepetidoException ex = new TrackingIdRepetidoException(string.Format("Id{0} ya ingresada", paquete.TrackingID));
                    throw ex;
                }
            }
            Thread thread = new Thread(new ThreadStart(p.MockCicloDeVida));

            thread.Start();
            c.mockPaquetes.Add(thread);
            c.Paquetes.Add(p);

            return(c);
        }
Пример #3
0
        public static Correo operator +(Correo c, Paquete p)
        {
            bool flag = false;

            //no es nulo
            if (p != null)
            {
                foreach (Paquete item in c.Paquetes)
                {
                    if (item == p)
                    {
                        flag = true;
                        string mensajeException = "El paquete con tracking ID:" + p.TrackingID + " ya fue enviado previamente.";

                        TrackingIdRepetidoException excep = new TrackingIdRepetidoException(mensajeException);
                        throw excep;
                    }
                }

                if (flag == false)
                {
                    c.Paquetes.Add(p);
                    try
                    {
                        Thread hiloParaPaquete = new Thread(p.MockClicloDeVida);
                        c.mockPaquetes.Add(hiloParaPaquete);
                        hiloParaPaquete.Start();
                    }
                    catch (Exception excep)
                    {
                        throw excep;
                    }
                }
            }
            return(c);
        }