Exemplo n.º 1
0
        /// <summary>
        ///   Stores a feature that can be queried and updated.
        /// </summary>
        /// <param name = "request"><see cref = "CreateFeatureRequest" /> instance that defines the state required to create a new Feature.</param>
        /// <returns>
        ///   <see cref = "CreateFeatureResponse" /> containing the results of the request to create a new Feature.
        /// </returns>
        public CreateFeatureResponse CreateFeature(CreateFeatureRequest request)
        {
            CreateFeatureResponse response;

            using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CreateFeature))
            {
                Feature feature;

                EnsureOwnerId(request.Feature);
                CheckDuplicateKey(request.Feature);

                try
                {
                    feature = m_StorageContainer.Store(request.Feature);
                }
                catch (Exception e)
                {
                    CreateFeatureException createFeatureException =
                        new CreateFeatureException(ExceptionMessageResources.FEATURE_CREATION_EXCEPTION, e);
                    m_Logger.Error(createFeatureException);

                    throw createFeatureException;
                }

                response = CreateFeatureResponse.Create(request.Header.MessageId, feature);
                LogInteraction(request, response);
            }

            return(response);
        }
Exemplo n.º 2
0
        public void CreateFeatureExceptionThrownWhenCreationFails()
        {
            string    messageId = Guid.NewGuid().ToString();
            Exception exception = m_MockRepository.StrictMock <Exception>();

            Feature toCreate             = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), FeatureName);
            CreateFeatureRequest request = CreateFeatureRequest.Create(messageId, toCreate);

            IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer);

            using (m_MockRepository.Record())
            {
                Expect.Call(exception.Message).Return("Bad Mojo");
                Expect.Call(m_StorageContainer.Retrieve(FeatureKey.Create(toCreate.Id, toCreate.OwnerId, toCreate.Space)))
                .Return(null);
                Expect.Call(m_StorageContainer.Store(toCreate)).Throw(exception);
                m_MockRepository.ReplayAll();

                try
                {
                    featureStore.CreateFeature(request);
                    Assert.Fail("Expected FeatureCreationException");
                }
                catch (CreateFeatureException)
                {
                }

                m_MockRepository.VerifyAll();
            }
        }
Exemplo n.º 3
0
        public void CreateFeature()
        {
            Feature toCreate = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), FeatureName);

            IStorageContainer container = m_MockRepository.StrictMock <IStorageContainer>();
            string            messageId = Guid.NewGuid().ToString();

            using (m_MockRepository.Record())
            {
                Expect.Call(container.Retrieve(FeatureKey.Create(toCreate.Id, toCreate.OwnerId, toCreate.Space))).Return
                    (null);
                Expect.Call(container.Store(toCreate)).Return(toCreate);
                m_MockRepository.ReplayAll();

                StandardFeatureStore service = new StandardFeatureStore(container);

                CreateFeatureRequest request = CreateFeatureRequest.Create(messageId, toCreate);

                CreateFeatureResponse response = service.CreateFeature(request);

                Assert.AreEqual(messageId, response.Header.MessageId);
                Assert.AreEqual(toCreate.Id, response.Result.Id);
                Assert.AreEqual(toCreate.Name, response.Result.Name);
                Assert.AreEqual(toCreate.Space, response.Result.Space);
                Assert.AreEqual(toCreate.OwnerId, response.Result.OwnerId);

                m_MockRepository.VerifyAll();
            }
        }
Exemplo n.º 4
0
        public void MultipleFeaturesCanBeAddedToStorageAndQueriedIndividually()
        {
            const string featureNameBase = "Feature Name ";
            const int    count           = 5;

            Guid[] spaces = new Guid[count];
            Guid[] owners = new Guid[count];

            for (int index = 0; index < count; index++)
            {
                spaces[index] = Guid.NewGuid();
                owners[index] = Guid.NewGuid();

                Feature feature = Feature.Create(index, owners[index], spaces[index], featureNameBase + index);
                Feature stored  = m_StorageContainer.Store(feature);

                Assert.AreEqual(feature.Id, stored.Id);
                Assert.AreEqual(feature.Space, stored.Space);
                Assert.AreEqual(feature.OwnerId, stored.OwnerId);
                Assert.AreEqual(feature.Name, stored.Name);
                Assert.IsFalse(stored.Enabled);
            }

            for (int index = 0; index < 5; index++)
            {
                Feature retrieved = m_StorageContainer.Retrieve(FeatureKey.Create(index, owners[index], spaces[index]));

                Assert.IsNotNull(retrieved);

                Assert.AreEqual(index, retrieved.Id);
                Assert.AreEqual(spaces[index], retrieved.Space);
                Assert.AreEqual(owners[index], retrieved.OwnerId);
                Assert.AreEqual(featureNameBase + index, retrieved.Name);
                Assert.IsFalse(retrieved.Enabled);
            }

            Assert.IsNull(m_StorageContainer.Retrieve(FeatureKey.Create(2112, Guid.Empty, Guid.Empty)));
        }
        public static SqlConnection GetSqlConnection()
        {
            IStorageContainer <SqlConnection> _container = DataContextStorageFactory <SqlConnection> .CreateStorageContainer();

            var _connection = _container.GetObject(key);

            if (_connection == null || _connection.State == System.Data.ConnectionState.Closed)
            {
                _connection = new SqlConnection(conStr);
                _connection.Open();
                _container.Store(key, _connection);
            }
            return(_connection);
        }
Exemplo n.º 6
0
        public static SqlTransaction GetSqlTransaction()
        {
            IStorageContainer <SqlTransaction> _container = DataContextStorageFactory <SqlTransaction> .CreateStorageContainer();

            var tran = _container.GetObject(key);

            if (tran == null)
            {
                tran = SqlConnectionContextFactory.GetSqlConnection().BeginTransaction();
                _container.Store(key, tran);
            }

            return(tran);
        }
Exemplo n.º 7
0
        private void WriteTileToBackingStoreSync(PositionKey key, CachedTile tile)
        {
            if (key == null)
            {
                return;
            }

            if (tile == null)
            {
                return;
            }
            if (tile.State == TileState.Locked)
            {
                return;
            }


            var red   = RawDataPool.Capture();
            var green = RawDataPool.Capture();
            var blue  = RawDataPool.Capture();

            try
            {
                var name = key.ToString();

                if (tile.ImageIsBlank())
                {
                    _tileStore.Delete(name, "img");
                    tile.SetState(TileState.Empty);
                }
                else
                {
                    var packed = tile.GetTileData();
                    if (packed == null)
                    {
                        return;
                    }

                    var end = TileImageSize * TileImageSize;
                    for (int i = 0; i < end; i++)
                    {
                        blue[i]  = packed[4 * i + 0];
                        green[i] = packed[4 * i + 1];
                        red[i]   = packed[4 * i + 2];
                    }

                    using (var ms = new MemoryStream())
                    {
                        WaveletCompress.Compress(red, green, blue, tile.Width, tile.Height).WriteToStream(ms);
                        ms.Seek(0, SeekOrigin.Begin);
                        var ok = _tileStore.Store(name, "img", ms);

                        if (ok.IsFailure)
                        {
                            throw new Exception("Storage error: DB might be corrupt.", ok.FailureCause);
                        }
                    }
                }
            }
            finally
            {
                RawDataPool.Release(red);
                RawDataPool.Release(green);
                RawDataPool.Release(blue);
            }
        }