Ejemplo n.º 1
0
        public virtual ShippingRate GetRate(IShipment shipment, ShippingMethodInfoModel shippingMethodInfoModel, IMarket currentMarket)
        {
            var type = Type.GetType(shippingMethodInfoModel.ClassName);

            if (type == null)
            {
                throw new TypeInitializationException(shippingMethodInfoModel.ClassName, null);
            }

            string message = null;

            var shippingPlugin = _shippingPluginsAccessor().FirstOrDefault(s => s.GetType() == type);

            if (shippingPlugin != null)
            {
                return(shippingPlugin.GetRate(currentMarket, shippingMethodInfoModel.MethodId, shipment, ref message));
            }

            var shippingGateway = _shippingGatewaysAccessor().FirstOrDefault(s => s.GetType() == type);

            if (shippingGateway != null)
            {
                return(shippingGateway.GetRate(currentMarket, shippingMethodInfoModel.MethodId, (Shipment)shipment, ref message));
            }

            throw new InvalidOperationException($"There is no registered {nameof(IShippingPlugin)} or {nameof(IShippingGateway)} instance.");
        }
Ejemplo n.º 2
0
        public virtual ShippingRate GetRate(IShipment shipment, ShippingMethodInfoModel shippingMethodInfoModel, IMarket currentMarket)
        {
            var    type            = Type.GetType(shippingMethodInfoModel.ClassName);
            var    shippingGateway = (IShippingPlugin)Activator.CreateInstance(type, currentMarket);
            string message         = null;

            return(shippingGateway.GetRate(shippingMethodInfoModel.MethodId, shipment, ref message));
        }
Ejemplo n.º 3
0
        public virtual ShippingRate GetRate(IShipment shipment, ShippingMethodInfoModel shippingMethodInfoModel, IMarket currentMarket)
        {
            var type = Type.GetType(shippingMethodInfoModel.ClassName);

            if (type == null)
            {
                throw new TypeInitializationException(shippingMethodInfoModel.ClassName, null);
            }

            string message = null;

            var shippingInstance = Activator.CreateInstance(type, currentMarket);
            var shippingPlugin   = shippingInstance as IShippingPlugin;

            if (shippingPlugin != null)
            {
                return(shippingPlugin.GetRate(shippingMethodInfoModel.MethodId, shipment, ref message));
            }
            return(((IShippingGateway)shippingInstance).GetRate(shippingMethodInfoModel.MethodId, (Shipment)shipment, ref message));
        }