示例#1
0
        private static DetailsCommandResult CreateDetailsResult(IEditableRoot editableRoot)
        {
            var result = new DetailsCommandResult { Id = editableRoot.Id, DisplayName = editableRoot.ProcessDisplayName, IsTabbedUI = IsTabbedUI(editableRoot) };
            var visibleFields = new HashSet<string>(editableRoot.Sections.SelectMany(s => s.Fields).Where(f => !f.IsHidden).Select(f => f.SystemName));
            var validationContext = editableRoot.GetValidationContext();

            foreach (var sect in editableRoot.Sections)
            {
                var section = new SectionInfo { Name = sect.Name };
                var row = new RowInfo();
                var rowLength = 0d;

                foreach (var field in sect.Fields)
                {
                    var prop = editableRoot.GetPropertyByName(field.SystemName);
                    if (!visibleFields.Contains(prop.Name))
                    {
                        continue;
                    }

                    var fieldInfo = FieldInfoFactory.Create(prop, editableRoot, field, GetValue(prop, editableRoot), validationContext);
                    if (rowLength + fieldInfo.Width > 100)
                    {
                        if (row.Fields.Any())
                            section.Rows.Add(row);
                        row = new RowInfo();
                        rowLength = fieldInfo.Width >= 100 ? 100 : fieldInfo.Width;
                    }
                    else
                        rowLength += fieldInfo.Width;

                    row.Fields.Add(fieldInfo);
                }

                if (row.Fields.Any())
                    section.Rows.Add(row);

                if (section.Rows.Any())
                    result.Sections.Add(section);
            }


            result.States = new List<IStateInfo>();
            var supportStates = editableRoot as ISupportStates;
            if (supportStates != null)
            {
                foreach (var s in supportStates.StateManager.States)
                {
                    result.States.Add(new StateInfo(s.Name, s.Guid));
                }
            }

            result.CurrentStateGuid = editableRoot.GetCurrentStateGuid();

            return result;
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// The <see cref="SampleTypeFieldOptions"/>.
        /// </returns>
        public static SampleTypeFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = new SampleTypeFieldOptions();

            var list = (from object sampleType in Enum.GetValues(typeof(SampleTypes)) select sampleType.ToString()).ToList();
            result.PossibleValues = list;

            var trueLabelProperty = model.GetPropertyByName(property.Name + Constants.SampleTrueLabel);
            var falseLabelProperty = model.GetPropertyByName(property.Name + Constants.SampleFalseLabel);

            if (trueLabelProperty != null)
            {
                result.TrueLabel = trueLabelProperty.GetValue(model, null) as string;
                if (string.IsNullOrEmpty(result.TrueLabel))
                {
                    result.TrueLabel = LanguageService.Translate("Item_Pass");
                }
            }

            if (falseLabelProperty != null)
            {
                result.FalseLabel = falseLabelProperty.GetValue(model, null) as string;
                if (string.IsNullOrEmpty(result.FalseLabel))
                {
                    result.FalseLabel = LanguageService.Translate("Item_Fail");
                }
            }

            return result;
        }
示例#3
0
        /// <summary>
        /// Copies the answer data.
        /// </summary>
        /// <param name="answerFieldValues">
        /// The answer field values.
        /// </param>
        /// <param name="answerItem">
        /// The answer item.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="answerFieldValues"/> parameter is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="answerItem"/> parameter is null.
        /// </exception>
        public static void CopyAnswerData(ICollection<ChecklistAnswerFieldValue> answerFieldValues, IEditableRoot answerItem)
        {
            if (answerFieldValues == null)
                throw new ArgumentNullException("answerFieldValues");

            if (answerItem == null)
                throw new ArgumentNullException("answerItem");

            using (new ThreadLocalBypassPropertyCheckContext())
            {
                foreach (var fieldValue in answerFieldValues.Where(f => f.Value != null))
                {
                    var answerProperty = answerItem.GetPropertyByName(fieldValue.FieldName);
                    var answerValue = answerItem.GetValueByPropertyName(fieldValue.FieldName);

                    if (fieldValue.Value is ICrossRefItemList && answerValue is ICrossRefItemList)
                    {
                        var qList = (ICrossRefItemList)fieldValue.Value;
                        var aList = (ICrossRefItemList)answerValue;

                        aList.Clear();
                        foreach (var crItem in qList.Cast<ICrossRefItemInfo>())
                        {
#if !SILVERLIGHT
                            aList.Assign(crItem.Id);
#else
                            aList.Assign(crItem.Id, (o, e) => { });
#endif
                        }

                        continue;
                    }

                    if (answerProperty.PropertyType.IsInstanceOfType(fieldValue.Value))
                    {
                        answerItem.SetValueByPropertyName(fieldValue.FieldName, fieldValue.Value);
                    }
                    else
                    {
                        throw new VeyronException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Cannot assign value of type \"{0}\" to property \"{1}\".",
                                fieldValue.Value.GetType().AssemblyQualifiedName,
                                fieldValue.FieldName));
                    }
                }
            }
        }
