コード例 #1
0
        public static void Run(
            [QueueTrigger(MessageQueues.AvContent)] ContentEncodedMessage contentMessage,
            [DocumentDB(nameof(Content), nameof(AvContent), Id = "{documentId}")] AvContent avContent,
            [Queue(MessageQueues.DocumentUpdate)] out DocumentUpdatedMessage updatedMessage, TraceWriter log)
        {
            try
            {
                log.Info(contentMessage.ToString());

                FunctionExtensions.HasValueOrThrow(avContent?.Id, "avContent", $"Unable to find record with Id: {contentMessage?.DocumentId}");

                FunctionExtensions.HasValueOrThrow(contentMessage?.RemoteAssetUri, "RemoteAssetUri");

                avContent.RemoteAssetUri = contentMessage.RemoteAssetUri;

                updatedMessage = new DocumentUpdatedMessage(contentMessage.DocumentId, contentMessage.CollectionId, contentMessage.NotificationTags)
                {
                    Title   = $"New {avContent.ContentType}!",
                    Message = avContent.DisplayName
                };
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw;
            }
        }
コード例 #2
0
        public static void Run(
            [BlobTrigger(Routes.EncodeBlob)] CloudBlockBlob inputBlob, string fileName, string fileExtension,
            [Queue(MessageQueues.AvContent)] out ContentEncodedMessage contentMessage, TraceWriter log)
        {
            try
            {
                contentMessage = FunctionExtensions.GetMessageOrThrow(inputBlob);

                CachedCredentials = new MediaServicesCredentials(EnvironmentVariables.MediaServicesAccountName, EnvironmentVariables.MediaServicesAccountKey);

                Context = new CloudMediaContext(CachedCredentials);


                var newAsset = CreateAssetFromBlob(inputBlob, log).GetAwaiter().GetResult();

                var newAssetName = GetEncodedAssetName(fileName, fileExtension, encoderProcessorName);


                var job = Context.Jobs.CreateWithSingleTask(encoderProcessorName, encoderTaskConfigName, newAsset, newAssetName, AssetCreationOptions.None);

                job.Submit();


                job = job.StartExecutionProgressTask(j => log.Info($"Encoding Job Id: {job.Id}  State: {job.State}  Progress: {j.GetOverallProgress ().ToString ("P")}"), CancellationToken.None).Result;


                switch (job.State)
                {
                case JobState.Finished:
                    log.Info($"Encoding Job Id: {job.Id} is complete.");
                    break;

                case JobState.Error: throw new Exception($"Encoding Job Id: {job.Id} failed.");
                }


                var outputAsset = job.OutputMediaAssets [0];

                Context.Locators.Create(LocatorType.OnDemandOrigin, outputAsset, AccessPermissions.Read, TimeSpan.FromDays(365 * 10), DateTime.UtcNow);


                contentMessage.SetRemoteAssetUri(outputAsset.GetHlsUri());


                log.Info($"Output Asset - {contentMessage}");
            }
            catch (Exception ex)
            {
                log.Error($"ERROR: failed with exception {ex.Message}.\n {ex.StackTrace}");
                throw;
            }
        }
コード例 #3
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, Routes.Post, Route = Routes.PublishContent)] DocumentUpdatedMessage updateMessage,
            [NotificationHub(ConnectionStringSetting = EnvironmentVariables.AzureWebJobsNotificationHubsConnectionString, /*Platform = NotificationPlatform.Apns,*/ TagExpression = "{NotificationTags}")] IAsyncCollector <Notification> notification,
            TraceWriter log)
        {
            log.Info(updateMessage?.ToString());

            UserStore userStore = null;

            var userId = Thread.CurrentPrincipal.GetClaimsIdentity()?.UniqueIdentifier();

            if (!string.IsNullOrEmpty(userId))
            {
                log.Info($"User is authenticated and has userId: {userId}");

                userStore = await DocumentClient.GetUserStore(userId, log);
            }


            if (!userStore?.UserRole.CanWrite() ?? false)
            {
                log.Info("Not authenticated");

                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            try
            {
                FunctionExtensions.HasValueOrThrow(updateMessage?.CollectionId, DocumentUpdatedMessage.CollectionIdKey);

                var template = PushTemplate.FromMessage(updateMessage);

                await notification.AddAsync(new TemplateNotification (template.GetProperties()));

                throw new HttpResponseException(HttpStatusCode.Accepted);
            }
            catch (HttpResponseException response)
            {
                return(response.Response);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw;
            }
        }
コード例 #4
0
        public static async Task Run(
            [QueueTrigger(MessageQueues.DocumentUpdate, Connection = EnvironmentVariables.AzureWebJobsStorage)] DocumentUpdatedMessage updateMessage,
            [NotificationHub(ConnectionStringSetting = EnvironmentVariables.AzureWebJobsNotificationHubsConnectionString, TagExpression = "{NotificationTags}")] IAsyncCollector <Notification> notification,
            TraceWriter log)
        {
            try
            {
                log.Info(updateMessage?.ToString());

                FunctionExtensions.HasValueOrThrow(updateMessage?.CollectionId, DocumentUpdatedMessage.CollectionIdKey);

                var template = PushTemplate.FromMessage(updateMessage);

                await notification.AddAsync(new TemplateNotification (template.GetProperties()));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                throw;
            }
        }