Ejemplo n.º 1
0
        private static string GetCustomPropertyChar(PropertyLite propertyValue, WorkflowPropertyType propertyType)
        {
            // BluePrintSys.RC.CrossCutting.Logging.Log.Assert(
            //    (propertyValue != null) && propertyValue.SaveState.HasFlag(NodeSaveState.MemoryNode));
            if ( /*propertyValue.NodeDeleted ||*/
                (((int)PropertyTypePredefined.GroupMask & (int)propertyType.Predefined) !=
                 (int)PropertyTypePredefined.CustomGroup))
            {
                return(null);
            }
            PropertyPrimitiveType primitiveType;

            if (propertyType is NumberPropertyType)
            {
                primitiveType = PropertyPrimitiveType.Number;
            }
            else if (propertyType is DatePropertyType)
            {
                primitiveType = PropertyPrimitiveType.Date;
            }
            else if (propertyType is TextPropertyType)
            {
                primitiveType = PropertyPrimitiveType.Text;
            }
            else if (propertyType is UserPropertyType)
            {
                primitiveType = PropertyPrimitiveType.User;
            }
            else if (propertyType is ChoicePropertyType)
            {
                primitiveType = PropertyPrimitiveType.Choice;
            }
            // else if (propertyValue is DImagePropertyValue)
            // {
            //    primitiveType = PropertyPrimitiveType.Image;
            // }
            else
            {
                // BluePrintSys.RC.CrossCutting.Logging.Log.Assert(false);
                return(null);
            }
            XmlCustomProperties customProperties = new XmlCustomProperties();
            XmlCustomProperty   customProperty   = XmlCustomProperty.CreateAsValue(propertyType.PropertyTypeId,
                                                                                   (int)primitiveType);

            customProperties.CustomProperties.Add(customProperty);
            if (propertyType is ChoicePropertyType)
            {
                List <XmlCustomPropertyValidValue> validValues = customProperty.ValidValues;
                foreach (int choiceId in propertyValue.ChoiceIds)
                {
                    var customChoice = (propertyType as ChoicePropertyType).ValidValues
                                       .Where(v => v.Sid.Value == choiceId)
                                       .Select(v => v.Id).FirstOrDefault().Value;
                    XmlCustomPropertyValidValue validValue = XmlCustomPropertyValidValue.CreateAsValue(customChoice);
                    validValues.Add(validValue);
                }
            }
            return(XmlModelSerializer.SerializeCustomProperties(customProperties));
        }
        private void InitializeUserPropertyChangeAction()
        {
            DefaultUserPropertyType = new UserPropertyType()
            {
                InstancePropertyTypeId = DefaultUserInstancePropertyTypeId,
                PrimitiveType          = PropertyPrimitiveType.User
            };
            _propertyChangeAction = new PropertyChangeUserGroupsAction()
            {
                InstancePropertyTypeId = DefaultUserInstancePropertyTypeId
            };
            ((PropertyChangeUserGroupsAction)_propertyChangeAction).UserGroups.AddRange(DefaultUserGroups);

            _customPropertyTypes = new List <WorkflowPropertyType>()
            {
                DefaultUserPropertyType
            };
            _executionParameters = new ExecutionParameters(
                1,
                new VersionControlArtifactInfo(),
                null,
                _customPropertyTypes,
                _saveRepositoryMock.Object,
                null,
                null,
                new List <IPropertyValidator>(),
                _reuseValidatorMock.Object);
        }
 public void TestInitialize()
 {
     _validator    = new UserPropertyValidator();
     _propertyLite = new PropertyLite()
     {
         PropertyTypeId = DefaultInstancePropertyTypeId
     };
     _propertyType = new UserPropertyType()
     {
         PropertyTypeId         = DefaultPropertyTypeId,
         InstancePropertyTypeId = DefaultInstancePropertyTypeId
     };
     _validationContext = new ValidationContext(
         new List <SqlUser>()
     {
         new SqlUser()
         {
             UserId = DefaultUser.Id.Value
         }
     },
         new List <SqlGroup>()
     {
         new SqlGroup()
         {
             GroupId = DefaultGroup.Id.Value
         }
     });
 }
Ejemplo n.º 4
0
 private static string GetSearchableValue(PropertyLite propertyLite, WorkflowPropertyType propertyType)
 {
     if (propertyType is TextPropertyType)
     {
         return(propertyLite.TextOrChoiceValue);
     }
     return(null);
 }
        private PropertySetResult UserPropertyChangedToAnotherPropertyValidation(WorkflowPropertyType propertyType)
        {
            // Arrange
            InitializeUserPropertyChangeAction();
            _executionParameters.CustomPropertyTypes.Clear();
            _executionParameters.CustomPropertyTypes.Add(propertyType);

            // Act
            return(_propertyChangeAction.ValidateAction(_executionParameters));
        }
