/// <summary>
        /// Determines whether the mapping of the specified field is valid.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns>Returns true if mapping is valid; otherwise false.</returns>
        public bool IsValidMapping(DestinationField field)
        {
            if (!IsMapped(field))
                return true;

            if (!IsAccessible(field))
                return false;

            // List destination fields can access any source fields.
            // If the source collection field is nested in a collection field (e.g. Employees.Roles -> Roles), a SelectMany operation will be used.
            if (field.DataType == NodeDataType.List || field.DataType == NodeDataType.Array || field.DataType == NodeDataType.FixedArray
                || field.DataType == NodeDataType.Checklist || field.DataType == NodeDataType.Sample)
                return true;

            return IsValidMapping(field.ConnectorIn.Connection.Source, GetSourceContext((DestinationField)field.ParentField));
        }
Example #2
0
 /// <summary>
 /// Collects all fields.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="parentField">The parent field.</param>
 private void CollectAllFields(IList<DestinationField> result, DestinationField parentField)
 {
     if (parentField == null)
     {
         foreach (var field in Fields)
         {
             result.Add(field);
             CollectAllFields(result, field);
         }
     }
     else
     {
         foreach (DestinationField field in parentField.Subfields)
         {
             result.Add(field);
             CollectAllFields(result, field);
         }
     }
 }
        /// <summary>
        /// Converts to source.
        /// </summary>
        /// <param name="sourceType">Type of the source.</param>
        /// <returns>DestinationFieldList.</returns>
        public static DestinationFieldList ConvertToSource(Type sourceType)
        {
            var result = new DestinationFieldList {ExpressionName = sourceType.Name};

            var properties = sourceType.GetProperties();

            foreach (var property in properties)
            {
                var dn = new DestinationField(result)
                             {
                                 Name = property.Name,
                                 DataType = GetDataType(property.PropertyType),
                                 ConnectorIn = {DataType = GetDataType(property.PropertyType), Name = property.Name}
                             };
                dn.Id = dn.ConnectorIn.Id;
                result.Fields.Add(dn);
            }

            return result;
        }
        /// <summary>
        /// Verifies that source and destination SCR fields both reference the same process
        /// </summary>
        /// <param name="sourceField">The source field</param>
        /// <param name="destinationField">The destination field</param>
        /// <returns><c>True</c> if the source field references the same process as the destination field, otherwise <c>False</c></returns>
        private ConnectivityState CrossRefFieldsAreCompatible(SourceField sourceField, DestinationField destinationField)
        {
            var sourceFieldRefProcess = sourceField.AdditionalInfo != null
                    ? ((CrossReferenceFieldInfo)sourceField.AdditionalInfo).ReferencedProcessName
                    : string.Empty;

            var destinationFieldRefProcess = destinationField.AdditionalInfo != null
                ? ((CrossReferenceFieldInfo)destinationField.AdditionalInfo).ReferencedProcessName
                : string.Empty;

            if (!string.IsNullOrWhiteSpace(sourceFieldRefProcess) &&
                !string.IsNullOrWhiteSpace(destinationFieldRefProcess) &&
                sourceFieldRefProcess != destinationFieldRefProcess)
            {
                return ConnectivityState.Refuse(
                    Regex.Unescape(LanguageService.Translate("Warn_ExpressionBuilder_IncompatibleCrossRefFields")));
            }

            return ConnectivityState.Allow();
        }
        private static bool IsMapped(DestinationField field)
        {
            if (field.ConnectorIn != null && field.ConnectorIn.Connection != null && field.ConnectorIn.Connection.Source != null)
            {
                return true;
            }

            return field.Subfields.OfType<DestinationField>().Any(f => f.IsKey && IsMapped(f));
        }
        /// <summary>
        /// Determines whether the specified field is accessible.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns><c>true</c> if the specified field is accessible; otherwise, <c>false</c>.</returns>
        private bool IsAccessible(DestinationField field)
        {
            if (field.ParentField == null)
                return true;

            if (field.ParentField.DataType == NodeDataType.Array && !IsMapped((DestinationField)field.ParentField))
                return false;

            return IsAccessible((DestinationField)field.ParentField);
        }
 /// <summary>
 /// Determines whether the specified field is mapped.
 /// </summary>
 /// <param name="field">The destination field.</param>
 /// <returns>Returns true if the specified field is mapped.</returns>
 public bool IsMapped(DestinationField field)
 {
     return field.With(f => f.ConnectorIn).With(c => c.Connection).With(c => c.Source) != null;
 }
        /// <summary>
        /// Gets the source context.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns>SourceField.</returns>
        private SourceField GetSourceContext(DestinationField field)
        {
            if (field == null)
                return null;

            if (field.DataType != NodeDataType.List && field.DataType != NodeDataType.Array && field.DataType != NodeDataType.Checklist
                && field.DataType != NodeDataType.Sample)
                return GetSourceContext((DestinationField)field.ParentField);

            if (!IsMapped(field))
                return null;

            return GetSourceContext(field.ConnectorIn.Connection.Source);
        }
        private static string AddExternalDataFieldMapping(
            StringBuilder assemblyCode,
            DestinationField destinationField,
            IDictionary<string, string> expressionScripts,
            ref int variableIndex)
        {
            const string PadLeft = "\t\t\t";

            var variableName = "v" + variableIndex++;

            assemblyCode.AppendLine()
                        .Append(PadLeft)
                        .AppendFormat(CultureInfo.InvariantCulture, @"var {0} = new FieldMapping({1});", variableName, destinationField.SystemName.ToLiteral());

            string expressionScript;

            if (expressionScripts.TryGetValue(destinationField.GetFullPath(), out expressionScript))
            {
                assemblyCode.AppendLine()
                            .Append(PadLeft)
                            .AppendFormat(CultureInfo.InvariantCulture, @"{0}.Expression = () => {1};", variableName, expressionScript);
            }

            foreach (var subfield in destinationField.Subfields.OfType<DestinationField>())
            {
                var childMappingVariableName = AddExternalDataFieldMapping(assemblyCode, subfield, expressionScripts, ref variableIndex);
                assemblyCode.AppendLine()
                            .Append(PadLeft)
                            .AppendFormat(CultureInfo.InvariantCulture, @"{0}.ChildMappings.Add({1});", variableName, childMappingVariableName);
            }

            return variableName;
        }
        /// <summary>
        /// Creates the LastModifiedOn system field.
        /// </summary>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The LastModifiedOn system field.
        /// </returns>
        protected virtual DestinationField CreateLastModifiedOnField(DestinationFieldList destination)
        {
            const string LastModifiedOnDisplayName = "Last Modified On";

            var dataType = SourceNodeFactory.GetDataType(typeof(DateTime));
            var df = new DestinationField(destination)
                         {
                             DataType = dataType,
                             Name = LastModifiedOnDisplayName,
                             ConnectorIn = { DataType = dataType, Name = Constants.LastModifiedOn },
                             InnerName = Constants.LastModifiedOn,
                             SystemName = Constants.LastModifiedOn
                         };

            return df;
        }
