/// <summary>
        /// Publishes route information in diff storage to Embedded Social for an agency
        /// </summary>
        /// <param name="diffRoutes">list of route entities to publish</param>
        /// <param name="regionId">region that the route entities belong to</param>
        /// <param name="agencyId">agency that the route entities belong to</param>
        /// <param name="publishStorage">interface to data published to Embedded Social</param>
        /// <param name="publishMetadataStorage">inteface to publish metadata</param>
        /// <param name="embeddedSocial">interface to Embedded Social</param>
        /// <param name="runId">uniquely identifies a run of the service</param>
        /// <returns>task that publishes routes for an agency to Embedded Social</returns>
        public static async Task PublishRoutesToEmbeddedSocial(IEnumerable <RouteEntity> diffRoutes, string regionId, string agencyId, StorageManager publishStorage, StorageManager publishMetadataStorage, EmbeddedSocial embeddedSocial, string runId)
        {
            // create the publish metadata entity
            PublishMetadataEntity publishMetadataEntity = new PublishMetadataEntity()
            {
                RunId            = runId,
                RegionId         = regionId,
                AgencyId         = agencyId,
                RecordType       = Storage.RecordType.Route.ToString(),
                AddedCount       = 0,
                UpdatedCount     = 0,
                DeletedCount     = 0,
                ResurrectedCount = 0
            };

            // iterate over each route
            foreach (RouteEntity diffRoute in diffRoutes)
            {
                switch ((DataRowState)Enum.Parse(typeof(DataRowState), diffRoute.RowState))
                {
                case DataRowState.Create:
                    await embeddedSocial.CreateRoute(diffRoute);

                    await publishStorage.RouteStore.Insert(diffRoute);

                    publishMetadataEntity.AddedCount++;
                    break;

                case DataRowState.Delete:
                    await embeddedSocial.DeleteRoute(diffRoute);

                    await publishStorage.RouteStore.Update(diffRoute);

                    publishMetadataEntity.DeletedCount++;
                    break;

                case DataRowState.Update:
                    await embeddedSocial.UpdateRoute(diffRoute);

                    await publishStorage.RouteStore.Update(diffRoute);

                    publishMetadataEntity.UpdatedCount++;
                    break;

                case DataRowState.Resurrect:
                    await embeddedSocial.ResurrectRoute(diffRoute);

                    await publishStorage.RouteStore.Update(diffRoute);

                    publishMetadataEntity.ResurrectedCount++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("RowState");
                }
            }

            // publish the metadata entity
            await publishMetadataStorage.PublishMetadataStore.Insert(publishMetadataEntity);
        }
        public async Task InsertAndGet()
        {
            // create tables
            string         runId          = RunId.GenerateTestRunId();
            StorageManager storageManager = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.PublishMetadata, runId);
            await storageManager.CreateTables();

            // create a bogus publish metadata entity
            PublishMetadataEntity entity = new PublishMetadataEntity()
            {
                RunId            = runId,
                RegionId         = "abcd",
                AgencyId         = "1234",
                RecordType       = RecordType.Route.ToString(),
                AddedCount       = 50,
                UpdatedCount     = 75,
                DeletedCount     = 1,
                ResurrectedCount = 5
            };

            // stick it into store
            List <PublishMetadataEntity> entities = new List <PublishMetadataEntity>();

            entities.Add(entity);
            await storageManager.PublishMetadataStore.Insert(entities);

            // get it from the store
            IEnumerable <PublishMetadataEntity> retrievedEntities1 = storageManager.PublishMetadataStore.Get(runId);

            // clean up
            await storageManager.PublishMetadataStore.Delete(runId);

            // get it from the store again
            IEnumerable <PublishMetadataEntity> retrievedEntities2 = storageManager.PublishMetadataStore.Get(runId);

            // check the retrieved records
            Assert.IsNotNull(retrievedEntities1);
            Assert.AreEqual(retrievedEntities1.Count(), entities.Count);
            Assert.IsNull(retrievedEntities2);
            Assert.AreEqual(entity.RunId, retrievedEntities1.First().RunId);
            Assert.AreEqual(entity.RegionId, retrievedEntities1.First().RegionId);
            Assert.AreEqual(entity.AgencyId, retrievedEntities1.First().AgencyId);
            Assert.AreEqual(entity.RecordType, retrievedEntities1.First().RecordType);
            Assert.AreEqual(entity.AddedCount, retrievedEntities1.First().AddedCount);
            Assert.AreEqual(entity.UpdatedCount, retrievedEntities1.First().UpdatedCount);
            Assert.AreEqual(entity.DeletedCount, retrievedEntities1.First().DeletedCount);
            Assert.AreEqual(entity.ResurrectedCount, retrievedEntities1.First().ResurrectedCount);
        }
Beispiel #3
0
 /// <summary>
 /// Stores a publish metadata entity in Azure Tables
 /// </summary>
 /// <param name="record">publish metadata entity</param>
 /// <returns>task that stores the entity</returns>
 public async Task Insert(PublishMetadataEntity record)
 {
     await this.Insert(new List <PublishMetadataEntity>() { record });
 }