public static ListModuleService Create(ListMethodType methodType)
        {
            ListModuleService listManageModule;

            switch (methodType)
            {
            case ListMethodType.NEWS:
                listManageModule = new NewsModule();
                break;

            case ListMethodType.PRODUCT:
                listManageModule = new ProductModule();
                break;

            case ListMethodType.PRODUCTKIND:
                listManageModule = new ProductKindModule();
                break;

            case ListMethodType.WORKS:
                listManageModule = new WorksModule();
                break;

            case ListMethodType.AGENT:
                listManageModule = new AgentModule();
                break;

            default:
                listManageModule = null;
                break;
            }
            return(listManageModule);
        }
Пример #2
0
        /// <summary>
        /// Updates product module properties. See NetLicensingAPI JavaDoc for details:
        /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/ProductModuleService.html
        /// </summary>
        public static ProductModule update(Context context, String number, ProductModule updateProductModule)
        {
            updateProductModule.number = number;
            netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.ProductModule.ENDPOINT_PATH + "/" + number, updateProductModule.ToDictionary());

            return(new ProductModule(output.items.item[0]));
        }
Пример #3
0
        /// <summary>
        /// Creates new ProductModel object with given properties. See NetLicensingAPI JavaDoc for details:
        /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/ProductModuleService.html
        /// </summary>
        public static ProductModule create(Context context, String productNumber, ProductModule newProductModule)
        {
            newProductModule.productNumber = productNumber;
            netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.ProductModule.ENDPOINT_PATH, newProductModule.ToDictionary());

            return(new ProductModule(output.items.item[0]));
        }
Пример #4
0
        public ViewModelLocator()
        {
            PersonModule = new PersonModule();

            ProductModule = new ProductModule();

            CalculationModule = new CalculationModule();
        }
Пример #5
0
 public ErpService()
 {
     ErpName        = "LogoGoPlus";
     CustomerModule = new CustomerModule(this);
     ProductModule  = new ProductModule();
     InvoiceModule  = null;
     DespatchModule = null;
 }
Пример #6
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // внедрение зависимостей
            NinjectModule orderModule   = new ProductModule();
            NinjectModule serviceModule = new ServiceModule("NLayerContext");
            var           kernel        = new StandardKernel(orderModule, serviceModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Пример #7
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            NinjectModule productModule = new ProductModule();
            NinjectModule serviceModule = new ServiceModule("Default");
            var           kernel        = new StandardKernel(productModule, serviceModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
            Database.SetInitializer <ApplicationDbContext>(new UserDbInitializer());
        }
Пример #8
0
        protected void cboOptionValue_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectedOptions = new List <OptionListInfo>();
            DropDownList cbo = sender as DropDownList;

            if (cbo != null && cbo.SelectedItem != null)
            {
                cbo.Attributes.Remove("style");
                cbo.Attributes.Add("style", cbo.SelectedItem.Attributes["style"]);
            }

            ProductModule.ResetWarning();
        }
Пример #9
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // внедрение зависимостей
            NinjectModule productModule = new ProductModule();
            NinjectModule serviceModule = new ServiceModule("ProductStore");
            var           kernel        = new StandardKernel(productModule, serviceModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Пример #10
0
        /// <summary>
        /// 方法说明:PBOM文件夹新增
        /// 作    者:jason.tang
        /// 完成时间:2013-03-13
        /// </summary>
        /// <param name="product">产品文件夹实体</param>
        /// <returns>Guid</returns>
        public static Guid InsertPBomFolder(ProductModule product)
        {
            Guid result;

            try
            {
                result = ProductModuleDAL.InsertPBomFolder(product);
            }
            catch
            {
                throw;
            }
            return(result);
        }
Пример #11
0
        public void ShouldGetProduct()
        {
            MockedDatabase <Product> database;
            ProductModule            module;
            Product result;

            database = new MockedDatabase <Product>(false, 1, (t) => new Product()
            {
                ProductID = t
            });
            module = new ProductModule(NullLogger.Instance, database);
            result = module.GetProduct(1);
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.ProductID);
        }
Пример #12
0
        protected void Application_Start()
        {
            ModelBinders.Binders.Add(typeof(ProductViewModel), new CartModelBinder());
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            NinjectModule productModule = new ProductModule();
            NinjectModule adminModule   = new AdminModule();
            NinjectModule serviceModule = new ServiceModule("IdentityDB");
            var           kernel        = new StandardKernel(productModule, adminModule, serviceModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
            Database.SetInitializer <ApplicationDbContext>(new UserDbInitializer());
        }
Пример #13
0
        public void ShouldNotGetProductsAndLogError()
        {
            MockedDatabase <Product> database;
            ProductModule            module;
            MemoryLogger             logger;


            logger   = new MemoryLogger();
            database = new MockedDatabase <Product>(true, 3, (t) => new Product()
            {
                ProductID = t
            });
            module = new ProductModule(logger, database);
            Assert.ThrowsException <PIODataException>(() => module.GetProducts(BuildingTypeIDs.Stockpile));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));
        }
Пример #14
0
        public void ShouldCreateProduct()
        {
            MockedDatabase <Product> database;
            ProductModule            module;
            Product result;

            database = new MockedDatabase <Product>(false, 1, (t) => new Product()
            {
                ProductID = t
            });
            module = new ProductModule(NullLogger.Instance, database);
            result = module.CreateProduct(BuildingTypeIDs.Forest, ResourceTypeIDs.Wood, 1, 10);
            Assert.IsNotNull(result);
            Assert.AreEqual(ResourceTypeIDs.Wood, result.ResourceTypeID);
            Assert.AreEqual(1, database.InsertedCount);
        }
