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); }
public static Boolean GetCurrentMessagesImpl(string deviceUniqueKeyVar, ref ArrayList messages) { ArrayList returnValues = new ArrayList(); int deviceId = KeyToIdHelpers.ConvertDeviceKey(deviceUniqueKeyVar); if (deviceId != -1) { DeviceMessageCollection deviceMessages = new DeviceMessageCollection(); PredicateExpression filter = new PredicateExpression(DeviceMessageFields.DeviceId == deviceId); deviceMessages.GetMulti(filter); foreach (DeviceMessageEntity deviceMessage in deviceMessages) { if (deviceMessage.DeliveryTime == null) { MessageEntity message = deviceMessage.Message; if (message.IsActive) { MessageTransport messageTransport = new MessageTransport { MessageId = message.MessageId, MessageType = (short)message.MessageType, MessageTitle = message.Title, MessageBody = message.Body, MessageTime = message.CreateTime }; returnValues.Add(messageTransport); } deviceMessage.DeliveryTime = DateTime.UtcNow; deviceMessage.Save(); } } messages = returnValues; return(true); } return(false); }