private IndiciaToken() { _warehouseURL = ConfigurationManager.AppSettings["Indicia_WarehouseURL"]; if (String.IsNullOrEmpty(_warehouseURL)) { throw new ConfigurationException("Application setting Indicia_WarehouseURL required"); } _websiteID = ConfigurationManager.AppSettings["Indicia_WebsiteID"]; if (String.IsNullOrEmpty(_websiteID)) { throw new ConfigurationException("Application setting Indicia_WebsiteID required"); } else { int tempID; int.TryParse(_websiteID, out tempID); if (tempID <= 0) { throw new ConfigurationException("Application setting Indicia_WebsiteID must be a positive integer"); } } _websitePassword = ConfigurationManager.AppSettings["Indicia_WebsitePassword"]; if (String.IsNullOrEmpty(_websitePassword)) { throw new ConfigurationException("Application setting Indicia_WebsitePassword required"); } _serviceURI = new Uri(new Uri(_warehouseURL), SERVICEURL); _readToken = GetReadToken(); _writeToken = GetWriteToken(); }
/// <summary> /// Gets a read token from the Indicia Warehouse /// </summary> /// <returns>Indicia Read Authorisation token</returns> private Authorisation.AuthorisationToken GetReadToken() { Uri URL = new Uri(_serviceURI, READNONCE); string nonce = GetNonce(URL); byte[] authToken = GetAuthToken(nonce); Authorisation.AuthorisationToken token = new Authorisation.AuthorisationToken(nonce, authToken, Authorisation.AuthorisationTokenType.Read); return token; }
/// <summary> /// Gets a write token from the Indicia Warehouse /// </summary> /// <returns>Indicia Write Authorisation token</returns> private Authorisation.AuthorisationToken GetWriteToken() { Uri URL = new Uri(_serviceURI, WRITENONCE); string nonce = GetNonce(URL); byte[] authToken = GetAuthToken(nonce); Authorisation.AuthorisationToken token = new Authorisation.AuthorisationToken(nonce, authToken, Authorisation.AuthorisationTokenType.Write); return token; }
/// <summary> /// Request new write token from Indicia Warehouse /// </summary> public void RefreshWriteToken() { Boolean haveEntered = false; try { if (Monitor.TryEnter(padlockRefreshWriteToken)) { haveEntered = true; WriteToken = GetWriteToken(); Monitor.Exit(padlockRefreshWriteToken); haveEntered = false; } else { //wait for refresh to finish Monitor.Enter(padlockRefreshWriteToken); haveEntered = true; Monitor.Exit(padlockRefreshWriteToken); haveEntered = false; } } finally { if (haveEntered) { Monitor.Exit(padlockRefreshWriteToken); } } }