예제 #1
0
        public Task <BroadcastProfileMessage> GetProfile(Signature signature)
        {
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            var broadcastMetadata = _coreManager.GetBroadcastMetadata(signature, "Profile");

            if (broadcastMetadata == null)
            {
                return(Task.FromResult <BroadcastProfileMessage>(null));
            }

            // Cache
            {
                if (_cache_Profiles.TryGetValue(broadcastMetadata, out var result))
                {
                    return(Task.FromResult(result));
                }
            }

            return(Task.Run(() =>
            {
                try
                {
                    var stream = _coreManager.VolatileGetStream(broadcastMetadata.Metadata, 1024 * 1024 * 32);
                    if (stream == null)
                    {
                        return null;
                    }

                    var content = ContentConverter.FromStream <ProfileContent>(stream, 0);
                    if (content == null)
                    {
                        return null;
                    }

                    var result = new BroadcastProfileMessage(
                        broadcastMetadata.Certificate.GetSignature(),
                        broadcastMetadata.CreationTime,
                        content);

                    _cache_Profiles[broadcastMetadata] = result;

                    return result;
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }

                return null;
            }));
        }
예제 #2
0
        public Task <BroadcastProfileMessage> GetProfile(Signature signature, DateTime?creationTimeLowerLimit)
        {
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            var broadcastMetadata = _coreManager.GetBroadcastMetadata(signature, "Profile");

            if (broadcastMetadata == null)
            {
                return(Task.FromResult <BroadcastProfileMessage>(null));
            }
            if (creationTimeLowerLimit != null && broadcastMetadata.CreationTime <= creationTimeLowerLimit)
            {
                return(Task.FromResult <BroadcastProfileMessage>(null));
            }

            return(Task.Run(() =>
            {
                try
                {
                    var stream = _coreManager.VolatileGetStream(broadcastMetadata.Metadata, 1024 * 1024 * 32);
                    if (stream == null)
                    {
                        return null;
                    }

                    var content = ContentConverter.FromStream <ProfileContent>(stream, 0);
                    if (content == null)
                    {
                        return null;
                    }

                    var result = new BroadcastProfileMessage(
                        broadcastMetadata.Certificate.GetSignature(),
                        broadcastMetadata.CreationTime,
                        content);

                    return result;
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }

                return null;
            }));
        }