Пример #1
0
        /// <summary>
        /// Generate a license from the command line arguments.
        /// </summary>
        void GenerateLicense()
        {
            // A license requires the product.  This will extract the product id from the command line and attempt to find it in the table of products.
            Guid productId = Guid.Parse(this.commandLine[Parameter.Product]);

            DataSet.ProductRow productRow = DataModel.Product.FindByProductId(productId);

            // The email address is used as a unique identifier for the customer.
            String email      = this.commandLine[Parameter.Email];
            Guid   customerId = Guid.Empty;
            var    results    = from row in DataModel.Customer.AsEnumerable() where row.Email == email select row;

            DataSet.CustomerRow customerRow = results.FirstOrDefault();

            // If the customer doesn't exist yet, then create one from the command line parameters.
            if (customerRow == null)
            {
                // This will generate a new record from the command line arguments which likely have been provided by a daemon process in Outlook.
                customerRow              = DataModel.Customer.NewCustomerRow();
                customerRow.Address      = this.commandLine[Parameter.Address];
                customerRow.City         = this.commandLine[Parameter.City];
                customerRow.Country      = this.commandLine[Parameter.Country];
                customerRow.CustomerId   = Guid.NewGuid();
                customerRow.DateCreated  = DateTime.Now;
                customerRow.DateModified = DateTime.Now;
                customerRow.Email        = email;
                customerRow.FirstName    = this.commandLine[Parameter.FirstName];
                customerRow.LastName     = this.commandLine[Parameter.LastName];
                customerRow.Phone        = this.commandLine[Parameter.Phone];
                customerRow.PostalCode   = this.commandLine[Parameter.PostalCode];
                customerRow.Province     = this.commandLine[Parameter.Province];

                // Add the customer and update the database.
                DataModel.Customer.AddCustomerRow(customerRow);
                DataModel.CustomerTableAdapter.Update(DataModel.Customer);
            }

            // Create a perpetual license for development and runtime.
            Byte[] licenseTypeArray = new Byte[2];
            licenseTypeArray[0] = LicenseType.Perpetual;
            licenseTypeArray[1] = LicenseType.Perpetual;
            Int16 licenseType = BitConverter.ToInt16(licenseTypeArray, 0);

            // The effective date of this license is right now.
            DateTime dateCreated = DateTime.Now;

            // This will generate the license from the command line arguments parsed above and deposit it in a file also parsed from the command line.
            LicenseInfo licenseInfo = new LicenseInfo()
            {
                DateCreated = dateCreated,
                CustomerId  = customerRow.CustomerId,
                LicenseType = licenseType,
                ProductId   = productRow.ProductId
            };

            LicenseManager.GenerateLicense(licenseInfo, this.commandLine[Parameter.Output]);
        }
Пример #2
0
        void OnGenerateLicense(Object sender, RoutedEventArgs e)
        {
            Byte[] licenseTypeArray = new Byte[2];
            licenseTypeArray[0] = LicenseType.Evaluation3Month;
            licenseTypeArray[1] = LicenseType.Evaluation3Month;
            Int16 licenseType = BitConverter.ToInt16(licenseTypeArray, 0);

            DateTime dateCreated = DateTime.Now;

            LicenseInfo licenseInfo = new LicenseInfo()
            {
                DateCreated = dateCreated,
                CustomerId  = MainWindow.TeraqueCustomerId,
                LicenseType = licenseType,
                ProductId   = MainWindow.ExplorerChromeSuite
            };

            LicenseManager.GenerateLicense(licenseInfo, "../../license.lic");
        }