Exemple #1
0
 protected virtual MDSResult <QuotedAssetSet> OnRequestPricingStructure(
     IModuleInfo clientInfo,
     Guid requestId,
     MDSRequestType requestType,
     NamedValueSet requestParams,
     DateTimeOffset subsExpires,
     NamedValueSet structureParams)
 {
     throw new NotSupportedException("This provider (" + ProviderId.ToString() + ") does not support the OnRequestPricingStructure method!");
 }
Exemple #2
0
 public string GetKey(
     MDSDictionaryType dictType, MDSRequestType requestType,
     MDSProviderId sourceProvider, MDSProviderId targetProvider, string sourceValue)
 {
     //return String.Format("{0};{1};{2}:{3};{4}:{5}",
     return
         ($"{dictType.ToString()};{requestType.ToString()}:{sourceProvider.ToString()};{sourceValue.ToUpper()}:{targetProvider.ToString()}");
 }
        public static V221ProviderId ToV221ProviderId(MDSProviderId provider)
        {
            switch (provider)
            {
            case MDSProviderId.GlobalIB: return(V221ProviderId.GlobalIB);

            case MDSProviderId.Bloomberg: return(V221ProviderId.Bloomberg);

            //case MDSProviderId.ReutersIDN: return V221ProviderId.ReutersIDN;
            //case MDSProviderId.ReutersDTS: return V221ProviderId.ReutersDTS;
            case MDSProviderId.Simulator: return(V221ProviderId.Simulator);

            default:
                throw new NotSupportedException("MDSProviderId: " + provider.ToString());
            }
        }
Exemple #4
0
        public string Convert(
            MDSDictionaryType dictType, MDSRequestType requestType,
            MDSProviderId sourceProvider, MDSProviderId targetProvider,
            string sourceValue, ConvertFailMode failMode)
        {
            // method:
            // 1. check for cached result
            // 2. find relevant maps (by dicttype, reqtype, assettype, source, target)
            // 3. process maps in priority order until hit, fail if no hit
            // 4. save outbound and inbound results in cache
            if (dictType == MDSDictionaryType.Undefined)
            {
                throw new ArgumentNullException(nameof(dictType));
            }
            if (requestType == MDSRequestType.Undefined)
            {
                throw new ArgumentNullException(nameof(requestType));
            }
            //if (assetType == MDSAssetType.Undefined)
            //    throw new ArgumentNullException("assetType");
            if (sourceProvider == MDSProviderId.Undefined)
            {
                throw new ArgumentNullException(nameof(sourceProvider));
            }
            if (targetProvider == MDSProviderId.Undefined)
            {
                throw new ArgumentNullException(nameof(targetProvider));
            }
            if (sourceValue == null)
            {
                throw new ArgumentNullException(nameof(sourceValue));
            }
            sourceValue = sourceValue.Trim().ToUpper();
            if (sourceValue == "")
            {
                throw new ArgumentNullException(nameof(sourceValue));
            }
            const string cUnknownValue = "[unknown]";
            // check for cached result
            string forwardKey = GetKey(dictType, requestType, //assetType,
                                       sourceProvider, targetProvider, sourceValue);

            lock (_forwardCache)
            {
                if (_forwardCache.TryGetValue(forwardKey, out var cachedResult))
                {
                    //Logger.LogDebug("Converted {0} {1} '{2}' to {3} '{4}' (via forward cache)",
                    //    sourceProvider.ToString(), dictType.ToString(), sourceValue, targetProvider.ToString(), cachedResult);
                    return(cachedResult);
                }
            }
            // find relevant maps (by dicttype, reqtype, assettype, source, target)
            var maps = new List <MapRule>();

            _rules.Locked((rules) =>
            {
                foreach (var rule in rules)
                {
                    if ((!rule.Disabled) &&
                        (rule.DictType == MDSDictionaryType.Undefined || (rule.DictType == dictType)) &&
                        (rule.SourceProvider == MDSProviderId.Undefined || (rule.SourceProvider == sourceProvider)) &&
                        (rule.TargetProvider == MDSProviderId.Undefined || (rule.TargetProvider == targetProvider))
                        //&& (rule.AssetIdType == MDSAssetType.Undefined || (rule.AssetIdType == assetType))
                        && (rule.RequestType == MDSRequestType.Undefined || (rule.RequestType == requestType)))
                    {
                        maps.Add(rule);
                    }
                }
            });
            // process maps in priority order until hit, fail if no hit
            string result   = sourceValue;
            bool   replaced = false;

            foreach (var map in maps)
            {
                Match match = map.Regex.Match(sourceValue);
                if (match.Success)
                {
                    result   = map.Regex.Replace(sourceValue, map.OutputValue);
                    replaced = true;
                    break;
                }
            }
            if (replaced)
            {
                result = result.Trim().ToUpper();
                //_Logger.LogDebug("Converted {0} {1} '{2}' to {3} '{4}' (via mapping rules)",
                //    sourceProvider.ToString(), dictType.ToString(), sourceValue, targetProvider.ToString(), result);
                // update forward and reverse caches
                UpdateForwardCache(forwardKey, result);
                string reverseKey = GetKey(dictType, requestType, //assetType,
                                           targetProvider, sourceProvider, result);
                UpdateReverseCache(reverseKey, sourceValue);
            }
            else
            {
                // no replacement rules - try the reverse cache
                string cachedResult;
                bool   foundInReverseCache;
                lock (_reverseCache)
                {
                    foundInReverseCache = _reverseCache.TryGetValue(forwardKey, out cachedResult);
                }
                if (foundInReverseCache)
                {
                    _logger.LogDebug("Converted {0} {1} '{2}' to {3} '{4}' (via reverse cache)",
                                     sourceProvider.ToString(), dictType.ToString(), sourceValue, targetProvider.ToString(), cachedResult);
                    // update forward cache
                    UpdateForwardCache(forwardKey, cachedResult);
                    return(cachedResult);
                }
                // exhausted all conversion options
                _logger.LogWarning("Cannot convert {0} {1} '{2}' to {3} (no matching map found)",
                                   sourceProvider.ToString(), dictType.ToString(), sourceValue, targetProvider.ToString());
                switch (failMode)
                {
                case ConvertFailMode.PassThrough:
                    result = sourceValue;
                    break;

                case ConvertFailMode.ReturnNull:
                    result = null;
                    break;

                case ConvertFailMode.ReturnUnknown:
                    result = cUnknownValue;
                    break;

                default:
                    throw new ApplicationException(
                              String.Format("Cannot convert {0} {1} '{2}' to {3} ",
                                            sourceProvider.ToString(), dictType.ToString(), sourceValue, targetProvider.ToString()));
                }
            }
            return(result);
        }