Esempio n. 1
0
        /// <summary>
        /// Gets volume by id
        /// </summary>
        /// <param name="volumeId">Volume id (vol-xxxxxxxxx)</param>
        /// <param name="userId">User id</param>
        /// <returns></returns>
        public async Task <VolumeReply> Get(string volumeId, string userId)
        {
            logger.LogInformation($"Searching the volume with id {volumeId}");
            logger.LogDebug($"Try to connect to the Redis");

            using IConnectionMultiplexer redis = redisService.Connect();
            var db = redis.GetDatabase();

            logger.LogDebug($"Connected to the Redis");

            string redisKey = GetVolumeKey(userId, volumeId);

            if (db.KeyExists(redisKey, CommandFlags.None) == false)
            {
                logger.LogError($"Cannot find a volume with id {redisKey}");
                throw new VolumeException($"Cannot find a volume with id {redisKey}");
            }
            logger.LogInformation($"The volume with id {redisKey} is exists in the store. " +
                                  $"Reqding the values..");

            VolumeModel volumeModel = new VolumeModel();

            foreach (PropertyInfo property in volumeModel.GetType().GetProperties())
            {
                RedisValue value = await db.HashGetAsync(redisKey, property.Name);

                property.SetValue(volumeModel, Convert.ChangeType(value, property.PropertyType));
            }

            logger.LogInformation($"The volume successfully read from the store");
            return(VolumeAdapter.Volume(volumeModel));
        }
Esempio n. 2
0
        /// <summary>
        /// List of volumes by user Id
        /// </summary>
        /// <param name="userId">Use Id</param>
        /// <returns></returns>
        public async Task <IEnumerable <VolumeReply> > List(string userId)
        {
            using IConnectionMultiplexer redisConnection = redisService.Connect();
            var db = redisConnection.GetDatabase();

            logger.LogDebug("Connected to Redis");

            string redisKey = GetVolumeKey(userId);

            logger.LogDebug($"Searching by key pattern: {redisKey}");

            EndPoint endPoint = redisConnection.GetEndPoints().First() ?? throw new VolumeException($"Cannot find the endpoint");

            RedisKey[] keys = redisConnection.GetServer(endPoint).Keys(pattern: redisKey).ToArray();
            logger.LogDebug($"Found {keys.Length} keys");

            List <VolumeModel> volumes = new List <VolumeModel>();

            foreach (RedisKey key in keys)
            {
                logger.LogDebug($"Reading the key {key}");
                VolumeModel volumeModel = new VolumeModel();
                foreach (PropertyInfo property in volumeModel.GetType().GetProperties())
                {
                    var value = await db.HashGetAsync(key, property.Name);

                    property.SetValue(volumeModel, Convert.ChangeType(value, property.PropertyType));
                }
                volumes.Add(volumeModel);
            }

            logger.LogDebug($"All volumes ejected successfully");
            return(volumes.ConvertAll(v => VolumeAdapter.Volume(v)));
        }
Esempio n. 3
0
        /// <summary>
        /// Create a volume
        /// </summary>
        /// <param name="createVolumeRequest">Parameters for create</param>
        /// <param name="userId">User id</param>
        /// <exception cref="VolumeException">If cannot create a volume</exception>
        /// <returns>gRPC reply with volume id</returns>
        public async Task <VolumeReply> Create(CreateVolumeRequest createVolumeRequest, string userId)
        {
            logger.LogInformation("Requested for creaton of a volume"); // english

            string      volumeId = IdentityFabric.GenVolumeId();
            VolumeModel volume   = VolumeAdapter.Volume(volumeId, createVolumeRequest);

            logger.LogInformation($"Created the VolumeModel with Id {volumeId}");

            using IConnectionMultiplexer redis = redisService.Connect();
            IDatabase db = redis.GetDatabase();

            logger.LogInformation($"Connected to the Redis servier");

            ITransaction transaction = db.CreateTransaction();

            logger.LogInformation($"Bigin transaction");

            string redisKey = GetVolumeKey(userId, volumeId);

            foreach (PropertyInfo propInfo in volume.GetType().GetProperties())
            {
                _ = transaction.HashSetAsync(redisKey, propInfo.Name, propInfo.GetValue(volume).ToString());
            }

            if (await transaction.ExecuteAsync() == false)
            {
                logger.LogError("Cannot create a volume. Transaction failed");
                throw new VolumeException("Cannot create a volume");
            }
            logger.LogInformation($"Creansaction completed successfully");
            return(VolumeAdapter.Volume(volume));
        }
Esempio n. 4
0
        public override void GetObjectsInVolume(VolumeAdapter volume, ICollection <WorldObject> output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            foreach (WorldObject worldObject in registeredObjects)
            {
                // BUG: in intersection method
                //if (volume.Intersects(worldObject.WorldBoundary))
                output.Add(worldObject);
            }
        }
Esempio n. 5
0
        public void GetObjectsInVolume(Sector startSector, VolumeAdapter volume, ICollection <WorldObject> output,
                                       int maxDepth)
        {
            if (startSector == null)
            {
                throw new ArgumentNullException("startSector");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (maxDepth < 0)
            {
                throw new ArgumentOutOfRangeException("maxDepth", "Parameter should have non-negative value.");
            }

            GetObjectsInVolumeImpl(startSector, volume, output, maxDepth);
        }
Esempio n. 6
0
        private void GetObjectsInVolumeImpl(Sector currentSector, VolumeAdapter volume,
                                            ICollection <WorldObject> output, int curDepth)
        {
            if (!volume.Intersects(currentSector.Boundary))
            {
                return;
            }

            currentSector.GetObjectsInVolume(volume, output);

            if (portalsBySourceSector.ContainsKey(currentSector) && curDepth > 0)
            {
                foreach (Portal portal in portalsBySourceSector[currentSector])
                {
                    if (volume.Intersects(portal.Boundary))
                    {
                        GetObjectsInVolumeImpl(portal.DestinationSector, volume, output, curDepth - 1);
                    }
                }
            }
        }
Esempio n. 7
0
 public abstract void GetObjectsInVolume(VolumeAdapter volume, ICollection <WorldObject> output);
Esempio n. 8
0
 public virtual bool AffectsVolume(VolumeAdapter volumeAdapter)
 {
     return(true);
 }