Пример #1
0
 public OrdersController(OrderRepository orderRepository, IShoppingService shoppingService, ICurrencyInfoProvider currencyInfoProvider, IOrderStatusInfoProvider orderStatusInfoProvider,
                         ICountryInfoProvider countryInfoProvider, IStateInfoProvider stateInfoProvider)
 {
     this.orderRepository         = orderRepository;
     this.shoppingService         = shoppingService;
     this.currencyInfoProvider    = currencyInfoProvider;
     this.orderStatusInfoProvider = orderStatusInfoProvider;
     this.countryInfoProvider     = countryInfoProvider;
     this.stateInfoProvider       = stateInfoProvider;
 }
Пример #2
0
 //DocSection:Constructor
 /// <summary>
 /// Initializes instances of service used to facilitate shopping cart, currency and order interactions.
 /// </summary>
 public OrderController(IShoppingService shoppingService,
                        ICurrencyInfoProvider currencyInfoProvider,
                        IOrderInfoProvider orderInfoProvider,
                        ISiteService siteService)
 {
     this.shoppingService      = shoppingService;
     this.currencyInfoProvider = currencyInfoProvider;
     this.orderInfoProvider    = orderInfoProvider;
     this.siteService          = siteService;
 }
 public AcceptJSController(IOrderInfoProvider orderInfoProvider, IOrderItemInfoProvider orderItemInfoProvider, ICustomerInfoProvider customerInfoProvider, IStateInfoProvider stateInfoProvider, IAcceptJSOptions acceptJSOptions, IExchangeRateInfoProvider exchangeRateInfoProvider, ICurrencyInfoProvider currencyInfoProvider)
 {
     OrderInfoProvider        = orderInfoProvider;
     OrderItemInfoProvider    = orderItemInfoProvider;
     CustomerInfoProvider     = customerInfoProvider;
     StateInfoProvider        = stateInfoProvider;
     AcceptJSOptions          = acceptJSOptions;
     ExchangeRateInfoProvider = exchangeRateInfoProvider;
     CurrencyInfoProvider     = currencyInfoProvider;
 }
Пример #4
0
    void Start()
    {
        Time.timeScale = TimeScale;

        //////////////// Currency Information Provider Setup \\\\\\\\\\\\\\\\\\
        var realtimeCurrencyProvider = gameObject.AddComponent <RealtimeCurrencyInfoProvider>();

        realtimeCurrencyProvider.SetUpdateIntervalInSeconds(PriceUpdateInterval);

        CurrencyInfoProvider = realtimeCurrencyProvider;
        ////////////////////////////////////////////////////////////////////////

        secondsLeftToWait = secondsToWaitBeforeRunning;
    }
