Ejemplo n.º 1
0
        /// <summary>
        /// To Custom View Property
        /// </summary>
        /// <param name="input">View Property</param>
        /// <returns>Custom View Proerty</returns>
        public static CustomViewProperty ToCustomViewProperty(this ViewProperty input)
        {
            AvailableSelectionsPolicy availableSelectionPolicy = input.GetPolicy <AvailableSelectionsPolicy>();

            return(new CustomViewProperty()
            {
                DisplayName = input.DisplayName,
                Name = input.Name,
                OriginalType = input.OriginalType,
                RawValue = input.RawValue,
                Value = input.Value,
                AvailableSelectionPolicy = availableSelectionPolicy.List == null || !availableSelectionPolicy.List.Any() ? null : availableSelectionPolicy.ToCustomAvailableSelectionPolicy()
            });
        }
        private void AddOptionConstraintToPropertyFromProxy(ViewProperty engineViewProperty, ProxyCore.AvailableSelectionsPolicy proxyAvailableSelectionsPolicy)
        {
            if (proxyAvailableSelectionsPolicy.List == null || !proxyAvailableSelectionsPolicy.List.Any())
            {
                return;
            }

            AvailableSelectionsPolicy engineAvailableSelectionPolicy = engineViewProperty.GetPolicy <AvailableSelectionsPolicy>();

            foreach (var proxySelection in proxyAvailableSelectionsPolicy.List)
            {
                Selection selection = new Selection();
                selection.DisplayName = proxySelection.DisplayName;
                selection.Name        = proxySelection.Name;
                selection.IsDefault   = proxySelection.IsDefault;
                engineAvailableSelectionPolicy.List.Add(selection);
            }
        }
Ejemplo n.º 3
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null");

            if (entityView.Name != "DevOps-PullEnvironment")
            {
                return(entityView);
            }

            var entityViewArgument = _commerceCommander.Command <ViewCommander>().CurrentEntityViewArgument(context.CommerceContext);

            if (entityViewArgument.Entity == null)
            {
                var appService = await _commerceCommander
                                 .GetEntity <AppService>(context.CommerceContext, entityView.ItemId);

                if (appService == null)
                {
                }
                else
                {
                    var serviceUri = $"http://{appService.Host}/commerceops/Environments";

                    try
                    {
                        var jsonResponse = await _commerceCommander.Command <JsonCommander>()
                                           .Process(context.CommerceContext, serviceUri);

                        dynamic dynJson = JsonConvert.DeserializeObject(jsonResponse.Json);

                        var environments = dynJson.value;

                        var templateViewProperty = new ViewProperty
                        {
                            Name        = "Environment",
                            DisplayName = "Selected Environment",
                            IsHidden    = false,
                            IsRequired  = true,
                            RawValue    = string.Empty
                        };

                        entityView.Properties.Add(templateViewProperty);

                        var availableSelections = templateViewProperty.GetPolicy <AvailableSelectionsPolicy>();

                        foreach (var environment in environments)
                        {
                            availableSelections.List.Add(new Selection {
                                Name = environment.Name, DisplayName = environment.Name, IsDefault = false
                            });
                        }

                        entityView.Properties.Add(new ViewProperty
                        {
                            Name        = "NameAs",
                            DisplayName = "Name Environment As",
                            IsHidden    = false,
                            IsRequired  = false,
                            RawValue    = string.Empty
                        });
                    }
                    catch (Exception ex)
                    {
                        context.Logger.LogError($"DevOps.FormPullEnvironment.Exception: Message={ex.Message}");
                    }
                }
            }
            return(entityView);
        }