/// <summary>
        /// Determines whether this instance [can be key field] the specified field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns><c>true</c> if this instance [can be key field] the specified field; otherwise, <c>false</c>.</returns>
        private static bool CanBeKeyField(FieldEdit field)
        {
            if (!CanBeDestinationField(field))
                return false;

            switch (field.GetColumnType())
            {
                case ColumnTypes.Integer:
                case ColumnTypes.String:
                case ColumnTypes.Reference:
                case ColumnTypes.Numeric:
                case ColumnTypes.Boolean:
                case ColumnTypes.DateTime:
                case ColumnTypes.Double:
                    return true;
            }

            return false;
        }
        /// <summary>
        /// Determines whether this instance [can be destination field] the specified field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns><c>true</c> if this instance [can be destination field] the specified field; otherwise, <c>false</c>.</returns>
        private static bool CanBeDestinationField(FieldEdit field)
        {
            if (field.IsDeleted || field.IsCalculated())
                return false;

            return CanBeDestinationField(field.GetColumnType());
        }
예제 #3
0
        /// <summary>
        /// Creates the dependencies.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="field">The field.</param>
        /// <returns>IEnumerable{ExpressionDependency}.</returns>
        private IEnumerable<ExpressionDependency> CreateDependencies(ProcessDefinition process, FieldEdit field)
        {
            var declaringProcess = FindBaseProcess(process, field.GetBaseCopy().GetParent<IProcessEdit>().SystemName);

            switch (field.GetColumnType())
            {
                case ColumnTypes.ReverseReference:
                case ColumnTypes.ReverseMultiReference:
                    {
                        var join = (ReverseCrossReferenceFieldDefinition)CreateJoin(process, field);

                        foreach (var dependency in CreateDependencies(join.ReferencedProcess, join.ReferenceField.SystemName))
                        {
                            dependency.JoinFields.Insert(0, join);
                            yield return dependency;                          
                        }
                    }

                    yield break;

                case ColumnTypes.MultiReference:
                    {
                        var join = (MultiCrossReferenceFieldDefinition)CreateJoin(process, field);

                        if (join.LinkField == null)
                        {
                            yield return new ExpressionDependency
                                             {
                                                 ProcessName = join.DeclaringProcess.SystemName,
                                                 FieldName = join.SystemName
                                             };
                        }
                        else
                        {
                            foreach (var dependency in CreateDependencies(join.ReferencedProcess, join.LinkField.SystemName))
                            {
                                dependency.JoinFields.Insert(0, join);

                                yield return dependency;
                            }
                        }
                    }

                    yield break;

                case ColumnTypes.DisplayList:
                    // Since we can't determine which items should recalculate expressions when a DL item changes
                    // and recalculating expressions for all items is too slow, we'll skip DL dependencies.

                    yield break;

                default:
                    {
                        yield return new ExpressionDependency
                                         {
                                             ProcessName = declaringProcess.SystemName,
                                             FieldName = field.SystemName
                                         };
                    }

                    yield break;
            }
        }
