Exemplo n.º 1
0
        private void PrepareModelForSave()
        {
            // If the Specification doesn't have an enumeration for its values...
            if (!SpecModel.IsEnumeration)
            {
                // Currently do nothing
            }
            // If the Specification does have an enumeration for its values...
            else
            {
                // Check if Specification is not multilingual
                if (SpecModel.IsMultilingual == false)
                {
                    // If the spec is not multilingual but is an enumeration...
                    // Put the same value for every language

                    SpecModel.Enumerations = SpecificationEnumList.ToList();

                    foreach (var enums in SpecModel.Enumerations)
                    {
                        foreach (var lang in LanguageList)
                        {
                            LocalizedEnumValue locEnum = enums.LocalizedEnumValues.FirstOrDefault(x => x.LanguageID == lang.ID);

                            if (locEnum == null)
                            {
                                locEnum = new LocalizedEnumValue()
                                {
                                    LanguageID    = lang.ID,
                                    EnumerationID = enums.ID
                                };
                                enums.LocalizedEnumValues.Add(locEnum);
                            }
                        }

                        foreach (var val in enums.LocalizedEnumValues)
                        {
                            val.Value = enums.TemporaryNonMLValue;
                        }
                    }
                }
                else
                {
                    // If the spec is multilingual, every value will already be filled in, so it's just added to the model
                    SpecModel.Enumerations = SpecificationEnumList.ToList();
                }
            }
        }
Exemplo n.º 2
0
        public async Task UpdateTypeChangeLocalizedEnumValueLabel()
        {
            var newEnumValueLabel = $"enum-label-{TestingUtility.RandomInt()}";

            await WithUpdateableType(client, async type =>
            {
                Assert.NotEmpty(type.FieldDefinitions);
                var enumFieldDefinition =
                    type.FieldDefinitions.FirstOrDefault(field => field.Type.GetType() == typeof(LocalizedEnumFieldType));

                Assert.NotNull(enumFieldDefinition);

                var enumField = enumFieldDefinition.Type as LocalizedEnumFieldType;

                Assert.NotNull(enumField);
                Assert.NotEmpty(enumField.Values);

                var updateActions = new List <UpdateAction <Type> >();
                var newEnumValue  = new LocalizedEnumValue
                {
                    Key   = enumField.Values[0].Key,
                    Label = new LocalizedString
                    {
                        { "en", newEnumValueLabel }
                    }
                };
                var changeLocalizedEnumValueLabelAction = new ChangeLocalizedEnumValueLabelUpdateAction
                {
                    FieldName = enumFieldDefinition.Name,
                    Value     = newEnumValue
                };
                updateActions.Add(changeLocalizedEnumValueLabelAction);

                var updatedType = await client
                                  .ExecuteAsync(new UpdateByIdCommand <Type>(type, updateActions));

                var updatedEnumField =
                    updatedType.FieldDefinitions.FirstOrDefault(field => field.Type.GetType() == typeof(LocalizedEnumFieldType))?.Type as LocalizedEnumFieldType;

                Assert.NotNull(updatedEnumField);

                Assert.Contains(updatedEnumField.Values,
                                value => value.Key == newEnumValue.Key && value.Label["en"] == newEnumValue.Label["en"]);
                return(updatedType);
            });
        }
Exemplo n.º 3
0
        private void AddMenuItem(LocalizedEnumValue enumValue, string resourceSpecialization)
        {
            string str         = resourceSpecialization.IsNullOrEmpty() ? enumValue.EnumValueName : (enumValue.EnumValueName + "." + resourceSpecialization);
            Image  reference   = PdnResources.GetImageResource($"Icons.Enum.{typeof(TEnumType).Name}.{str}.png").Reference;
            Image  scaledImage = null;

            if (reference != null)
            {
                UIUtil.ScaleImage(reference, out scaledImage);
            }
            ToolStripMenuItem item = new ToolStripMenuItem(enumValue.LocalizedName, scaledImage, new EventHandler(this.OnDropDownItemClick))
            {
                Tag          = enumValue.EnumValue,
                ImageScaling = ToolStripItemImageScaling.None
            };

            base.DropDownItems.Add(item);
        }
