예제 #1
0
        public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
        {
            ArgumentUtility.CheckNotNull("value", value);
            ArgumentUtility.CheckNotNull("property", property);

            return(!Array.Exists(_disabledEnumValues, disabledValue => disabledValue.Equals(value.Value)));
        }
예제 #2
0
        /// <summary>
        /// Determines whether the specified value is enabled. A value is enabled if it is not in the list of <see cref="DisabledIDs"/>.
        /// </summary>
        /// <param name="value">The value to check.</param>
        /// <param name="businessObject">The business object hosting the property for which the check is performed.</param>
        /// <param name="property">The property for which the check is performed.</param>
        /// <returns>
        ///     <see langword="true" /> if the specified value is enabled; otherwise, <see langword="false" />.
        /// </returns>
        public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
        {
            ArgumentUtility.CheckNotNull("value", value);
            ArgumentUtility.CheckNotNull("property", property);

            return(!_disabledIDs.Contains(value.Identifier));
        }
        public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
        {
            ArgumentUtility.CheckNotNull("value", value);
            ArgumentUtility.CheckNotNull("property", property);

            return(!_filters.Any(f => !f.IsEnabled(value, businessObject, property)));
        }
예제 #4
0
        private ListControl GetListControl(BocEnumValueRenderingContext renderingContext)
        {
            ListControl listControl = renderingContext.Control.ListControlStyle.Create(false);

            listControl.ID      = renderingContext.Control.GetValueName();
            listControl.Enabled = renderingContext.Control.Enabled;

            listControl.Width  = Unit.Empty;
            listControl.Height = Unit.Empty;
            listControl.ApplyStyle(renderingContext.Control.CommonStyle);
            renderingContext.Control.ListControlStyle.ApplyStyle(listControl);

            bool needsNullValueItem = (renderingContext.Control.Value == null) && (renderingContext.Control.ListControlStyle.ControlType != ListControlType.RadioButtonList);

            if (!renderingContext.Control.IsRequired || needsNullValueItem)
            {
                listControl.Items.Add(CreateNullItem(renderingContext));
            }

            IEnumerationValueInfo[] valueInfos = renderingContext.Control.GetEnabledValues();

            for (int i = 0; i < valueInfos.Length; i++)
            {
                IEnumerationValueInfo valueInfo = valueInfos[i];
                ListItem item = new ListItem(valueInfo.DisplayName, valueInfo.Identifier);
                if (valueInfo.Value.Equals(renderingContext.Control.Value))
                {
                    item.Selected = true;
                }

                listControl.Items.Add(item);
            }

            return(listControl);
        }
예제 #5
0
        public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
        {
            ArgumentUtility.CheckNotNull("value", value);
            ArgumentUtility.CheckNotNull("businessObject", businessObject);
            ArgumentUtility.CheckNotNull("property", property);

            return((int)value.Value % 2 == 1);
        }