Пример #5
0
 public OrderViewModel(OrderInfo order, ICurrencyInfoProvider currencyInfoProvider)
 {
     OrderID                = order.OrderID;
     OrderStatusID          = order.OrderStatusID;
     CurrencyFormatString   = currencyInfoProvider.Get(order.OrderCurrencyID).CurrencyFormatString;
     OrderDate              = order.OrderDate;
     OrderTotalPrice        = order.OrderTotalPrice;
     OrderIsPaid            = order.OrderIsPaid;
     OrderStatusDisplayName = OrderStatusInfo.Provider.Get(order.OrderStatusID)?.StatusDisplayName;
     if (order.OrderPaymentResult != null)
     {
         OrderPaymentResult = new OrderPaymentResultViewModel()
         {
             PaymentMethodName  = order.OrderPaymentResult.PaymentMethodName,
             PaymentIsCompleted = order.OrderPaymentResult.PaymentIsCompleted
         };
     }
 }
        public static ICurrencyInfoProvider Merge(
            [NotNull] this ICurrencyInfoProvider first,
            [NotNull] ICurrencyInfoProvider second)
        {
            if (first == null)
            {
                throw new ArgumentNullException(nameof(first));
            }
            if (second == null)
            {
                throw new ArgumentNullException(nameof(second));
            }

            ICurrencyInfoProvider newest = first.Published > second.Published ? first : second;

            second = first.Published > second.Published ? second : first;

            bool areSameDate = newest.Published == second.Published;

            // Optimise out empty providers
            if (newest.Count < 1)
            {
                return(second.Count < 1 ? newest : second);
            }
            if (second.Count < 1)
            {
                return(newest);
            }

            Dictionary <string, CurrencyInfo> currencies = newest.All.ToDictionary(
                c => c.Code,
                StringComparer.InvariantCultureIgnoreCase);

            foreach (CurrencyInfo currency in second.All)
            {
                if (!currencies.ContainsKey(currency.Code))
                {
                    currencies.Add(currency.Code, areSameDate ? currency.GetOutOfDate() : currency);
                }
            }

            Debug.Assert(currencies.Count > 0);
            return(new CurrencyInfoProvider(newest.Published, currencies.Values));
        }
        /// <summary>
        /// Converts this <see cref="CurrencyInfoProvider" /> to binary.
        /// </summary>
        /// <param name="currencyInfoProvider">The currency information provider.</param>
        /// <param name="stream">The binary stream to save to.</param>
        /// <param name="leaveOpen">if set to <see langword="true" /> the <paramref name="stream" /> will be left open.</param>
        public static void ToBinary(
            [NotNull] this ICurrencyInfoProvider currencyInfoProvider,
            [NotNull] Stream stream,
            bool leaveOpen = false)
        {
            if (currencyInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(currencyInfoProvider));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using (BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen))
            {
                writer.Write(CurrencyInfoProvider.BinaryHeader);
                writer.Write(currencyInfoProvider.Published.Ticks);

                int count = currencyInfoProvider.Count;
                writer.Write(count);
                if (count < 1)
                {
                    return;
                }

                foreach (CurrencyInfo currency in currencyInfoProvider.All)
                {
                    writer.Write(currency.ISONumber);
                    writer.Write(currency.Code);
                    writer.Write(currency.FullName);
                    writer.Write(currency.Exponent.HasValue);
                    if (currency.Exponent.HasValue)
                    {
                        writer.Write(currency.Exponent.Value);
                    }
                    writer.Write(currency.IsLatest);
                }
            }
        }
        public OrdersListViewModel(OrderInfo order, ICurrencyInfoProvider currencyInfoProvider, IOrderStatusInfoProvider orderStatusInfoProvider)
        {
            if (order == null)
            {
                return;
            }

            if (currencyInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(currencyInfoProvider));
            }

            if (orderStatusInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(orderStatusInfoProvider));
            }

            OrderID             = order.OrderID;
            OrderInvoiceNumber  = order.OrderInvoiceNumber;
            OrderDate           = order.OrderDate;
            StatusName          = orderStatusInfoProvider.Get(order.OrderStatusID)?.StatusDisplayName;
            FormattedTotalPrice = String.Format(currencyInfoProvider.Get(order.OrderCurrencyID).CurrencyFormatString, order.OrderTotalPrice);
        }
        public static string ToXml([NotNull] this ICurrencyInfoProvider currencyInfoProvider)
        {
            if (currencyInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(currencyInfoProvider));
            }

            XElement ccyTbl = new XElement("CcyTbl");

            XDocument doc = new XDocument(
                new XElement(
                    "ISO_4217",
                    new XAttribute("Pblshd", currencyInfoProvider.Published.ToString(InstantPattern.ExtendedIsoPattern.PatternText, null)),
                    ccyTbl));

            foreach (CurrencyInfo currency in currencyInfoProvider.All)
            {
                XElement ccyNtry = new XElement(
                    "CcyNtry",
                    new XElement("CcyNm", currency.FullName),
                    new XElement("Ccy", currency.Code),
                    new XElement("CcyNbr", currency.ISONumber));
                if (currency.Exponent.HasValue)
                {
                    ccyNtry.Add(new XElement("CcyMnrUnts", currency.Exponent.Value));
                }
                if (!currency.IsLatest)
                {
                    ccyNtry.Add(new XAttribute("IsLatest", "false"));
                }

                ccyTbl.Add(ccyNtry);
            }

            return(doc.ToString());
        }
Пример #10
0
        /// <summary>
        /// Initialized static shortcuts and caches
        /// </summary>
        static Currency()
        {
            _provider = CurrencyInfo.CreateProvider();

            using (var initializer = CurrencyInfo.CreateInitializer())
            {
                Aud = init(CurrencyIsoCode.AUD, initializer.Get);
                CurrencyCache.Add(Aud);

                Cad = init(CurrencyIsoCode.CAD, initializer.Get);
                CurrencyCache.Add(Cad);

                Chf = init(CurrencyIsoCode.CHF, initializer.Get);
                CurrencyCache.Add(Chf);

                Cny = init(CurrencyIsoCode.CNY, initializer.Get);
                CurrencyCache.Add(Cny);

                Dkk = init(CurrencyIsoCode.DKK, initializer.Get);
                CurrencyCache.Add(Dkk);

                Eur = init(CurrencyIsoCode.EUR, initializer.Get);
                CurrencyCache.Add(Eur);

                Gbp = init(CurrencyIsoCode.GBP, initializer.Get);
                CurrencyCache.Add(Gbp);

                Hkd = init(CurrencyIsoCode.HKD, initializer.Get);
                CurrencyCache.Add(Hkd);

                Huf = init(CurrencyIsoCode.HUF, initializer.Get);
                CurrencyCache.Add(Huf);

                Inr = init(CurrencyIsoCode.INR, initializer.Get);
                CurrencyCache.Add(Inr);

                Jpy = init(CurrencyIsoCode.JPY, initializer.Get);
                CurrencyCache.Add(Jpy);

                Mxn = init(CurrencyIsoCode.MXN, initializer.Get);
                CurrencyCache.Add(Mxn);

                Myr = init(CurrencyIsoCode.MYR, initializer.Get);
                CurrencyCache.Add(Myr);

                Nok = init(CurrencyIsoCode.NOK, initializer.Get);
                CurrencyCache.Add(Nok);

                Nzd = init(CurrencyIsoCode.NZD, initializer.Get);
                CurrencyCache.Add(Nzd);

                Rub = init(CurrencyIsoCode.RUB, initializer.Get);
                CurrencyCache.Add(Rub);

                Sek = init(CurrencyIsoCode.SEK, initializer.Get);
                CurrencyCache.Add(Sek);

                Sgd = init(CurrencyIsoCode.SGD, initializer.Get);
                CurrencyCache.Add(Sgd);

                Thb = init(CurrencyIsoCode.THB, initializer.Get);
                CurrencyCache.Add(Thb);

                Usd = init(CurrencyIsoCode.USD, initializer.Get);
                CurrencyCache.Add(Usd);

                Zar = init(CurrencyIsoCode.ZAR, initializer.Get);
                CurrencyCache.Add(Zar);

                Xxx = init(CurrencyIsoCode.XXX, initializer.Get);
                CurrencyCache.Add(Xxx);

                Xts = init(CurrencyIsoCode.XTS, initializer.Get);
                CurrencyCache.Add(Xts);
            }

            Euro   = Eur;
            Dollar = Usd;
            Pound  = Gbp;
            None   = Xxx;
            Test   = Xts;
        }