Example #11
0
        /// <summary>
        /// Deserializes the specified XML reader.
        /// </summary>
        /// <param name="xmlReader">The XML reader.</param>
        public override void Deserialize(XmlReader xmlReader)
        {
            base.Deserialize(xmlReader);

            if (xmlReader.IsEmptyElement)
                return;

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.EndElement && !"DestinationField".Equals(xmlReader.Name))
                {
                    return;
                }

                if (xmlReader.NodeType == XmlNodeType.Element && "DestinationField".Equals(xmlReader.Name))
                {
                    var field = new DestinationField(this);
                    field.Deserialize(xmlReader);
                    Fields.Add(field);
                }
            }
        }
        /// <summary>
        /// Creates version-related system fields.
        /// </summary>
        /// <param name="destination">
        /// The destination field list.
        /// </param>
        /// <returns>
        /// The collection of version-related system fields.
        /// </returns>
        protected virtual IEnumerable<DestinationField> CreateVersionFields(DestinationFieldList destination)
        {
            var dataType = SourceNodeFactory.GetDataType(typeof(string));
            var df = new DestinationField(destination)
                         {
                             DataType = dataType,
                         Name = Constants.VersionNumberName,
                         ConnectorIn = { DataType = dataType, Name = Constants.VersionNumberName, IsNullable = false },
                             InnerName = Constants.VersionNumber,
                             SystemName = Constants.VersionNumber
                         };

            yield return df;

            dataType = SourceNodeFactory.GetDataType(typeof(DateTime));
            df = new DestinationField(destination)
                     {
                         DataType = dataType,
                         Name = VersionDateDisplayName,
                         ConnectorIn = { DataType = dataType, Name = VersionDateDisplayName },
                         InnerName = Constants.VersionDate,
                         SystemName = Constants.VersionDate
                     };

            yield return df;

            dataType = SourceNodeFactory.GetDataType(typeof(int));
            df = new DestinationField(destination)
                     {
                         DataType = dataType,
                         Name = VersionMasterIdDisplayName,
                         ConnectorIn = { DataType = dataType, Name = VersionMasterIdDisplayName, IsNullable = false },
                         InnerName = Constants.VersionMasterId,
                         SystemName = Constants.VersionMasterId
                     };

            yield return df;
        }
        /// <summary>
        /// Creates state-related system fields.
        /// </summary>
        /// <param name="destination">
        /// The destination field list.
        /// </param>
        /// <returns>
        /// The collection of state-related system fields.
        /// </returns>
        protected virtual IEnumerable<DestinationField> CreateStateFields(DestinationFieldList destination)
        {
            var dataType = SourceNodeFactory.GetDataType(typeof(string));
            var df = new DestinationField(destination)
                         {
                             DataType = dataType,
                             Name = Constants.CurrentStateDisplayName,
                             ConnectorIn = { DataType = dataType, Name = Constants.CurrentStateDisplayName, IsNullable = false },
                             InnerName = Constants.CurrentStateColumnName,
                             SystemName = Constants.CurrentStateColumnName
                         };

            yield return df;

            dataType = SourceNodeFactory.GetDataType(typeof(DateTime));
            df = new DestinationField(destination)
                     {
                         DataType = dataType,
                         Name = Constants.StateModifiedDisplayName,
                         ConnectorIn = { DataType = dataType, Name = Constants.StateModifiedDisplayName },
                         InnerName = Constants.StateModifiedColumnName,
                         SystemName = Constants.StateModifiedColumnName
                     };

            yield return df;
        }
        /// <summary>
        /// Adds the 'Id' field to the specified <see cref="DestinationFieldList" />.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <exception cref="System.ArgumentNullException">destination</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="destination" /> parameter is null.</exception>
        protected virtual void AddIdField(DestinationFieldList destination)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");

            var dataType = DestinationNodeFactory.GetDataType(typeof(int));

            var df = new DestinationField(destination)
                         {
                             Name = "Id",
                             SystemName = Constants.IdColumnName,
                             DataType = dataType,
                             ConnectorIn = { DataType = dataType, Name = "Id", IsNullable = false },
                             IsKeyEnabled = true,
                             IsKeyVisible = true
                         };

            destination.Fields.Add(df);
        }
        private static OneInTwoOutExpression CreateValidExpression()
        {
            var source = new ConstantExpression();
            var destination = new DestinationFieldList();
            var destinationField1 = new DestinationField(destination);
            var destinationField2 = new DestinationField(destination);
            var expression = new OneInTwoOutExpression();
            expression.ConnectorIn.ConnectedTo = source.ConnectorOut;
            expression.Connector1Out.ConnectedTo = destinationField1.ConnectorIn;
            expression.Connector2Out.ConnectedTo = destinationField2.ConnectorIn;

            return expression;
        }
