Ejemplo n.º 1
0
        public void CreateGamefield()
        {
            field = _fieldFactory.CreateField();
            bool filledWithAnimals = false;

            while (!filledWithAnimals)
            {
                _facade.SetCursorPosition();
                _display.DrawAnimals(field);

                var key = _facade.ConsoleKey();

                var animalKey = key == TextParameters.AntelopeKey ||
                                key == TextParameters.LionKey;


                if (key == TextParameters.EnterKey)
                {
                    filledWithAnimals = true;
                    LifeCycle(field);
                }
                else if (animalKey)
                {
                    _animalFactory.CreateAnimal(key, field);
                }
            }
        }
Ejemplo n.º 2
0
        public override FrameworkElementFactory GenerateField(IFactoryContext context, ItemsControlDescription fieldDescription)
        {
            FrameworkElementFactory element = new FrameworkElementFactory(typeof(ItemsControl));

            element.SetValue(Grid.IsSharedSizeScopeProperty, true);

            if (fieldDescription.ItemTemplate != null)
            {
                element.SetValue(ItemsControl.ItemTemplateProperty, fieldDescription.ItemTemplate);
            }
            else
            {
                DataTemplate dt = new DataTemplate();

                if (fieldDescription.ItemDefinition != null)
                {
                    IFieldFactory factory = context.Mapping.Context.GetFactory(fieldDescription.ItemDefinition.GetType());

                    dt.VisualTree = factory.CreateField(context, fieldDescription.ItemDefinition);
                }
                else
                {
                    var lbl = new FrameworkElementFactory(typeof(TextBlock));
                    lbl.SetBinding(TextBlock.TextProperty, new Binding());

                    dt.VisualTree = lbl;
                }

                element.SetValue(ItemsControl.ItemTemplateProperty, dt);
            }
            element.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(fieldDescription.ItemsSource));

            if (fieldDescription.Rows != null || fieldDescription.Columns != null)
            {
                FrameworkElementFactory uniformPanel = new FrameworkElementFactory(typeof(UniformGrid));

                if (fieldDescription.Rows != null)
                {
                    uniformPanel.SetValue(UniformGrid.RowsProperty, fieldDescription.Rows.Value);
                }

                if (fieldDescription.Columns != null)
                {
                    uniformPanel.SetValue(UniformGrid.ColumnsProperty, fieldDescription.Columns.Value);
                }

                element.SetValue(ItemsControl.ItemsPanelProperty, new ItemsPanelTemplate(uniformPanel));
            }

            FrameworkElementFactory scrollviewer = new FrameworkElementFactory(typeof(ScrollViewer));

            scrollviewer.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);
            scrollviewer.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto);
            scrollviewer.AppendChild(element);

            return(scrollviewer);
        }
Ejemplo n.º 3
0
        public Fields(
            TType declaringType,
            IFieldFactory <TField, TConstant, TType> fieldFactory)
        {
            List <TField>    fields    = new List <TField>();
            List <TConstant> constants = new List <TConstant>();

            foreach (FieldInfo fieldDefinition in
                     declaringType.Type.GetAllFields().Where(field => !field.IsDefined(typeof(CompilerGeneratedAttribute))))
            {
                if (fieldDefinition.IsLiteral)
                {
                    constants.Add(fieldFactory.CreateConstant(declaringType, fieldDefinition));
                }
                else
                {
                    fields.Add(fieldFactory.CreateField(declaringType, fieldDefinition));
                }
            }

            FieldsWithReflection    = fields;
            ConstantsWithReflection = constants;
        }
Ejemplo n.º 4
0
        public Fields(
            TType declaringType,
            IFieldFactory <TField, TConstant, TType> fieldFactory)
        {
            List <TField>    fields    = new List <TField>();
            List <TConstant> constants = new List <TConstant>();

            foreach (FieldDefinition fieldDefinition in
                     declaringType.TypeDefinition.Fields.Where(field => !field.IsDefined(declaringType.Assembly, typeof(CompilerGeneratedAttribute))))
            {
                if (fieldDefinition.HasConstant)
                {
                    constants.Add(fieldFactory.CreateConstant(declaringType, fieldDefinition));
                }
                else
                {
                    fields.Add(fieldFactory.CreateField(declaringType, fieldDefinition));
                }
            }

            FieldsWithMonoCecil    = fields;
            ConstantsWithMonoCecil = constants;
        }
