protected virtual async Task <ItemModel> GetItem(CommerceContext context, string id, string language = null) { Condition.Requires(context).IsNotNull($"{this.Name}: the context cannot be null."); Condition.Requires(id).IsNotNullOrEmpty($"{this.Name}: the id cannot be null or empty."); context.Logger.LogInformation($"{this.Name}.{id}: Language={language}"); ItemModel item = null; try { var startTime = DateTimeOffset.UtcNow; var timer = System.Diagnostics.Stopwatch.StartNew(); item = await new SitecoreConnectionManager().GetItemByIdAsync(context, id, language); timer.Stop(); context.TelemetryClient.TrackDependency("Sitecore", "GetItemById", startTime, timer.Elapsed, true); } catch (Exception ex) { context.LogException(this.Name, ex); } return(item); }
public virtual async Task <string> Process(CommerceContext commerceContext, string entityId) { using (CommandActivity.Start(commerceContext, this)) { var sqlContext = this.GetReadOnlySQLContext(commerceContext); try { commerceContext.Logger.LogTrace($"DevOps.GetEntityCommandNoDeserialize.Converting: EntityId={entityId}|Environment={commerceContext.Environment.Name}"); using (var connection = new SqlConnection(sqlContext.ConnectionString)) { await connection.OpenAsync(); var command = connection.CreateCommand(); command.CommandText = "sp_CommerceEntitiesSelect"; command.CommandType = CommandType.StoredProcedure; var entityIdParameter = command.CreateParameter(); entityIdParameter.ParameterName = "@Id"; entityIdParameter.DbType = DbType.String; entityIdParameter.Value = entityId; command.Parameters.Add(entityIdParameter); var environmentIdParameter = command.CreateParameter(); environmentIdParameter.ParameterName = "@EnvironmentId"; environmentIdParameter.DbType = DbType.Guid; environmentIdParameter.Value = commerceContext.Environment.ArtifactStoreId; command.Parameters.Add(environmentIdParameter); using (var reader = await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess)) { if (await reader.ReadAsync()) { try { var result = reader.GetString(0); return(result); } catch (Exception ex) { commerceContext.LogException("DevOps.GetEntityCommandAsString", ex); } } } return(null); } } catch (SqlException ex) { string message = $"SQL.GetEntityCommand.Exception: Id={entityId}|Environment={commerceContext.Environment.Id}|Message='{ex.Message}'|Number={ex.Number}|Procedure='{ex.Procedure}'|Line={ex.LineNumber}"; throw this.EvaluateSqlException(ex, message, commerceContext); } } }