Example #16
0
        /// <summary>
        /// Deserializes the specified XML reader.
        /// </summary>
        /// <param name="xmlReader">The XML reader.</param>
        public void Deserialize(XmlReader xmlReader)
        {
            Id = Guid.Parse(xmlReader.GetAttribute("id"));
            Name = xmlReader.GetAttribute("name");
            DataType = (NodeDataType)Enum.Parse(typeof(NodeDataType), xmlReader.GetAttribute("dataType"), false);
            InnerName = xmlReader.GetAttribute("innerName");
            SetName = xmlReader.GetAttribute("setName");
            SystemName = xmlReader.GetAttribute("systemName");
            UniqueName = xmlReader.GetAttribute("uniqueName");

            //for backward compatibility with previously saved xml
            var param = xmlReader.GetAttribute("keepSubfieldsAlive");
            KeepSubfieldsAlive = param != null && Convert.ToBoolean(param);
            param = xmlReader.GetAttribute("hideConnector");
            HideConnector = param != null && Convert.ToBoolean(param);
            param = xmlReader.GetAttribute("isGroupingField");
            IsGroupingField = param != null && Convert.ToBoolean(param);
            param = xmlReader.GetAttribute("isGroupCollapsed");
            IsGroupCollapsed = param != null && Convert.ToBoolean(param);

            var temp = false;
            
            if (bool.TryParse(xmlReader.GetAttribute("isKey"), out temp))
            {
                IsKey = temp;
            }

            if (bool.TryParse(xmlReader.GetAttribute("isKeyEnabled"), out temp))
            {
                IsKeyEnabled = temp;
            }

            if (bool.TryParse(xmlReader.GetAttribute("isKeyVisible"), out temp))
            {
                IsKeyVisible = temp;
            }

            if (!"ConnectorIn".Equals(xmlReader.Name))
            {
                xmlReader.ReadToFollowing("ConnectorIn");
            }
            ConnectorIn.Deserialize(xmlReader);

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element && "AdditionalInfo".Equals(xmlReader.Name))
                {
                    try
                    {
                        if (AdditionalInfo == null)
                            AdditionalInfo = Activator.CreateInstance(Type.GetType(xmlReader.GetAttribute("Type"))) as IExpressionFieldInfo;

                        AdditionalInfo.Deserialize(xmlReader);
                    }
                    catch (Exception) { }
                }

                if (xmlReader.NodeType == XmlNodeType.EndElement && "DestinationField".Equals(xmlReader.Name))
                {
                    return;
                }

                if (xmlReader.NodeType == XmlNodeType.Element && "Subfields".Equals(xmlReader.Name))
                {
                    while (xmlReader.Read())
                    {
                        if (xmlReader.NodeType == XmlNodeType.EndElement && !"Subfields".Equals(xmlReader.Name))
                        {
                            return;
                        }

                        if (xmlReader.NodeType == XmlNodeType.Element && "DestinationField".Equals(xmlReader.Name))
                        {
                            var field = new DestinationField(ConnectorIn.Owner);
                            field.Deserialize(xmlReader);
                            field.ParentField = this;
                            _subfields.Add(field);
                        }
                    }
                }
            }
        }