Пример #1
0
        private static IReadOnlyDictionary<string, AnalyticsBondStaticData> BulkGetBondStaticDataFromCarbon(ICarbonClient client,
            IReadOnlyCollection<string> bondIds)
        {
            if (bondIds == null || bondIds.Count == 0) return new Dictionary<string, AnalyticsBondStaticData>();

            var dict = new ConcurrentDictionary<string, AnalyticsBondStaticData>();
            var ids = new List<string>();
            foreach (var id in bondIds)
            {
                AnalyticsBondStaticData data;

                if (BondStaticDataCache.TryGetValue(id, out data))
                {
                    dict.TryAdd(id, data);
                }
                else
                {
                    var carbonBond = client.GetCachedCarbonBond(id);
                    if (carbonBond == null)
                    {
                        ids.Add(id);
                    }
                    else
                    {
                        var bond = ConvertCarbonBondToAnalyticsBondStaticData(carbonBond);
                        if (bond != null)
                        {
                            dict.TryAdd(id, bond);
                            BondStaticDataCache.TryAdd(id, bond);
                            BondStaticDataCache.TryAdd(bond.Id, bond);
                        }
                        else
                        {
                            ids.Add(id);
                        }
                    }
                }
            }

            if (ids.Count == 0) return dict.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            var datas = client.BulkGetSecurityMetadataInternal(ids, "static-bond");

            if (datas == null || datas.Count == 0) return dict.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            Parallel.ForEach(datas, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount },
                data =>
                {
                    var bond = ConvertCarbonBondStaticToAnalyticBondStatic(client, data);
                    if (bond != null)
                    {
                        BondStaticDataCache.TryAdd(bond.Id, bond);
                        BondStaticDataCache.TryAdd(data.Identifier, bond);
                        dict.TryAdd(bond.Id, bond);
                    }
                });

            return dict.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
        }
Пример #2
0
        private static AnalyticsBondStaticData GetBondStaticDataFromCarbon(ICarbonClient client, string bondId)
        {
            if (string.IsNullOrEmpty(bondId)) return null;

            AnalyticsBondStaticData bond = null;
            var carbonBond = client.GetCachedCarbonBond(bondId);
            if (carbonBond != null)
            {
                bond = ConvertCarbonBondToAnalyticsBondStaticData(carbonBond);
            }

            if (bond != null) return bond;

            var data = client.GetSecurityMetadataInternal(bondId, "static-bond");
            if (data == null) return null;

            bond = ConvertCarbonBondStaticToAnalyticBondStatic(client, data);

            return bond;
        }