private void SearchPathAndAdd(AppProjectGenerator appgen, INodeGenSettings ngs, IvPluginGenerator gen)
        {
            foreach (var t in gen.GetListNodeGenerationSettings())
            {
                string modelPath     = this.ModelPath;
                var    searchPattern = t.SearchPathInModel;
                var    is_found      = SearchInModelPathByPattern(modelPath, searchPattern);

                if (is_found)
                {
                    GeneratorSettings gs = new GeneratorSettings(this);
                    gs.NodeSettingsVmGuid = t.Guid;
                    gs.AppGeneratorGuid   = appgen.Guid;
                    _logger.LogTrace("Adding Node Settings. {Path} NodeSettingsVmGuid={NodeSettingsVmGuid} Name={Name}".CallerInfo(), t.SearchPathInModel, gs.NodeSettingsVmGuid, appgen.Name);
#if DEBUG
                    foreach (var ttt in ngs.ListGeneratorsSettings)
                    {
                        if (ttt.AppGeneratorGuid == appgen.Guid)
                        {
                            throw new Exception();
                        }
                    }
#endif
                    ngs.ListGeneratorsSettings.Add(gs);
                    gs.SettingsVm = t.GetAppGenerationNodeSettingsVm(gs.Settings);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem)
        {
            Contract.Requires(propertyItem != null);
            INodeGenSettings instance = (INodeGenSettings)propertyItem.Instance;
            ComboBox         cbx      = new ComboBox();

            cbx.DisplayMemberPath = "GroupInfo";
            cbx.SelectedValuePath = "GroupGuid";
            var _binding_lst = new Binding("ListPluginsGroups"); // bind to the Value property of the PropertyItem

            _binding_lst.Source = instance;
            _binding_lst.ValidatesOnExceptions = false;
            _binding_lst.ValidatesOnDataErrors = false;
            _binding_lst.Mode = BindingMode.OneWay;
            BindingOperations.SetBinding(cbx, ComboBox.ItemsSourceProperty, _binding_lst);
            var _binding = new Binding("Value"); // bind to the Value property of the PropertyItem

            _binding.Source = propertyItem;
            _binding.ValidatesOnExceptions = true;
            _binding.ValidatesOnDataErrors = true;
            _binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            BindingOperations.SetBinding(cbx, ComboBox.SelectedValueProperty, _binding);
            return(cbx);
        }
        public void CreatePropertyGridNodeGenSettings(INodeGenSettings p)
        {
            // create a dynamic assembly and module
            AssemblyBuilder assemblyBldr = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("tmpAssembly"), AssemblyBuilderAccess.Run);
            //AssemblyBuilder assemblyBldr = Thread.GetDomain().DefineDynamicAssembly(new AssemblyName("tmpAssembly"), AssemblyBuilderAccess.Run);
            ModuleBuilder moduleBldr = assemblyBldr.DefineDynamicModule("tmpModule");
            // create a new type builder
            TypeBuilder typeBldr = moduleBldr.DefineType("GenSettings", TypeAttributes.Public | TypeAttributes.Class, null);

            var cfg = (Config)this.GetConfig();

            foreach (var t in p.ListGeneratorsSettings)
            {
                var propType = typeof(object);
                var appGen   = cfg.DicNodes[t.AppGeneratorGuid];
                // Generate a private field for the property
                FieldBuilder fldBldr = typeBldr.DefineField("_" + t.Name, propType, FieldAttributes.Private);
                // Generate a public property
                PropertyBuilder prptyBldr = typeBldr.DefineProperty(t.Name, PropertyAttributes.None, propType, new Type[] { propType });

                // The property set and property get methods need the following attributes:
                MethodAttributes GetSetAttr = MethodAttributes.Public | MethodAttributes.HideBySig;
                // Define the "get" accessor method for newly created private field.
                MethodBuilder currGetPropMthdBldr = typeBldr.DefineMethod("get_value", GetSetAttr, propType, null);

                // Intermediate Language stuff... as per MS
                ILGenerator currGetIL = currGetPropMthdBldr.GetILGenerator();
                currGetIL.Emit(OpCodes.Ldarg_0);
                currGetIL.Emit(OpCodes.Ldfld, fldBldr);
                currGetIL.Emit(OpCodes.Ret);

                // Define the "set" accessor method for the newly created private field.
                MethodBuilder currSetPropMthdBldr = typeBldr.DefineMethod("set_value", GetSetAttr, null, new Type[] { propType });

                // More Intermediate Language stuff...
                ILGenerator currSetIL = currSetPropMthdBldr.GetILGenerator();
                currSetIL.Emit(OpCodes.Ldarg_0);
                currSetIL.Emit(OpCodes.Ldarg_1);
                currSetIL.Emit(OpCodes.Stfld, fldBldr);
                currSetIL.Emit(OpCodes.Ret);

                // Assign the two methods created above to the PropertyBuilder's Set and Get
                prptyBldr.SetGetMethod(currGetPropMthdBldr);
                prptyBldr.SetSetMethod(currSetPropMthdBldr);

                ConstructorInfo        cons      = typeof(ExpandableObjectAttribute).GetConstructor(new Type[] { });
                CustomAttributeBuilder attribute = new CustomAttributeBuilder(cons, new object[] { }, new FieldInfo[] { }, new object[] { });
                prptyBldr.SetCustomAttribute(attribute);

                cons      = typeof(DescriptionAttribute).GetConstructor(new Type[] { typeof(string) });
                attribute = new CustomAttributeBuilder(cons, new object[] { t.Description }, new FieldInfo[] { }, new object[] { });
                prptyBldr.SetCustomAttribute(attribute);
            }
            var dynamicType = typeBldr.CreateType();
            var instance    = Activator.CreateInstance(dynamicType);

            foreach (var t in p.ListGeneratorsSettings)
            {
                PropertyInfo prop = dynamicType.GetProperty(t.Name);
                prop.SetValue(instance, t.SettingsVm, null);
            }
            p.GenSettings = instance;
        }