/// <summary> /// Validates active licenses of the licensee. See NetLicensingAPI for details: /// https://www.labs64.de/confluence/display/NLICPUB/Licensee+Services#LicenseeServices-Validatelicensee /// </summary> public static ValidationResult validate(Context context, String number, ValidationParameters validationParameters) { Dictionary <String, String> parameters = new Dictionary <String, String> (); if (!String.IsNullOrEmpty(validationParameters.getProductNumber())) { parameters.Add(Constants.Product.PRODUCT_NUMBER, validationParameters.getProductNumber()); } if (!String.IsNullOrEmpty(validationParameters.getLicenseeName())) { parameters.Add(Constants.Licensee.PROP_LICENSEE_NAME, validationParameters.getLicenseeName()); } if (!String.IsNullOrEmpty(validationParameters.getLicenseeSecret())) { parameters.Add(Constants.Licensee.PROP_LICENSEE_SECRET, validationParameters.getLicenseeSecret()); } int pmIndex = 0; foreach (KeyValuePair <String, Dictionary <String, String> > productModuleValidationParams in validationParameters.getParameters()) { parameters.Add(Constants.ProductModule.PRODUCT_MODULE_NUMBER + pmIndex, productModuleValidationParams.Key); foreach (KeyValuePair <String, String> param in productModuleValidationParams.Value) { parameters.Add(param.Key + pmIndex, param.Value); } pmIndex++; } netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Licensee.ENDPOINT_PATH + "/" + number + "/" + Constants.Licensee.ENDPOINT_PATH_VALIDATE, parameters); return(new ValidationResult(output)); }
/// <summary> /// Validates active licenses of the licensee. See NetLicensingAPI for details: /// https://netlicensing.io/wiki/licensee-services#validate-licensee /// </summary> public static ValidationResult validate(Context context, String number, ValidationParameters validationParameters) { Dictionary <String, String> parameters = new Dictionary <String, String> (); if (!String.IsNullOrEmpty(validationParameters.getProductNumber())) { parameters.Add(Constants.Product.PRODUCT_NUMBER, validationParameters.getProductNumber()); } if (!String.IsNullOrEmpty(validationParameters.getLicenseeName())) { parameters.Add(Constants.Licensee.PROP_LICENSEE_NAME, validationParameters.getLicenseeName()); } #pragma warning disable 0618 // This section is only left to verify backwards compatibility. // Don't use LicenseeSecret, use Node-Locked licensing model instead. if (!String.IsNullOrEmpty(validationParameters.getLicenseeSecret())) { parameters.Add(Constants.Licensee.PROP_LICENSEE_SECRET, validationParameters.getLicenseeSecret()); } #pragma warning restore 0618 int pmIndex = 0; foreach (KeyValuePair <String, Dictionary <String, String> > productModuleValidationParams in validationParameters.getParameters()) { parameters.Add(Constants.ProductModule.PRODUCT_MODULE_NUMBER + pmIndex, productModuleValidationParams.Key); foreach (KeyValuePair <String, String> param in productModuleValidationParams.Value) { parameters.Add(param.Key + pmIndex, param.Value); } pmIndex++; } netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Licensee.ENDPOINT_PATH + "/" + number + "/" + Constants.Licensee.ENDPOINT_PATH_VALIDATE, parameters); return(new ValidationResult(output)); }
/// <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])); }
public static List <Token> list(Context context, String tokenType, String filter) { Dictionary <String, String> parameters = new Dictionary <String, String>(); if (!String.IsNullOrEmpty(tokenType)) { parameters.Add(Constants.Token.TOKEN_TYPE, tokenType); } if (!String.IsNullOrEmpty(filter)) { parameters.Add(Constants.FILTER, filter); } netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.GET, Constants.Token.ENDPOINT_PATH, parameters); List <Token> tokens = new List <Token>(); if (output.items.item != null) { foreach (item i in output.items.item) { tokens.Add(new Token(i)); } } return(tokens); }
/// <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])); }
/// <summary> /// Updates transactions properties. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/TransactionService.html /// </summary> public static Transaction update(Context context, String number, Transaction updateTransaction) { updateTransaction.number = number; netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Transaction.ENDPOINT_PATH + "/" + number, updateTransaction.ToDictionary()); return(new Transaction(output.items.item[0])); }
/// <summary> /// Validates active licenses of the licensee. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseeService.html /// </summary> public static ValidationResult validate(Context context, String number, String productNumber) { Dictionary <String, String> parameters = new Dictionary <String, String>(); if (!String.IsNullOrEmpty(productNumber)) { parameters.Add("productNumber", productNumber); } netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.GET, Constants.Licensee.ENDPOINT_PATH + "/" + number + "/validate", parameters); return(new ValidationResult(output)); }
/// <summary> /// Returns all payment methods. See NetLicensingAPI JavaDoc for details: /// https://go.netlicensing.io/javadoc/v2/com/labs64/netlicensing/service/PaymentMethodService.html /// </summary> public static List <PaymentMethod> list(Context context) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.GET, Constants.PaymentMethod.ENDPOINT_PATH, null); List <PaymentMethod> paymentMethods = new List <PaymentMethod>(); if (output.items.item != null) { foreach (item i in output.items.item) { paymentMethods.Add(new PaymentMethod(i)); } } return(paymentMethods); }
/// <summary> /// Creates new license object with given properties. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseService.html /// </summary> public static License create(Context context, String licenseeNumber, String licenseTemplateNumber, String transactionNumber, License newLicense) { newLicense.licenseeNumber = licenseeNumber; newLicense.licenseTemplateNumber = licenseTemplateNumber; string transactionOldValue; if (newLicense.licenseProperties.TryGetValue(Constants.Transaction.TRANSACTION_NUMBER, out transactionOldValue)) { newLicense.licenseProperties.Remove(Constants.Transaction.TRANSACTION_NUMBER); } newLicense.licenseProperties.Add(Constants.Transaction.TRANSACTION_NUMBER, transactionNumber); netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.License.ENDPOINT_PATH, newLicense.ToDictionary()); return(new License(output.items.item[0])); }
public ValidationResult(netlicensing source) { validations = new Dictionary <String, Composition>(); ttl = source.ttl; if (source.items.item == null) { return; } foreach (item i in source.items.item) { if (!Constants.ValidationResult.VALIDATION_RESULT_TYPE.Equals(i.type)) { throw new NetLicensingException(String.Format("Wrong object type '{0}', expected '{1}'", (i.type != null) ? i.type : "<null>", Constants.ValidationResult.VALIDATION_RESULT_TYPE)); } Composition pmValidateProperties = new Composition(); String productModuleNumber = null; if (i.property != null) { foreach (property p in i.property) { switch (p.name) { case Constants.ProductModule.PRODUCT_MODULE_NUMBER: productModuleNumber = p.Value; break; default: pmValidateProperties.put(p.name, p.Value); break; } } } if (i.list != null) { foreach (list l in i.list) { pmValidateProperties.properties.Add(l.name, convertFromList(l)); } } if (productModuleNumber == null) { throw new NetLicensingException(String.Format("Validation item does not contain property '{0}'", Constants.ProductModule.PRODUCT_MODULE_NUMBER)); } setProductModuleValidation(productModuleNumber, pmValidateProperties); } }
/// <summary> /// Returns all licenses of a vendor. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseService.html /// </summary> public static List <License> list(Context context, String filter) { Dictionary <String, String> parameters = new Dictionary <String, String>(); if (!String.IsNullOrEmpty(filter)) { parameters.Add(Constants.FILTER, filter); } netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.GET, Constants.License.ENDPOINT_PATH, parameters); List <License> licenses = new List <License>(); if (output.items.item != null) { foreach (item i in output.items.item) { licenses.Add(new License(i)); } } return(licenses); }
/// <summary> /// Genarates token by its number. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/TokenService.html /// </summary> public static Token create(Context context, Token newToken) { Dictionary <String, String> parameters = new Dictionary <String, String>(); if (newToken.tokenType == null) { newToken.tokenType = Constants.Token.TYPE_DEFAULT; } parameters.Add(Constants.Token.TOKEN_TYPE, newToken.tokenType); if (newToken.tokenType.Equals(Constants.Token.TYPE_SHOP) && newToken.tokenProperties.ContainsKey(Constants.Licensee.LICENSEE_NUMBER)) { String licenseeNumber = newToken.tokenProperties[Constants.Licensee.LICENSEE_NUMBER]; if (!String.IsNullOrEmpty(licenseeNumber)) { parameters.Add(Constants.Licensee.LICENSEE_NUMBER, licenseeNumber); } } netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Token.ENDPOINT_PATH, parameters); return(new Token(output.items.item[0])); }
/// <summary> /// Returns all licensing models. /// </summary> public static List <String> listLicensingModels(Context context) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.GET, Constants.Utility.ENDPOINT_PATH + "/" + Constants.Utility.LICENSING_MODELS, null); List <String> licensingModels = new List <String>(); if (output.items.item != null) { foreach (item i in output.items.item) { if (Constants.Utility.LICENSING_MODELS_PROPERTIES.Equals(i.type)) { foreach (property p in i.property) { if (p.name == Constants.NAME) { licensingModels.Add(p.Value); } } } } } return(licensingModels); }
/// <summary> /// Deletes license. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseService.html /// </summary> public static void delete(Context context, String number) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.DELETE, Constants.License.ENDPOINT_PATH + "/" + number, null); }
/// <summary> /// Updates license properties. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseService.html /// </summary> public static License update(Context context, String number, String transactionNumber, License updateLicense) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.License.ENDPOINT_PATH + "/" + number, updateLicense.ToDictionary()); return(new License(output.items.item[0])); }
/// <summary> /// Gets license by its number. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseService.html /// </summary> public static License get(Context context, String number) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.GET, Constants.License.ENDPOINT_PATH + "/" + number, null); return(new License(output.items.item[0])); }
/// <summary> /// Deletes product module. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/ProductModuleService.html /// </summary> public static void delete(Context context, String number, bool forceCascade) { String strCascade = Convert.ToString(forceCascade).ToLower(); netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.DELETE, Constants.ProductModule.ENDPOINT_PATH + "/" + number, Utilities.forceCascadeToDict(forceCascade)); }
/// <summary> /// Genarates token by its number. See NetLicensingAPI JavaDoc for details: /// https://go.netlicensing.io/javadoc/v2/com/labs64/netlicensing/service/TokenService.html /// </summary> public static Token create(Context context, Token newToken) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Token.ENDPOINT_PATH, newToken.ToDictionary()); return(new Token(output.items.item[0])); }
public ValidationResult(netlicensing source) { validations = new Dictionary<String, Composition>(); if (source.items.item == null) { return; } foreach (item i in source.items.item) { if (!Constants.ValidationResult.VALIDATION_RESULT_TYPE.Equals(i.type)) { throw new NetLicensingException(String.Format("Wrong object type '{0}', expected '{1}'", (i.type != null) ? i.type : "<null>", Constants.ValidationResult.VALIDATION_RESULT_TYPE)); } Composition pmValidateProperties = new Composition(); String productModuleNumber = null; if (i.property != null) { foreach (property p in i.property) { switch (p.name) { case Constants.ProductModule.PRODUCT_MODULE_NUMBER: productModuleNumber = p.Value; break; default: pmValidateProperties.put(p.name, p.Value); break; } } } if (i.list != null) { foreach (list l in i.list) { pmValidateProperties.properties.Add(l.name, convertFromList(l)); } } if (productModuleNumber == null) { throw new NetLicensingException(String.Format("Validation item does not contain property '{0}'", Constants.ProductModule.PRODUCT_MODULE_NUMBER)); } setProductModuleValidation(productModuleNumber, pmValidateProperties); } }
/// <summary> /// Deletes licensee. See NetLicensingAPI JavaDoc for details: /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseeService.html /// </summary> public static void delete(Context context, String number, Boolean forceCascade) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.DELETE, Constants.Licensee.ENDPOINT_PATH + "/" + number, Utilities.forceCascadeToDict(forceCascade)); }
/// <summary> /// Updates payment method with the given number.. See NetLicensingAPI JavaDoc for details: /// https://go.netlicensing.io/javadoc/v2/com/labs64/netlicensing/service/PaymentMethodService.html /// </summary> public static PaymentMethod update(Context context, String number, PaymentMethod newPaymentMethod) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.PaymentMethod.ENDPOINT_PATH + "/" + number, newPaymentMethod.ToDictionary()); return(new PaymentMethod(output.items.item[0])); }
public static netlicensing request(Context context, Method method, String path, Dictionary <String, String> parameters) { #region HTTP request preparation // Workaround of the mod_proxy_ajp problem. // mod_proxy_ajp has problem processing HTTP/1.1 POST request with delayed payload transmission (Expect: 100 Continue), causes 500 Server Error in AJP module. // Resources on the topic: // http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx // http://stackoverflow.com/questions/3889574/apache-and-mod-proxy-not-handling-http-100-continue-from-client-http-417 // https://issues.apache.org/bugzilla/show_bug.cgi?id=46709 // https://issues.apache.org/bugzilla/show_bug.cgi?id=47087 ServicePointManager.Expect100Continue = false; StringBuilder requestPayload = new StringBuilder(); if (parameters != null) { bool first = true; foreach (KeyValuePair <String, String> param in parameters) { if (first) { first = false; } else { requestPayload.Append("&"); } requestPayload.Append(HttpUtility.UrlEncode(Regex.Replace(param.Key, "discount[[0-9]+]", "discount"))); requestPayload.Append("="); requestPayload.Append(HttpUtility.UrlEncode(param.Value)); } } String urlParam = ""; String requestBody = null; if (requestPayload.Length > 0) { switch (method) { case Method.GET: case Method.DELETE: urlParam = "?" + requestPayload.ToString(); break; case Method.POST: requestBody = requestPayload.ToString(); break; } } HttpWebRequest request = WebRequest.Create(context.baseUrl + "/" + path + urlParam) as HttpWebRequest; request.UserAgent = "NetLicensing/C# " + Constants.NETLICENSING_VERSION + "/" + System.Environment.Version + " (https://netlicensing.io)"; switch (method) { case Method.GET: request.Method = "GET"; break; case Method.POST: request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; break; case Method.DELETE: request.Method = "DELETE"; break; default: throw new RestException("Invalid request type:" + method + ", allowed requests types: GET, POST, DELETE"); } switch (context.securityMode) { case SecurityMode.BASIC_AUTHENTICATION: request.Credentials = new NetworkCredential(context.username, context.password); break; case SecurityMode.APIKEY_IDENTIFICATION: request.Credentials = new NetworkCredential(Constants.APIKEY_USER, context.apiKey); break; case SecurityMode.ANONYMOUS_IDENTIFICATION: break; default: throw new RestException("Unknown security mode"); } request.PreAuthenticate = true; request.Accept = "application/xml"; request.SendChunked = false; if (requestBody != null) { byte[] byteArray = Encoding.UTF8.GetBytes(requestBody); request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); } #endregion netlicensing responsePayload = null; try { #region HTTP response parsing using (HttpWebResponse response = (request as HttpWebRequest).GetResponse() as HttpWebResponse) { HttpStatusCode statusCode = response.StatusCode; switch (statusCode) { case HttpStatusCode.OK: responsePayload = deserialize(response.GetResponseStream()); break; case HttpStatusCode.NoContent: break; default: throw new NetLicensingException(String.Format("Got unsupported response result code {0}: '{1}'", response.StatusCode, response.StatusDescription)); } response.Close(); } #endregion } catch (WebException ex) { #region HTTP and NetLicensing errors conversion to Exception String plainTextResponse = null; using (HttpWebResponse response = ex.Response as HttpWebResponse) { if (response != null) { if (response.ContentLength > 0) { try { responsePayload = deserialize(response.GetResponseStream()); } catch (Exception) { // Ignore deserialization errors - response is not necessarily formatted as NetLicensing response.GetResponseStream().Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(response.GetResponseStream())) { plainTextResponse = reader.ReadToEnd(); } } } response.Close(); } } StringBuilder messages = new StringBuilder(); messages.AppendLine("Bad request to the NetLicensingAPI:"); if (responsePayload != null) { foreach (info i in responsePayload.infos) { messages.AppendLine(i.Value); } } if (plainTextResponse != null) { messages.AppendLine(plainTextResponse); } throw new NetLicensingException(messages.ToString(), ex); #endregion } return(responsePayload); }
/// <summary> /// Creates new product object with given properties. See NetLicensingAPI JavaDoc for details: /// https://go.netlicensing.io/javadoc/v2/com/labs64/netlicensing/service/ProductService.html /// </summary> public static Product create(Context context, Product newProduct) { netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Product.ENDPOINT_PATH, newProduct.ToDictionary()); return(new Product(output.items.item[0])); }