public static IShopOrder CreateNewOrder(CreateOrderOptions options)
        {
            if (OrderProcessor == null)
            {
                throw new InvalidOperationException("No order processor present, can't generate a new order id");
            }

            var orderId = OrderProcessor.GenerateNextOrderId(options);

            using (var data = new DataConnection())
            {
                var order = data.CreateNew <IShopOrder>();

                order.Id         = orderId;
                order.CreatedOn  = DateTime.UtcNow;
                order.OrderTotal = options.TotalAmount;
                order.Currency   = options.Currency.ToString();
                order.CustomData = options.CustomData;

                order = data.Add(order);

                order.WriteLog("created");

                return(order);
            }
        }
        public virtual string GenerateNextOrderId(CreateOrderOptions settings)
        {
            int orderId;

            lock (Lock)
            {
                var content = C1File.ReadAllText(LastUsedOrderIdFile);
                int.TryParse(content, out orderId);

                orderId = orderId + 1;

                C1File.WriteAllText(LastUsedOrderIdFile, orderId.ToString(CultureInfo.InvariantCulture));
            }

            string sOrderId;

            if (settings.MinimumOrderIdLength > 0)
            {
                var format = "D" + settings.MinimumOrderIdLength;

                sOrderId = orderId.ToString(format, CultureInfo.InvariantCulture);
            }
            else
            {
                sOrderId = orderId.ToString(CultureInfo.InvariantCulture);
            }

            if (!String.IsNullOrEmpty(settings.OrderIdPrefix))
            {
                sOrderId = settings.OrderIdPrefix + sOrderId;
            }

            if (ECommerce.IsTestMode)
            {
                var hashMachineName = Environment.MachineName.GetHashCode().ToString(CultureInfo.InvariantCulture);
                if (hashMachineName.StartsWith("-"))
                {
                    hashMachineName = hashMachineName.Remove(0, 1);
                }

                var maxMachineNameLength = 20 - 6 - sOrderId.Length;
                if (hashMachineName.Length > maxMachineNameLength)
                {
                    hashMachineName = hashMachineName.Substring(0, maxMachineNameLength);
                }

                sOrderId = $"TEST-{hashMachineName}-{sOrderId}";
            }

            sOrderId = sOrderId.Trim();

            return(sOrderId);
        }