コード例 #1
0
        public UnifiedAccountOperation Map(AccountOperationBase operationBase, CultureInfo culture)
        {
            var mapper           = _mappers[operationBase.SourceKind];
            var unifiedOperation = mapper.Map(operationBase, culture);

            return(unifiedOperation);
        }
        public UnifiedAccountOperation Apply(AccountOperationBase operation, CultureInfo culture)
        {
            var unified = _mapper.Map(operation, culture);

            return(Apply(operation, unified));
        }
        public UnifiedAccountOperation Apply(AccountOperationBase source, UnifiedAccountOperation target)
        {
            var tuples = _patterns
                         .SelectMany(p => p.PatternMappings.Select(patternMapping => new
            {
                patternMapping,
                p.CompiledOperationIdPattern
            }))
                         .Where(p => p.patternMapping.SourceKind == source.SourceKind)
                         .Select(p => new
            {
                p.patternMapping,
                p.CompiledOperationIdPattern,
                Match = p.patternMapping.CompiledExpression.Match(source)
            })
                         .Where(p => p.Match.Success)
                         .ToList();

            var tuple = tuples.FirstOrDefault();

            if (tuple == null)
            {
                _logger.WarnFormat("no mapper found for operation {0}", target.OperationId);
                return(target);
            }

            if (tuples.Count > 1)
            {
                _logger.WarnFormat(
                    "multiple mappers found for a sinle operation. OperationId : {0}. Mapper names: {1}.",
                    target.OperationId,
                    string.Join(",", tuples.Select(p => p.patternMapping.Name)));
            }

            var symbols = new Dictionary <string, object>();

            AddSourcePropertiesToSymbols(source, symbols);

            var pattern    = tuple.patternMapping;
            var groupNames = pattern.CompiledExpression.GetGroupNames();
            var match      = tuple.Match;

            target.PatternName = pattern.Name;

            foreach (var groupName in groupNames)
            {
                var matchGroup = match.Groups[groupName];
                if (matchGroup.Success)
                {
                    var input = matchGroup.Value.Trim();
                    symbols[groupName] = input;
                    if (_unifiedOpProperties.ContainsKey(groupName))
                    {
                        _unifiedOpAccessors[target, groupName] = input;
                    }
                    else if (groupName.Equals("PatternNameSuffix"))
                    {
                        target.PatternName += input;
                    }
                    else if (groupName.EndsWith("ThenCity"))
                    {
                        var placeInfo = _placeInfoResolver.ResolveFromEndOfText(input, false);
                        var freeTextWithoutPlaceInfo = placeInfo.GetFreeTextWithoutPlaceInfo();

                        target.City = placeInfo.City;

                        if (groupName.Equals("ThirdPartyThenCity"))
                        {
                            target.ThirdParty = freeTextWithoutPlaceInfo;
                        }
                        else if (groupName.Equals("CommunicationThenCity"))
                        {
                            target.Communication = freeTextWithoutPlaceInfo;
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                    else if (groupName.EndsWith("ThenAddress"))
                    {
                        var placeInfo = _placeInfoResolver.ResolveFromEndOfText(input, true);
                        var freeTextWithoutPlaceInfo = placeInfo.GetFreeTextWithoutPlaceInfo();

                        target.City    = placeInfo.City;
                        target.Address = placeInfo.Adress;

                        if (groupName.Equals("ThirdPartyThenAddress"))
                        {
                            target.ThirdParty = freeTextWithoutPlaceInfo;
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                }
            }

            if (pattern.ExplicitMappings != null)
            {
                foreach (var property in pattern.ExplicitMappings.Properties())
                {
                    var memberType = _unifiedOpProperties[property.Name];
                    _unifiedOpAccessors[target, property.Name] = EvaluateValue(symbols, (string)property.Value, memberType);
                }
            }

            if (!tuple.CompiledOperationIdPattern.IsMatch(target.OperationId))
            {
                target.OperationId = string.Empty;
            }

            return(target);
        }
 public override UnifiedAccountOperation Map(AccountOperationBase operationBase, CultureInfo culture)
 {
     return((UnifiedAccountOperation)operationBase);
 }