Ejemplo n.º 6
0
        private string GetTextPropertyValue(WorkflowPropertyType propertyType, PropertyLite property)
        {
            if (property.TextOrChoiceValue == null)
            {
                return(null);
            }

            if (propertyType.Predefined == PropertyTypePredefined.Name)
            {
                return(property.TextOrChoiceValue);
            }
            else
            {
                return("<html><head/><p>" + property.TextOrChoiceValue + "</p></html>");
            }
        }
 private void InitializeChoicePropertyChangeAction()
 {
     DefaultChoicePropertyType = new ChoicePropertyType()
     {
         InstancePropertyTypeId = DefaultChoiceInstancePropertyTypeId,
         PrimitiveType          = PropertyPrimitiveType.Choice
     };
     _propertyChangeAction = new PropertyChangeAction()
     {
         InstancePropertyTypeId = DefaultChoiceInstancePropertyTypeId
     };
     _customPropertyTypes = new List <WorkflowPropertyType>()
     {
         DefaultChoicePropertyType
     };
 }
        protected override PropertySetResult PopulatePropertyLite(WorkflowPropertyType propertyType)
        {
            if (!propertyType.PrimitiveType.HasValue ||
                propertyType.PrimitiveType.Value != PropertyPrimitiveType.User ||
                !String.IsNullOrEmpty(PropertyValue))
            {
                return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty,
                                             "Property type is not a user property anymore. Property change action is currently invalid"));
            }

            PropertyLiteValue = new PropertyLite()
            {
                PropertyTypeId = InstancePropertyTypeId
            };
            PropertyLiteValue.UsersAndGroups.AddRange(UserGroups);
            return(null);
        }
Ejemplo n.º 9
0
        protected virtual PropertySetResult PopulatePropertyLite(WorkflowPropertyType propertyType)
        {
            switch (propertyType?.PrimitiveType)
            {
            case PropertyPrimitiveType.Text:
                PropertyLiteValue = new PropertyLite()
                {
                    PropertyTypeId    = InstancePropertyTypeId,
                    TextOrChoiceValue = PropertyValue
                };
                break;

            case PropertyPrimitiveType.Number:
                return(PopulateNumberPropertyLite());

            case PropertyPrimitiveType.Date:
                return(PopulateDatePropertyLite());

            case PropertyPrimitiveType.Choice:
                PropertyLiteValue = new PropertyLite
                {
                    PropertyTypeId = InstancePropertyTypeId,
                };
                if (!ValidValues.Any() && !propertyType.Validate.GetValueOrDefault(false))
                {
                    PropertyLiteValue.TextOrChoiceValue = PropertyValue;
                }
                else
                {
                    PropertyLiteValue.ChoiceIds.AddRange(ValidValues);
                }
                break;

            case PropertyPrimitiveType.User:
                return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now user, but does not contain user and group change actions"));

            default:
                PropertyLiteValue = new PropertyLite()
                {
                    PropertyTypeId = InstancePropertyTypeId
                };
                break;
            }
            return(null);
        }
