Пример #1
0
        public static Boolean DeleteAMessageImpl(long messageId, int organizationId)
        {
            // Make sure customer owns the message, thus preventing customers from possibly
            // deleting other customers messages.
            OrganizationEntity organization = new OrganizationEntity(organizationId);

            foreach (LocationEntity location in organization.Locations)
            {
                DeviceCollection devices = new DeviceCollection();
                devices.GetMulti(new PredicateExpression(DeviceFields.LocationId == location.LocationId));
                foreach (DeviceEntity device in devices)
                {
                    DeviceMessageCollection deviceMessages = new DeviceMessageCollection();
                    PredicateExpression     filter         = new PredicateExpression {
                        DeviceMessageFields.DeviceId == device.DeviceId, DeviceMessageFields.MessageId == messageId
                    };
                    deviceMessages.GetMulti(filter);
                    if (deviceMessages.Count > 0)
                    {
                        DeviceMessageEntity deviceMessage = deviceMessages[0];
                        deviceMessage.DeliveryTime = DateTime.UtcNow;
                        deviceMessage.Save();
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
        public static Int32 GetScansAvailableImpl(string deviceUniqueKeyVar)
        {
            DeviceEntity        deviceEntity;
            DeviceCollection    deviceCollection = new DeviceCollection();
            PredicateExpression filter           = new PredicateExpression(DeviceFields.UniqueIdentifier == deviceUniqueKeyVar);

            deviceCollection.GetMulti(filter);
            if (deviceCollection.Count > 0)
            {
                deviceEntity = deviceCollection[0];
                return(deviceEntity.ScansAvailable);
            }
            return(0);
        }
        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);
            }
        }
Пример #4
0
        public static DeviceEntity GetByUid(string deviceUid)
        {
            // check system wide access
            var  system = new SystemSettingEntity("Enabled");
            bool value;

            // this is pretty fail safe, the setting Enabled must exist and be set to "0" in order for this to pass, otherwise authentication is done at the device level
            if (!system.IsNew && bool.TryParse(system.Value, out value) && value == false)
            {
                return(null);
            }
            // NOTE:  device Active is checked at the individual service level because some services like uploading depend on old devices.

            DeviceCollection devices = new DeviceCollection();

            devices.GetMulti(new PredicateExpression(DeviceFields.UniqueIdentifier == deviceUid));
            return(devices.Count > 0 ? devices[0] : null);
        }
Пример #5
0
        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);
        }
Пример #6
0
 public static int ConvertDeviceKey(string deviceUid)
 {
     try
     {
         DeviceCollection    deviceCollection = new DeviceCollection();
         PredicateExpression filter           = new PredicateExpression(DeviceFields.UniqueIdentifier == deviceUid);
         deviceCollection.GetMulti(filter);
         if (deviceCollection.Count > 0)
         {
             return(deviceCollection[0].DeviceId);
         }
         else
         {
             throw(new Exception("Unable to locate device with key: " + deviceUid));
         }
     }
     catch (Exception ex)
     {
         Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
         return(-1);
     }
 }