public static LocationEntity GetByUid(string locationUid) { LocationCollection locations = new LocationCollection(); locations.GetMulti(new PredicateExpression(LocationFields.UniqueIdentifier == locationUid)); return(locations.Count > 0 ? locations[0] : null); }
public static string CreateUniqueId(UniqueIdType idType) { Int32 attempts = 0; string returnValue = String.Empty; try { do { attempts++; returnValue = Guid.NewGuid().ToString(); if (idType == UniqueIdType.OrganizationUniqueId) { OrganizationCollection ecCustomerCollection = new OrganizationCollection(); PredicateExpression filter = new PredicateExpression(OrganizationFields.UniqueIdentifier == returnValue); ecCustomerCollection.GetMulti(filter); if (ecCustomerCollection.Count == 0) { break; } } else if (idType == UniqueIdType.DeviceUniqueId) { DeviceCollection ecDeviceCollection = new DeviceCollection(); PredicateExpression filter = new PredicateExpression(DeviceFields.UniqueIdentifier == returnValue); ecDeviceCollection.GetMulti(filter); if (ecDeviceCollection.Count == 0) { break; } } else if (idType == UniqueIdType.LocationUniqueId) { LocationCollection ecCustomerLocationCollection = new LocationCollection(); PredicateExpression filter = new PredicateExpression(LocationFields.UniqueIdentifier == returnValue); ecCustomerLocationCollection.GetMulti(filter); if (ecCustomerLocationCollection.Count == 0) { break; } } } while (attempts < GlobalSettings.MAX_KEYGEN_ATTEMPTS); return(returnValue); } catch (Exception ex) { Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex); return(returnValue); } }
public static Boolean IsDeviceAuthorizedImpl(string locationUniqueKeyVar, string deviceUniqueKeyVar) { // This check will verify that the account, location and device are activated LocationEntity locationEntity; // Locate the customers location Id by using the unique key value and verify that the location is in // fact authorized. LocationCollection ecCustomerLocationCollection = new LocationCollection(); PredicateExpression filter = new PredicateExpression(LocationFields.UniqueIdentifier == locationUniqueKeyVar); ecCustomerLocationCollection.GetMulti(filter); if (ecCustomerLocationCollection.Count > 0) { locationEntity = ecCustomerLocationCollection[0]; if (locationEntity.IsActive) { // Verify that the device belongs to the specified location DeviceCollection ecDeviceCollection = new DeviceCollection(); PredicateExpression filter1 = new PredicateExpression(DeviceFields.UniqueIdentifier == deviceUniqueKeyVar); filter1.Add(DeviceFields.LocationId == locationEntity.LocationId); ecDeviceCollection.GetMulti(filter1); if (ecDeviceCollection.Count > 0) { // Finally verify that there are scans left in the bank for the customer to use if (ecDeviceCollection[0].ScansAvailable <= 0) { throw (new Exception("There are no scans available for this location: " + locationUniqueKeyVar)); } } else { throw (new Exception("The device does not appear to belong to the specified location, the location is: " + locationUniqueKeyVar + " the device is: " + deviceUniqueKeyVar)); } } else { throw (new Exception("The location is not active, the key is: " + locationUniqueKeyVar)); } } else { throw (new Exception("Unable to locate location with key: " + locationUniqueKeyVar)); } return(true); }
public static int ConvertLocationKey(string locationUid) { try { LocationCollection locationCollection = new LocationCollection(); PredicateExpression filter = new PredicateExpression(LocationFields.UniqueIdentifier == locationUid); locationCollection.GetMulti(filter); if (locationCollection.Count > 0) { return(locationCollection[0].LocationId); } else { throw(new Exception("Unable to locate location with key: " + locationUid)); } } catch (Exception ex) { Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex); return(-1); } }