示例#1
0
        public async void Resolve(string uuid, Action <string> DisplayName)
        {
            if (!Guid.TryParse(uuid, out Guid NOP_0))
            {
                return;
            }

            ReadCache();

            // Find zone name from cache
            if (ZoneMap.ContainsKey(uuid))
            {
                DisplayName(ZoneMap[uuid]);
                return;
            }

            if (ResolvQs.TryGetValue(uuid, out ConcurrentQueue <Action <string> > RQ))
            {
                RQ.Enqueue(DisplayName);
                return;
            }
            else
            {
                ResolvQs.TryAdd(uuid, new ConcurrentQueue <Action <string> >());
            }

            // Find zone name from online directory
            IEnumerable <string> AccessTokens = new TokenManager().AuthList.Remap(x => ( string )x.Value);
            SHSearchLoader       SHSL         = new SHSearchLoader("uuid: " + uuid, AccessTokens);

            IList <HubScriptItem> HSIs = await SHSL.NextPage();

            if (HSIs.Any())
            {
                string ZName = HSIs.First().Name;
                DisplayName(ZName);
                ZoneMap[uuid] = ZName;

                Shared.ZCacheDb.Write(CacheId, ZoneMap.Data);

                if (ResolvQs.TryRemove(uuid, out ConcurrentQueue <Action <string> > ResolvQ))
                {
                    while (ResolvQ.TryDequeue(out Action <string> Resolved))
                    {
                        Resolved(ZName);
                    }
                }
            }
            else
            {
                // Drop the entire waiting queue as we cannot resolve the name
                ResolvQs.TryRemove(uuid, out ConcurrentQueue <Action <string> > NOP_1);
            }
        }