Esempio n. 1
0
        private ReferenceDisplayFieldDefinition GetDisplayField(ReferenceHelperContext context, FieldEdit fieldInfo, bool throwOnError)
        {
            var publishedProcess = fieldInfo.GetParent<ProcessEdit>();

            if (context.VisitedFields.Contains(Tuple.Create(publishedProcess.SystemName, fieldInfo.SystemName)))
            {
                throw new CircularReferenceException("Circular reference detected.");
            }

            var fieldDefinition = new ReferenceDisplayFieldDefinition
            {
                Name = fieldInfo.Name,
                SystemName = fieldInfo.SystemName,
                ColumnType = fieldInfo.FieldType.ColumnType,
                DefinedIn = GetProcessDefinition(publishedProcess),
            };

            var tuple = Tuple.Create(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

            try
            {
                context.VisitedFields.Add(tuple);

                if (fieldDefinition.IsRef)
                {
                    var crStep = (CrossRefRequiredStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is CrossRefRequiredStepEdit);

                    if (crStep == null || !crStep.CrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Cross reference process is null.");

                    if (crStep.AllowMultiple)
                        fieldDefinition.ColumnType = ColumnTypes.MultiReference;

                    var referencedProcess = Cache.GetProcessInfo(crStep.CrossRefProcessId.Value);

                    fieldDefinition.ReferencedProcess = GetProcessDefinition(referencedProcess);

                    if (fieldDefinition.ColumnType == ColumnTypes.MultiReference && !string.IsNullOrEmpty(crStep.LinkFieldSystemName))
                    {
                        var referenceField = GetJoinField(referencedProcess.SystemName, crStep.LinkFieldSystemName);

                        if (referenceField.ColumnType != ColumnTypes.Reference)
                            throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Invalid link field type.");

                        if (referenceField.ReferencedProcess.SystemName != fieldDefinition.DefinedIn.SystemName)
                            throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Invalid link field.");

                        fieldDefinition.ReferenceField = referenceField;
                    }

                    var order = 0;
                    ReferenceDisplayFieldDefinition fd;

                    foreach (var displayField in crStep.SelectedFields)
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, displayField.FullPath, throwOnError);

                        ++order;
                        fd.Order = order;
                        fd.Guid = displayField.FieldGuid;
                        fd.ShowOnDetails = true;
                        fd.ShowOnSearch = false;
                        fieldDefinition.Subfields.Add(fd);
                    }

                    fd = fieldDefinition.Subfields.FirstOrDefault(x => x.FullPath == crStep.DisplayFieldName);

                    if (fd != null)
                        fd.ShowOnSearch = true;
                    else
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, crStep.DisplayFieldName, throwOnError);

                        fd.Order = 1;
                        fd.Guid = Guid.NewGuid();
                        fd.ShowOnDetails = false;
                        fd.ShowOnSearch = true;
                        fieldDefinition.Subfields.Add(fd);
                    }
                }

                if (fieldDefinition.IsReverseRef)
                {
                    var rcrStep = (ReverseCrossRefRequiredStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is ReverseCrossRefRequiredStepEdit);
                    var rcrOptions = (ReverseCrossRefOptionsStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is ReverseCrossRefOptionsStepEdit);

                    if (rcrStep == null || rcrOptions == null || !rcrStep.ReverseCrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(
                            fieldDefinition.DefinedIn.SystemName,
                            fieldDefinition.SystemName,
                            "Reverse cross reference process is null.");

                    var referencedProcess = Cache.GetProcessInfo(rcrStep.ReverseCrossRefProcessId.Value);

                    var crStep = Cache.GetCrossReferenceRequiredStep(referencedProcess.SystemName, rcrStep.CrossRefFieldName);
                    if (!crStep.CrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(
                            fieldDefinition.DefinedIn.SystemName,
                            fieldDefinition.SystemName,
                            "Cross reference process is null.");

                    fieldDefinition.ShowLatestVersion = rcrOptions.ShowLatestVersion && referencedProcess.ProcessOption == ProcessOption.VersionEnabled;
                    fieldDefinition.ReferenceField = new ReferenceJoinFieldDefinition
                    {
                        SystemName = rcrStep.CrossRefFieldName,
                        ColumnType =
                            crStep.AllowMultiple
                                ? ColumnTypes.MultiReference
                                : ColumnTypes.Reference,
                        DefinedIn = GetProcessDefinition(referencedProcess),
                        ReferencedProcess = GetProcessDefinition(publishedProcess)
                    };

                    var order = 0;
                    ReferenceDisplayFieldDefinition fd;

                    foreach (var displayField in rcrStep.DisplayFields.OrderBy(df => df.Order))
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, displayField.FullPath, throwOnError);

                        if (fd != null)
                        {
                            ++order;
                            fd.Order = order;
                            fd.Guid = displayField.Guid;
                            fd.ShowOnDetails = true;
                            fd.ShowOnSearch = false;
                            fieldDefinition.Subfields.Add(fd);
                        }
                    }

                    fd = fieldDefinition.Subfields.FirstOrDefault(x => x.FullPath == rcrStep.DisplayFieldName);

                    if (fd != null)
                    {
                        fd.ShowOnSearch = true;
                    }
                    else
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, rcrStep.DisplayFieldName, throwOnError);

                        fd.Order = 1;
                        fd.Guid = Guid.NewGuid();
                        fd.ShowOnDetails = false;
                        fd.ShowOnSearch = true;

                        fieldDefinition.Subfields.Add(fd);
                    }
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Numeric)
                {
                    var numericStep = (NumericRequiredStepEdit)fieldInfo.StepList.First(s => s is NumericRequiredStepEdit);

                    fieldDefinition.NumericType = NumericTypes.Numeric;

                    if (numericStep.NumberOfDigits == 0 && numericStep.Minimum >= int.MinValue && numericStep.Maximum <= int.MaxValue && numericStep.NumericType == NumericTypes.Numeric)
                        fieldDefinition.ColumnType = ColumnTypes.Integer;

                    fieldDefinition.NumericType = numericStep.NumericType;
                    fieldDefinition.NumberOfDigits = numericStep.NumberOfDigits;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.DateTime)
                {
                    var dateTimeStep = (DateRequiredSettingsStepEdit)fieldInfo.StepList.First(s => s is DateRequiredSettingsStepEdit);
                    fieldDefinition.DateTimeFormat = DateTimeFormat.DateTime;

                    DateTimeFormat format;

                    if (Enum.TryParse(dateTimeStep.SelectedDateTimeFormat, true, out format))
                    {
                        fieldDefinition.DateTimeFormat = format;
                    }
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Boolean)
                {
                    var checkboxStep = (CheckboxOptionsStepEdit)fieldInfo.StepList.First(s => s is CheckboxOptionsStepEdit);
                    fieldDefinition.MainLabel = checkboxStep.MainLabel;
                    fieldDefinition.UndefinedLabel = checkboxStep.UndefinedLabel;
                    fieldDefinition.TrueLabel = checkboxStep.TrueLabel;
                    fieldDefinition.FalseLabel = checkboxStep.FalseLabel;
                    fieldDefinition.IsSwitchToggle = checkboxStep.IsSwitchToggle;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Image)
                {
                    var pictureStep = fieldInfo.StepList.OfType<PictureSetupStepEdit>().First();

                    fieldDefinition.SearchImageWidth = pictureStep.SearchWidth;
                    fieldDefinition.SearchImageHeight = pictureStep.SearchHeight;
                    fieldDefinition.DetailsImageWidth = pictureStep.DetailsWidth;
                    fieldDefinition.DetailsImageHeight = pictureStep.DetailsHeight;
                    fieldDefinition.UseOriginalImageSize = pictureStep.UseOriginalSize;
                }
            }
            finally
            {
                context.VisitedFields.Remove(tuple);
            }

            return fieldDefinition;
        }