예제 #6
0
        private ListControl GetListControl(BocEnumValueRenderingContext renderingContext)
        {
            ListControl listControl = renderingContext.Control.ListControlStyle.Create(false);

            listControl.ClientIDMode = ClientIDMode.Static;
            listControl.ID           = renderingContext.Control.GetValueName();
            listControl.Enabled      = renderingContext.Control.Enabled;

            listControl.Width  = Unit.Empty;
            listControl.Height = Unit.Empty;
            listControl.ApplyStyle(renderingContext.Control.CommonStyle);
            renderingContext.Control.ListControlStyle.ApplyStyle(listControl);

            var oneBasedIndex = 1;

            bool needsNullValueItem = (renderingContext.Control.Value == null) &&
                                      (renderingContext.Control.ListControlStyle.ControlType != ListControlType.RadioButtonList);

            if (!renderingContext.Control.IsRequired || needsNullValueItem)
            {
                var nullItem = CreateNullItem(renderingContext);

                if (IsDiagnosticMetadataRenderingEnabled)
                {
                    nullItem.Attributes[DiagnosticMetadataAttributes.ItemID]            = "==null==";
                    nullItem.Attributes[DiagnosticMetadataAttributes.IndexInCollection] = oneBasedIndex.ToString();
                    nullItem.Attributes[DiagnosticMetadataAttributes.Content]           = HtmlUtility.StripHtmlTags(renderingContext.Control.GetNullItemText());
                }

                listControl.Items.Add(nullItem);
                oneBasedIndex++;
            }

            IEnumerationValueInfo[] valueInfos = renderingContext.Control.GetEnabledValues();

            for (int i = 0; i < valueInfos.Length; i++, oneBasedIndex++)
            {
                IEnumerationValueInfo valueInfo = valueInfos[i];
                ListItem item = new ListItem(valueInfo.DisplayName, valueInfo.Identifier);
                if (valueInfo.Value.Equals(renderingContext.Control.Value))
                {
                    item.Selected = true;
                }

                if (IsDiagnosticMetadataRenderingEnabled)
                {
                    item.Attributes[DiagnosticMetadataAttributes.ItemID]            = valueInfo.Identifier;
                    item.Attributes[DiagnosticMetadataAttributes.IndexInCollection] = oneBasedIndex.ToString();
                    item.Attributes[DiagnosticMetadataAttributes.Content]           = HtmlUtility.StripHtmlTags(valueInfo.DisplayName);
                }

                listControl.Items.Add(item);
            }

            return(listControl);
        }
예제 #7
0
        private void CheckEnumerationValueInfo(BooleanEnumerationValueInfo expected, IEnumerationValueInfo actual)
        {
            ArgumentUtility.CheckNotNull("expected", expected);

            Assert.That(actual, Is.InstanceOf(expected.GetType()));
            Assert.That(actual.Value, Is.EqualTo(expected.Value));
            Assert.That(actual.Identifier, Is.EqualTo(expected.Identifier));
            Assert.That(actual.IsEnabled, Is.EqualTo(expected.IsEnabled));
            Assert.That(actual.DisplayName, Is.EqualTo(expected.DisplayName));
        }
        private string GetStringValueForEnumerationProperty(object value, IBusinessObjectEnumerationProperty property, IBusinessObject businessObject)
        {
            IEnumerationValueInfo enumValueInfo = property.GetValueInfoByValue(value, businessObject);

            if (enumValueInfo == null)
            {
                return(string.Empty);
            }
            return(enumValueInfo.DisplayName);
        }
예제 #9
0
        public void DisabledEnumValue()
        {
            IBusinessObjectEnumerationProperty property = CreateProperty(typeof(ClassWithDisabledEnumValue), "DisabledFromProperty");

            _mockRepository.ReplayAll();

            IEnumerationValueInfo actual = property.GetValueInfoByValue(TestEnum.Value1, _mockBusinessObject);

            _mockRepository.VerifyAll();
            CheckEnumerationValueInfo(new EnumerationValueInfo(TestEnum.Value1, "Value1", "Value1", false), actual);
        }
예제 #10
0
        /// <summary> Returns a list of all the enumeration's values. </summary>
        /// <returns>
        ///   A list of <see cref="IEnumerationValueInfo"/> objects encapsulating the values defined in the enumeration.
        /// </returns>
        public IEnumerationValueInfo[] GetAllValues(IBusinessObject businessObject)
        {
            var valueInfos = new List <IEnumerationValueInfo>();

            foreach (Enum value in Enum.GetValues(UnderlyingType))
            {
                IEnumerationValueInfo enumerationValueInfo = GetValueInfoByValue(value, businessObject);
                if (enumerationValueInfo != null)
                {
                    valueInfos.Add(enumerationValueInfo);
                }
            }
            return(valueInfos.ToArray());
        }
