Example #1
0
        /// <summary>
        /// Sets a model id as the default model
        /// </summary>
        /// <param name="modelId">The model id to be set as default</param>
        /// <param name="cancellationToken">The cancellation token assigned for the operation.</param>
        /// <returns>
        /// <value>true</value> if the model was set as default or <value>false</value> if
        /// the model was not found or its status is not <see cref="ModelStatus.Completed"/>
        /// </returns>
        public async Task <bool> SetDefaultModelIdAsync(Guid modelId, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            Model newDefaultModel = await GetModelAsync(modelId, cancellationToken);

            if (newDefaultModel?.Status != ModelStatus.Completed)
            {
                return(false);
            }

            // create a default model entity using the model id
            var defaultModelEntity = new ModelIdTableEntity(DefaultModelIdKeyName, newDefaultModel.Id);

            try
            {
                Trace.TraceInformation($"Setting the default model id to '{modelId}'");
                bool result = await _modelsTable.InsertOrReplaceEntityAsync(defaultModelEntity, cancellationToken);

                Trace.TraceInformation($"Default model id updated to '{modelId}' returned with '{result}'");
                return(result);
            }
            catch (StorageException storageException)
            {
                var exception = new Exception(
                    $"Exception while trying to update default model id ({newDefaultModel.Id}) entity to the table",
                    storageException);
                Trace.TraceError(exception.ToString());
                throw exception;
            }
        }
Example #2
0
        /// <summary>
        /// Gets the default model id.
        /// </summary>
        /// <returns>The default model id or <value>null</value> if a default model is not defined</returns>
        /// <param name="cancellationToken">The cancellation token assigned for the operation.</param>
        public async Task <Guid?> GetDefaultModelIdAsync(CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            try
            {
                Trace.TraceInformation("Getting the default model id from the table");
                ModelIdTableEntity entity = await _modelsTable.GetEntityAsync <ModelIdTableEntity>(
                    DefaultModelIdKeyName, cancellationToken, nameof(ModelIdTableEntity.ModelId));

                Guid?defaultModelId = entity?.ModelId;
                Trace.TraceInformation($"Found the default model id {defaultModelId}");
                return(defaultModelId);
            }
            catch (StorageException storageException)
            {
                var exception = new Exception("Exception while trying to get default model id entity from table",
                                              storageException);
                Trace.TraceError(exception.ToString());
                throw exception;
            }
        }