private static IReadOnlyList <IOperationProvider> SetupCustomOperations(IReadOnlyList <ICustomOperationModel> customModel, IDirectory templateRoot, IVariableCollection variables)
        {
            ITemplateEngineHost       host             = templateRoot.MountPoint.EnvironmentSettings.Host;
            List <IOperationProvider> customOperations = new List <IOperationProvider>();

            foreach (ICustomOperationModel opModelUntyped in customModel)
            {
                CustomOperationModel opModel = opModelUntyped as CustomOperationModel;
                if (opModel == null)
                {
                    host.LogMessage($"Operation type = [{opModelUntyped.Type}] could not be cast as a CustomOperationModel");
                    continue;
                }

                string opType    = opModel.Type;
                string condition = opModel.Condition;

                if (string.IsNullOrEmpty(condition) ||
                    CppStyleEvaluatorDefinition.EvaluateFromString(templateRoot.MountPoint.EnvironmentSettings, condition, variables))
                {
                    IOperationConfig realConfigObject;
                    if (_operationConfigLookup.TryGetValue(opType, out realConfigObject))
                    {
                        customOperations.AddRange(
                            realConfigObject.ConfigureFromJObject(opModel.Configuration, templateRoot));
                    }
                    else
                    {
                        host.LogMessage($"Operation type = [{opType}] from configuration is unknown.");
                    }
                }
            }

            return(customOperations);
        }
        internal static ICustomOperationModel FromJObject(JObject jObject)
        {
            CustomOperationModel model = new CustomOperationModel
            {
                Type          = jObject.ToString(nameof(Type)),
                Condition     = jObject.ToString(nameof(Condition)),
                Configuration = jObject.Get <JObject>(nameof(Configuration)),
            };

            return(model);
        }
示例#3
0
        public static CustomFileGlobModel FromJObject(JObject globData, string globName)
        {
            // setup the variable config
            IVariableConfig variableConfig;
            JToken          variableData;

            if (globData.TryGetValue(nameof(VariableFormat), System.StringComparison.OrdinalIgnoreCase, out variableData))
            {
                variableConfig = VariableConfig.FromJObject((JObject)variableData);
            }
            else
            {
                variableConfig = VariableConfig.DefaultVariableSetup();
            }

            // setup the custom operations
            List <ICustomOperationModel> customOpsForGlob = new List <ICustomOperationModel>();
            JToken operationData;

            if (globData.TryGetValue("Operations", System.StringComparison.OrdinalIgnoreCase, out operationData))
            {
                foreach (JObject operationConfig in (JArray)operationData)
                {
                    customOpsForGlob.Add(CustomOperationModel.FromJObject(operationConfig));
                }
            }

            CustomFileGlobModel globModel = new CustomFileGlobModel()
            {
                Glob           = globName,
                Operations     = customOpsForGlob,
                VariableFormat = variableConfig,
                FlagPrefix     = globData.ToString(nameof(FlagPrefix)),
                Condition      = globData.ToString(nameof(Condition))
            };

            return(globModel);
        }