Пример #15
0
        public void ShouldNotCreateProductAndLogError()
        {
            MockedDatabase <Product> database;
            ProductModule            module;
            MemoryLogger             logger;


            logger   = new MemoryLogger();
            database = new MockedDatabase <Product>(true, 1, (t) => new Product()
            {
                ProductID = t
            });
            module = new ProductModule(logger, database);
            Assert.ThrowsException <PIODataException>(() => module.CreateProduct(BuildingTypeIDs.Forest, ResourceTypeIDs.Wood, 1, 10));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));
            Assert.AreEqual(0, database.InsertedCount);
        }
Пример #16
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);



            //внедрение зависимостей
            NinjectModule orderModule   = new OrderModule();
            NinjectModule productModule = new ProductModule();
            NinjectModule serviceModule = new ServiceModule("WebApiContext");
            var           kernel        = new StandardKernel(orderModule, productModule, serviceModule);

            GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(kernel);
        }
Пример #17
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            ServiceModule serviceModule = new ServiceModule("EFdbContext");
            ProductModule orderModule   = new ProductModule();
            var           kernel        = new StandardKernel(serviceModule, orderModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

            //NinjectModule productModule = new ProductModule();
            //NinjectModule serviceModule = new ServiceModule("EFdbContext");
            //var kernel = new StandardKernel(productModule, serviceModule);
            //DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Пример #18
0
        protected void Application_Start()
        {
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            NinjectModule productModule = new ProductModule();
            NinjectModule cartModule    = new CartModule();
            NinjectModule serviceModule = new ServiceModule("DefaultConnection");
            var           kernel        = new StandardKernel(productModule, cartModule, serviceModule);

            kernel.Unbind <ModelValidatorProvider>();
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

            ModelBinders.Binders.Add(typeof(CartDTO), new CartModelBinder());
        }
Пример #19
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // подключение modelbinder
            ModelBinders.Binders.Add(typeof(CartSVCClient), new CartModelBinder());

            // внедрение зависимостей
            NinjectModule productModule        = new ProductModule();
            NinjectModule orderProcessorModule = new OrderProcessorModule();
            NinjectModule salesPersonModule    = new SalesPersonModule();
            NinjectModule accountModule        = new AccountModule();
            NinjectModule serviceModule        = new ServiceModule("ItmContext");
            var           kernel = new StandardKernel(productModule, orderProcessorModule, salesPersonModule, accountModule, serviceModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
            kernel.Unbind <ModelValidatorProvider>();
        }
Пример #20
0
        public void ShouldGetProducts()
        {
            MockedDatabase <Product> database;
            ProductModule            module;

            Product[] results;

            database = new MockedDatabase <Product>(false, 3, (t) => new Product()
            {
                ProductID = t
            });
            module  = new ProductModule(NullLogger.Instance, database);
            results = module.GetProducts(BuildingTypeIDs.Stockpile);
            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.Length);
            for (int t = 0; t < 3; t++)
            {
                Assert.IsNotNull(results[t]);
                Assert.AreEqual(t, results[t].ProductID);
            }
        }
Пример #21
0
        /// <summary>
        /// 方法说明:新建文件夹
        /// 作    者:jason.tang
        /// 完成时间:2013-03-13
        /// </summary>
        private void NewFolder()
        {
            TreeNode node = tvMaterialPBom.SelectedNode;

            if (node != null)
            {
                TreeNode tn = new TreeNode();
                tn.ImageKey = "folder";

                ProductModule pm = new ProductModule();
                if (node.Tag != null)
                {
                    pm.ParentFolderId = node.Tag.ToString();
                }
                CommonInputFrm frm = new CommonInputFrm();
                frm.CommonObject = pm;

                //从属性类获取对应的Attributes
                AttributeCollection attributes =
                    TypeDescriptor.GetProperties(pm)["FolderCode"].Attributes;

                // 从属性集合获取分类属性
                CategoryAttribute myAttribute =
                    (CategoryAttribute)attributes[typeof(CategoryAttribute)];

                frm.FormTitle = myAttribute.Category;
                //MainFrm.mainFrm.OpenModule(frm);
                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    pm = (ProductModule)frm.CommonObject;
                    Guid gid = ProductModuleBLL.InsertPBomFolder(pm);
                    tn.Text = pm.FolderName;
                    tn.Name = gid.ToString();
                    tn.Tag  = gid.ToString();
                    node.Nodes.Add(tn);
                }
            }
        }
Пример #22
0
 protected void txtOptionValue_TextChanged(object sender, EventArgs e)
 {
     _selectedOptions = new List <OptionListInfo>();
     ProductModule.ResetWarning();
 }
