private SqlCommand GetCommand(SqlConnection cn, T t, IContext context, ModelActionOption option) { SqlCommand cmd = null; var found = _Model.ModelActions.Find(x => x.Verb.Equals(option)); if (found == null) { XF.Common.Discovery.SqlTable table = null; if (SprocMapCache.Instance.TryGetTable <T>(context, cn, out table)) { cmd = XF.Common.Discovery.InlineSqlCommandGenerator.Generate <T>(cn, table, option, t); } } else { cmd = cn.CreateCommand(); XF.Common.Db.DbCommand dbCmd = null; var foundAction = _Model.ModelActions.Find(x => x.Verb.Equals(option)); if (foundAction != null) { dbCmd = _Model.Commands.Find(x => x.Key.Equals(foundAction.DbCommandKey, StringComparison.OrdinalIgnoreCase)); } if (dbCmd != null) { cmd.CommandType = ConvertCommandType(dbCmd.CommandType); cmd.CommandText = dbCmd.CommandText; AddParameters(cmd, dbCmd.Parameters, t, context); } } return(cmd); }
private void WriteEvent <T>(ModelActionOption modelAction, T t, IDictionary <string, object> properties) where T : class, new() { var props = EnsureProperties(properties); props.Add(XFConstants.EventWriter.Model, t.ToString()); WriteEvent <T>(modelAction, props); }
public static ExceptionMessage ComposeResourceNotFoundError <T>(ModelActionOption modelActionOption, T t, ICriterion criterion, IContext context) where T : class, new() { ExceptionMessage message = new ExceptionMessage(); //if (eXtensibleConfig.IsSeverityAtLeast(TraceEventTypeOption.Verbose)) //{ StringBuilder sb = new StringBuilder(); if (t != null) { sb.AppendLine(String.Format(ErrorMessages.ModelFormat, t.ToString())); } if (criterion != null) { sb.AppendLine(String.Format(ErrorMessages.ICriterionFormat, criterion.ToString())); } sb.AppendLine(String.Format(ErrorMessages.IContextFormat, context.ToString())); string verboseMessage = String.Format(ErrorMessages.ResourceNotFoundFormatVerbose, GetModelType <T>().FullName, modelActionOption, sb.ToString(), message.Id); message.Add(ExceptionMessageOption.Log, verboseMessage); //} //else //{ //string simpleMessage = String.Format(ErrorMessages.ResourceNotFoundFormat, GetModelType<T>().FullName, modelActionOption); message.Add(ExceptionMessageOption.Publish, ErrorMessage); //} return(message); }
public static ExceptionMessage ComposeDbConnectionStringFormatError <T>(ModelActionOption modelActionOption, T t, IContext context, string connectionStringKey, string connectionString) where T : class, new() { ExceptionMessage message = new ExceptionMessage(); //if (eXtensibleConfig.IsSeverityAtLeast(TraceEventTypeOption.Verbose)) //{ StringBuilder sb = new StringBuilder(); if (t != null) { sb.AppendLine(String.Format(ErrorMessages.ModelFormat, t.ToString())); } sb.AppendLine(String.Format(ErrorMessages.IContextFormat, context.ToString())); //var verboseMessage = String.Format(ErrorMessages.DbConnectionStringNullSettingsVerbose, GetModelType<T>().FullName, modelActionOption, connectionStringKey, sb.ToString(), message.Id); var verboseMessage = String.Format(ErrorMessages.DbConnectionStringFormatVerbose, connectionStringKey, connectionString, GetModelType <T>().FullName, message.Id); message.Add(ExceptionMessageOption.Log, verboseMessage); //} //else //{ //var simpleMessage = String.Format(ErrorMessages.DbConnectionStringNullSettings, GetModelType<T>().FullName, modelActionOption, connectionStringKey); message.Add(ExceptionMessageOption.Publish, ErrorMessage); //} return(message); //string s = String.Format("Improperly formatted Connection string ({0}={1})",connectionStringKey, settings.ConnectionString); }
public static ExceptionMessage ComposeGeneralExceptionError <T>(ModelActionOption modelActionOption, Exception ex, T t, ICriterion criterion, IContext context, string implementor) where T : class, new() { ExceptionMessage message = new ExceptionMessage(); //if (eXtensibleConfig.IsSeverityAtLeast(TraceEventTypeOption.Verbose)) //{ StringBuilder sb = new StringBuilder(); string s = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; sb.AppendLine(String.Format(ErrorMessages.ExceptionFormat, s)); if (t != null) { sb.AppendLine(String.Format(ErrorMessages.ModelFormat, t.ToString())); } if (criterion != null) { sb.AppendLine(String.Format(ErrorMessages.ICriterionFormat, criterion.ToString())); } sb.AppendLine(String.Format(ErrorMessages.IContextFormat, context.ToString())); string verboseMessage = String.Format(ErrorMessages.GeneralExceptionInFormatVerbose, GetModelType <T>().FullName, modelActionOption, implementor, sb.ToString(), message.Id); message.Add(ExceptionMessageOption.Log, verboseMessage); //} //else //{ //string simpleMessage = String.Format(ErrorMessages.GeneralExceptionInFormat, GetModelType<T>().FullName, modelActionOption, implementor); message.Add(ExceptionMessageOption.Publish, ErrorMessage); //} message.Add(ExceptionMessageOption.Stacktrace, ex.StackTrace); return(message); }
public static ExceptionMessage ComposeDatastoreException <T>(ModelActionOption modelActionOption, string ex, T t, ICriterion criterion, IContext context, string implementor, string datastoreType = "Datastore", string dataSource = "") where T : class, new() { ExceptionMessage message = new ExceptionMessage(); //if (eXtensibleConfig.IsSeverityAtLeast(TraceEventTypeOption.Verbose)) //{ StringBuilder sb = new StringBuilder(); sb.AppendLine(String.Format(ErrorMessages.ExceptionFormat, ex)); if (t != null) { sb.AppendLine(String.Format(ErrorMessages.ModelFormat, t.ToString())); } if (!String.IsNullOrWhiteSpace(dataSource)) { sb.AppendLine(dataSource); } if (criterion != null) { sb.AppendLine(String.Format(ErrorMessages.ICriterionFormat, criterion.ToString())); } sb.AppendLine(String.Format(ErrorMessages.IContextFormat, context.ToString())); string verboseMessage = String.Format(ErrorMessages.DatastoreExceptionFormatVerbose, GetModelType <T>().FullName, modelActionOption, implementor, datastoreType, sb.ToString(), message.Id); message.Add(ExceptionMessageOption.Log, verboseMessage); //} //else //{ //string simpleMessage = String.Format(ErrorMessages.SqlExceptionFormat, GetModelType<T>().FullName, modelActionOption, implementor, datastoreType); message.Add(ExceptionMessageOption.Publish, ErrorMessage); //} return(message); }
public string Get <T>(IContext context, ICriterion criterion, ModelActionOption option, SqlConnection connection) where T : class, new() { string s = String.Empty; if (!IsCacheLoaded(connection)) { LoadCache(connection); } //string hash = ComposeHash<T>("demo",criterion, option); string hash = ComposeHash <T>(context.ApplicationContextKey, criterion, option); List <Discovery.SqlStoredProcedure> list = StoredProcedures[connection.ConnectionString]; if (list != null && list.Count > 0) { var found = list.FirstOrDefault(x => { return(!String.IsNullOrEmpty(x.Hash) && x.Hash.Equals(hash, StringComparison.OrdinalIgnoreCase)); } ); if (found != null) { s = String.Format("[{0}].[{1}]", found.Schema, found.Name); } } return(s); }
private IRpcHander <T> ResolveImplementor <T>(ModelActionOption option, IContext context, T t, ICriterion criterion) where T : class, new() { IRpcHander <T> implementor = null; Type type = _TypeCache.ResolveType <T>(); if (type == null) { var message = Exceptions.ComposeRpcImplementorResolutionError <T>(option, t, context); context.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error); } else { implementor = Activator.CreateInstance(type) as IRpcHander <T>; if (implementor == null) { var message = Exceptions.ComposeRpcImplementorInstantiationError <T>(option, t, context, type.FullName); context.SetError(500, message.ToPublish()); var props = eXtensibleConfig.GetProperties(); props.Add(XFConstants.Context.Ticket, message.Id); EventWriter.WriteError(message.ToLog(), SeverityType.Error, XFConstants.Category.DataAccess, props); } else { EventWriter.Inform(String.Format("RpcHandler selected: {0}", type.FullName)); implementor.Context = context; } } return(implementor); }
private SqlCommand CreateCommand <T>(IContext context, ModelActionOption option, SqlConnection connection, ICriterion criteria) where T : class, new() { SqlCommand cmd = null; Discovery.SqlStoredProcedure sproc; if (SprocMapCache.Instance.TryGetStoredProcedure <T>(context, criteria, option, connection, out sproc)) { cmd = connection.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = String.Format("[{0}].[{1}]", sproc.Schema, sproc.Name); if (criteria != null && sproc.Parameters != null && sproc.Parameters.Count > 0) { List <PropertyInfo> list = new List <PropertyInfo>(typeof(T).GetProperties()); foreach (var item in sproc.Parameters) { string paramName = item.ParamName.Replace("@", String.Empty); SqlParameter sqlparam = cmd.CreateParameter(); sqlparam.ParameterName = paramName; //sqlparam.DbType = (DbType)Enum.Parse(typeof(DbType), item.Datatype, true); if (paramName.Equals(XFConstants.Application.UserIdentityParamName, StringComparison.OrdinalIgnoreCase)) { string useridentityvalue = context.GetValue <string>(XFConstants.Application.UserIdentityParamName); if (!String.IsNullOrEmpty(useridentityvalue)) { sqlparam.Value = useridentityvalue; } } else { if (criteria.Contains(paramName)) { TypedItem found = criteria.Items.First(x => x.Key.Equals(paramName, StringComparison.OrdinalIgnoreCase)); if (found != null) { if (item.Datatype == "DateTime" && found.Value.GetType().Equals(typeof(DateTime))) { DateTime target = (DateTime)found.Value; if (target >= new DateTime(1753, 1, 1)) { sqlparam.Value = found.Value; } } else { sqlparam.Value = found.Value; } } } } cmd.Parameters.Add(sqlparam); } } } return(cmd); }
string ISqlStoredProcedureFormatter.ComposeFormat <T>(ModelActionOption modelActionOption) { T t = new T(); string model = t.GetType().Name; string format = "{0}:{1}:"; return(String.Format(format, model, modelActionOption.ToString())); }
private void WriteEvent <T>(ModelActionOption modelAction, IDictionary <string, object> properties) where T : class, new() { var props = EnsureProperties(properties); string modelname = GetModelName <T>(); props.Add(XFConstants.EventWriter.ModelAction, modelAction); props.Add(XFConstants.EventWriter.EventType, EventTypeOption.Event); LocalPublish(EventTypeOption.Event, props); }
void IModelDataGatewayInitializeable.Initialize<T>(ModelActionOption option, IContext context, T t, ICriterion criterion, ResolveDbKey<T> dbkeyResolver) { string key = ResolveConnectionStringKey(context); if (String.IsNullOrWhiteSpace(key)) { key = dbkeyResolver.Invoke(context); } if (String.IsNullOrEmpty(key)) { var message = Exceptions.ComposeDbConnectionStringKeyResolutionError<T>(option, t, context); context.SetError(500, message.ToPublish() ); EventWriter.WriteError(message.ToLog(), SeverityType.Error); } else { var cn = ConfigurationManager.ConnectionStrings[key]; if (cn != null) { MongoConnectionInfo info = new MongoConnectionInfo(); if (info.Initialize(cn)) { MongoDb = info.GetDatabase(); } if (MongoDb == null) { var message = Exceptions.ComposeDbConnectionCreationError<T>(option, t, context, key); context.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error); } else { Collection = GetCollection(); if (Collection == null) { context.SetError(500, "MongoDB.Collection is Null"); } else if (eXtensibleConfig.CaptureMetrics) { IRequestContext ctx = context as IRequestContext; ctx.SetMetric(XFConstants.Metrics.Scope.DataStore, XFConstants.Metrics.Database.Datasource, String.Format("server:{0};database:{1};", cn.ConnectionString, key)); ; } } } else { var message = Exceptions.ComposeDbConnectionCreationError<T>(option, t, context, key); context.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error); } } }
protected virtual SqlCommand PostSqlCommand(SqlConnection cn, T t, IContext context) { ModelActionOption option = ModelActionOption.Post; SqlCommand cmd = null; XF.Common.Discovery.SqlTable table = null; if (SprocMapCache.Instance.TryGetTable <T>(context, cn, out table)) { cmd = XF.Common.Discovery.InlineSqlCommandGenerator.Generate <T>(cn, table, option, t); } return(cmd); }
public DataPacket Serialize <T>(IContext ctx, ModelActionOption modelAction, T model) where T : class, new() { DataPacket item = new DataPacket() { Context = (ApplicationContext)ctx, ModelAction = modelAction, Typename = GetTypename <T>(), Items = GenerateMessage <T>(ctx, modelAction), Buffer = GenericSerializer.ItemToByteArray(model) }; return(item); }
public static SqlCommand Generate <T>(SqlConnection cn, SqlTable table, ModelActionOption option, T t) { SqlCommand cmd = null; if (option.Equals(ModelActionOption.Post)) { cmd = Post <T>(cn, table, t); } else if (option.Equals(ModelActionOption.Put)) { cmd = Put <T>(cn, table, t); } return(cmd); }
internal SqlCommand ResolveCommand <T>(IContext context, ModelActionOption option, SqlConnection cn, string schema, T t, List <DataMap> dataMaps) where T : class, new() { SqlCommand cmd = null; Model m = Models.Find(x => x.modelType.Equals(typeof(T).FullName, StringComparison.OrdinalIgnoreCase)); string dbSchema = (m != null && !String.IsNullOrEmpty(m.dbSchema)) ? m.dbSchema : (!String.IsNullOrEmpty(DefaultDbSchema)) ? DefaultDbSchema : schema; if (m != null) { ModelAction a = m.ModelActions.Find(x => x.Verb.Equals(option)); if (a != null) { if (a.Strategy == StrategyOption.None) { } else if (a.Strategy == StrategyOption.Config) { string cmdKey = String.Empty; if (!String.IsNullOrEmpty(a.SqlCommandKey)) { cmdKey = a.SqlCommandKey; } SQLCommand sqlcmd = m.SqlCommands.Find(x => x.Key.Equals(cmdKey, StringComparison.OrdinalIgnoreCase)); if (sqlcmd != null) { //cmd = resolver.Resolve<T>(context, sqlcmd, criteria, schema); } else { //Logger.Write(message, new string[] { Constants.Category.### }, -1, -1, TraceEventTypeOption.Warning, String.Empty, extendedproperties); } } } } else // Model not found in config, so try Convention over Configuration (sproc based) { //string sprocname = GetStoredProcedure<T>(context, criterion, option, cn); //cmd = CreateCommand(cn, sprocname); // now append any appropriate parameters cmd = CreateCommand <T>(context, option, cn, t, dataMaps); } if (cmd == null) // dynamic sql based { } return(cmd); }
private static List <TypedItem> GenerateMessage <T>(IContext context, ModelActionOption modelAction) { List <TypedItem> items = new List <TypedItem>(); items.Add(new TypedItem(XFConstants.Message.Verb, XFConstants.Message.VerbConstList[modelAction]) { Domain = XFConstants.Domain.Context }); items.Add(new TypedItem(XFConstants.Context.Application, context.ApplicationContextKey) { Domain = XFConstants.Domain.Context }); items.Add(new TypedItem(XFConstants.Context.USERIDENTITY, context.UserIdentity) { Domain = XFConstants.Domain.Context }); items.Add(new TypedItem(XFConstants.Context.UICULTURE, context.UICulture) { Domain = XFConstants.Domain.Context }); items.Add(new TypedItem(XFConstants.Context.ZONE, context.Zone) { Domain = XFConstants.Domain.Context }); if (context.Claims != null && context.Claims.Count() > 0) { int i = 1; foreach (var item in context.Claims) { items.Add(new TypedItem(String.Format("{0}.{1}", XFConstants.Context.Claim, i++), item) { Domain = XFConstants.Domain.Claims }); } } items.Add(new TypedItem(XFConstants.Context.INSTANCEIDENTIFIER, Environment.MachineName) { Domain = XFConstants.Domain.Context }); items.Add(new TypedItem(XFConstants.Context.RequestBegin, DateTime.Now) { Domain = XFConstants.Domain.Metrics }); items.Add(new TypedItem(XFConstants.Context.Model, GetModelType <T>().FullName) { Domain = XFConstants.Domain.Context }); return(items); }
public DataPacket Serialize <T>(IContext ctx, ModelActionOption modelAction, IEnumerable <TypedItem> items) where T : class, new() { DataPacket item = new DataPacket() { Context = (ApplicationContext)ctx, Typename = GetTypename <T>(), ModelAction = modelAction, Criteria = new Criterion() { Items = items }, Items = GenerateMessage <T>(ctx, modelAction) }; return(item); }
public SqlCommand ResolveCommand <T>(IContext context, ModelActionOption option, SqlConnection cn, string schema, T t, List <DataMap> dataMaps) where T : class, new() { SqlCommand cmd = null; string contextKey = (context != null) ? context.ApplicationContextKey : XFConstants.Context.DefaultApplication; var found = Contexts.Find(x => x.Context.Equals(contextKey, StringComparison.OrdinalIgnoreCase)); if (found == null) { } else { cmd = found.ResolveCommand <T>(context, option, cn, schema, t, dataMaps); } return(cmd); }
public DataPacket Serialize <T>(IContext ctx, ModelActionOption modelAction, IEnumerable <T> list, IEnumerable <TypedItem> items) where T : class, new() { DataPacket item = new DataPacket() { Context = (ApplicationContext)ctx, Typename = GetTypename <List <T> >(), ModelAction = modelAction, Criteria = new Criterion() { Items = items }, Items = GenerateMessage <T>(ctx, modelAction), Buffer = GenericSerializer.GenericListToByteArray <T>(list.ToList()) }; return(item); }
public bool TryGetStoredProcedure(IContext context, ICriterion criterion, ModelActionOption option, SqlConnection connection, string hash, out Discovery.SqlStoredProcedure storedProcedure) { bool b = false; storedProcedure = null; string s = String.Empty; if (!IsCacheLoaded(connection)) { LoadCache(connection); } List <Discovery.SqlStoredProcedure> list = StoredProcedures[connection.ConnectionString]; if (list != null && list.Count > 0) { Discovery.SqlStoredProcedure found = null; if (option == ModelActionOption.Post | option == ModelActionOption.Put) { found = list.FirstOrDefault(x => { bool b1 = false; if (!String.IsNullOrEmpty(x.Hash) && x.Hash.Length >= hash.Length) { b1 = hash.Equals(x.Hash.Substring(0, hash.Length), StringComparison.OrdinalIgnoreCase); } return(b1); }); } else { found = list.FirstOrDefault(x => { return(!String.IsNullOrEmpty(x.Hash) && x.Hash.Equals(hash, StringComparison.OrdinalIgnoreCase)); }); } if (found != null) { storedProcedure = found; b = true; } } return(b); }
public DataPacket Serialize <T, U>(IContext ctx, ModelActionOption modelAction, T model, IEnumerable <TypedItem> items) where T : class, new() { DataPacket item = new DataPacket() { Context = (ApplicationContext)ctx, Typename = GetTypename <T>(), ModelAction = modelAction, Criteria = new Criterion() { Items = items }, Items = GenerateMessage <T>(ctx, modelAction), Buffer = GenericSerializer.ItemToByteArray(model), SecondaryTypename = typeof(U).FullName }; return(item); }
public static ExceptionMessage ComposeRpcImplementorResolutionError <T>(ModelActionOption modelActionOption, T t, IContext context) where T : class, new() { ExceptionMessage message = new ExceptionMessage(); string m = String.Empty; StringBuilder sb = new StringBuilder(); if (t != null) { sb.AppendLine(String.Format(ErrorMessages.ModelFormat, t.ToString())); } sb.AppendLine(String.Format(ErrorMessages.IContextFormat, context.ToString())); m = String.Format(ErrorMessages.NullRpcHandlerImplementation, GetModelType <T>().FullName, modelActionOption, sb.ToString(), message.Id); message.Add(ExceptionMessageOption.Log, m); //string simpleMessage = String.Format(ErrorMessages.NullModelDataGatewayImplementation, GetModelType<T>().FullName, modelActionOption); message.Add(ExceptionMessageOption.Publish, ErrorMessage); return(message); }
public static ExceptionMessage ComposeRpcImplementorInstantiationError <T>(ModelActionOption modelActionOption, T t, IContext context, string implementor) where T : class, new() { ExceptionMessage message = new ExceptionMessage(); //if (eXtensibleConfig.IsSeverityAtLeast(TraceEventTypeOption.Verbose)) //{ StringBuilder sb = new StringBuilder(); if (t != null) { sb.AppendLine(String.Format(ErrorMessages.ModelFormat, t.ToString())); } sb.AppendLine(String.Format(ErrorMessages.IContextFormat, context.ToString())); string verboseMessage = String.Format(ErrorMessages.ModelDataGatewayImplementationInstantiationVerbose, GetModelType <T>().FullName, modelActionOption, implementor, sb.ToString(), message.Id); message.Add(ExceptionMessageOption.Log, verboseMessage); //} //else //{ //string simpleMessage = String.Format(ErrorMessages.ModelDataGatewayImplementationInstantiation, GetModelType<T>().FullName, modelActionOption,implementor); message.Add(ExceptionMessageOption.Publish, ErrorMessage); //} return(message); }
public bool TryGetStoredProcedure <T>(IContext context, ICriterion criterion, ModelActionOption option, SqlConnection connection, out Discovery.SqlStoredProcedure storedProcedure) where T : class, new() { string hash = ComposeHash <T>(context.ApplicationContextKey, criterion, option); return(TryGetStoredProcedure(context, criterion, option, connection, hash, out storedProcedure)); }
public static void WriteEvent <T>(ModelActionOption modelAction, T t, IDictionary <string, object> properties) where T : class, new() { Writer.WriteEvent <T>(modelAction, t, properties); }
void IEventWriter.WriteEvent <T>(ModelActionOption modelAction, T t, IDictionary <string, object> properties) { WriteEvent <T>(modelAction, t, properties); }
public Message(IContext context, ModelActionOption modelActionOption) : base(context, modelActionOption) { }
void IModelDataGatewayInitializeable.Initialize <T>(ModelActionOption option, IContext context, T t, ICriterion criterion, ResolveDbKey <T> dbkeyResolver) { string connectionStringKey = ResolveConnectionStringKey(context); if (String.IsNullOrWhiteSpace(connectionStringKey)) { connectionStringKey = dbkeyResolver.Invoke(context); } if (String.IsNullOrEmpty(connectionStringKey)) { int connectionStringCount = ConfigurationManager.ConnectionStrings.Count; if (connectionStringCount > 0) { var found = ConfigurationManager.ConnectionStrings[connectionStringCount - 1]; connectionStringKey = found.Name; if (eXtensibleConfig.Inform) { EventWriter.Inform(String.Format("Could not resolve the database key, selecting a connection string from configuration (key={0})", found.Name)); } } } if (String.IsNullOrEmpty(connectionStringKey)) { var message = Exceptions.ComposeDbConnectionStringKeyResolutionError <T>(option, t, context); context.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error, XFConstants.Category.DataAccess, context.ToDictionary(message.Id)); } else { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionStringKey]; if (settings == null) { var message = Exceptions.ComposeDbConnectionNullSettingsError <T>(option, t, context, connectionStringKey); context.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error, XFConstants.Category.DataAccess, context.ToDictionary(message.Id)); } else { SqlConnection connection = null; try { connection = new SqlConnection(settings.ConnectionString); } catch (Exception ex) { var message = Exceptions.ComposeDbConnectionStringFormatError <T>(option, t, context, connectionStringKey, settings.ConnectionString); context.SetError(500, message.ToPublish()); context.SetStacktrace(ex.StackTrace); EventWriter.WriteError(message.ToLog(), SeverityType.Error, XFConstants.Category.DataAccess, context.ToDictionary(message.Id)); } if (connection == null) { var message = Exceptions.ComposeDbConnectionCreationError <T>(option, t, context, connectionStringKey); context.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error, XFConstants.Category.DataAccess, context.ToDictionary(message.Id)); } else { DbConnection = connection; if (eXtensibleConfig.CaptureMetrics) { IRequestContext ctx = context as IRequestContext; ctx.SetMetric(XFConstants.Metrics.Scope.DataStore, XFConstants.Metrics.Database.Datasource, String.Format("server:{0};database:{1};", connection.DataSource, connection.Database)); } } } } }
private string ComposeHash <T>(string applicationContext, ICriterion criteria, ModelActionOption option) where T : class, new() { string s = String.Empty; StringBuilder sb = new StringBuilder(); sb.Append(_SprocFormatters[0].ComposeFormat <T>(option)); if (criteria != null && criteria.Items != null) { List <TypedItem> list = (criteria.Items.Where(x => !x.Key.Equals("UserIdentity", StringComparison.OrdinalIgnoreCase) & !x.Key.Equals("action.modifier", StringComparison.OrdinalIgnoreCase)).OrderBy(x => x.Key)).ToList(); if (list != null && list.Count > 0) { foreach (var item in list) { sb.Append(String.Format("@{0}", item.Key)); } } } s = sb.ToString(); return(s); }