Exemple #1
0
        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);
        }
Exemple #2
0
        //public DbCommand ResolveCommand<T>(DbCommandResolver resolver, IContext context, ModelActionOption option, ICriterion criteria) where T : new()
        //{
        //    DbCommand cmd = null;
        //    Model m = Models.Find(x => x.modelType.Equals(typeof(T).FullName, StringComparison.OrdinalIgnoreCase));

        //    string schema = (m != null && !String.IsNullOrEmpty(m.dbSchema)) ? m.dbSchema : (!String.IsNullOrEmpty(DefaultDbSchema)) ? DefaultDbSchema : "dbo";

        //    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;
        //                string switchKey = String.Empty;
        //                string caseKey = String.Empty;
        //                Switch found = null;
        //                if (!String.IsNullOrEmpty(a.SqlCommandKey))
        //                {
        //                    cmdKey = a.SqlCommandKey;
        //                }
        //                else if (criteria == null)
        //                {
        //                    found = a.Switches.Find(x => x.CriteriaKey.Equals(XAFConstants.SYSTEMNULL, StringComparison.OrdinalIgnoreCase));
        //                    if (found != null && found.Cases != null && found.Cases.Count >= 1)
        //                    {
        //                        cmdKey = found.Cases[0].SqlCommandKey;
        //                    }
        //                }
        //                else
        //                {
        //                    switchKey = criteria.GetValue<string>(XAFConstants.STRATEGYKEY);
        //                    found = a.Switches.Find(x => x.CriteriaKey.Equals(switchKey, StringComparison.OrdinalIgnoreCase));
        //                    caseKey = criteria.GetValue<string>(switchKey);
        //                }

        //                if (found != null && found.Cases != null && m.SqlCommands != null)
        //                {
        //                    if (found.Cases.Count == 1)
        //                    {
        //                        cmdKey = found.Cases[0].SqlCommandKey;
        //                    }
        //                    else
        //                    {
        //                        Case obj = found.Cases.FirstOrDefault(x => x.Value.Equals(caseKey, StringComparison.OrdinalIgnoreCase));
        //                        if (obj != null && !String.IsNullOrEmpty(obj.SqlCommandKey))
        //                        {
        //                            cmdKey = obj.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
        //        {
        //            cmd = resolver.Resolve<T>(context, option, criteria, schema);
        //        }
        //    }
        //    else // Model not found in config, so try Convention over Configuration
        //    {
        //        cmd = resolver.Resolve<T>(context, criteria, option, schema);
        //    }
        //    if (cmd == null)
        //    {
        //        cmd = resolver.Resolve<T>(context, criteria, option, schema);
        //    }

        //    return cmd;
        //}

        internal SqlCommand ResolveCommand <T>(IContext context, ModelActionOption option, SqlConnection cn, string schema, ICriterion criterion) 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;
                        string switchKey = String.Empty;
                        string caseKey   = String.Empty;
                        Switch found     = null;
                        if (!String.IsNullOrEmpty(a.SqlCommandKey))
                        {
                            cmdKey = a.SqlCommandKey;
                        }
                        else if (criterion == null)
                        {
                            found = a.Switches.Find(x => x.CriteriaKey.Equals(XFConstants.SystemNull, StringComparison.OrdinalIgnoreCase));
                            if (found != null && found.Cases != null && found.Cases.Count >= 1)
                            {
                                cmdKey = found.Cases[0].SqlCommandKey;
                            }
                        }
                        else
                        {
                            switchKey = criterion.GetValue <string>(XFConstants.StrategyKey);
                            found     = a.Switches.Find(x => x.CriteriaKey.Equals(switchKey, StringComparison.OrdinalIgnoreCase));
                            caseKey   = criterion.GetValue <string>(switchKey);
                        }

                        if (found != null && found.Cases != null && m.SqlCommands != null)
                        {
                            if (found.Cases.Count == 1)
                            {
                                cmdKey = found.Cases[0].SqlCommandKey;
                            }
                            else
                            {
                                Case obj = found.Cases.FirstOrDefault(x => x.Value.Equals(caseKey, StringComparison.OrdinalIgnoreCase));
                                if (obj != null && !String.IsNullOrEmpty(obj.SqlCommandKey))
                                {
                                    cmdKey = obj.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, criterion);
            }

            if (cmd == null) // dynamic sql based
            {
            }

            return(cmd);
        }