/// <summary>
        /// Constructs a parse tree for an On Error statement.
        /// </summary>
        /// <param name="onErrorType">The type of the On Error statement.</param>
        /// <param name="errorLocation">The location of the 'Error'.</param>
        /// <param name="resumeOrGoToLocation">The location of the 'Resume' or 'GoTo'.</param>
        /// <param name="nextOrZeroOrMinusLocation">The location of the 'Next', '0' or '-', if any.</param>
        /// <param name="oneLocation">The location of the '1', if any.</param>
        /// <param name="name">The label to branch to, if any.</param>
        /// <param name="isLineNumber">Whether the label is a line number.</param>
        /// <param name="span">The location of the parse tree.</param>
        /// <param name="comments">The comments for the parse tree.</param>
        public OnErrorStatement(OnErrorType onErrorType, Location errorLocation, Location resumeOrGoToLocation, Location nextOrZeroOrMinusLocation, Location oneLocation, SimpleName name, bool isLineNumber, Span span, IList <Comment> comments) : base(TreeType.OnErrorStatement, name, isLineNumber, span, comments)
        {
            if (!Enum.IsDefined(typeof(OnErrorType), onErrorType))
            {
                throw new ArgumentOutOfRangeException("onErrorType");
            }

            _OnErrorType               = onErrorType;
            _ErrorLocation             = errorLocation;
            _ResumeOrGoToLocation      = resumeOrGoToLocation;
            _NextOrZeroOrMinusLocation = nextOrZeroOrMinusLocation;
            _OneLocation               = oneLocation;
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"AMS v3 Function - CreateTransform was triggered!");

            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            if (data.transformName == null)
            {
                return(new BadRequestObjectResult("Please pass transformName in the input object"));
            }
            string transformName = data.transformName;

            if (data.mode == null)
            {
                return(new BadRequestObjectResult("Please pass mode in the input object"));
            }
            string description = null;

            if (data.description != null)
            {
                description = data.description;
            }

            string mode = data.mode;

            if (mode != "simple" && mode != "advanced")
            {
                return(new BadRequestObjectResult("Please pass valid mode in the input object"));
            }
            //
            // Simple Mode
            //
            if (mode == "simple" && data.preset == null)
            {
                return(new BadRequestObjectResult("Please pass preset in the input object"));
            }
            string presetName = data.preset;

            if (presetName == "CustomPreset" && data.customPresetJson == null)
            {
                return(new BadRequestObjectResult("Please pass customPresetJson in the input object"));
            }
            //
            // Advanced Mode
            //
            if (mode == "advanced" && data.transformOutputs == null)
            {
                return(new BadRequestObjectResult("Please pass transformOutputs in the input object"));
            }

            MediaServicesConfigWrapper amsconfig = new MediaServicesConfigWrapper();
            string transformId = null;

            JsonConverter[] jsonReaders =
            {
                new MediaServicesHelperJsonReader(),
                new MediaServicesHelperTimeSpanJsonConverter()
            };

            try
            {
                IAzureMediaServicesClient client = MediaServicesHelper.CreateMediaServicesClientAsync(amsconfig);

                // Does a Transform already exist with the desired name?
                // Assume that an existing Transform with the desired name
                // also uses the same recipe or Preset for processing content.
                Transform transform = client.Transforms.Get(amsconfig.ResourceGroup, amsconfig.AccountName, transformName);
                if (transform == null)
                {
                    TransformOutput[]      outputs          = null;
                    List <TransformOutput> transformOutputs = new List <TransformOutput>();
                    if (mode == "simple")
                    {
                        Preset preset        = null;
                        string audioLanguage = null;
                        if (data.audioLanguage != null)
                        {
                            audioLanguage = data.audioLanguage;
                        }
                        if (presetName == "VideoAnalyzer")
                        {
                            bool insightEnabled = false;
                            if (data.insightsToExtract != null && InsightTypeList.ContainsKey(data.insightsToExtract))
                            {
                                insightEnabled = true;
                            }
                            preset = new VideoAnalyzerPreset(audioLanguage, insightEnabled ? InsightTypeList[data.insightsToExtract] : null);
                        }
                        else if (presetName == "AudioAnalyzer")
                        {
                            preset = new AudioAnalyzerPreset(audioLanguage);
                        }
                        else if (presetName == "CustomPreset")
                        {
                            preset = JsonConvert.DeserializeObject <StandardEncoderPreset>(data.customPresetJson.ToString(), jsonReaders);
                        }
                        else
                        {
                            if (!EncoderNamedPresetList.ContainsKey(presetName))
                            {
                                return(new BadRequestObjectResult("Preset not found"));
                            }
                            preset = new BuiltInStandardEncoderPreset(EncoderNamedPresetList[presetName]);
                        }

                        OnErrorType onError = OnErrorType.StopProcessingJob;
                        string      temp    = data.onError;
                        if (!string.IsNullOrEmpty(temp) && OnErrorTypeList.ContainsKey(temp))
                        {
                            onError = OnErrorTypeList[temp];
                        }

                        Priority relativePriority = Priority.Normal;
                        temp = data.relativePriority;
                        if (!string.IsNullOrEmpty(temp) && PriorityList.ContainsKey(temp))
                        {
                            relativePriority = PriorityList[temp];
                        }

                        transformOutputs.Add(new TransformOutput(preset, onError, relativePriority));
                        outputs = transformOutputs.ToArray();
                    }
                    else if (mode == "advanced")
                    {
                        List <TransformOutput> transformOutputList = JsonConvert.DeserializeObject <List <TransformOutput> >(data.transformOutputs.ToString(), jsonReaders);
                        outputs = transformOutputList.ToArray();
                    }
                    else
                    {
                        return(new BadRequestObjectResult("Invalid mode found"));
                    }

                    // Create Transform
                    transform = client.Transforms.CreateOrUpdate(amsconfig.ResourceGroup, amsconfig.AccountName, transformName, outputs);
                }
                transformId = transform.Id;
            }
            catch (ApiErrorException e)
            {
                log.LogError($"ERROR: AMS API call failed with error code: {e.Body.Error.Code} and message: {e.Body.Error.Message}");
                return(new BadRequestObjectResult("AMS API call error: " + e.Message + "\nError Code: " + e.Body.Error.Code + "\nMessage: " + e.Body.Error.Message));
            }
            catch (Exception e)
            {
                log.LogError($"ERROR: Exception with message: {e.Message}");
                return(new BadRequestObjectResult("Error: " + e.Message));
            }

            return((ActionResult) new OkObjectResult(new
            {
                transformName = transformName,
                transformId = transformId
            }));
        }
Exemple #3
0
 public OnErrorArgs(T model, Exception error, OnErrorType type)
 {
     Model = model;
     Error = error;
     Type  = type;
 }