Class SerialNumberHandler
Interface to handle serialnumbers from WATS MES. Written by Ragnar Engnes, Virinco as - 2016
Inheritance
Namespace: Virinco.WATS.Interface.MES.Production
Assembly: Virinco.WATS.Interface.MES.dll
Syntax
public class SerialNumberHandler : object
Remarks
Some methods need a special access token to use, called token (not to be confused with tokenID, which is WATS token). That access token is '1C3CFC7C-1386-4219-94F4-06D2B7FD8E18'.
Constructors
SerialNumberHandler(String)
Constructor, creates an object reference
Declaration
public SerialNumberHandler(string serialNumberTypeName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | serialNumberTypeName | Type of serial number, e.g. MACAddress |
Methods
CancelAllReservations()
Cancels all reservations for all types. Useful before disconnecting the client to ensure all unused reserved serial numbers are freed.
Declaration
public static void CancelAllReservations()
CancelReservations(Guid)
Cancels any reservations that is not taken from the local store on the server.
Declaration
public void CancelReservations(Guid token = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | token | Deprecated. Used to be a special Guid needed to perform this function |
FormatAsMAC(Int64, Char)
Converts from Int to MAC string
Declaration
public string FormatAsMAC(Int64 i, char separator)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | i | |
| System.Char | separator |
Returns
| Type | Description |
|---|---|
| System.String |
GenerateAndUploadSerialNumbers(String, String, Int64, Int64, Char, out Int32, out Int32, Guid)
Generates and uploads serialnumbers to server.MACToInt(String) can be used to convert a MAC string
Declaration
public List<string> GenerateAndUploadSerialNumbers(string tokenID, string serviceUrl, Int64 fromSN, Int64 toSN, char separator, out int uploaded, out int rejected, Guid token)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | tokenID | |
| System.String | serviceUrl | |
| Int64 | fromSN | |
| Int64 | toSN | |
| System.Char | separator | Use to format mac string |
| System.Int32 | uploaded | Successfully uploaded |
| System.Int32 | rejected | Already exists |
| Guid | token | Secret token from support@virinco.com |
Returns
| Type | Description |
|---|---|
| List<System.String> | A list of serialnumbers that already existed |
GetFreeLocalSerialNumbers()
Returns the number of local serial numbers that are not taken.
Declaration
public int GetFreeLocalSerialNumbers()
Returns
| Type | Description |
|---|---|
| System.Int32 | Free local serialnumbers |
GetLocalSerialNumbers()
Declaration
public IEnumerable<SerialNumbersSN> GetLocalSerialNumbers()
Returns
| Type | Description |
|---|---|
| IEnumerable<SerialNumbersSN> |
GetPoolInfo(out Boolean, out Int32, out Int32, out String, out String)
Returns information about the current pool when type is Reserve
Declaration
public void GetPoolInfo(out bool onlyInSequence, out int batchSize, out int fetchWhenLessThan, out string startFromSerialNumber, out string siteName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | onlyInSequence | |
| System.Int32 | batchSize | |
| System.Int32 | fetchWhenLessThan | |
| System.String | startFromSerialNumber | |
| System.String | siteName |
GetPoolInfo(out Boolean, out Int32, out Int32, out String, out String, out SerialNumberHandler.RequestType)
Returns information about the current pool when type is Reserve
Declaration
public void GetPoolInfo(out bool onlyInSequence, out int batchSize, out int fetchWhenLessThan, out string startFromSerialNumber, out string siteName, out SerialNumberHandler.RequestType requestType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | onlyInSequence | |
| System.Int32 | batchSize | |
| System.Int32 | fetchWhenLessThan | |
| System.String | startFromSerialNumber | |
| System.String | siteName | |
| SerialNumberHandler.RequestType | requestType |
GetResuseOnDuplicateRequest()
Declaration
public bool GetResuseOnDuplicateRequest()
Returns
| Type | Description |
|---|---|
| System.Boolean |
GetSerialNumber(String, String)
Returns one serial number, see also GetSerialNumbers(Int32, String, String)
Declaration
public string GetSerialNumber(string serialnumberRef, string partnumberRef)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | serialnumberRef | Associate this serial number to this serialnumber |
| System.String | partnumberRef | Associate this serial number to this partnumber |
Returns
| Type | Description |
|---|---|
| System.String | Serial number as string |
GetSerialNumbers(Int32, String, String)
Retrieves serialnumber from local store or server
Declaration
public string[] GetSerialNumbers(int numToGet, string serialnumberRef, string partnumberRef)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | numToGet | Number of serialnumbers wanted |
| System.String | serialnumberRef | Reference to a serial number |
| System.String | partnumberRef | Reference to a part number |
Returns
| Type | Description |
|---|---|
| System.String[] | String array with serial numbers |
GetSerialNumberTypes()
Declaration
public static IEnumerable<SerialNumberType> GetSerialNumberTypes()
Returns
| Type | Description |
|---|---|
| IEnumerable<SerialNumberType> |
GetStatus()
Returns the status of a SerialnumberType
Declaration
public SerialNumberHandler.Status GetStatus()
Returns
| Type | Description |
|---|---|
| SerialNumberHandler.Status | Ready/NotInitialized |
GetTakenSerialNumbers(String, String)
Returns serial numbers already taken.
Declaration
public string[] GetTakenSerialNumbers(string serialnumberRef, string partnumberRef)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | serialnumberRef | Search for serial numbers associated with this serial number, or null to only search by reference part number. |
| System.String | partnumberRef | Search for part numbers associated with this serial number, or null to only search by reference serial number. |
Returns
| Type | Description |
|---|---|
| System.String[] | Serial numbers as array of strings |
Initialize(String, String, SerialNumberHandler.RequestType, Boolean, Int32, Int32, String, String, Guid)
Initialize a client and make it ready for serial number retrieval.
Declaration
public void Initialize(string tokenID, string serviceUrl, SerialNumberHandler.RequestType requestType, bool onlyInSequence, int batchSize, int fetchWhenLessThan, string startFromSerialNumber, string siteName, Guid token = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | tokenID | Authentication token generated on the WATS server according to this procedure: https://virinco.zendesk.com/hc/en-us/articles/207424253-Authentication /// |
| System.String | serviceUrl | The service address, e.g.: http://localhost/SerialnumberAdmin/api/SerialNumber/ |
| SerialNumberHandler.RequestType | requestType | Legal Values SerialNumberHandler.RequestType : Take: Client must be online and requested number of serialnumbers will be marked as Taken in the SN database
Reserve: Client downloads a The downloaded serial numbers are stored and maintained in an XML file on the client (C:\ProgramData\Virinco\WATS\AddressStore)
When there are
|
| System.Boolean | onlyInSequence | If set to true, requested serialnumbers will be contiguous (NB: Only MAC addresses) |
| System.Int32 | batchSize | How many serialnumbers that are reserved on the server (When requestType=Resvere) |
| System.Int32 | fetchWhenLessThan | Number of remaining offline serialnumbers before server is polled for a new batch |
| System.String | startFromSerialNumber | If specified, will restrict serial numbers retrieved to be greater or equal this value |
| System.String | siteName | Deprecated. Used to be that serial numbers would be registered to the site with this name. |
| Guid | token | Deprecated. Used to be a special Guid needed to perform this function. |
MACToInt(String)
Converts MAC string to int
Declaration
public Int64 MACToInt(string mac)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | mac | MAC String, supported separators are -,:,blank |
Returns
| Type | Description |
|---|---|
| Int64 | Int64 |
SetReuseOnDuplicateRequest(Boolean)
Change the behaviour of the serialnumber handler to re-use serialnumbers if referencedSN and referencedPN and number requested has been requested earlier (in the same call)
Declaration
public void SetReuseOnDuplicateRequest(bool on)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | on | Turns on this functionality (default is off) |
UploadSerialNumbersFromFile(String, String, String, out Int32, out Int32, Guid)
Uploads a text file with serialnumbers to the server, one sn per line - separated by CR/LF
Declaration
public List<string> UploadSerialNumbersFromFile(string tokenID, string serviceUrl, string fileName, out int uploaded, out int rejected, Guid token)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | tokenID | |
| System.String | serviceUrl | |
| System.String | fileName | |
| System.Int32 | uploaded | |
| System.Int32 | rejected | |
| Guid | token |
Returns
| Type | Description |
|---|---|
| List<System.String> |