コード例 #1
0
        public async Task AddUserRegistrationOrganizationAsync(IEnumerable <string> deviceIds, string organizationId)
        {
            await PatchTagsForUserDevicesAsync(deviceIds, UpdateOperationType.Add, $"organizationId:{organizationId}");

            if (deviceIds.Any() && InstallationDeviceEntity.IsInstallationDeviceId(deviceIds.First()))
            {
                var entities = deviceIds.Select(e => new InstallationDeviceEntity(e));
                await _installationDeviceRepository.UpsertManyAsync(entities.ToList());
            }
        }
コード例 #2
0
        public async Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier,
                                                         string deviceId = null)
        {
            var tag = BuildTag($"template:payload && organizationId:{orgId}", identifier);

            await SendPayloadAsync(tag, type, payload);

            if (InstallationDeviceEntity.IsInstallationDeviceId(deviceId))
            {
                await _installationDeviceRepository.UpsertAsync(new InstallationDeviceEntity(deviceId));
            }
        }
コード例 #3
0
        public async Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier,
                                                 string deviceId = null)
        {
            var tag = BuildTag($"template:payload_userId:{SanitizeTagInput(userId)}", identifier);

            await SendPayloadAsync(tag, type, payload);

            if (InstallationDeviceEntity.IsInstallationDeviceId(deviceId))
            {
                await _installationDeviceRepository.UpsertAsync(new InstallationDeviceEntity(deviceId));
            }
        }
コード例 #4
0
 public async Task DeleteAsync(InstallationDeviceEntity entity)
 {
     try
     {
         entity.ETag = "*";
         await _table.ExecuteAsync(TableOperation.Delete(entity));
     }
     catch (StorageException e) when(e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound)
     {
         throw;
     }
 }
コード例 #5
0
        public async Task DeleteRegistrationAsync(string deviceId)
        {
            try
            {
                await _client.DeleteInstallationAsync(deviceId);

                if (InstallationDeviceEntity.IsInstallationDeviceId(deviceId))
                {
                    await _installationDeviceRepository.DeleteAsync(new InstallationDeviceEntity(deviceId));
                }
            }
            catch (Exception e) when(e.InnerException == null || !e.InnerException.Message.Contains("(404) Not Found"))
            {
                throw;
            }
        }
コード例 #6
0
 public async Task UpsertAsync(InstallationDeviceEntity entity)
 {
     await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
 }
コード例 #7
0
 public Task UpsertAsync(InstallationDeviceEntity entity)
 {
     return(Task.FromResult(0));
 }
コード例 #8
0
        public async Task CreateOrUpdateRegistrationAsync(string pushToken, string deviceId, string userId,
                                                          string identifier, DeviceType type)
        {
            if (string.IsNullOrWhiteSpace(pushToken))
            {
                return;
            }

            var installation = new Installation
            {
                InstallationId = deviceId,
                PushChannel    = pushToken,
                Templates      = new Dictionary <string, InstallationTemplate>()
            };

            installation.Tags = new List <string>
            {
                $"userId:{userId}"
            };

            if (!string.IsNullOrWhiteSpace(identifier))
            {
                installation.Tags.Add("deviceIdentifier:" + identifier);
            }

            string payloadTemplate = null, messageTemplate = null, badgeMessageTemplate = null;

            switch (type)
            {
            case DeviceType.Android:
                payloadTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}}";
                messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," +
                                  "\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}";

                installation.Platform = NotificationPlatform.Fcm;
                break;

            case DeviceType.iOS:
                payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}," +
                                  "\"aps\":{\"alert\":null,\"badge\":null,\"content-available\":1}}";
                messageTemplate = "{\"data\":{\"type\":\"#(type)\"}," +
                                  "\"aps\":{\"alert\":\"$(message)\",\"badge\":null,\"content-available\":1}}";
                badgeMessageTemplate = "{\"data\":{\"type\":\"#(type)\"}," +
                                       "\"aps\":{\"alert\":\"$(message)\",\"badge\":\"#(badge)\",\"content-available\":1}}";

                installation.Platform = NotificationPlatform.Apns;
                break;

            case DeviceType.AndroidAmazon:
                payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}";
                messageTemplate = "{\"data\":{\"type\":\"#(type)\",\"message\":\"$(message)\"}}";

                installation.Platform = NotificationPlatform.Adm;
                break;

            default:
                break;
            }

            BuildInstallationTemplate(installation, "payload", payloadTemplate, userId, identifier);
            BuildInstallationTemplate(installation, "message", messageTemplate, userId, identifier);
            BuildInstallationTemplate(installation, "badgeMessage", badgeMessageTemplate ?? messageTemplate,
                                      userId, identifier);

            await _client.CreateOrUpdateInstallationAsync(installation);

            if (InstallationDeviceEntity.IsInstallationDeviceId(deviceId))
            {
                await _installationDeviceRepository.UpsertAsync(new InstallationDeviceEntity(deviceId));
            }
        }
コード例 #9
0
 public async Task DeleteAsync(InstallationDeviceEntity entity)
 {
     await _table.ExecuteAsync(TableOperation.Delete(entity));
 }