Ejemplo n.º 1
0
        /// <summary>
        /// Preps and calls the Flip API to encode a video.
        /// </summary>
        /// <param name="sasUri">Generated asset Uri with SAS token.</param>
        /// <param name="requestorFlipEncodeCreateDTO">Encode specific data object.</param>
        ///
        /// <returns>A "Video" object.</returns>
        private async Task <Video> CreateVideoAsync(string sasUri, RequestFlipEncodeCreateDTO requestorFlipEncodeCreateDTO)
        {
            // Get or create the TelestreamCloud storage reference to our output container.
            var store = await _telestreamCloudStorageProvider.GetStoreByNameAsync(new Uri(requestorFlipEncodeCreateDTO.OutputContainer)).ConfigureAwait(false);

            var newVideo = new CreateVideoBody
            {
                Profiles  = requestorFlipEncodeCreateDTO.Profiles,
                SourceUrl = sasUri,
                StoreId   = store.Id
            };

            var factory = await GetFactoryByNameAsync(requestorFlipEncodeCreateDTO.FactoryName).ConfigureAwait(false);

            // configure the encode payload for Correlation Vector
            var payload = new FlipPayload()
            {
                OperationContext = requestorFlipEncodeCreateDTO.OperationContext,
                FactoryId        = factory.Id,
                OutputContainer  = requestorFlipEncodeCreateDTO.OutputContainer
            };

            newVideo.Payload = JsonConvert.SerializeObject(payload);

            try
            {
                var video = await _telestreamCloudClientProvider.FlipApi.CreateVideoAsync(factory.Id, newVideo).ConfigureAwait(false);

                return(video);
            }
            catch (ApiException ae)
            {
                throw new GridwichFlipApiException("Error calling CreateVideoAsync.", requestorFlipEncodeCreateDTO.OperationContext, ae);
            }
        }
Ejemplo n.º 2
0
        private async Task <WorkflowJob> CreateWorkflowJobAsync(string inputURL, string jobName, RequestCloudPortEncodeCreateDTO cloudPortEncodeCreateDTO)
        {
            var workflow = await GetWorkflowByNameAsync(cloudPortEncodeCreateDTO.WorkflowName).ConfigureAwait(false);

            var store = await _telestreamCloudStorageProvider.GetStoreByNameAsync(new Uri(cloudPortEncodeCreateDTO.OutputContainer)).ConfigureAwait(false);

            var workflowJob = new WorkflowJob
            {
                Name = jobName
            };

            // We need to pass all source files
            var workflowJobSources = new Dictionary <string, string>();

            foreach (var source in workflow.Input.Sources)
            {
                workflowJobSources[source.Key] = inputURL;
            }

            var variables = ProcessWorkflowVariables(workflow, cloudPortEncodeCreateDTO);

            workflowJob.Inputs = new WorkflowJobInputs(sources: workflowJobSources, variables: variables);

            // Configure the encode payload for OpContext and other data that needs to be tunneled thru the payload.
            // Pass the OutputContainer in the Payload, so we can get it back from CloudPort.
            var payload = new CloudPortPayload()
            {
                OperationContext = cloudPortEncodeCreateDTO.OperationContext,
                OutputContainer  = cloudPortEncodeCreateDTO.OutputContainer
            };

            workflowJob.Payload = JsonConvert.SerializeObject(payload);

            // The Storage Reference section of the Input is where the workflow will advertise which Actions (denoted by the Identifier associated with those actions) which have been configured to emit outputs.
            // Additionally, this information will indicate which outputs are TRANSIENT (or temporary) and which outputs are PERMANENT (or intended to exist beyond the lifetime of the job)
            // The intent of the Storage Reference section is to provide the entity which is submitting to this workflow the requisite information necessary to specify the desired STORAGE that the action should utilize when running.
            workflowJob.StorageReferences = new Dictionary <string, WorkflowJobStorageReferences>();

            foreach (var workflowStorageReference in workflow.Input.StorageReferences)
            {
                workflowJob.StorageReferences[workflowStorageReference.Key] = new WorkflowJobStorageReferences(
                    storeId: store.Id,
                    folderOffset: ":id");  // use the job id as a blob name prefix.
            }

            try
            {
                var job = await _telestreamCloudClientProvider.CloudPortApi.CreateWorkflowJobAsync(workflow.Id, workflowJob).ConfigureAwait(false);

                return(job);
            }
            catch (ApiException ae)
            {
                throw new GridwichCloudPortApiException("Error calling CreateWorkflowJobAsync.", cloudPortEncodeCreateDTO.OperationContext, ae);
            }
        }