예제 #11
0
 /// <summary> Ensures that the <see cref="Value"/> is set to the enum-value of the <see cref="InternalValue"/>. </summary>
 protected void EnsureValue()
 {
     if (_enumerationValueInfo != null &&
         _enumerationValueInfo.Identifier == _internalValue)
     {
         //  Still chached in _enumerationValueInfo
         _value = _enumerationValueInfo.Value;
     }
     else if (_internalValue != null && Property != null)
     {
         //  Can get a new EnumerationValueInfo
         _enumerationValueInfo = Property.GetValueInfoByIdentifier(_internalValue, GetBusinessObject());
         _value = _enumerationValueInfo.Value;
     }
     else if (_internalValue == null)
     {
         _value = null;
         _enumerationValueInfo = null;
     }
 }
예제 #12
0
        /// <summary>
        /// Sets the value from the backing field.
        /// </summary>
        /// <remarks>
        /// <para>Setting the value via this method does not affect the control's dirty state.</para>
        /// </remarks>
        protected void SetValue(object value)
        {
            _value = value;

            if (Property != null && _value != null)
            {
                _enumerationValueInfo = Property.GetValueInfoByValue(_value, GetBusinessObject());
            }
            else
            {
                _enumerationValueInfo = null;
            }

            if (_enumerationValueInfo != null)
            {
                InternalValue = _enumerationValueInfo.Identifier;
            }
            else
            {
                InternalValue = null;
            }
        }
예제 #13
0
        public void GetDisplayNameFromGlobalizationSerivce()
        {
            var mockEnumerationGlobalizationService     = _mockRepository.StrictMock <IEnumerationGlobalizationService>();
            IBusinessObjectEnumerationProperty property = CreateProperty(
                typeof(ClassWithValueType <TestEnum>),
                "Scalar",
                bindableObjectGlobalizationService: new BindableObjectGlobalizationService(
                    MockRepository.GenerateStub <IGlobalizationService>(),
                    MockRepository.GenerateStub <IMemberInformationGlobalizationService>(),
                    mockEnumerationGlobalizationService,
                    MockRepository.GenerateStub <IExtensibleEnumGlobalizationService>()));

            Expect.Call(
                mockEnumerationGlobalizationService.TryGetEnumerationValueDisplayName(Arg.Is(TestEnum.Value1), out Arg <string> .Out("MockValue1").Dummy))
            .Return(true);
            _mockRepository.ReplayAll();

            IEnumerationValueInfo actual = property.GetValueInfoByValue(TestEnum.Value1, null);

            _mockRepository.VerifyAll();
            CheckEnumerationValueInfo(new EnumerationValueInfo(TestEnum.Value1, "Value1", "MockValue1", true), actual);
        }
예제 #14
0
        public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
        {
            ArgumentUtility.CheckNotNull("value", value);
            ArgumentUtility.CheckNotNullAndType <AccessControlEntry> ("businessObject", businessObject);
            ArgumentUtility.CheckNotNull("property", property);

            AccessControlEntry ace = (AccessControlEntry)businessObject;
            bool isStateful        = ace.AccessControlList is StatefulAccessControlList;

            switch (property.Identifier)
            {
            case "TenantCondition":
                return(value.IsEnabled && IsTenantConditionEnabled((TenantCondition)value.Value, isStateful));

            case "GroupCondition":
                return(value.IsEnabled && IsGroupConditionEnabled((GroupCondition)value.Value, isStateful));

            case "UserCondition":
                return(value.IsEnabled && IsUserConditionEnabled((UserCondition)value.Value, isStateful));

            default:
                throw CreateInvalidOperationException("The property '{0}' is not supported by the '{1}'.", property.Identifier, typeof(AccessControlEntryPropertiesEnumerationValueFilter).FullName);
            }
        }
 public BooleanToEnumPropertyConverter(IBusinessObjectBooleanProperty property)
 {
     _enumInfoTrue  = new BooleanEnumerationValueInfo(true, property);
     _enumInfoFalse = new BooleanEnumerationValueInfo(false, property);
 }
 public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
 {
     return(true);
 }
 public bool IsEnabled(IEnumerationValueInfo value, IBusinessObject businessObject, IBusinessObjectEnumerationProperty property)
 {
     throw new NotImplementedException();
 }