コード例 #1
0
ファイル: SalesEsnecilGenerator.cs プロジェクト: nitware/cfa
        protected override RawEsnecil GenerateLicenseHelper(Dictionary <string, string> customerInfo, CryptoLicenseGenerator generator)
        {
            string id       = customerInfo["CodeID"];
            string userData = SetCustomerInfo(customerInfo);

            //generator.UserData = customerInfo;
            generator.NumberOfUsers = 1;
            generator.SetCustomInfo(id, userData); // not working yet
            generator.MachineCodeAsString  = MachineCode;
            generator.DetectDateRollback   = true;
            generator.EnableTamperChecking = true;

            string licCode    = generator.Generate();
            string serialCode = generator.SerialCodes[0];

            RawEsnecil esnecil = new RawEsnecil();

            esnecil.NoOfUsers            = generator.NumberOfUsers;
            esnecil.DetectDateRollback   = generator.DetectDateRollback;
            esnecil.EnableTamperChecking = generator.EnableTamperChecking;
            esnecil.RawUserData          = userData;
            esnecil.SerialCode           = serialCode;
            esnecil.MachineKey           = MachineCode;
            esnecil.EsnecilCode          = licCode;
            esnecil.GeneratedOn          = DateTime.UtcNow;

            return(esnecil);
        }
コード例 #2
0
ファイル: OrderService.cs プロジェクト: nitware/cfa
        public OperationResult <Order> PlaceOrder(Cart cart)
        {
            const int MAX_RETRY = 10;

            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            Dictionary <string, string> customerInfo = new Dictionary <string, string>();

            customerInfo.Add("Email", cart.Customer.Email);
            customerInfo.Add("Phone", cart.Customer.Phone);
            customerInfo.Add("Address", cart.Customer.Address);
            customerInfo.Add("CodeID", cart.Customer.Id.ToString());
            //customerInfo.Add("Name", cart.Customer.Email);

            cart.Order.Esnecils = new List <Esnecil>();
            foreach (ProductPrice productPrice in cart.ProductPrices)
            {
                RawEsnecil rawEsnecil = _esnecilGenerator.GenerateLicense(customerInfo);
                Esnecil    esnecil    = rawEsnecil.ToEsnecil();
                esnecil.ProductPriceId = productPrice.Id;
                cart.Order.Esnecils.Add(esnecil);
            }

            for (int i = 1; i <= MAX_RETRY; i++)
            {
                try
                {
                    Invoice invoice = _invoiceManager.GetNextInvoiceNo();
                    cart.Order.InvoiceNo = invoice.InvoiceNo;
                    cart.Order.SerialNo  = invoice.SerialNo;

                    _repository.Add(cart.Order);
                    _repository.Save();

                    break;
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Violation of UNIQUE KEY constraint"))
                    {
                        if (i == MAX_RETRY)
                        {
                            throw new Exception("Violation of UNIQUE KEY constraint. Cannot insert duplicate key in object. The statement has been terminated. Please try again.");
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(new OperationResult <Order>(true)
            {
                Entity = cart.Order
            });
        }
コード例 #3
0
ファイル: TrialEsnecilGenerator.cs プロジェクト: nitware/cfa
        public override RawEsnecil GenerateLicense(Dictionary <string, string> customerInfo)
        {
            try
            {
                string filePath = _esnecilGeneratorFile.GetResource();
                ValidateGenerator(filePath);

                CryptoLicenseGenerator generator = base.InitializeGenerator(filePath); // Load license project file
                RawEsnecil             esnecil   = GenerateLicenseHelper(customerInfo, generator);

                return(esnecil);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #4
0
        public void GenerateLicense_Should_GenerateEsnecilSerialNoAndCode_WhenValidGeneratorFileAndCustomerInfoIsSet()
        {
            //Dictionary<string, string> customerInfo = new Dictionary<string, string>();
            //customerInfo.Add("Email", "*****@*****.**");
            //customerInfo.Add("Name", "Akuabata Egenti");
            //customerInfo.Add("Phone", "09087651122");
            //customerInfo.Add("Address", "99 Opebi road, Ikeja Lagos");
            //customerInfo.Add("CodeID", "109930");

            Dictionary <string, string> customerInfo = new Dictionary <string, string>
            {
                { "Email", "*****@*****.**" },
                { "Name", "Akuabata Egenti" },
                { "Phone", "09087651122" },
                { "Address", "99 Opebi road, Ikeja Lagos" },
                { "CodeID", "109930" }
            };

            //var discountsDictionary = new Dictionary<AccountStatus, IAccountDiscountCalculator>
            //  {
            //    {AccountStatus.NotRegistered, new NotRegisteredDiscountCalculator()},
            //    {AccountStatus.SimpleCustomer, new SimpleCustomerDiscountCalculator()},
            //    {AccountStatus.ValuableCustomer, new ValuableCustomerDiscountCalculator()},
            //    {AccountStatus.MostValuableCustomer, new MostValuableCustomerDiscountCalculator()}
            //};

            IEsnecilGeneratorResource esnecilGeneratorFile = new EsnecilGeneratorFile();
            IEsnecilGeneratorFactory  generatorFactory     = new EsnecilGeneratorFactory(esnecilGeneratorFile);
            EsnecilGeneratorBase      generator            = generatorFactory.Create(EsnecilType.Trial);
            RawEsnecil esnecil = generator.GenerateLicense(customerInfo);

            //RawEsnecil esnecil = generator.GenerateLicense(filePath, customerInfo);

            Assert.NotNull(esnecil);
            Assert.NotNull(esnecil.SerialCode);
            Assert.NotNull(esnecil.EsnecilCode);
            Assert.True(esnecil.GeneratedOn.Date == DateTime.Today.Date);
            Assert.True(esnecil.SerialCode.Length > 5);
            Assert.True(esnecil.EsnecilCode.Length > 5);
            Assert.True(esnecil.DetectDateRollback);
            Assert.True(esnecil.EnableTamperChecking);
            Assert.Equal(1, esnecil.NoOfUsers);
        }
コード例 #5
0
ファイル: EsnecilExtensions.cs プロジェクト: nitware/cfa
        public static Esnecil ToEsnecil(this RawEsnecil rawEsnecil)
        {
            if (rawEsnecil == null)
            {
                throw new ArgumentNullException("rawEsnecil cannot be null!");
            }

            Esnecil esnecil = new Esnecil()
            {
                EsnecilCode          = rawEsnecil.EsnecilCode,
                MachineKey           = rawEsnecil.MachineKey,
                EnableTamperChecking = rawEsnecil.EnableTamperChecking,
                DetectDateRollback   = rawEsnecil.DetectDateRollback,
                SerialCode           = rawEsnecil.SerialCode,
                RawUserData          = rawEsnecil.RawUserData,
                NoOfUsers            = rawEsnecil.NoOfUsers,
                GeneratedOn          = rawEsnecil.GeneratedOn,
            };

            return(esnecil);
        }