Class: StringMap
PackageAPI.StringMap is a dictionary of strings: it implements IDictionary<string, string>, so it can be indexed by key (info["vendor"]) and enumerated as KeyValuePair<string, string>, and LINQ's ToArray() copies it to an array. PackageAPI.StringMapVector, returned by listPackages(), is a list of StringMap with Count and an indexer. PackageAPI.StringVector, returned by getWarnings(), is a list of strings.
using (PackageAPI.StringMap map = new PackageAPI.StringMap()) {
map.Add("canonicalName", "mypkg");
map.Add("language","en");
map.Add("type","extension");
Console.WriteLine("Contents of map");
foreach (var kv in map) {
Console.WriteLine($" {kv.Key} = {kv.Value}");
}
// Copy to array
KeyValuePair<string, string>[] arr = map.ToArray();
Console.WriteLine("\nContents of managed array");
foreach (var kv in arr) {
Console.WriteLine($" {kv.Key} = {kv.Value}");
}
}
getVersion()Class: PackageAPI
Returns the version of SmartPackager whose package code the SDK contains (for example "1.4.0"). For the SDK's own version, use getSdkVersion().
public string getVersion()
var api = new PackageAPI.PackageAPI();
string version = api.getVersion();
getSdkVersion()Class: PackageAPI
Returns the version of the PackageAPI SDK, the same as the .whl or .nupkg package version (for example "1.0.0").
public string getSdkVersion()
var api = new PackageAPI.PackageAPI();
string sdkVersion = api.getSdkVersion();
validate(string packageFile, string validationLevel, string vendorKeyFile, string authKeyFile)Class: PackageAPI
Marks the package as validated by Yaskawa at the given level and rewrites the .yip file. validationLevel must be "endorsed" or "registered". It doesn't check the package's contents.
It needs a Yaskawa authorization key in authKeyFile; without one it returns false. The package keeps its own vendor key: vendorKeyFile is only used as the authorization key when authKeyFile is "". Returns true if the package was validated, otherwise false (see getLastError()).
public bool validate(string packageFile, string validationLevel, string vendorKeyFile, string authKeyFile)
var api = new PackageAPI.PackageAPI();
string pkgFile = "pkg.yip";
string validationLevel = "endorsed"; // or "registered"
string vendorKeyFile = ""; // not needed: the package keeps its own key
string authKeyFile = "auth.key"; // Yaskawa authorization key
bool validateResult = api.validate(pkgFile,
validationLevel,
vendorKeyFile,
authKeyFile);
getPackageInfo(string packageFile)Class: PackageAPI
Returns the information for a package file, with the key fields below. displayName is in the language set by a packager.ini in the current directory, if any (default English). Returns an empty StringMap if the file isn't a valid .yip package (see getLastError()).
The key fields:
public StringMap getPackageInfo(string packageFile)
var api = new PackageAPI.PackageAPI();
var pkgFile = "package.yip";
PackageAPI.StringMap infoResult = api.getPackageInfo(pkgFile);
listPackages(string folder)Class: PackageAPI
Returns the information for every valid .yip package directly in the given folder (not in sub-folders), in file-name order, with the same key fields as getPackageInfo(). Invalid .yip files are skipped and reported by getWarnings(). Returns an empty StringMapVector if the folder doesn't exist.
The key fields:
public StringMapVector listPackages(string folder)
var api = new PackageAPI.PackageAPI();
string packageDir = "PackagesDir";
PackageAPI.StringMapVector packages = api.listPackages(packageDir);
generateVendorKey(string vendorKeyFile)Class: PackageAPI
Generates a private vendor key and saves it to the given file, readable only by you. Keep it safe and backed up: it is needed to change packages protected with it, or read their contents. Returns true if successful, otherwise false.
public bool generateVendorKey(string vendorKeyFile)
var api = new PackageAPI.PackageAPI();
bool created = api.generateVendorKey("private.key");
exportPublicKey(string vendorKeyFile)Class: PackageAPI
Returns the public key that pairs with the private vendor key in vendorKeyFile, as a hexadecimal string. Returns "" if the file is missing or isn't a valid key.
public string exportPublicKey(string vendorKeyFile)
var api = new PackageAPI.PackageAPI();
string publicKey = api.exportPublicKey("private.key");
exportPublicKeyHash(string vendorKeyFile)Class: PackageAPI
Returns the SHA-512 hash of the public key that pairs with the private vendor key in vendorKeyFile, as a hexadecimal string. Returns "" if the file is missing or isn't a valid key.
public string exportPublicKeyHash(string vendorKeyFile)
var api = new PackageAPI.PackageAPI();
string publicKeyHash = api.exportPublicKeyHash("private.key");
isValidVendorKey(string vendorKeyFile)Class: PackageAPI
Returns true if vendorKeyFile holds a valid private vendor key, otherwise false.
public bool isValidVendorKey(string vendorKeyFile)
var api = new PackageAPI.PackageAPI();
bool isValid = api.isValidVendorKey("private.key");
createUnprotectedPackage(string packageFile, string packageTemplateFile, string archiveFolder, string packageVariables)Class: PackageAPI
Creates an unprotected package in packageFile from the package template packageTemplateFile (.json or .jsonnet). archiveFolder is a folder whose files are included in the package; it must exist. Use "" for no archive. packageVariables sets template variables - see Package variables. Use "" for none. Returns true if the package was created, otherwise false.
IMPORTANT: Anyone can change an unprotected package.
For the package template format, see Install Package Format.
public bool createUnprotectedPackage(string packageFile, string packageTemplateFile, string archiveFolder, string packageVariables)
var api = new PackageAPI.PackageAPI();
bool done = api.createUnprotectedPackage("pkg.yip", "pkg_template.json", "", "");
createProtectedPackage(string packageFile, string packageTemplateFile, string archiveFolder, string vendorPrivateKeyFile, string packageVariables)Class: PackageAPI
Creates a protected package in packageFile from the package template packageTemplateFile (.json or .jsonnet), protected by the vendor key in vendorPrivateKeyFile. Only the holder of that key (or Yaskawa) can change the package or read its JSON (see Package protection and keys). archiveFolder is a folder whose files are included; it must exist. Use "" for no archive. packageVariables sets template variables - see Package variables. Use "" for none. Returns true if the package was created, otherwise false (including when vendorPrivateKeyFile is "").
For the package template format, see Install Package Format.
public bool createProtectedPackage(string packageFile, string packageTemplateFile, string archiveFolder, string vendorPrivateKeyFile, string packageVariables)
var api = new PackageAPI.PackageAPI();
bool done = api.createProtectedPackage("pkg.yip", "pkg_template.json", "", "private.key", "");
addComponent(string packageFile, string compFile, string vendorPrivateKeyFile)Class: PackageAPI
Adds the component defined in compFile (.json or .jsonnet) to packageFile. If the package already has a component with the same canonical name, it is replaced. If the package is protected, vendorPrivateKeyFile must hold its key (or a Yaskawa key); for an unprotected package use "". The package keeps its own key. Returns true if the component was added or replaced, otherwise false.
For the component format, see Components in the Install Package Format.
public bool addComponent(string packageFile, string compFile, string vendorPrivateKeyFile)
var api = new PackageAPI.PackageAPI();
bool done = api.addComponent("pkg.yip", "component.json", "private.key");
removeComponent(string packageFile, string compCanonicalName, string vendorKeyFile)Class: PackageAPI
Removes the component with canonical name compCanonicalName from packageFile. If the package is protected, vendorKeyFile must hold its key (or a Yaskawa key); for an unprotected package use "". The package keeps its own key. Returns true if the component was removed, otherwise false - including when the package has no such component.
public bool removeComponent(string packageFile, string compCanonicalName, string vendorKeyFile)
var api = new PackageAPI.PackageAPI();
bool done = api.removeComponent("pkg.yip", "com.example.mypkg.component", "private.key");
getJson(string packageFile, string compCanonicalName, string vendorKeyFile)Class: PackageAPI
Returns the JSON for a whole .yip package (compCanonicalName "") or for one of its components (compCanonicalName set to that component's canonical name). For a protected package, vendorKeyFile must be the package's vendor private key, or a Yaskawa key. For an unprotected package, use "". Returns "" if the package is invalid, the key doesn't match, or the package has no such component (see getLastError()).
public string getJson(string packageFile, string compCanonicalName, string vendorKeyFile)
var api = new PackageAPI.PackageAPI();
string json = api.getJson("pkg.yip", "", "private.key");
changeVendorKey(string packageFile, string vendorKeyFile, string newVendorKeyFile)Class: PackageAPI
Changes the key protecting packageFile. vendorKeyFile is the package's current key ("" if it is unprotected) or a Yaskawa key. newVendorKeyFile is the new key, or "" to make the package unprotected. Use it to protect an unprotected package, move a package to another vendor key, or remove its protection. Returns true if the key was changed, otherwise false.
public bool changeVendorKey(string packageFile, string vendorKeyFile, string newVendorKeyFile)
var api = new PackageAPI.PackageAPI();
bool done = api.changeVendorKey("pkg.yip", "private.key", "new.key");
getLastError()Class: PackageAPI
Returns why the last call failed, including any detail from the package code, or "" if it succeeded.
public string getLastError()
getWarnings()Class: PackageAPI
Returns the problems noted during the last call that didn't stop it, such as an invalid package skipped by listPackages() or an icon that isn't a .png or .jpg file and so wasn't included. A StringVector of strings. Empty if there were none.
public StringVector getWarnings()
var api = new PackageAPI.PackageAPI();
bool done = api.addComponent("pkg.yip", "component.json", "private.key");
if (!done)
Console.WriteLine("Failed: " + api.getLastError());
foreach (string warning in api.getWarnings())
Console.WriteLine("Warning: " + warning);
packageVariables is a comma-separated list of name=value pairs, for example "title=My Package,level=2". Spaces around names and values are ignored, and a name on its own is set to "true". Values can't contain commas or equals signs. Use them in the template with std.extVar('name'), for example displayNames: { en: std.extVar('title') }.