Exemple #1
0
        /// <summary>
        /// Sets the anchor key asynchronously.
        /// </summary>
        /// <param name="anchorKey">The anchor key.</param>
        /// <returns>An <see cref="Task{System.Int64}" /> representing the anchor identifier.</returns>
        public async Task <long> SetAnchorKeyAsync(string anchorKey)
        {
            await this.InitializeAsync();

            if (lastAnchorNumberIndex == long.MaxValue)
            {
                // Reset the anchor number index.
                lastAnchorNumberIndex = -1;
            }

            if (lastAnchorNumberIndex < 0)
            {
                // Query last row key
                var rowKey = (await this.GetLastAnchorAsync())?.RowKey;
                long.TryParse(rowKey, out lastAnchorNumberIndex);
            }

            long newAnchorNumberIndex = ++lastAnchorNumberIndex;

            AnchorCacheEntity anchorEntity = new AnchorCacheEntity(newAnchorNumberIndex, CosmosDbCache.partitionSize)
            {
                AnchorKey = anchorKey
            };

            await this.dbCache.ExecuteAsync(TableOperation.Insert(anchorEntity));

            return(newAnchorNumberIndex);
        }
        /// <summary>
        /// Determines whether the cache contains the specified anchor identifier.
        /// </summary>
        /// <param name="anchorId">The anchor identifier.</param>
        /// <returns>A <see cref="Task{System.Boolean}" /> containing true if the identifier is found; otherwise false.</returns>
        public async Task <bool> ContainsAsync(long anchorId)
        {
            await this.InitializeAsync();

            TableResult result = await this.dbCache.ExecuteAsync(TableOperation.Retrieve <AnchorCacheEntity>((anchorId / CosmosDbCache.partitionSize).ToString(), anchorId.ToString()));

            AnchorCacheEntity anchorEntity = result.Result as AnchorCacheEntity;

            return(anchorEntity != null);
        }
        /// <summary>
        /// Sets the anchor key asynchronously.
        /// </summary>
        /// <param name="groupingKey">The grouping key between several anchors.</param>
        /// <param name="anchorId">The anchor id.</param>
        /// <returns>A Task</returns>
        public async Task SetAnchorIdAsync(string groupingKey, string anchorId)
        {
            await InitializeAsync();

            AnchorCacheEntity anchorEntity = new AnchorCacheEntity(groupingKey, anchorId, CosmosDbCache.partitionKey);

            await this.dbCache.ExecuteAsync(TableOperation.Insert(anchorEntity));

            return;
        }
        /// <summary>
        /// Gets the anchor key asynchronously.
        /// </summary>
        /// <param name="anchorId">The anchor identifier.</param>
        /// <exception cref="KeyNotFoundException"></exception>
        /// <returns>The anchor key.</returns>
        public async Task <string> GetAnchorKeyAsync(string anchorName)
        {
            await this.InitializeAsync();

            TableResult result = await this.dbCache.ExecuteAsync(TableOperation.Retrieve <AnchorCacheEntity>("0", anchorName));

            AnchorCacheEntity anchorEntity = result.Result as AnchorCacheEntity;

            if (anchorEntity != null)
            {
                return(anchorEntity.RowKey + ":" + anchorEntity.AnchorKey + ":" + anchorEntity.Location + ":" + anchorEntity.Expiration + ":" + anchorEntity.Description);
            }

            throw new KeyNotFoundException($"The {nameof(anchorName)} {anchorName} could not be found.");
        }
Exemple #5
0
        /// <summary>
        /// Gets the anchor key asynchronously.
        /// </summary>
        /// <param name="anchorId">The anchor identifier.</param>
        /// <exception cref="KeyNotFoundException"></exception>
        /// <returns>The anchor key.</returns>
        public async Task <string> GetAnchorKeyAsync(long anchorId)
        {
            await this.InitializeAsync();

            TableResult result = await this.dbCache.ExecuteAsync(TableOperation.Retrieve <AnchorCacheEntity>((anchorId / CosmosDbCache.partitionSize).ToString(), anchorId.ToString()));

            AnchorCacheEntity anchorEntity = result.Result as AnchorCacheEntity;

            if (anchorEntity != null)
            {
                return(anchorEntity.AnchorKey);
            }

            throw new KeyNotFoundException($"The {nameof(anchorId)} {anchorId} could not be found.");
        }
Exemple #6
0
        /// <summary>
        /// Sets the anchor key asynchronously.
        /// </summary>
        /// <param name="anchorKey">The anchor key.</param>
        /// <returns>An <see cref="Task{System.Int64}" /> representing the anchor identifier.</returns>
        public async Task <long> SetAnchorKeyAsync(string anchorKey)
        {
            await InitializeAsync();

            if (this.anchorNumberIndex == long.MaxValue)
            {
                // Reset the anchor number index.
                this.anchorNumberIndex = -1;
            }

            long newAnchorNumberIndex = ++this.anchorNumberIndex;

            AnchorCacheEntity anchorEntity = new AnchorCacheEntity(newAnchorNumberIndex, CosmosDbCache.partitionSize)
            {
                AnchorKey = anchorKey
            };

            await this.dbCache.ExecuteAsync(TableOperation.Insert(anchorEntity));

            return(newAnchorNumberIndex);
        }
        /// <summary>
        /// Sets the anchor key asynchronously.
        /// </summary>
        /// <param name="anchorKey">The anchor key.</param>
        /// <returns>An <see cref="Task{System.Int64}" /> representing the anchor identifier.</returns>
        public async Task <string> SetAnchorKeyAsync(string anchorKey, string anchorName, string location, string expiration, string description)
        {
            await this.InitializeAsync();

            if (lastAnchorNumberIndex == long.MaxValue)
            {
                // Reset the anchor number index.
                lastAnchorNumberIndex = -1;
            }

            /*
             * if(lastAnchorNumberIndex < 0)
             * {
             *  // Query last row key
             *  var rowKey = (await this.GetLastAnchorAsync())?.RowKey;
             *  long.TryParse(rowKey, out lastAnchorNumberIndex);
             * }
             */

            long newAnchorNumberIndex = ++lastAnchorNumberIndex;

            // Elimiating "RowKey" from Cosmos. Now going to just use the row name (insert or update)

            AnchorCacheEntity anchorEntity = new AnchorCacheEntity(CosmosDbCache.partitionSize, anchorName, location, expiration, description)
            {
                AnchorKey = anchorKey,
                //AnchorName = anchorName,
                Location    = location,
                Expiration  = expiration,
                Description = description
            };

            await this.dbCache.ExecuteAsync(TableOperation.InsertOrReplace(anchorEntity));

            //return newAnchorNumberIndex;
            return(anchorName);
        }