/// <summary>
        /// Returns all payment methods. See LmBoxAPI JavaDoc for details:
        /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/PaymentMethodService.html
        /// </summary>
        public static List<PaymentMethod> list(Context context)
        {
            lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.PaymentMethod.ENDPOINT_PATH, null);

            List<PaymentMethod> paymentMethods = new List<PaymentMethod>();
            foreach (item i in output.items)
            {
                paymentMethods.Add(new PaymentMethod(i));
            }
            return paymentMethods;
        }
        /// <summary>
        /// Returns all licensees of a vendor. See LmBoxAPI JavaDoc for details:
        /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseeService.html
        /// </summary>
        public static List<Licensee> list(Context context, String filter)
        {
            Dictionary<String, String> parameters = new Dictionary<String, String>();
            if (filter != null && filter.Length > 0)
            {
                parameters.Add("filter", filter);
            }

            lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.Licensee.ENDPOINT_PATH, parameters);

            List<Licensee> licensees = new List<Licensee>();
            foreach (item i in output.items)
            {
                licensees.Add(new Licensee(i));
            }
            return licensees;
        }
        /// <summary>
        /// Returns all products of a vendor. See LmBoxAPI JavaDoc for details:
        /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/ProductService.html
        /// </summary>
        public static List<Product> list(Context context, String filter)
        {
            Dictionary<String, String> parameters = new Dictionary<String, String>();
            if (filter != null && filter.Length > 0)
            {
                parameters.Add("filter", filter);
            }

            lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.Product.ENDPOINT_PATH, null);

            List<Product> products = new List<Product>();
            foreach (item i in output.items)
            {
               products.Add(new Product(i));
            }
            return products;
        }
        /// <summary>
        /// Returns all licensing models.
        /// </summary>
        public static List<String> listLicensingModels(Context context)
        {
            lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.Utility.ENDPOINT_PATH + "/" + Constants.Utility.LICENSING_MODELS, null);

            List<String> licensingModels = new List<String>();
            foreach (item i in output.items)
            {
                if (Constants.Utility.LICENSING_MODELS_PROPERTIES.Equals(i.type))
                {
                    foreach (property p in i.property)
                    {
                        if (p.name == Constants.NAME)
                        {
                            licensingModels.Add(p.Value);
                        }
                    }
                }
            }
            return licensingModels;
        }
        static void Main(string[] args)
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; // Trust the self-signed certificate at lmbox.labs64.com.
            Context context = new Context();
            context.baseUrl = "https://lmbox.labs64.com";
            context.username = "******";
            context.password = "******";

            String demoProductNumber = "P001demo";
            String demoProductModuleNumber = "M001demo";
            String demoLicensingModel = "TimeEvaluation";

            String demoLicenseTemplate1_Number = "E001demo";
            String demoLicenseTemplate1_Name = "Demo Evaluation Period";
            String demoLicenseTemplate1_Type = "FEATURE";
            Decimal demoLicenseTemplate1_Price = 12.50M;
            String demoLicenseTemplate1_Currency = "EUR";
            Boolean demoLicenseTemplate1_Automatic = false;
            Boolean demoLicenseTemplate1_Hidden = false;

            String demoLicenseeNumber = "I001demo";

            String demoLicenseNumber = "L001demoTV";

            String demoTokenType = "SHOP";

            try
            {

                List<String> licenseTypes = UtilityService.listLicenseTypes(context);
                ConsoleWriter.WriteList("Licensing Models:", licenseTypes);

                List<String> licensingModels = UtilityService.listLicensingModels(context);
                ConsoleWriter.WriteList("Licensing Types:", licensingModels);

                #region ****************** Product

                Product newProduct = new Product();
                newProduct.number = demoProductNumber;
                newProduct.name = "Demo product";
                Product product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product:", product);

                product = ProductService.get(context, demoProductNumber);
                ConsoleWriter.WriteEntity("Got product:", product);

                List<Product> products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following products:", products);

                Product updateProduct = new Product();
                updateProduct.productProperties.Add("Updated property name", "Updated value");
                product = ProductService.update(context, demoProductNumber, updateProduct);
                ConsoleWriter.WriteEntity("Updated product:", product);

                ProductService.delete(context, demoProductNumber, true);
                ConsoleWriter.WriteMsg("Deleted Product!");

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product again:", product);

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                #endregion

                #region ****************** ProductModule

                ProductModule newProductModule = new ProductModule();
                newProductModule.number = demoProductModuleNumber;
                newProductModule.name = "Demo product module";
                newProductModule.licensingModel = demoLicensingModel;
                ProductModule productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module:", productModule);

                productModule = ProductModuleService.get(context, demoProductModuleNumber);
                ConsoleWriter.WriteEntity("Got product module:", productModule);

                List<ProductModule> productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                ProductModule updateProductModule = new ProductModule();
                updateProductModule.productModuleProperties.Add("Updated property name", "Updated property value");
                productModule = ProductModuleService.update(context, demoProductModuleNumber, updateProductModule);
                ConsoleWriter.WriteEntity("Updated product module:", productModule);

                ProductModuleService.delete(context, demoProductModuleNumber, true);
                ConsoleWriter.WriteMsg("Deleted ProductModule!");

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module again:", productModule);

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                #endregion

                #region ****************** LicenseTemplate
                LicenseTemplate newLicenseTemplate = new LicenseTemplate();
                newLicenseTemplate.number = demoLicenseTemplate1_Number;
                newLicenseTemplate.name = demoLicenseTemplate1_Name;
                newLicenseTemplate.licenseType = demoLicenseTemplate1_Type;
                newLicenseTemplate.price = demoLicenseTemplate1_Price;
                newLicenseTemplate.currency = demoLicenseTemplate1_Currency;
                newLicenseTemplate.automatic = demoLicenseTemplate1_Automatic;
                newLicenseTemplate.hidden = demoLicenseTemplate1_Hidden;
                ConsoleWriter.WriteEntity("Adding license template:", newLicenseTemplate);
                LicenseTemplate licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template:", licenseTemplate);

                licenseTemplate = LicenseTemplateService.get(context, demoLicenseTemplate1_Number);
                ConsoleWriter.WriteEntity("Got licenseTemplate:", licenseTemplate);

                List<LicenseTemplate> licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                LicenseTemplate updateLicenseTemplate = new LicenseTemplate();
                updateLicenseTemplate.active = true;
                updateLicenseTemplate.automatic = demoLicenseTemplate1_Automatic; // workaround: at the moment not specified booleans treated as "false"
                updateLicenseTemplate.hidden = demoLicenseTemplate1_Hidden; // workaround: at the moment not specified booleans treated as "false"
                licenseTemplate = LicenseTemplateService.update(context, demoLicenseTemplate1_Number, updateLicenseTemplate);
                ConsoleWriter.WriteEntity("Updated license template:", licenseTemplate);

                LicenseTemplateService.delete(context, demoLicenseTemplate1_Number, true);
                ConsoleWriter.WriteMsg("Deleted LicenseTemplate!");

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template again:", licenseTemplate);

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                #endregion

                #region ****************** Licensee

                Licensee newLicensee = new Licensee();
                newLicensee.number = demoLicenseeNumber;
                Licensee licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee:", licensee);

                List<Licensee> licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                LicenseeService.delete(context, demoLicenseeNumber, true);
                ConsoleWriter.WriteMsg("Deleted licensee!");

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee again:", licensee);

                licensee = LicenseeService.get(context, demoLicenseeNumber);
                ConsoleWriter.WriteEntity("Got licensee:", licensee);

                Licensee updateLicensee = new Licensee();
                updateLicensee.licenseeProperties.Add("Updated property name", "Updated value");
                licensee = LicenseeService.update(context, demoLicenseeNumber, updateLicensee);
                ConsoleWriter.WriteEntity("Updated licensee:", licensee);

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                #endregion

                #region ****************** License
                License newLicense = new License();
                newLicense.number = demoLicenseNumber;
                License license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license:", license);

                List<License> licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenses);

                LicenseService.delete(context, demoLicenseNumber);
                Console.WriteLine("Deleted license");

                licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenses);

                license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license again:", license);

                license = LicenseService.get(context, demoLicenseNumber);
                ConsoleWriter.WriteEntity("Got license:", license);

                License updateLicense = new License();
                updateLicense.licenseProperties.Add("Updated property name", "Updated value");
                license = LicenseService.update(context, demoLicenseNumber, null, updateLicense);
                ConsoleWriter.WriteEntity("Updated license:", license);

                #endregion

                #region ****************** PaymentMethod

                List<PaymentMethod> paymentMethods = PaymentMethodService.list(context);
                ConsoleWriter.WriteList("Got the following payment methods:", paymentMethods);

                #endregion

                #region ****************** Validate

                ValidationResult validationResult = LicenseeService.validate(context, demoLicenseeNumber, demoProductNumber);
                ConsoleWriter.WriteEntity("Validation result for created licensee:", validationResult);
                #endregion

                #region ****************** Token

                Token token = TokenService.generate(context, demoTokenType, demoLicenseeNumber);
                ConsoleWriter.WriteEntity("Got the following token:", token);

                #endregion

            }
            catch (LmBoxException e)
            {
                Console.WriteLine("Got LmBox exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup - delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (LmBoxException e)
                {
                    Console.WriteLine("Got LmBox exception during cleanup:");
                    Console.WriteLine(e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got exception during cleanup:");
                    Console.WriteLine(e);
                }
            }

            Console.WriteLine("Press <Enter> to exit...");
            Console.ReadLine();
        }
        /// <summary>
        /// Validates active licenses of the licensee. See LmBoxAPI JavaDoc for details:
        /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseeService.html
        /// </summary>
        public static ValidationResult validate(Context context, String number, String productNumber)
        {
            Dictionary<String, String> parameters = new Dictionary<String, String>();
            if (productNumber != null || productNumber.Length > 0)
            {
                parameters.Add("productNumber", productNumber);
            }

            lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.Licensee.ENDPOINT_PATH + "/" + number + "/validate", parameters);
            return new ValidationResult(output);
        }
 /// <summary>
 /// Updates licensee properties. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseeService.html
 /// </summary>
 public static Licensee update(Context context, String number, Licensee updateLicensee)
 {
     updateLicensee.number = number;
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.POST, Constants.Licensee.ENDPOINT_PATH + "/" + number, updateLicensee.ToDictionary());
     return new Licensee(output.items[0]);
 }
 /// <summary>
 /// Gets licensee by its number. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseeService.html
 /// </summary>
 public static Licensee get(Context context, String number)
 {
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.Licensee.ENDPOINT_PATH + "/" + number, null);
     return new Licensee(output.items[0]);
 }
 /// <summary>
 /// Deletes licensee. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseeService.html
 /// </summary>
 public static void delete(Context context, String number, Boolean forceCascade)
 {
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.DELETE, Constants.Licensee.ENDPOINT_PATH + "/" + number, Utilities.forceCascadeToDict(forceCascade));
 }
 /// <summary>
 /// Creates new licensee object with given properties. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseeService.html
 /// </summary>
 public static Licensee create(Context context, String productNumber, Licensee newLicensee)
 {
     newLicensee.productNumber = productNumber;
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.POST, Constants.Licensee.ENDPOINT_PATH, newLicensee.ToDictionary());
     return new Licensee(output.items[0]);
 }
 /// <summary>
 /// Updates payment method with the given number.. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/PaymentMethodService.html
 /// </summary>
 public static PaymentMethod update(Context context, String number, PaymentMethod newPaymentMethod)
 {
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.POST, Constants.PaymentMethod.ENDPOINT_PATH + "/" + number, newPaymentMethod.ToDictionary());
     return new PaymentMethod(output.items[0]);
 }
 /// <summary>
 /// Gets payment method by its number. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/PaymentMethodService.html
 /// </summary>
 public static PaymentMethod get(Context context, String number)
 {
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.GET, Constants.PaymentMethod.ENDPOINT_PATH + "/" + number, null);
     return new PaymentMethod(output.items[0]);
 }
 /// <summary>
 /// Deletes license template. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/LicenseTemplateService.html
 /// </summary>
 public static void delete(Context context, String number, Boolean forceCascade)
 {
     String strCascade = Convert.ToString(forceCascade).ToLower();
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.DELETE, Constants.LicenseTemplate.ENDPOINT_PATH + "/" + number, Utilities.forceCascadeToDict(forceCascade));
 }
 /// <summary>
 /// Updates product properties. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/ProductService.html
 /// </summary>
 public static Product update(Context context, String number, Product updateProduct)
 {
     updateProduct.number = number;
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.POST, Constants.Product.ENDPOINT_PATH + "/" + number, updateProduct.ToDictionary());
     return new Product(output.items[0]);
 }
 /// <summary>
 /// Creates new product object with given properties. See LmBoxAPI JavaDoc for details:
 /// http://lmbox.labs64.com/javadoc/index.html?com/labs64/lmbox/core/service/ProductService.html
 /// </summary>
 public static Product create(Context context, Product newProduct)
 {
     lmbox output = LmBoxAPI.request(context, LmBoxAPI.Method.POST, Constants.Product.ENDPOINT_PATH, newProduct.ToDictionary());
     return new Product(output.items[0]);
 }