Ejemplo n.º 5
0
        public DataTemplate CreateTemplate(FormState formState, DataFormMapperRegion region = DataFormMapperRegion.MainContent)
        {
            DataTemplate template = new DataTemplate();

            DataFormMappingItem <T> form = new DataFormMappingItem <T>();

            switch (region)
            {
            case DataFormMapperRegion.MainContent:
                form = MainContent;
                break;

            case DataFormMapperRegion.Header:
                form = TopContent;
                break;

            case DataFormMapperRegion.Footer:
                form = BottomContent;
                break;
            }

            if (form.GroupCollection.Groups.Any() == false)
            {
                return(template);
            }

            IFieldFactory collectionFactory = Context.GetFactory <GroupCollectionDescription>();

            FactoryContext factoryContext = new FactoryContext(this, formState);

            FrameworkElementFactory mainGrid = collectionFactory.CreateField(factoryContext, form.GroupCollection);

            template.VisualTree = mainGrid;

            return(template);
        }
Ejemplo n.º 6
0
        public override FrameworkElementFactory GenerateField(IFactoryContext context, GroupDescription fieldDescription)
        {
            FrameworkElementFactory root;

            root = new FrameworkElementFactory(typeof(DockPanel));

            if (fieldDescription.RowSpan != null)
            {
                root.SetValue(Grid.RowSpanProperty, fieldDescription.RowSpan.Value);
            }

            if (fieldDescription.ColumnSpan != null)
            {
                root.SetValue(Grid.ColumnSpanProperty, fieldDescription.ColumnSpan.Value);
            }

            if (fieldDescription.DataContext != null)
            {
                root.SetBinding(Grid.DataContextProperty, new Binding(fieldDescription.DataContext));
            }

            //group label
            if (!String.IsNullOrEmpty(fieldDescription.DisplayName))
            {
                FrameworkElementFactory labelGroup = new FrameworkElementFactory(typeof(TextBlock));
                labelGroup.SetValue(TextBlock.TextProperty, fieldDescription.DisplayName);
                labelGroup.SetValue(Control.FontWeightProperty, FontWeights.Bold);
                labelGroup.SetValue(FrameworkElement.MarginProperty, new Thickness(2));
                labelGroup.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);

                FrameworkElementFactory borderForLabelGroup = new FrameworkElementFactory(typeof(Grid));
                borderForLabelGroup.SetValue(Grid.ColumnProperty, 0);
                borderForLabelGroup.SetValue(Grid.ColumnSpanProperty, 2);
                borderForLabelGroup.SetValue(Grid.RowProperty, 0);
                borderForLabelGroup.SetValue(DockPanel.DockProperty, Dock.Top);
                borderForLabelGroup.SetValue(Control.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                borderForLabelGroup.SetValue(Control.VerticalAlignmentProperty, VerticalAlignment.Top);

                borderForLabelGroup.AppendChild(labelGroup);

                root.AppendChild(borderForLabelGroup);
            }

            int row = 1;

            FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid));

            grid.SetValue(FrameworkElement.MarginProperty, new Thickness(4, 0, 4, 4));

            //columns
            FrameworkElementFactory groupColumnLabel   = new FrameworkElementFactory(typeof(ColumnDefinition));
            FrameworkElementFactory groupColumnContent = new FrameworkElementFactory(typeof(ColumnDefinition));

            groupColumnLabel.SetValue(ColumnDefinition.WidthProperty, GridLength.Auto);

            grid.AppendChild(groupColumnLabel);
            grid.AppendChild(groupColumnContent);

            //group row
            FrameworkElementFactory rowGroupDefinition = new FrameworkElementFactory(typeof(RowDefinition));

            rowGroupDefinition.SetValue(RowDefinition.HeightProperty, GridLength.Auto);
            grid.AppendChild(rowGroupDefinition);

            //Properties
            foreach (FieldDescription property in fieldDescription.FieldDescriptions)
            {
                FrameworkElementFactory rowDefinition = new FrameworkElementFactory(typeof(RowDefinition));
                if (!property.IsVerticalStretched)
                {
                    rowDefinition.SetValue(RowDefinition.HeightProperty, GridLength.Auto);
                }
                else
                {
                }

                grid.AppendChild(rowDefinition);

                if (property.DisplayName != null)
                {
                    //label
                    FrameworkElementFactory label = new FrameworkElementFactory(typeof(TextBlock));
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.SetValue(Grid.RowProperty, row);
                    label.SetValue(TextBlock.TextProperty, property.DisplayName);
                    label.SetValue(FrameworkElement.MarginProperty, new Thickness(2, 1, 4, 1));
                    label.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
                    if (property.Visibiliy != null)
                    {
                        IValueConverter converter = property.VisibilityConverter;

                        if (converter == null)
                        {
                            converter = new NotBoolToVisibilityConverter();
                        }

                        label.SetBinding(FrameworkElement.VisibilityProperty, new Binding(property.Visibiliy)
                        {
                            Converter = converter
                        });
                    }

                    grid.AppendChild(label);
                }

                IFieldFactory factory = context.Mapping.Context.GetFactory(property.GetType());

                //PropertyDefinitions
                FrameworkElementFactory element = factory.CreateField(context, property);
                element.SetValue(Grid.ColumnProperty, 1);
                element.SetValue(Grid.RowProperty, row);
                element.SetValue(FrameworkElement.MarginProperty, new Thickness(0, 0, 0, 1));

                if (property.IsEnabled != null)
                {
                    element.SetValue(FrameworkElement.IsEnabledProperty, property.IsEnabled.Value);
                }

                if (property.Visibiliy != null)
                {
                    IValueConverter converter = property.VisibilityConverter;

                    if (converter == null)
                    {
                        converter = new NotBoolToVisibilityConverter();
                    }

                    element.SetBinding(FrameworkElement.VisibilityProperty, new Binding(property.Visibiliy)
                    {
                        Converter = converter
                    });
                }

                if (property.DisplayName == null)
                {
                    element.SetValue(Grid.ColumnProperty, 0);
                    element.SetValue(Grid.ColumnSpanProperty, 2);
                }

                element.SetValue(FrameworkElement.HorizontalAlignmentProperty, property.HorizontalAlignment);

                if (property.Width != null)
                {
                    element.SetValue(FrameworkElement.WidthProperty, property.Width.Value);
                    element.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                }

                if (property.Style != null)
                {
                    element.SetValue(Control.StyleProperty, property.Style);
                }

                grid.AppendChild(element);

                row++;
            }

            root.AppendChild(grid);


            return(root);
        }