Exemplo n.º 4
0
        protected override DeviceBitmap GetItemBitmap(object item, int maxHeight)
        {
            if (item == this.solidBrushText)
            {
                return(null);
            }
            LocalizedEnumValue value2 = (LocalizedEnumValue)item;

            System.Drawing.Drawing2D.HatchStyle enumValue = (System.Drawing.Drawing2D.HatchStyle)value2.EnumValue;
            using (IBitmap <ColorPbgra32> bitmap = BitmapAllocator.Pbgra32.Allocate <ColorPbgra32>(maxHeight, maxHeight, AllocationOptions.Default))
            {
                using (IDrawingContext context = DrawingContext.FromBitmap(bitmap, FactorySource.PerThread))
                {
                    PaintDotNet.UI.Media.HatchBrush brush = new PaintDotNet.UI.Media.HatchBrush((PaintDotNet.UI.Media.HatchStyle)enumValue, (ColorRgba128Float)Colors.Black, (ColorRgba128Float)Colors.White);
                    context.FillRectangle(new RectDouble(PointDouble.Zero, bitmap.Size), brush);
                }
                return(new DeviceBitmap(bitmap));
            }
        }
Exemplo n.º 5
0
        public async Task UpdateTypeAddLocalizedEnumValueToFieldDefinition()
        {
            var rand         = TestingUtility.RandomInt();
            var newEnumValue = new LocalizedEnumValue
            {
                Key = $"enum-key-{rand}", Label = new LocalizedString()
                {
                    { "en", $"enum-label-{rand}" }
                }
            };

            await WithUpdateableType(client, async type =>
            {
                Assert.NotEmpty(type.FieldDefinitions);
                var enumField =
                    type.FieldDefinitions.FirstOrDefault(field => field.Type.GetType() == typeof(LocalizedEnumFieldType));

                Assert.NotNull(enumField);
                var updateActions = new List <UpdateAction <Type> >();
                var addLocalizedEnumValueToFieldAction = new AddLocalizedEnumToFieldDefinitionUpdateAction
                {
                    Value     = newEnumValue,
                    FieldName = enumField.Name
                };
                updateActions.Add(addLocalizedEnumValueToFieldAction);

                var updatedType = await client
                                  .ExecuteAsync(new UpdateByIdCommand <Type>(type, updateActions));

                var updatedEnumField =
                    updatedType.FieldDefinitions.FirstOrDefault(field => field.Type.GetType() == typeof(LocalizedEnumFieldType))?.Type as LocalizedEnumFieldType;

                Assert.NotNull(updatedEnumField);

                Assert.Contains(updatedEnumField.Values,
                                value => value.Key == newEnumValue.Key && value.Label["en"] == newEnumValue.Label["en"]);
                return(updatedType);
            });
        }
