Esempio n. 1
0
        public MediaPublishNotification PublishJobOutput(string transformName, string jobName, string eventType)
        {
            MediaPublishNotification publishNotification = new MediaPublishNotification
            {
                PhoneNumber   = this.UserAccount.MobilePhoneNumber,
                StatusMessage = string.Format(Constant.Message.JobPublishNotification, Constant.TextFormatter.FormatValue(transformName), jobName, eventType)
            };
            Job job = GetEntity <Job>(MediaEntity.TransformJob, jobName, transformName);

            if (job != null)
            {
                switch (eventType)
                {
                case Constant.Media.Job.EventType.Errored:
                    string jobError = null;
                    foreach (JobOutput jobOutput in job.Outputs)
                    {
                        if (!string.IsNullOrEmpty(jobError))
                        {
                            jobError = string.Concat(jobError, Constant.Message.NewLine);
                        }
                        jobError = string.Concat(jobError, jobOutput.Error.Message);
                    }
                    publishNotification.StatusMessage = string.Concat(publishNotification.StatusMessage, Constant.Message.NewLine, jobError);
                    break;

                case Constant.Media.Job.EventType.Finished:
                    string settingKey        = Constant.AppSettingKey.MediaPlayerDemoUrl;
                    string mediaPlayerUrl    = AppSetting.GetValue(settingKey);
                    string outputPublishData = job.CorrelationData[Constant.Media.Job.CorrelationData.OutputPublish].ToString();
                    MediaJobOutputPublish jobOutputPublish = JsonConvert.DeserializeObject <MediaJobOutputPublish>(outputPublishData);
                    foreach (JobOutputAsset jobOutput in job.Outputs)
                    {
                        Asset             outputAsset = GetEntity <Asset>(MediaEntity.Asset, jobOutput.AssetName);
                        StorageBlobClient blobClient  = new StorageBlobClient(this.MediaAccount, outputAsset.StorageAccountName);
                        if (blobClient.ContainsFile(outputAsset.Container, null, null, Constant.Media.Stream.ManifestExtension))
                        {
                            StreamingLocator streamingLocator = GetStreamingLocator(jobOutput.AssetName, jobOutput.AssetName, jobOutputPublish.StreamingPolicyName, jobOutputPublish.ContentProtection);
                            string           mediaStreamUrl   = GetStreamingUrl(streamingLocator, null);
                            mediaStreamUrl = string.Format(mediaPlayerUrl, mediaStreamUrl);
                            publishNotification.StatusMessage = string.Concat(publishNotification.StatusMessage, Constant.Message.NewLine, mediaStreamUrl);
                        }
                    }
                    SetJobInputAssetArchive(job.Input, jobOutputPublish.InputAssetStorageTier);
                    break;
                }
            }
            return(publishNotification);
        }
Esempio n. 2
0
        public MediaPublishNotification UnpublishJobOutput(string transformName, string jobName)
        {
            MediaPublishNotification publishNotification = new MediaPublishNotification()
            {
                PhoneNumber   = this.UserAccount.MobilePhoneNumber,
                StatusMessage = string.Format(Constant.Message.JobUnpublishNotification, jobName)
            };
            Job job = GetEntity <Job>(MediaEntity.TransformJob, jobName, transformName);

            if (job != null)
            {
                foreach (JobOutputAsset jobOutput in job.Outputs)
                {
                    DeleteLocators(jobOutput.AssetName);
                }
            }
            return(publishNotification);
        }
Esempio n. 3
0
        public static MediaPublishNotification PublishJobOutput(EventGridEvent eventTrigger)
        {
            MediaPublishNotification publishNotification = new MediaPublishNotification();
            JObject eventData = JObject.FromObject(eventTrigger.Data);
            JObject jobData   = (JObject)eventData["correlationData"];

            if (jobData.HasValues)
            {
                string       mediaAccountData = jobData[Constant.Media.Job.CorrelationData.MediaAccount].ToString();
                string       userAccountData  = jobData[Constant.Media.Job.CorrelationData.UserAccount].ToString();
                MediaAccount mediaAccount     = JsonConvert.DeserializeObject <MediaAccount>(mediaAccountData);
                UserAccount  userAccount      = JsonConvert.DeserializeObject <UserAccount>(userAccountData);
                using (MediaClient mediaClient = new MediaClient(mediaAccount, userAccount))
                {
                    string transformName = eventTrigger.Subject.Split('/')[1];
                    string jobName       = Path.GetFileName(eventTrigger.Subject);
                    publishNotification = mediaClient.PublishJobOutput(transformName, jobName, eventTrigger.EventType);
                }
            }
            return(publishNotification);
        }