Ejemplo n.º 7
0
        public Schema CreateSchema(Type type)
        {
            SchemaAttribute schemaAttribute =
                _schemaAttributeExtractor.GetAttribute(type);

            // Create a new Schema using SchemaAttribute Properties
            SchemaBuilder schemaBuilder = new SchemaBuilder(schemaAttribute.GUID);

            schemaBuilder.SetSchemaName(schemaAttribute.SchemaName);

            // Set up other schema properties if they exists
            if (schemaAttribute.ApplicationGUID != Guid.Empty)
            {
                schemaBuilder.SetApplicationGUID(schemaAttribute.ApplicationGUID);
            }

            if (!string.IsNullOrEmpty(schemaAttribute.Documentation))
            {
                schemaBuilder.SetDocumentation(schemaAttribute.Documentation);
            }

            if (schemaAttribute.ReadAccessLevel != default(AccessLevel))
            {
                schemaBuilder.SetReadAccessLevel(schemaAttribute.ReadAccessLevel);
            }

            if (schemaAttribute.WriteAccessLevel != default(AccessLevel))
            {
                schemaBuilder.SetWriteAccessLevel(schemaAttribute.WriteAccessLevel);
            }

            if (!string.IsNullOrEmpty(schemaAttribute.VendorId))
            {
                schemaBuilder.SetVendorId(schemaAttribute.VendorId);
            }

            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            // Iterate all of the RevitEntity Properties
            foreach (var pi in properties)
            {
                //get the field attribute of public properties
                var propertyAttributes =
                    pi.GetCustomAttributes(typeof(FieldAttribute), true);

                // if property does not have a FieldAttribute
                // skip this property
                if (propertyAttributes.Length == 0)
                {
                    continue;
                }

                FieldAttribute fieldAttribute =
                    _fieldAttributeExtractor.GetAttribute(pi);

                FieldBuilder fieldBuilder =
                    _fieldFactory.CreateField(schemaBuilder, pi);

                /*
                 * //If entity contains field of IRevitEntity
                 * //also create a schema and add subSchemaId
                 * var iRevitEntity = pi.PropertyType.GetInterface("IRevitEntity");
                 * if (iRevitEntity != null)
                 * {
                 *  fieldBuilder = schemaBuilder.AddSimpleField(pi.Name, typeof(Entity));
                 *  var subSchemaAttribute = _schemaAttributeExtractor.GetAttribute(pi.PropertyType);
                 *  fieldBuilder.SetSubSchemaGUID(subSchemaAttribute.GUID);
                 * }
                 * else
                 * {
                 *  fieldBuilder = schemaBuilder.AddSimpleField(pi.Name, pi.PropertyType);
                 * }
                 */

                if (!string.IsNullOrEmpty(fieldAttribute.Documentation))
                {
                    fieldBuilder.SetDocumentation(fieldAttribute.Documentation);
                }
                if (fieldBuilder.NeedsUnits())
                {
                    fieldBuilder.SetUnitType(fieldAttribute.UnitType);
                }
            }

            return(schemaBuilder.Finish());
        }
        public override FrameworkElementFactory GenerateField(IFactoryContext context, GroupCollectionDescription fieldDescription)
        {
            //main control
            FrameworkElementFactory mainGrid = new FrameworkElementFactory(typeof(Grid));

            mainGrid.SetValue(FrameworkElement.MarginProperty, new Thickness(4));

            int maxMainColumnIndex = fieldDescription.Groups.Max(x => x.Column);
            int maxMainRowIndex    = fieldDescription.Groups.Max(x => x.Row);

            //create columns
            for (int i = 0; i <= maxMainColumnIndex; i++)
            {
                FrameworkElementFactory column = new FrameworkElementFactory(typeof(ColumnDefinition));

                GroupDescription foundGroup = fieldDescription.Groups.First(x => x.Column == i);

                if (foundGroup.Width != null)
                {
                    column.SetValue(ColumnDefinition.WidthProperty, new GridLength(foundGroup.Width.Value));
                }
                else
                {
                    column.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));
                }

                mainGrid.AppendChild(column);
            }

            //create rows
            for (int i = 0; i <= maxMainRowIndex; i++)
            {
                FrameworkElementFactory row = new FrameworkElementFactory(typeof(RowDefinition));
                if (!fieldDescription.Groups.Any(x => x.Row == i && x.FieldDescriptions.Any(p => p.IsVerticalStretched)))
                {
                    row.SetValue(RowDefinition.HeightProperty, GridLength.Auto);
                }
                else
                {
                }

                mainGrid.AppendChild(row);
            }

            //Groups by column
            foreach (var groupsByColumn in fieldDescription.Groups
                     .GroupBy(x => x.Column)
                     .OrderBy(x => x.Key))
            {
                //Groups
                foreach (var groups in groupsByColumn
                         .GroupBy(x => x.Row)
                         .OrderBy(x => x.Key))
                {
                    FrameworkElementFactory stackpanel = null;

                    if (groups.Count() > 1)
                    {
                        stackpanel = new FrameworkElementFactory(typeof(StackPanel));
                        stackpanel.SetValue(Grid.ColumnProperty, groupsByColumn.Key);
                        stackpanel.SetValue(Grid.RowProperty, groups.Key);
                        stackpanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);

                        mainGrid.AppendChild(stackpanel);
                    }

                    IFieldFactory groupFactory = context.Mapping.Context.GetFactory <GroupDescription>();

                    foreach (var group in groups)
                    {
                        FrameworkElementFactory g = groupFactory.CreateField(context, group);
                        g.SetValue(Grid.RowProperty, group.Row);
                        g.SetValue(Grid.ColumnProperty, group.Column);

                        if (group.ColumnSpan.HasValue)
                        {
                            g.SetValue(Grid.ColumnSpanProperty, group.ColumnSpan.Value);
                        }

                        if (groups.Count() > 1)
                        {
                            stackpanel.AppendChild(g);
                        }
                        else
                        {
                            g.SetValue(Grid.ColumnProperty, groupsByColumn.Key);
                            g.SetValue(Grid.RowProperty, groups.Key);
                            mainGrid.AppendChild(g);
                        }
                    }
                }
            }

            return(mainGrid);
        }
Ejemplo n.º 9
0
        public IFormBuilder <T> Field <TProperty>(Expression <Func <T, TProperty> > fieldProperty, Action <FormField> setupField = null)
        {
            m_children.Add(m_owner.CreateField(fieldProperty, setupField));

            return(this);
        }