Пример #23
0
        static int Main(string[] args)
        {
            // ServicePointManager.ServerCertificateValidationCallback = delegate { return true;  // Trust any (self-signed) certificate };

            Context context = new Context();

            context.baseUrl = "https://go.netlicensing.io/core/v2/rest";

            context.username     = "******";
            context.password     = "******";
            context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

            String randomNumber = randomString(8);

            String  demoProductNumber              = numberWithPrefix("P", randomNumber);
            String  demoProductModuleNumber        = numberWithPrefix("PM", randomNumber);
            String  demoLicensingModel             = Constants.LicensingModel.TryAndBuy.NAME;
            String  demoLicenseTemplate1_Number    = numberWithPrefix("LT", randomNumber);
            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             = numberWithPrefix("L", randomNumber);
            String  demoLicenseNumber              = numberWithPrefix("LC", randomNumber);
            String  demoLicenseeName = "Demo Licensee";

            try
            {
                #region ****************** Lists

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

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

                #endregion

                #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 after delete:", 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 licenses:", licenses);

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

                licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following licenses:", 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 ****************** Token

                //NetLicensing supports API Key Identification to allow limited API access on vendor's behalf.
                //See: https://netlicensing.io/wiki/security for details.
                Token newToken = new Token();
                newToken.tokenType = Constants.Token.TYPE_APIKEY;
                Token apiKey = TokenService.create(context, newToken);
                ConsoleWriter.WriteEntity("Created APIKey:", apiKey);
                context.apiKey = apiKey.number;

                newToken.tokenType = Constants.Token.TYPE_SHOP;
                newToken.tokenProperties.Add(Constants.Licensee.LICENSEE_NUMBER, demoLicenseeNumber);
                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                Token shopToken = TokenService.create(context, newToken);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Got the following shop token:", shopToken);

                String       filter = Constants.Token.TOKEN_TYPE + "=" + Constants.Token.TYPE_SHOP;
                List <Token> tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens:", tokens);

                TokenService.delete(context, shopToken.number);
                ConsoleWriter.WriteMsg("Deactivated shop token!");

                tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens after deactivate:", tokens);

                #endregion

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

                ValidationParameters validationParameters = new ValidationParameters();
                validationParameters.setLicenseeName(demoLicenseeName);
                validationParameters.setProductNumber(demoProductNumber);
                validationParameters.put(demoProductModuleNumber, "paramKey", "paramValue");
                ValidationResult validationResult = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                ConsoleWriter.WriteEntity("Validation result for created licensee:", validationResult);

                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Validation repeated with APIKey:", validationResult);

                #endregion

                #region ****************** Transfer

                Licensee transferLicensee = new Licensee();
                transferLicensee.number = "TR" + demoLicenseeNumber;
                transferLicensee.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicensee = LicenseeService.create(context, demoProductNumber, transferLicensee);
                ConsoleWriter.WriteEntity("Added transfer licensee:", transferLicensee);

                License transferLicense = new License();
                transferLicense.number = "LTR" + demoLicenseNumber;
                License newTransferLicense = LicenseService.create(context, transferLicensee.number, demoLicenseTemplate1_Number, null, transferLicense);
                ConsoleWriter.WriteEntity("Added license for transfer:", newTransferLicense);

                LicenseeService.transfer(context, licensee.number, transferLicensee.number);

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                Licensee transferLicenseeWithApiKey = new Licensee();
                transferLicenseeWithApiKey.number = "Key" + demoLicenseeNumber;
                transferLicenseeWithApiKey.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicenseeWithApiKey = LicenseeService.create(context, demoProductNumber, transferLicenseeWithApiKey);

                License transferLicenseWithApiKey = new License();
                transferLicenseWithApiKey.number = "Key" + demoLicenseNumber;
                LicenseService.create(context, transferLicenseeWithApiKey.number, demoLicenseTemplate1_Number, null,
                                      transferLicenseWithApiKey);

                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                LicenseeService.transfer(context, licensee.number, transferLicenseeWithApiKey.number);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                #endregion

                #region ****************** Transactions

                List <Transaction> transactions = TransactionService.list(context, Constants.Transaction.SOURCE_SHOP_ONLY + "=" + Boolean.TrueString.ToLower());
                ConsoleWriter.WriteList("Got the following transactions shop only:", transactions);

                transactions = TransactionService.list(context, null);
                ConsoleWriter.WriteList("Got the following transactions after transfer:", transactions);

                #endregion

                Console.WriteLine("All done.");

                return(0);
            }
            catch (NetLicensingException e)
            {
                Console.WriteLine("Got NetLicensing exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup:
                    context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                    // deactivate api key in case APIKey was used (exists)
                    if (!String.IsNullOrEmpty(context.apiKey))
                    {
                        TokenService.delete(context, context.apiKey);
                    }
                    // delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (NetLicensingException e)
                {
                    Console.WriteLine("Got NetLicensing exception during cleanup:");
                    Console.WriteLine(e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got exception during cleanup:");
                    Console.WriteLine(e);
                }
            }

            return(1);
        }
Пример #24
0
        /// <summary>
        /// 短信ISMP 需要的配置接口
        /// </summary>
        /// <returns></returns>
        public ActionResult ISMPConfigList()
        {
            string host = Util.SMSHost;

            IProductConfiguration config = new ProductConfiguration();

            config.ProductId = Util.SMSProductId;

            config.PaymentsType = new List <string>()
            {
                "短信充值"
            };

            #region Functions
            config.Functions = new List <IProductFunction>();

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSActive" + Util.ProductSuffix,
                Name         = "短信激活" + Util.MenuSuffix,
                FunctionType = FunctionType.Activate,
                Url          = "----"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSSale" + Util.ProductSuffix,
                Name         = "短信销售" + Util.MenuSuffix,
                FunctionType = FunctionType.Sale,
                Url          = host + @"/Sale"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSRecharge" + Util.ProductSuffix,
                Name         = "短信充值" + Util.MenuSuffix,
                FunctionType = FunctionType.Recharge,
                Url          = host + @"/Sale/Recharge"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSCommand" + Util.ProductSuffix,
                Name         = "命令" + Util.MenuSuffix,
                FunctionType = FunctionType.Command,
                Url          = host + "/SMS/Command"
            });


            config.Functions.Add(new ProductAudit()
            {
                AuditsType   = Util.AuditTypeList,
                Id           = "SMSAudit" + Util.ProductSuffix,
                Name         = "短信产品审核" + Util.MenuSuffix,
                FunctionType = FunctionType.Audit,
                Url          = host + "/Platform/Audit"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSAuditEdit" + Util.ProductSuffix,
                Name         = "短信产品审核失败编辑重提" + Util.MenuSuffix,
                FunctionType = FunctionType.AuditEdit,
                Url          = host + "/Platform/AuditEdit"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSSaleCheckSubmit" + Util.ProductSuffix,
                Name         = "套餐验证" + Util.MenuSuffix,
                FunctionType = FunctionType.SaleCheckSubmit,
                Url          = host + "/SMS/SaleCheckSubmit"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSEnterpriseSMSStatus" + Util.ProductSuffix,
                Name         = "短信详单" + Util.MenuSuffix,
                FunctionType = FunctionType.Status,
                Url          = host + "/Enterprise/EnterpriseSMSStatus"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSEnterpriseSMSHomePageStatistics" + Util.ProductSuffix,
                Name         = "短信首页统计" + Util.MenuSuffix,
                FunctionType = FunctionType.HomePageStatistics,
                Url          = host + "/Enterprise/EnterpriseSMSHomePageStatistics"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSEnterpriseSMSAutoRechargeAsk" + Util.ProductSuffix,
                Name         = "短信企业自充值可选金额或套餐查询" + Util.MenuSuffix,
                FunctionType = FunctionType.AutoRechargeAsk,
                Url          = host + "/Enterprise/EnterpriseSMSAutoRechargeAsk"
            });

            config.Functions.Add(new ProductFunction()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSEnterpriseSMSAutoRecharge" + Util.ProductSuffix,
                Name         = "短信企业自充值" + Util.MenuSuffix,
                FunctionType = FunctionType.AutoRecharge,
                Url          = host + "/Enterprise/EnterpriseSMSAutoRecharge"
            });

            #endregion

            config.Modules = new List <IProductModule>();



            #region 中呼端功能

            IProductModule GatewayConfig = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSGateway" + Util.ProductSuffix,
                Name         = "网关配置" + Util.MenuSuffix,
                Url          = host + "/Platform/GatewayConfig",
                OrderNumber  = 100,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(GatewayConfig);

            IProductModule Channel = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSChannel" + Util.ProductSuffix,
                Name         = "通道配置" + Util.MenuSuffix,
                Url          = host + "/Platform/ChannelManage",
                OrderNumber  = 200,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(Channel);

            IProductModule SMSSystemBlackList = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSSystemBlackList" + Util.ProductSuffix,
                Name         = "系统黑名单" + Util.MenuSuffix,
                Url          = host + "/Platform/SMSSystemBlackList",
                OrderNumber  = 300,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSSystemBlackList);

            IProductModule SMSKeywordsGroup = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSKeywordsGroup" + Util.ProductSuffix,
                Name         = "敏感词组" + Util.MenuSuffix,
                Url          = host + "/Platform/KeywordsGroup",
                OrderNumber  = 400,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSKeywordsGroup);

            IProductModule SMSKeywords = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSKeywords" + Util.ProductSuffix,
                Name         = "敏感词" + Util.MenuSuffix,
                Url          = host + "/Platform/Keywords",
                OrderNumber  = 500,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSKeywords);

            IProductModule SMSSendSMSAudit = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSSendSMSAudit" + Util.ProductSuffix,
                Name         = "短信审核" + Util.MenuSuffix,
                Url          = host + "/Platform/SendSMSAudit",
                OrderNumber  = 600,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSSendSMSAudit);


            IProductModule SMSSendSMSAuditRecord = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSSendSMSAuditRecord" + Util.ProductSuffix,
                Name         = "短信审核记录" + Util.MenuSuffix,
                Url          = host + "/Platform/SendSMSAuditRecord",
                OrderNumber  = 700,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSSendSMSAuditRecord);


            IProductModule SMSSendSMSList = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSSendSMSList" + Util.ProductSuffix,
                Name         = "短信质检" + Util.MenuSuffix,
                Url          = host + "/Platform/SMSSendSMSList",
                OrderNumber  = 750,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSSendSMSList);

            IProductModule SMSTemplateAuditRecord = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSTemplateAuditRecord" + Util.ProductSuffix,
                Name         = "模板审核记录" + Util.MenuSuffix,
                Url          = host + "/Platform/TemplateAuditRecord",
                OrderNumber  = 800,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSTemplateAuditRecord);

            IProductModule EnterpriseChannelSettingList = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "EnterpriseChannelSettingList" + Util.ProductSuffix,
                Name         = "企业通道设置" + Util.MenuSuffix,
                Url          = host + "/Platform/EnterpriseChannelSettingList",
                OrderNumber  = 900,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(EnterpriseChannelSettingList);

            IProductModule SMSEnterpriseSetting = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSEnterpriseSetting" + Util.ProductSuffix,
                Name         = "企业设置" + Util.MenuSuffix,
                Url          = host + "/Platform/EnterpriseSetting",
                OrderNumber  = 1000,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSEnterpriseSetting);

            IProductModule SMSStatistics = new ProductModule()
            {
                FunctionRole = FunctionRole.System,
                Id           = "SMSStatistics" + Util.ProductSuffix,
                Name         = "短信统计" + Util.MenuSuffix,
                Url          = host + "/Platform/SMSStatistics",
                OrderNumber  = 2100,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSStatistics);
            #endregion



            #region 企业端功能

            IProductModule SMSContacts = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSContacts" + Util.ProductSuffix,
                Name         = "通讯录" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSContacts",
                OrderNumber  = 10100,
                Permissions  = new List <IPermission>(),
            };
            config.Modules.Add(SMSContacts);

            IProductModule SendSMS = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSSendSMS" + Util.ProductSuffix,
                Name         = "发送短信" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SendSMS",
                OrderNumber  = 10200,
                Permissions  = new List <IPermission>(),
            };
            config.Modules.Add(SendSMS);

            IProductModule SMSView = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSView" + Util.ProductSuffix,
                Name         = "短信查询" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSView",
                OrderNumber  = 10250,
                Permissions  = new List <IPermission>(),
            };
            config.Modules.Add(SMSView);

            IProductModule SMSTemplet = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSTemplet" + Util.ProductSuffix,
                Name         = "短信模板" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSTemplet",
                OrderNumber  = 10300,
                Permissions  = new List <IPermission>(),
            };
            config.Modules.Add(SMSTemplet);

            IProductModule SMSStatus = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSStatus" + Util.ProductSuffix,
                Name         = "状态报告(3天以内)" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSStatus",
                OrderNumber  = 10400,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSStatus);

            IProductModule SMSStatusHistory = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSStatusHistory" + Util.ProductSuffix,
                Name         = "历史状态报告" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSStatusHistory",
                OrderNumber  = 10500,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSStatusHistory);


            IProductModule SMSMoList = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSMoList" + Util.ProductSuffix,
                Name         = "接收短信" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSMoList",
                OrderNumber  = 10600,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSMoList);

            IProductModule SMSAuditFailure = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSAuditFailure" + Util.ProductSuffix,
                Name         = "审核失败短信" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSAuditFailure",
                OrderNumber  = 10700,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSAuditFailure);

            IProductModule SMSEnterpriseBlackList = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSEnterpriseBlackList" + Util.ProductSuffix,
                Name         = "企业黑名单" + Util.MenuSuffix,
                Url          = host + "/Enterprise/SMSEnterpriseBlackList",
                OrderNumber  = 10800,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSEnterpriseBlackList);

            IProductModule SMSChangePassword = new ProductModule()
            {
                FunctionRole = FunctionRole.Enterprise,
                Id           = "SMSChangePassword" + Util.ProductSuffix,
                Name         = "设置发送密码" + Util.MenuSuffix,
                Url          = host + "/Enterprise/ChangePassword",
                OrderNumber  = 10900,
                Permissions  = new List <IPermission>()
            };
            config.Modules.Add(SMSChangePassword);

            #endregion

            return(Content(JsonSerialize.Instance.Serialize(config)));
        }