Ejemplo n.º 10
0
        private Dictionary <int, List <WorkflowPropertyType> > ToItemTypePropertyTypesDictionary(IEnumerable <SqlPropertyType> sqlPropertyTypes)
        {
            var dictionary = new Dictionary <int, List <WorkflowPropertyType> >();

            foreach (var sqlPropertyType in sqlPropertyTypes)
            {
                WorkflowPropertyType workflowProperty;
                switch (sqlPropertyType.PrimitiveType)
                {
                case PropertyPrimitiveType.Text:
                {
                    workflowProperty = new TextPropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = GetInstancePropertyTypeId(sqlPropertyType.InstancePropertyTypeId, sqlPropertyType.Predefined),
                        Name               = sqlPropertyType.Name,
                        PropertyTypeId     = sqlPropertyType.PropertyTypeId,
                        PrimitiveType      = sqlPropertyType.PrimitiveType,
                        IsRequired         = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        StringDefaultValue = sqlPropertyType.StringDefaultValue,
                        VersionId          = sqlPropertyType.VersionId,
                        Predefined         = sqlPropertyType.Predefined,

                        DefaultValue = sqlPropertyType.StringDefaultValue,
                        IsValidate   = sqlPropertyType.Validate.GetValueOrDefault(false),
                        IsRichText   = sqlPropertyType.IsRichText
                    };
                    break;
                }

                case PropertyPrimitiveType.Number:
                {
                    workflowProperty = new NumberPropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValue           = PropertyHelper.ToDecimal((byte[])sqlPropertyType.DecimalDefaultValue),
                        DecimalPlaces          = sqlPropertyType.DecimalPlaces.GetValueOrDefault(0),
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        Range          = new Range <decimal>
                        {
                            End   = PropertyHelper.ToDecimal((byte[])sqlPropertyType.NumberRange_End).GetValueOrDefault(0),
                            Start = PropertyHelper.ToDecimal((byte[])sqlPropertyType.NumberRange_Start).GetValueOrDefault(0)
                        },
                        PrimitiveType = sqlPropertyType.PrimitiveType,
                        IsRequired    = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        IsValidate    = sqlPropertyType.Validate.GetValueOrDefault(false),
                        VersionId     = sqlPropertyType.VersionId,
                        Predefined    = sqlPropertyType.Predefined
                    };
                    break;
                }

                case PropertyPrimitiveType.Date:
                {
                    workflowProperty = new DatePropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValue           = sqlPropertyType.DateDefaultValue,
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        Range          = new Range <DateTime?>
                        {
                            End   = sqlPropertyType.DateRange_End,
                            Start = sqlPropertyType.DateRange_Start
                        },
                        PrimitiveType = sqlPropertyType.PrimitiveType,
                        IsRequired    = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        IsValidate    = sqlPropertyType.Validate.GetValueOrDefault(false),
                        VersionId     = sqlPropertyType.VersionId,
                        Predefined    = sqlPropertyType.Predefined
                    };
                    break;
                }

                case PropertyPrimitiveType.User:
                    workflowProperty = new UserPropertyType()
                    {
                        DefaultLabels          = sqlPropertyType.UserDefaultLabel,
                        DefaultValues          = sqlPropertyType.UserDefaultValue,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        PrimitiveType  = sqlPropertyType.PrimitiveType,
                        IsRequired     = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        VersionId      = sqlPropertyType.VersionId,
                        Predefined     = sqlPropertyType.Predefined
                    };
                    break;

                case PropertyPrimitiveType.Choice:
                {
                    workflowProperty = new ChoicePropertyType
                    {
                        AllowMultiple = sqlPropertyType.AllowMultiple,
                        // DefaultValue = PropertyHelper.ToDecimal((byte[])sqlPropertyType.DecimalDefaultValue),
                        ValidValues = XmlModelSerializer.DeserializeCustomProperties(sqlPropertyType.CustomProperty).CustomProperties[0]?.ValidValues
                                      .OrderBy(v => I18NHelper.Int32ParseInvariant(v.OrderIndex))
                                      .Select(v =>
                            {
                                int?vvId = null;
                                if (!string.IsNullOrWhiteSpace(v.LookupListItemId))
                                {
                                    int intValue;
                                    if (int.TryParse(v.LookupListItemId, out intValue))
                                    {
                                        vvId = intValue;
                                    }
                                }
                                int?vvSid = null;
                                if (!string.IsNullOrWhiteSpace(v.StandardLookupListItemId))
                                {
                                    int intValue;
                                    if (int.TryParse(v.StandardLookupListItemId, out intValue))
                                    {
                                        vvSid = intValue;
                                    }
                                }
                                return(new ValidValue {
                                    Id = vvId, Value = v.Value, Sid = vvSid
                                });
                            }).ToList(),
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        Name           = sqlPropertyType.Name,
                        PropertyTypeId = sqlPropertyType.PropertyTypeId,
                        PrimitiveType  = sqlPropertyType.PrimitiveType,
                        IsRequired     = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        IsValidate     = sqlPropertyType.Validate.GetValueOrDefault(false),
                        VersionId      = sqlPropertyType.VersionId,
                        Predefined     = sqlPropertyType.Predefined
                    };
                    break;
                }

                // TODO: add other DPropertyTypes
                default:
                {
                    workflowProperty = new WorkflowPropertyType
                    {
                        AllowMultiple          = sqlPropertyType.AllowMultiple,
                        DefaultValidValueId    = sqlPropertyType.DefaultValidValueId,
                        InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId,
                        IsRichText             = sqlPropertyType.IsRichText,
                        Name               = sqlPropertyType.Name,
                        PropertyTypeId     = sqlPropertyType.PropertyTypeId,
                        PrimitiveType      = sqlPropertyType.PrimitiveType,
                        IsRequired         = sqlPropertyType.Required != null && sqlPropertyType.Required.Value,
                        StringDefaultValue = sqlPropertyType.StringDefaultValue,
                        VersionId          = sqlPropertyType.VersionId,
                        Predefined         = sqlPropertyType.Predefined
                    };
                    break;
                }
                }

                if (dictionary.ContainsKey(sqlPropertyType.ItemTypeId))
                {
                    dictionary[sqlPropertyType.ItemTypeId].Add(workflowProperty);
                }
                else
                {
                    dictionary.Add(sqlPropertyType.ItemTypeId, new List <WorkflowPropertyType> {
                        workflowProperty
                    });
                }
            }
            return(dictionary);
        }