Exemplo n.º 6
0
        private void AddButton(LocalizedEnumValue enumValue)
        {
            Image reference = PdnResources.GetImageResource($"Icons.Enum.{typeof(TEnumType).Name}.{enumValue.EnumValueName}.png").Reference;

            if (reference != null)
            {
                ToolStripItemImageScaling sizeToFit = ToolStripItemImageScaling.SizeToFit;
                if (reference.Width > reference.Height)
                {
                    if ((UIUtil.GetXScaleFactor() != 1f) || (UIUtil.GetYScaleFactor() != 1f))
                    {
                        reference = new Bitmap(reference, UIUtil.ScaleSize(reference.Size));
                    }
                    sizeToFit = ToolStripItemImageScaling.None;
                }
                ToolStripButton item = new ToolStripButton(enumValue.LocalizedName, reference, new EventHandler(this.OnButtonClick))
                {
                    Tag          = enumValue.EnumValue,
                    ImageScaling = sizeToFit,
                    DisplayStyle = ToolStripItemDisplayStyle.Image
                };
                this.buttons.Add(item);
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributeName">The name of the attribute definition to update.</param>
 /// <param name="newValue">New Value</param>
 public ChangeLocalizedEnumValueLabelAction(string attributeName, LocalizedEnumValue newValue)
 {
     this.Action        = "changeLocalizedEnumValueLabel";
     this.AttributeName = attributeName;
     this.NewValue      = newValue;
 }
Exemplo n.º 8
0
 internal object <AddItems> b__8_0(LocalizedEnumValue lev) =>
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributeName">The name of the attribute definition to update.</param>
 /// <param name="value">Value</param>
 public AddLocalizedEnumValueAction(string attributeName, LocalizedEnumValue value)
 {
     this.Action        = "addLocalizedEnumValue";
     this.AttributeName = attributeName;
     this.Value         = value;
 }
Exemplo n.º 10
0
        private void GenerateMultilingualDataGridColumns()
        {
            // if it's the first load in an update, gets the specifications from the current model
            if (firstUpdateLoad)
            {
                SpecificationEnumList = new ObservableCollection <SpecificationEnum>(SpecModel.Enumerations);
            }
            // else, creates a new list
            else
            {
                SpecificationEnumList = new ObservableCollection <SpecificationEnum>();
            }

            // Binds the datagrid to the list
            dgEnumeration.ItemsSource = SpecificationEnumList;
            dgEnumeration.DataContext = SpecificationEnumList;

            dgEnumeration.Columns.Clear();

            // For each language it will check whether the items exist to bind on, and it will create a binded column
            foreach (var lang in LanguageList)
            {
                // Checks if each enumeration has a value for the current language
                foreach (var en in SpecModel.Enumerations)
                {
                    // Checks if there is already a localized enumeration value in the list.
                    var locEnum = en.LocalizedEnumValues.FirstOrDefault(x => x.LanguageID == lang.ID);

                    // If there is not one yet (for example in a create form, or in an update when a language was added)
                    if (locEnum == null)
                    {
                        // Create a new localized enumeration value and adds it to the model
                        locEnum = new LocalizedEnumValue()
                        {
                            LanguageID    = lang.ID,
                            EnumerationID = en.ID
                        };
                        en.LocalizedEnumValues.Add(locEnum);
                    }
                }

                // Creates a new textblock which will be used as header for the column
                TextBlock header = new TextBlock
                {
                    Text = lang.LocalName
                };
                header.Typography.Capitals = FontCapitals.SmallCaps;


                // Creates a constant binding location
                int     index           = LanguageList.IndexOf(lang);
                string  Bindinglocation = $"LocalizedEnumValues[{index}].Value";
                Binding valuesBinding   = new Binding(Bindinglocation);

                // Adds a column and adds a binding based on the matching language
                DataGridTextColumn dgCol
                    = new DataGridTextColumn
                    {
                    Header  = header,
                    Binding = valuesBinding,
                    Width   = new DataGridLength(1.0, DataGridLengthUnitType.Star)
                    };
                dgEnumeration.Columns.Add(dgCol);
            }

            if (!firstUpdateLoad)
            {
                // Add an empty row per default
                AddEnumRow(null, null);
            }
        }
Exemplo n.º 11
0
 public LocalizedEnumValueWrapper(LocalizedEnumValue localizedEnumValue)
 {
     Validate.IsNotNull <LocalizedEnumValue>(localizedEnumValue, "localizedEnumValue");
     this.localizedEnumValue = localizedEnumValue;
 }
Exemplo n.º 12
0
 internal EnumLocalizerFactory.LocalizedEnumValueWrapper <GetLocalizedEnumValues> b__4_0(LocalizedEnumValue lev) =>
 new EnumLocalizerFactory.LocalizedEnumValueWrapper(lev);