Пример #25
0
 public ProductController(IceFactoryUnitOfWork unitOfWork) : base(unitOfWork)
 {
     _objModule = new ProductModule(unitOfWork);
 }
Пример #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            ProductModule productModule = new ProductModule();

            productModule.ShowDialog();
        }
Пример #27
0
        static void Main(string[] args)
        {
            // ServicePointManager.ServerCertificateValidationCallback = delegate { return true;  // Trust any (self-signed) certificate };

            Context context = new Context();

            context.baseUrl      = "https://netlicensing.labs64.com";
            context.username     = "******";
            context.password     = "******";
            context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;

            String  demoProductNumber              = "P001demo";
            String  demoProductModuleNumber        = "M001demo";
            String  demoLicensingModel             = "TimeLimitedEvaluation";
            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";

            try
            {
                #region ****************** Lists

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

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

                #endregion

                #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 after delete:", 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 ****************** Token

                Token newToken = new Token();
                newToken.tokenType = Constants.Token.TYPE_APIKEY;
                Token apiKey = TokenService.create(context, newToken);
                ConsoleWriter.WriteEntity("Created API Key:", apiKey);
                context.apiKey = apiKey.number;

                newToken.tokenType = Constants.Token.TYPE_SHOP;
                newToken.tokenProperties.Add(Constants.Licensee.LICENSEE_NUMBER, demoLicenseeNumber);
                context.securityMode = SecutiryMode.APIKEY_IDENTIFICATION;
                Token shopToken = TokenService.create(context, newToken);
                context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Got the following shop token:", shopToken);

                List <Token> tokens = TokenService.list(context, Constants.Token.TYPE_SHOP, null);
                ConsoleWriter.WriteList("Got the following shop tokens:", tokens);

                TokenService.deactivate(context, shopToken.number);
                ConsoleWriter.WriteMsg("Deactivated shop token!");

                tokens = TokenService.list(context, Constants.Token.TYPE_SHOP, null);
                ConsoleWriter.WriteList("Got the following shop tokens after deactivate:", tokens);

                #endregion

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

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

                context.securityMode = SecutiryMode.APIKEY_IDENTIFICATION;
                validationResult     = LicenseeService.validate(context, demoLicenseeNumber, demoProductNumber);
                context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Validation repeated with API Key:", validationResult);

                #endregion
            }
            catch (NetLicensingException e)
            {
                Console.WriteLine("Got NetLicensing exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup:
                    context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;
                    // deactivate api key
                    TokenService.deactivate(context, context.apiKey);
                    // delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (NetLicensingException e)
                {
                    Console.WriteLine("Got NetLicensing 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();
        }
Пример #28
0
 public RedirectResult Add(ProductModule data)
 {
     _pmServ.Add(data);
     return(Redirect("/CRMarea/Product/List"));
 }
Пример #29
0
        static int Main(string[] args)
        {
            Context context = new Context();

            context.baseUrl = "https://go.netlicensing.io/core/v2/rest";

            context.username     = "******";
            context.password     = "******";
            context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

            String randomNumber = randomString(8);

            String  demoProductNumber              = numberWithPrefix("P", randomNumber);
            String  demoProductModuleNumber        = numberWithPrefix("PM", randomNumber);
            String  demoLicensingModel             = Constants.LicensingModel.TryAndBuy.NAME;
            String  demoLicenseTemplate1_Number    = numberWithPrefix("LT", randomNumber);
            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             = numberWithPrefix("L", randomNumber);
            String  demoLicenseNumber              = numberWithPrefix("LC", randomNumber);
            String  demoLicenseeName = "Demo Licensee";

            try
            {
                #region ****************** Lists

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

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

                #endregion

                #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 after delete:", 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 licenses:", licenses);

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

                licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following licenses:", 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 ****************** Token

                string privateKey      = @"-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7mCuhtyeM+HM6
/IbTkM45bpKVQgpruiaEksheXwPx+iG4dRpkugYDYWi3g4/+oVKDQMrh6BsJtT6k
Otqwy8q81MIzPDTKnNvIERphKbrC0R5TjmmlrCPQeM6Hc1GnYOzSFHzFIwoVFz/h
3zuGySPKMpc6qg5mGqNfBiTuhwh7oAM+kXhgKzl5jj/cIvUmci12UpBGyXxknRip
75+KB/1qAJa9DQ7R9pF2aCavt5SFT1pc29IlpUlduDpOOGHFW6PN6EXyyH/uzGAb
CpvK6cTXk5ajp0CtELI1R5E6770mni0RP7ZED8+6pBtZboRslYGGmSo13OL0Ji6G
5SO+TyZ3AgMBAAECggEBAItqwjKDbg9kri7Ocl1Vpw4j0SjAVgJN7EZm2CbaspHp
dZoi3aSyY7mrcSnBywhQWIRXaPCPkVibrJxdaR4vttKzxEhTnGBgRy7fFx3S54vV
4pXypy2LS2qp/cPIvoyIijhvJXNVYS7fgoiZYSIA5mplQuNEc0MK1RPP+y6SiIlm
0SEXUXl5OYn3AGQ6hJJXxbN36kOtcwb33C/cY3b9jPl1acAVk84dFl0aAv92ArST
PahsxQDbRDaDxZ/lfk1mZqPexiWorAZWMck8nOyZhKu5/oXy6OcXfqVjdwmlqY05
hNS7mxSOUy+7umqbcV/bdhvqMJr+DeI1vqQS5J+t3vECgYEA8GZ6oxUiuwYJ98jS
Nx+i7Jj+ZTEFJ7WiepX5mOU13GlS0vAvhPdK9juEYbS7Znpp35WgwxuPsCn9hXIO
gjR0eSYN7QB5RVn7zjo+SQRw2C+HAt7G/wazq3ekSdNgKe8+Wa7YxLL8ypaOy1me
7L4JQGgM6ORgnYH/+BC7P/KO80MCgYEAx8R7W2Fzo1I+RPfKQeVQ/i4a+/DMK0js
XhpkMh/8NXbdHYNDdsQTQ2E8V+5gNi+zCqMuwIxA8cx9lAL32x1fMWnbHV9YwSFZ
ZOEG/YFyqcBOtQztt8jHGtXN70FQdwSwqcFdntNTCjJquN2gX1n2qFR2bezcULaj
Iiyc/j3AWr0CgYBQmbtidFKpq/OpnS5GBxhkBUO9/7p/vtlUCnad+bOeS73WNWtp
RFRgzEGtVKBEUqSurwcwg0wgv2Nd24jbxOSMPeMLZE5En0/arBJ3/sIq6Xx1zOWh
Wcjho4J0sicayDj6brIE+RHihqonqcusCmclrf0uFGwEQzLkJA/z98pP6wKBgAti
iEE5+ZQqQMA/evhscEQ8Lm+DVq901Xu7d1BgAEivwIRJEdQ38n0Zko3UWQldiI+n
oyd4Fs9w/wsrbCLBtsYjKUiwQWeoVebo6DQUZ4uDGTk6RmX9/FLsMnNbPpG547OZ
AJPnqUjgfLKSduxYPTV0stcq85dqATwWXNAkhszlAoGBAOKLU6IKuiRLcOrVon/a
KlXkjBMP2EkTVhuIzgZp6v7P8LK+UfU/6vkJvBW5U9ZosS7f13t7/bJ0AzfJLW6m
J1IedEJExbLmuW7+HfEMyZ5g8dFJZvYBmN/zHQEhFUKDISDI2O2gmd9cPPsMnOxW
WW8VMSYMi1Wtb9v7eRPvRZlE
-----END PRIVATE KEY-----";
                string publicKey       = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5grobcnjPhzOvyG05DO
OW6SlUIKa7omhJLIXl8D8fohuHUaZLoGA2Fot4OP/qFSg0DK4egbCbU+pDrasMvK
vNTCMzw0ypzbyBEaYSm6wtEeU45ppawj0HjOh3NRp2Ds0hR8xSMKFRc/4d87hskj
yjKXOqoOZhqjXwYk7ocIe6ADPpF4YCs5eY4/3CL1JnItdlKQRsl8ZJ0Yqe+figf9
agCWvQ0O0faRdmgmr7eUhU9aXNvSJaVJXbg6TjhhxVujzehF8sh/7sxgGwqbyunE
15OWo6dArRCyNUeROu+9Jp4tET+2RA/PuqQbWW6EbJWBhpkqNdzi9CYuhuUjvk8m
dwIDAQAB
-----END PUBLIC KEY-----";
                string publicKey_wrong = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtq96itv1m00/czFD7IzE
mLiXPpvok1vjqB9VU6kTkq6QFGAfJF1G+m1fbK5NvpiDCsfuofdCFuhVnvLnzrpd
xUlse8erWEr9p9RAyh25NMK9/v0MAEAYV7zRa+ZOh31G54DwR7zk0TxyVzxKpjPi
wQSnv7UCY/IR7remLIYO92K7jAg9ZB4IHTuVulCtSrSQajZ8Ep2rFGPr8OeTsj9c
rBPpmL/ShdJOnL4NR0UnVWSpsCFW6wEqNafcUWnWpb98V49/p7fWDFJ1Tg6+OlVg
lgsNrqrqwJpxDLKnGAkkxHaVxSnZzAYh+HP8CbJmbzzE1GRXNgy3w+smWMv6M996
9wIDAQAB
-----END PUBLIC KEY-----";
                Console.WriteLine("loaded privateKey: {0}", privateKey);
                Console.WriteLine("loaded publicKey: {0}", publicKey);
                Console.WriteLine("loaded publicKey_wrong: {0}", publicKey_wrong);

                //NetLicensing supports API Key Identification to allow limited API access on vendor's behalf.
                //See: https://netlicensing.io/wiki/security for details.
                Token newToken = new Token();
                newToken.tokenType = Constants.Token.TYPE_APIKEY;
                newToken.tokenProperties.Add(Constants.Token.TOKEN_PROP_PRIVATE_KEY, privateKey);
                Token apiKey = TokenService.create(context, newToken);
                ConsoleWriter.WriteEntity("Created APIKey:", apiKey);
                context.apiKey = apiKey.number;

                newToken.tokenType = Constants.Token.TYPE_SHOP;
                newToken.tokenProperties.Add(Constants.Licensee.LICENSEE_NUMBER, demoLicenseeNumber);
                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                Token shopToken = TokenService.create(context, newToken);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Got the following shop token:", shopToken);

                String       filter = Constants.Token.TOKEN_TYPE + "=" + Constants.Token.TYPE_SHOP;
                List <Token> tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens:", tokens);

                TokenService.delete(context, shopToken.number);
                ConsoleWriter.WriteMsg("Deactivated shop token!");

                tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens after deactivate:", tokens);

                #endregion

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

                ValidationParameters validationParameters = new ValidationParameters();
                validationParameters.setLicenseeName(demoLicenseeName);
                validationParameters.setProductNumber(demoProductNumber);
                validationParameters.put(demoProductModuleNumber, "paramKey", "paramValue");

                ValidationResult validationResult = null;

                // Validate using Basic Auth
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                ConsoleWriter.WriteEntity("Validation result (Basic Auth):", validationResult);

                OSPlatform operatingSystem = GetOperatingSystem();
                Console.WriteLine("operatingSystem: {0}", operatingSystem);

                // Verify signature on Linux or OSX only
                // TODO: https://github.com/Labs64/NetLicensingClient-csharp/issues/25
                if (operatingSystem.Equals(OSPlatform.Linux) || operatingSystem.Equals(OSPlatform.OSX))
                {
                    // Validate using APIKey
                    context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                    validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                    ConsoleWriter.WriteEntity("Validation result (APIKey):", validationResult);

                    // Validate using APIKey signed
                    context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                    context.publicKey    = publicKey;
                    validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                    ConsoleWriter.WriteEntity("Validation result (APIKey / signed):", validationResult);

                    // Validate using APIKey wrongly signed
                    context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                    context.publicKey    = publicKey_wrong;
                    try
                    {
                        validationResult = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                    }
                    catch (NetLicensingException e)
                    {
                        Console.WriteLine("Validation result exception (APIKey / wrongly signed): {0}", e);
                    }
                }

                // Reset context for futher use
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                context.publicKey    = null;

                #endregion

                #region ****************** Transfer

                Licensee transferLicensee = new Licensee();
                transferLicensee.number = "TR" + demoLicenseeNumber;
                transferLicensee.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicensee = LicenseeService.create(context, demoProductNumber, transferLicensee);
                ConsoleWriter.WriteEntity("Added transfer licensee:", transferLicensee);

                License transferLicense = new License();
                transferLicense.number = "LTR" + demoLicenseNumber;
                License newTransferLicense = LicenseService.create(context, transferLicensee.number, demoLicenseTemplate1_Number, null, transferLicense);
                ConsoleWriter.WriteEntity("Added license for transfer:", newTransferLicense);

                LicenseeService.transfer(context, licensee.number, transferLicensee.number);

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                Licensee transferLicenseeWithApiKey = new Licensee();
                transferLicenseeWithApiKey.number = "Key" + demoLicenseeNumber;
                transferLicenseeWithApiKey.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicenseeWithApiKey = LicenseeService.create(context, demoProductNumber, transferLicenseeWithApiKey);

                License transferLicenseWithApiKey = new License();
                transferLicenseWithApiKey.number = "Key" + demoLicenseNumber;
                LicenseService.create(context, transferLicenseeWithApiKey.number, demoLicenseTemplate1_Number, null,
                                      transferLicenseWithApiKey);

                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                LicenseeService.transfer(context, licensee.number, transferLicenseeWithApiKey.number);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                #endregion

                #region ****************** Transactions

                List <Transaction> transactions = TransactionService.list(context, Constants.Transaction.SOURCE_SHOP_ONLY + "=" + Boolean.TrueString.ToLower());
                ConsoleWriter.WriteList("Got the following transactions shop only:", transactions);

                transactions = TransactionService.list(context, null);
                ConsoleWriter.WriteList("Got the following transactions after transfer:", transactions);

                #endregion

                Console.WriteLine("All done.");

                return(0);
            }
            catch (NetLicensingException e)
            {
                Console.WriteLine("Got NetLicensing exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup
                    context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                    // Deactivate APIKey in case this was used (exists)
                    if (!String.IsNullOrEmpty(context.apiKey))
                    {
                        TokenService.delete(context, context.apiKey);
                    }
                    // Delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (NetLicensingException e)
                {
                    Console.WriteLine("Got NetLicensing exception during cleanup:");
                    Console.WriteLine(e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got exception during cleanup:");
                    Console.WriteLine(e);
                }
            }

            return(1);
        }
Пример #30
0
        static void Main(string[] args)
        {
            ILogger logger;
            VersionControlModule versionControlModule;
            ServiceHostModule    pioServiceHostModule;
            ServiceHostModule    taskCallbackServiceHostModule;
            SchedulerModule      schedulerModule;

            IPIOService          pioService;
            ITaskCallbackService taskCallbackService;
            IDatabase            database;
            IConnectionFactory   connectionFactory;
            ICommandBuilder      commandBuilder;
            IDatabaseCreator     databaseCreator;

            IPlanetGeneratorModule planetGeneratorModule;

            IPhraseModule       phraseModule;
            IPlanetModule       planetModule;
            ICellModule         cellModule;
            IBuildingModule     buildingModule;
            IWorkerModule       workerModule;
            IBuilderModule      factoryBuilderModule;
            IStackModule        stackModule;
            IResourceTypeModule resourceTypeModule;
            IBuildingTypeModule buildingTypeModule;
            ITaskTypeModule     taskTypeModule;
            IMaterialModule     materialModule;
            IIngredientModule   ingredientModule;
            IProductModule      productModule;
            ITaskModule         taskModule;

            IIdlerModule           idlerModule;
            IResourceCheckerModule resourceCheckerModule;
            ILocationCheckerModule locationCheckerModule;
            IProducerModule        producerModule;
            IHarvesterModule       harvesterModule;
            IMoverModule           moverModule;
            ITakerModule           takerModule;
            IStorerModule          storerModule;

            quitEvent = new AutoResetEvent(false);
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);

            //logger = new ConsoleLogger(new DefaultLogFormatter());
            logger = new UnicastLogger(IPAddress.Loopback, Properties.Settings.Default.UnicastPort);
            //logger = new FileLogger(new DefaultLogFormatter(), "PIO.ServerHost.Log");

            databaseCreator   = new SqlDatabaseCreator(Properties.Settings.Default.Server, Properties.Settings.Default.DatabaseName);
            connectionFactory = new SqlConnectionFactory(Properties.Settings.Default.Server, Properties.Settings.Default.DatabaseName);
            commandBuilder    = new SqlCommandBuilder();
            database          = new Database(connectionFactory, commandBuilder);

            versionControlModule = new VersionControlModule(logger, databaseCreator, new PIOVersionControl(database));
            if (!versionControlModule.InitializeDatabase(Properties.Settings.Default.DropDatabase))
            {
                return;
            }


            phraseModule       = new PhraseModule(logger, database);
            planetModule       = new PlanetModule(logger, database);
            cellModule         = new CellModule(logger, database);
            buildingModule     = new BuildingModule(logger, database);
            workerModule       = new WorkerModule(logger, database);
            stackModule        = new StackModule(logger, database);
            resourceTypeModule = new ResourceTypeModule(logger, database);
            buildingTypeModule = new BuildingTypeModule(logger, database);
            taskTypeModule     = new TaskTypeModule(logger, database);
            materialModule     = new MaterialModule(logger, database);
            ingredientModule   = new IngredientModule(logger, database);
            productModule      = new ProductModule(logger, database);
            taskModule         = new TaskModule(logger, database);


            factoryBuilderModule  = new BuilderModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule);;
            idlerModule           = new IdlerModule(logger, taskModule, workerModule);
            resourceCheckerModule = new ResourceCheckerModule(logger, buildingModule, stackModule, ingredientModule, materialModule);
            locationCheckerModule = new LocationCheckerModule(logger, workerModule, buildingModule);
            producerModule        = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule);
            harvesterModule       = new HarvesterModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule);
            moverModule           = new MoverModule(logger, taskModule, workerModule, buildingModule);
            takerModule           = new TakerModule(logger, taskModule, workerModule, buildingModule, stackModule);
            storerModule          = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule);

            planetGeneratorModule = new PlanetGeneratorModule(logger, phraseModule, resourceTypeModule, buildingTypeModule, taskTypeModule, materialModule, ingredientModule, productModule, planetModule, cellModule, buildingModule, workerModule);
            if (!planetGeneratorModule.Generate())
            {
                return;
            }

            schedulerModule = new SchedulerModule(logger, taskModule, idlerModule, producerModule, harvesterModule, moverModule, takerModule, storerModule, factoryBuilderModule);
            schedulerModule.Start();


            pioService = new PIOService(
                logger, phraseModule, planetModule, cellModule, buildingModule, workerModule,
                stackModule, resourceTypeModule,
                buildingTypeModule, taskTypeModule, materialModule, ingredientModule, productModule, taskModule,
                schedulerModule,
                resourceCheckerModule, locationCheckerModule, idlerModule, producerModule, harvesterModule, moverModule, takerModule, storerModule,
                factoryBuilderModule);

            pioServiceHostModule = new ServiceHostModule(logger, pioService);
            pioServiceHostModule.Start();

            taskCallbackService           = new TaskCallbackService(logger, schedulerModule);
            taskCallbackServiceHostModule = new ServiceHostModule(logger, taskCallbackService);
            taskCallbackServiceHostModule.Start();

            WaitHandle.WaitAny(new WaitHandle[] { quitEvent }, -1);

            taskCallbackServiceHostModule.Stop();
            pioServiceHostModule.Stop();
            schedulerModule.Stop();

            Console.CancelKeyPress -= new ConsoleCancelEventHandler(Console_CancelKeyPress);
        }