예제 #4
0
        /// <summary>
        /// Creates the join.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="field">The field.</param>
        /// <returns>ReferenceFieldDefinition.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// </exception>
        private ReferenceFieldDefinition CreateJoin(ProcessDefinition process, FieldEdit field)
        {
            var declaringProcess = FindBaseProcess(process, field.GetBaseCopy().GetParent<IProcessEdit>().SystemName);

            switch (field.GetColumnType())
            {
                case ColumnTypes.Reference:
                    {
                        var step = field.StepList.OfType<CrossRefRequiredStepEdit>().FirstOrDefault();

                        if (step == null || !step.CrossRefProcessId.HasValue)
                            throw new InvalidOperationException(
                                string.Format(CultureInfo.InvariantCulture, "Field \"{0}\" is not a valid reference field.", field.SystemName));

                        var referencedProcess = GetPublishedProcessInfo(step.CrossRefProcessId.Value);
                        var join = new SingleCrossReferenceFieldDefinition
                                       {
                                           SystemName = field.SystemName,
                                           DeclaringProcess = declaringProcess,
                                           ReferencedProcess = CreateProcessDefinition(referencedProcess)
                                       };

                        return join;
                    }

                case ColumnTypes.MultiReference:
                    {
                        var step = field.StepList.OfType<CrossRefRequiredStepEdit>().FirstOrDefault();

                        if (step == null || !step.CrossRefProcessId.HasValue)
                            throw new InvalidOperationException(
                                string.Format(CultureInfo.InvariantCulture, "Field \"{0}\" is not a valid reference field.", field.SystemName));

                        var referencedProcess = GetPublishedProcessInfo(step.CrossRefProcessId.Value);
                        var join = new MultiCrossReferenceFieldDefinition
                                       {
                                           SystemName = field.SystemName,
                                           DeclaringProcess = declaringProcess,
                                           ReferencedProcess = CreateProcessDefinition(referencedProcess)
                                       };

                        if (!string.IsNullOrEmpty(step.LinkFieldSystemName))
                            join.LinkField =
                                (SingleCrossReferenceFieldDefinition)CreateJoin(join.ReferencedProcess, step.LinkFieldSystemName);

                        return join;
                    }

                case ColumnTypes.ReverseReference:
                    {
                        var step = field.StepList.OfType<ReverseCrossRefRequiredStepEdit>().FirstOrDefault();

                        if (step == null || !step.ReverseCrossRefProcessId.HasValue)
                            throw new InvalidOperationException(
                                string.Format(CultureInfo.InvariantCulture, "Field \"{0}\" is not a valid reference field.", field.SystemName));

                        var optionsStep = field.StepList.OfType<ReverseCrossRefOptionsStepEdit>().FirstOrDefault();
                        var referencedProcess = CreateProcessDefinition(GetPublishedProcessInfo(step.ReverseCrossRefProcessId.Value));
                        var join = new SingleReverseCrossReferenceFieldDefinition
                                       {
                                           SystemName = field.SystemName,
                                           DeclaringProcess = declaringProcess,
                                           ReferencedProcess = referencedProcess,
                                           ReferenceField = CreateJoin(referencedProcess, step.CrossRefFieldName),
                                           ShowLatestVersion = optionsStep != null && optionsStep.ShowLatestVersion
                                       };

                        return join;
                    }

                case ColumnTypes.ReverseMultiReference:
                    {
                        var step = field.StepList.OfType<ReverseCrossRefRequiredStepEdit>().FirstOrDefault();

                        if (step == null || !step.ReverseCrossRefProcessId.HasValue)
                            throw new InvalidOperationException(
                                string.Format(CultureInfo.InvariantCulture, "Field \"{0}\" is not a valid reference field.", field.SystemName));

                        var optionsStep = field.StepList.OfType<ReverseCrossRefOptionsStepEdit>().FirstOrDefault();
                        var referencedProcess = CreateProcessDefinition(GetPublishedProcessInfo(step.ReverseCrossRefProcessId.Value));
                        var join = new MultiReverseCrossReferenceFieldDefinition
                                       {
                                           SystemName = field.SystemName,
                                           DeclaringProcess = declaringProcess,
                                           ReferencedProcess = referencedProcess,
                                           ReferenceField = CreateJoin(referencedProcess, step.CrossRefFieldName),
                                           ShowLatestVersion = optionsStep != null && optionsStep.ShowLatestVersion
                                       };

                        return join;
                    }

                case ColumnTypes.Checklist:
                    {
                        var step = field.StepList.OfType<ChecklistSettingsStepEdit>().FirstOrDefault();

                        if (step == null || string.IsNullOrEmpty(step.AnswerProcessSystemName))
                            throw new InvalidOperationException(
                                string.Format(CultureInfo.InvariantCulture, "Field \"{0}\" is not a valid reference field.", field.SystemName));

                        var referencedProcess = GetPublishedProcessInfo(step.AnswerProcessSystemName);

                        var join = new ChecklistFieldDefinition
                                       {
                                           SystemName = field.SystemName,
                                           DeclaringProcess = declaringProcess,
                                           ReferencedProcess = CreateProcessDefinition(referencedProcess)
                                       };

                        return join;
                    }
            }

            throw new InvalidOperationException(
                string.Format(CultureInfo.InvariantCulture, "Field \"{0}\" is not a valid reference field.", field.SystemName));
        }
        /// <summary>
        /// Gets the <see cref="Type" /> of the specified <see cref="FieldEdit" />.
        /// </summary>
        /// <param name="field"> The field. </param>
        /// <returns> Returns a <see cref="Type" />. </returns>
        /// <exception cref="System.ArgumentNullException"> The Field. </exception>
        /// <exception cref="ArgumentNullException">The <see cref="field" /> parameter is null.</exception>
        protected Type GetFieldType(FieldEdit field)
        {
            if (field == null)
                throw new ArgumentNullException("field");

            return GetFieldType(field.GetColumnType());
        }