示例#4
0
        private static IApprovalFieldManager GetApprovalFieldManager(IEditableRoot item, string approvalFieldName)
        {
            var approvalProperty = item.GetPropertyByName(approvalFieldName);
            if (approvalProperty == null)
            {
                throw new ArgumentOutOfRangeException(
                    "approvalFieldName",
                    string.Format(CultureInfo.InvariantCulture, "Could not find the field '{0}' in process '{1}'.", approvalFieldName, item.ProcessName));
            }

            var declaringType = approvalProperty.DeclaringType;
            if (declaringType == null)
            {
                throw new ArgumentException("Declaring type is null.");
            }

            var approvalManagerPropertyName = string.Format(CultureInfo.InvariantCulture, "{0}Manager", approvalProperty.Name);
            var approvalManagerProperty = declaringType.GetProperty(approvalManagerPropertyName, BindingFlags.Public | BindingFlags.Static);

            if (approvalManagerProperty == null)
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Could not find the property '{0}' in type '{1}'.",
                        approvalManagerPropertyName,
                        declaringType.FullName));
            }

            return approvalManagerProperty.GetValue(null, null) as IApprovalFieldManager;
        }
示例#5
0
        /// <summary>
        /// Extracts and returns field back color, if specified. 
        /// </summary>
        /// <param name="baseModel">Editable root model.</param>
        /// <param name="property">Field property.</param>
        /// <returns>
        /// HTML color string (like "#ffffff") if field has back color. 
        /// Empty string if field does not have back color.
        /// null if field does not support back color change.
        /// </returns>
        public static string GetBackColor(IEditableRoot baseModel, PropertyInfo property)
        {
            if (baseModel == null)
            {
                throw new ArgumentNullException("baseModel");
            }

            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var fieldBackgoundAttr = (FieldBackgroundAttribute)property.GetCustomAttributes(typeof(FieldBackgroundAttribute), false).Select(d => d).FirstOrDefault();

            if (fieldBackgoundAttr != null)
            {
                var backcolorFieldName = fieldBackgoundAttr.BackcolorFieldName;

                if (string.IsNullOrEmpty(backcolorFieldName) || baseModel == null)
                {
                    return string.Empty;
                }

                var bcProperty = baseModel.GetPropertyByName(backcolorFieldName);
                if (bcProperty != null)
                {
                    var longColor = (long)(bcProperty.GetValue(baseModel, null) ?? 0);
                    return longColor == 0 ? string.Empty : ColorTranslator.ToHtml(Color.FromArgb((int)longColor));
                }

                return string.Empty;
            }

            return null;
        }
示例#6
0
 private bool IsCalculated(IEditableRoot obj)
 {
     return obj.GetPropertyByName(PrimaryProperty.Name).GetCustomAttributes(typeof(CalculatedAttribute), false).Any();
 }
示例#7
0
 /// <summary>
 /// Determines whether [is rich text] [the specified object].
 /// </summary>
 /// <param name="obj">The object.</param>
 /// <returns><c>true</c> if [is rich text] [the specified object]; otherwise, <c>false</c>.</returns>
 private bool IsRichText(IEditableRoot obj)
 {
     return obj.GetPropertyByName(PrimaryProperty.Name).GetCustomAttributes(typeof(RichTextAttribute), false).Any();
 }