Esempio n. 2
0
        private ReferenceJoinFieldDefinition GetJoinField(FieldEdit fieldInfo)
        {
            var columnType = fieldInfo.FieldType.ColumnType;
            var publishedProcess = fieldInfo.GetParent<ProcessEdit>();

            if (columnType == ColumnTypes.Reference || columnType == ColumnTypes.MultiReference)
            {
                var crStep = (CrossRefRequiredStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is CrossRefRequiredStepEdit);

                if (crStep != null)
                {
                    if (crStep.AllowMultiple)
                        columnType = ColumnTypes.MultiReference;

                    if (!crStep.CrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(publishedProcess.SystemName, fieldInfo.SystemName, "Cross reference process is null.");

                    var referencedProcess = Cache.GetProcessInfo(crStep.CrossRefProcessId.Value);

                    var joinField = new ReferenceJoinFieldDefinition
                    {
                        Name = fieldInfo.Name,
                        SystemName = fieldInfo.SystemName,
                        ColumnType = columnType,
                        DefinedIn = GetProcessDefinition(publishedProcess),
                        ReferencedProcess = GetProcessDefinition(referencedProcess)
                    };

                    if (columnType == ColumnTypes.MultiReference && !string.IsNullOrEmpty(crStep.LinkFieldSystemName))
                    {
                        var referenceField = GetJoinField(referencedProcess.SystemName, crStep.LinkFieldSystemName);

                        if (referenceField.ColumnType != ColumnTypes.Reference)
                            throw new InvalidReferenceFieldExpcetion(joinField.DefinedIn.SystemName, joinField.SystemName, "Invalid link field type.");

                        if (referenceField.ReferencedProcess.SystemName != joinField.DefinedIn.SystemName)
                            throw new InvalidReferenceFieldExpcetion(joinField.DefinedIn.SystemName, joinField.SystemName, "Invalid link field.");

                        joinField.ReferenceField = referenceField;
                    }

                    return joinField;
                }
            }

            if (columnType == ColumnTypes.ReverseReference || columnType == ColumnTypes.ReverseMultiReference)
            {
                var rcrStep = (ReverseCrossRefRequiredStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is ReverseCrossRefRequiredStepEdit);
                if (rcrStep != null)
                {
                    if (rcrStep.DisplayMultiple)
                        columnType = ColumnTypes.ReverseMultiReference;

                    if (!rcrStep.ReverseCrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(publishedProcess.SystemName, fieldInfo.SystemName, "Reverse cross reference process is null.");

                    var rcrOptions = (ReverseCrossRefOptionsStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is ReverseCrossRefOptionsStepEdit);
                    if (rcrOptions != null)
                    {
                        var referencedProcess = Cache.GetProcessInfo(rcrStep.ReverseCrossRefProcessId.Value);
                        var crStep = Cache.GetCrossReferenceRequiredStep(referencedProcess.SystemName, rcrStep.CrossRefFieldName);

                        if (!crStep.CrossRefProcessId.HasValue)
                            throw new InvalidReferenceFieldExpcetion(referencedProcess.SystemName, rcrStep.CrossRefFieldName, "Cross reference process is null.");

                        var joinField = new ReferenceJoinFieldDefinition
                        {
                            Name = fieldInfo.Name,
                            SystemName = fieldInfo.SystemName,
                            ColumnType = columnType,
                            ShowLatestVersion = rcrOptions.ShowLatestVersion && referencedProcess.ProcessOption == ProcessOption.VersionEnabled,
                            DefinedIn = GetProcessDefinition(publishedProcess),
                            ReferencedProcess = GetProcessDefinition(referencedProcess),
                            ReferenceField = new ReferenceJoinFieldDefinition
                            {
                                SystemName = rcrStep.CrossRefFieldName,
                                ColumnType =
                                    crStep.AllowMultiple
                                        ? ColumnTypes.MultiReference
                                        : ColumnTypes.Reference,
                                DefinedIn = GetProcessDefinition(referencedProcess),
                                ReferencedProcess = GetProcessDefinition(publishedProcess)
                            }
                        };

                        return joinField;
                    }
                }
            }

            throw new InvalidReferenceFieldExpcetion(publishedProcess.SystemName, fieldInfo.SystemName, string.Format(@"Column type '{0}' is not valid for a join field.", columnType));
        }