Пример #11
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            Debug.Assert(Log != null);

            // Validate uri.
            Uri uri;

            if (!Uri.TryCreate(ISO4217Uri, UriKind.Absolute, out uri) ||
                ReferenceEquals(uri, null))
            {
                Log.LogError("Invalid URL provided - '{0}'.", ISO4217Uri);
                return(false);
            }

            if (string.IsNullOrWhiteSpace(OutputFilePath))
            {
                Log.LogError("The output path was not specified");
                return(false);
            }

            string path          = Path.GetFullPath(OutputFilePath);
            string directoryName = Path.GetDirectoryName(path);

            if (string.IsNullOrWhiteSpace(directoryName))
            {
                Log.LogError("The output path was not specified");
                return(false);
            }

            bool saveBinary = !string.Equals(Path.GetExtension(path), ".xml", StringComparison.InvariantCultureIgnoreCase);

            Log.LogMessage(saveBinary ? "Data will be saved in binary." : "Data will be saved in XML.");

            try
            {
                CurrencyInfoProvider existing = null;

                if (!Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(path);
                }
                else if (File.Exists(path))
                {
                    if (Merge)
                    {
                        existing = CurrencyInfoProvider.LoadFromFile(path);
                    }
                    else if (!Overwrite)
                    {
                        Log.LogMessage(
                            MessageImportance.Normal,
                            string.Format(
                                "The output file path '{0}' exists and we are not overwriting so skipping download from '{1}'.",
                                path,
                                uri));
                        return(true);
                    }
                }

                using (WebClient webClient = new WebClient())
                {
                    if (UseDefaultCredentials)
                    {
                        webClient.Credentials = CredentialCache.DefaultCredentials;
                    }
                    else if (!string.IsNullOrWhiteSpace(Username))
                    {
                        webClient.Credentials = new NetworkCredential(Username, Password, Domain);
                    }

                    Log.LogMessage("Downloading XML from '{0}'.", uri);
                    string xml = webClient.DownloadString(uri);
                    Log.LogMessage("Successfully downloaded XML from '{0}'.", uri);

                    ICurrencyInfoProvider downloaded = CurrencyInfoProvider.LoadFromXml(xml);
                    if (downloaded == null)
                    {
                        Log.LogError("Could not parse the XML downloaded from '{0}'.", uri);
                        return(false);
                    }

                    if (existing != null)
                    {
                        Log.LogMessage("Merging downloaded file with the existing file.");
                        downloaded = downloaded.Merge(existing);
                    }

                    if (saveBinary)
                    {
                        Log.LogMessage("Converting XML to binary and saving to '{0}'.", path);
                        using (Stream file = File.Create(path))
                            downloaded.ToBinary(file);
                        Log.LogMessage("Successfully converted XML and saved to '{0}'.", path);
                    }
                    else
                    {
                        Log.LogMessage("Saving XML to '{0}'.", path);
                        File.WriteAllText(path, downloaded.ToXml());
                        Log.LogMessage("Successfully saved XML to '{0}'.", path);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
                return(false);
            }
        }
 /// <summary>
 /// Sets the current provider.
 /// </summary>
 /// <param name="path">The path.</param>
 public static void SetCurrentProvider(string path = null)
 {
     _current = LoadCurrencies(path);
     _isFromConfig = path == null;
 }
        /// <summary>
        /// Initializes the <see cref="CurrencyInfoProvider"/> class.
        /// </summary>
        /// <exception cref="System.IO.FileNotFoundException">The ISO 4217 file specified in the configuration file was not found.</exception>
        /// <exception cref="System.IO.InvalidDataException">The data in the ISO 4217 file was invalid.</exception>
        /// <exception cref="System.IO.FileLoadException">An exception was thrown while loading the currency information from the ISO 4217 file.</exception>
        static CurrencyInfoProvider()
        {
            _current = Empty = new EmptyCurrencyInfoProvider(DateTime.MinValue);

            SetCurrentProvider();
        }