private void OnStateChanged(JobStateChangedEventArgs jobStateChangedEventArgs) { EventHandler <JobStateChangedEventArgs> stateChangedEvent = this.StateChanged; if (stateChangedEvent != null) { stateChangedEvent(this, jobStateChangedEventArgs); } }
private static async void OnJobStateChanged(object sender, Microsoft.WindowsAzure.MediaServices.Client.JobStateChangedEventArgs e) { NamespaceManager nsMgr = NamespaceManager.CreateFromConnectionString(ServiceBusConnectionString); TopicDescription topic = null; if (!(await nsMgr.TopicExistsAsync("MediaJobStateChanged"))) { topic = await nsMgr.CreateTopicAsync("MediaJobStateChanged"); } else { topic = await nsMgr.GetTopicAsync("MediaJobStateChanged"); } MessagingFactory factory = MessagingFactory.CreateFromConnectionString(ServiceBusConnectionString); TopicClient topicClient = factory.CreateTopicClient(topic.Path); var job = ((IJob)sender); Common.AdaptiveStreamingInfo streamingInfo = null; if (job.State == JobState.Finished) { var mediaServicesWrapper = new MediaServicesWrapper(MediaServiceName, MediaServiceKey, StorageConnectionString); streamingInfo = await mediaServicesWrapper.PrepareAssetsForAdaptiveStreamingAsync(job.Id); } var jobStateChangedMessage = new Common.JobStateChangedMessage { JobId = job.Id, NewState = e.CurrentState.ToString(), OldState = e.PreviousState.ToString(), StreamingInfo = streamingInfo }; await topicClient.SendAsync(new BrokeredMessage(jobStateChangedMessage)); }