Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of a CategoryNode object.
        /// </summary>
        /// <param name="productRow"></param>
        public Product(IExplorerItem parent, DataSet.ProductRow productRow)
        {
            // Validate the parameters.
            if (productRow == null)
            {
                throw new ArgumentNullException("productRow");
            }

            // Extract the values from the record.
            base.Name   = productRow.Name;
            base.Parent = parent;

            // This will locat and disassemble the folder icon and give us the basic image sizes supported by the application framework.
            Uri uri = new Uri("/Teraque.DataModel;component/Resources/Product.ico", UriKind.Relative);
            Dictionary <ImageSize, ImageSource> images = ImageHelper.DecodeIcon(uri);

            base.SmallImageSource      = images[ImageSize.Small];
            base.MediumImageSource     = images[ImageSize.Medium];
            base.LargeImageSource      = images[ImageSize.Large];
            base.ExtraLargeImageSource = images[ImageSize.ExtraLarge];

            this.Viewer = new Uri(String.Format(@"pack://application:,,,/Teraque.LicenseBook;component/LicenseDirectory.xaml?path=\Root\Product\{0}", productRow.Name));

            foreach (DataSet.LicenseRow licenseRow in productRow.GetLicenseRows())
            {
                this.Add(new License(this, licenseRow));
            }
        }
Exemplo n.º 2
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]);
        }
Exemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //_code = GetUniqueIDRelativeTo();
     //_productName = Product.SearchById(_code).name;
     //_description = Product.SearchById(_code).description;
     if (!String.IsNullOrEmpty(Request.QueryString["ID"]))
     {
         id = int.Parse(Request.QueryString["ID"]);
     }
     DataSetTableAdapters.ProductTableAdapter ds = new DataSetTableAdapters.ProductTableAdapter();
     item = ds.GetDataByID(id)[0];
     Page.DataBind();
 }
Exemplo n.º 4
0
        internal static void GenerateLicense(LicenseInfo licenseInfo, String fileName)
        {
            if (licenseInfo == null)
            {
                throw new ArgumentNullException("licenseInfo");
            }

            DataSet.ProductRow  productRow  = DataModel.Product.FindByProductId(licenseInfo.ProductId);
            DataSet.CustomerRow customerRow = DataModel.Customer.FindByCustomerId(licenseInfo.CustomerId);

            // Generate a new license.
            DataSet.LicenseRow licenseRow = DataModel.License.AddLicenseRow(
                licenseInfo.DateCreated,
                customerRow,
                Guid.NewGuid(),
                licenseInfo.LicenseType,
                productRow);
            DataModel.LicenseTableAdapter.Update(DataModel.License);

            // Generate the payload from the license type, the product id, the serial number and the current date.
            Byte[] licenseType       = BitConverter.GetBytes(licenseRow.LicenseType);
            Byte[] productIdArray    = licenseRow.ProductId.ToByteArray();
            Byte[] serialNumberArray = BitConverter.GetBytes(licenseRow.SerialNumber);
            Byte[] dateCreatedArray  = BitConverter.GetBytes(licenseRow.DateCreated.ToBinary());
            Byte[] payload           = new Byte[licenseType.Length + productIdArray.Length + serialNumberArray.Length + dateCreatedArray.Length];
            Array.Copy(licenseType, payload, licenseType.Length);
            Array.Copy(productIdArray, 0, payload, licenseType.Length, productIdArray.Length);
            Array.Copy(serialNumberArray, 0, payload, licenseType.Length + productIdArray.Length, serialNumberArray.Length);
            Array.Copy(dateCreatedArray, 0, payload, licenseType.Length + productIdArray.Length + serialNumberArray.Length, dateCreatedArray.Length);

            RSAParameters rsaParameters = new RSAParameters();

            rsaParameters.D        = LicenseManager.privateKeyD;
            rsaParameters.DP       = LicenseManager.privateKeyDp;
            rsaParameters.DQ       = LicenseManager.privateKeyDq;
            rsaParameters.Exponent = LicenseManager.publicKeyExponent;
            rsaParameters.InverseQ = LicenseManager.privateKeyInverseQ;
            rsaParameters.Modulus  = LicenseManager.publicKeyModulus;
            rsaParameters.P        = LicenseManager.privateKeyP;
            rsaParameters.Q        = LicenseManager.privateKeyQ;
            RSACryptoServiceProvider rsaCryptoServiceProvider = new RSACryptoServiceProvider();

            rsaCryptoServiceProvider.ImportParameters(rsaParameters);

            SHA1CryptoServiceProvider sha1CryptoServiceProvider = new SHA1CryptoServiceProvider();

            Byte[] signature     = rsaCryptoServiceProvider.SignData(payload, sha1CryptoServiceProvider);
            Byte[] signedPayload = new Byte[payload.Length + signature.Length];
            Array.Copy(payload, signedPayload, payload.Length);
            Array.Copy(signature, 0, signedPayload, payload.Length, signature.Length);

            Byte[] publicKey = new Byte[LicenseManager.publicKeyExponent.Length + LicenseManager.publicKeyModulus.Length];
            Array.Copy(LicenseManager.publicKeyExponent, publicKey, LicenseManager.publicKeyExponent.Length);
            Array.Copy(LicenseManager.publicKeyModulus, 0, publicKey, LicenseManager.publicKeyExponent.Length, LicenseManager.publicKeyModulus.Length);

            Byte[] licenseKey = new Byte[publicKey.Length + signedPayload.Length];
            Array.Copy(publicKey, licenseKey, publicKey.Length);
            Array.Copy(signedPayload, 0, licenseKey, publicKey.Length, signedPayload.Length);

            using (StreamWriter streamWriter = new StreamWriter(fileName))
                streamWriter.WriteLine(Convert.ToBase64String(licenseKey));
        }