Ejemplo n.º 1
0
 public static void SetDB(CSDataProvider db, string contextName)
 {
     lock (_globalDbMap)
     {
         _globalDbMap[contextName]        = db;
         _globalDbMapChanged[contextName] = true;
     }
 }
 /// <summary>
 /// Recupera los nombres y tipos de los parametros de un stored procedure
 /// </summary>
 /// <param name="StoredProcedureName">Nombre del stored procedure</param>
 /// <param name="WithReturn">Si debe incluir en los parametros el tipo de retorno o no</param>
 /// <returns>Un array de SqlParameter con los parametros que espera (y devuelve, si aplica) el stored procedure</returns>
 private static CSParameterCollection InternalGetSpParams(CSDataProvider dp, string StoredProcedureName, bool WithReturn)
 {
     CSParameterCollection _SPParameters;
     using (ICSDbCommand dbCommand = dp.CreateCommandInternal(String.Format("!{0}", StoredProcedureName), null))
     {
         //Asigna el tipo a stored procedure, porque solo se pueden recuperar los parametros de sp's
         try
         {
             //SqlCommandBuilder.DeriveParameters(cmd);
             dp.DeriveParameters(dbCommand);
         }
         catch (InvalidOperationException)
         {
             //throw new GYF_InvalidStoredProcedureException(StoredProcedureName);
             throw new Exception(StoredProcedureName);
         }
         //Si no debe obtener el param de retorno, lo quita
         if (!WithReturn)
         {
             for (int i = 0; i < dbCommand.Parameters.Count; i++)
             {
                 if (((IDbDataParameter)dbCommand.Parameters[i]).Direction == ParameterDirection.ReturnValue)
                 {
                     dbCommand.Parameters.RemoveAt(i);
                     break;
                 }
             }
         }
         _SPParameters = new CSParameterCollection();
         for (int i = 0; i < dbCommand.Parameters.Count; i++)
         {
             IDbDataParameter dbparam = (IDbDataParameter)dbCommand.Parameters[i];
             CSParameter parameter = _SPParameters.Add(dbparam.ParameterName);
             parameter.Direction = dbparam.Direction;
             //if (dbparam.Size > 0)
             parameter.Size = dbparam.Size;
             parameter.Precision = dbparam.Precision;
             parameter.Scale = dbparam.Scale;
         }
     }
     return _SPParameters;
 }
Ejemplo n.º 3
0
	    internal CSTransaction()
	    {
            _database = CSConfig.GetDB(CSConfig.DEFAULT_CONTEXTNAME);

            _database.BeginTransaction();
        }
Ejemplo n.º 4
0
		public CSTransaction(IsolationLevel isolationLevel)
		{
			_database = CSConfig.GetDB(CSConfig.DEFAULT_CONTEXTNAME);

			_database.BeginTransaction(isolationLevel);
		}
Ejemplo n.º 5
0
        public CSTransaction(IsolationLevel isolationLevel, string contextName)
        {
            _database = CSConfig.GetDB(contextName);

            _database.BeginTransaction(isolationLevel);
        }
Ejemplo n.º 6
0
 public static void SetDB(CSDataProvider db)
 {
     SetDB(db, DEFAULT_CONTEXTNAME);
 }
Ejemplo n.º 7
0
 public static void SetDB(CSDataProvider db, string contextName)
 {
     lock (_globalDbMap)
     {
         _globalDbMap[contextName] = db;
         _globalDbMapChanged[contextName] = true;
     }
 }
Ejemplo n.º 8
0
        public CSTransaction(IsolationLevel isolationLevel, string contextName)
        {
            _database = CSConfig.GetDB(contextName);

            _database.BeginTransaction(isolationLevel);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="provider"></param>
 /// <returns></returns>
 internal CSDataProvider ApplyDecorators(CSDataProvider provider)
 {
     CSDataProvider prov = provider;
     if (Decorators != null)
     {
         Decorators.ForEach(decorator =>
         {
             // [ber] 20101110 - Permito cargar desde cualquier assembly
             //Type type = Type.GetType(decorator, false, true);
             Type type = CSTypeLoader.LoadType(decorator);
             prov = (CSDataProvider)Activator.CreateInstance(type, prov);
         });
     }
     return prov;
 }
Ejemplo n.º 10
0
 public static void SetDB(CSDataProvider db)
 {
     SetDB(db, DEFAULT_CONTEXTNAME);
 }
Ejemplo n.º 11
0
		internal CSTransaction(CSSchema schema)
		{
			_database = schema.DB;

			_database.BeginTransaction();
		}
Ejemplo n.º 12
0
        internal CSTransaction(CSSchema schema)
        {
            _database = schema.DB;

            _database.BeginTransaction();
        }
Ejemplo n.º 13
0
        internal CSTransaction(CSSchema schema, IsolationLevel isolationLevel)
        {
            _database = schema.DB;

            _database.BeginTransaction(isolationLevel);
        }
Ejemplo n.º 14
0
        internal CSTransaction(CSDataProvider dataProvider, IsolationLevel isolationLevel)
        {
            _database = dataProvider;

            _database.BeginTransaction(isolationLevel);
        }
Ejemplo n.º 15
0
        internal CSTransaction(CSDataProvider dataProvider)
        {
            _database = dataProvider;

            _database.BeginTransaction();
        }
Ejemplo n.º 16
0
        internal CSTransaction()
        {
            _database = CSConfig.GetDB(CSConfig.DEFAULT_CONTEXTNAME);

            _database.BeginTransaction();
        }
Ejemplo n.º 17
0
        internal CSTransaction(CSDataProvider dataProvider)
        {
            _database = dataProvider;

            _database.BeginTransaction();
        }
Ejemplo n.º 18
0
            internal CSDataProvider GetDB(string contextName)
            {
                lock (_globalDbMap)
                {
                    if (_globalDbMapChanged.ContainsKey(contextName) && _globalDbMapChanged[contextName])
                    {
                        _globalDbMapChanged[contextName] = false;

                        if (_threadDbMap.ContainsKey(contextName))
                        {
                            _threadDbMap[contextName].Dispose();
                            _threadDbMap.Remove(contextName);
                        }
                    }
                }

                if (_threadDbMap.ContainsKey(contextName))
                {
                    return(_threadDbMap[contextName]);
                }

                lock (_globalDbMap)
                {
                    if (!_globalDbMap.ContainsKey(contextName))
                    {
#if !PCL
                        object   configurationSection = System.Configuration.ConfigurationManager.GetSection("CoolStorage");
                        string[] settings             = GetCustomConfig(configurationSection, contextName);
                        if (settings == null)
                        {
                            settings = GetLegacyConfig(configurationSection, contextName);
                        }

                        if (settings != null)
                        {
                            Type type = Type.GetType(settings[0]);

                            if (type == null)
                            {
                                throw new CSException("Unable to load type <" + settings[0] + ">");
                            }

                            _globalDbMap[contextName] = (CSDataProvider)Activator.CreateInstance(type, new object[] { settings[1] });
                        }
#endif

                        if (!_globalDbMap.ContainsKey(contextName))
                        {
                            throw new CSException("GetDB(): context [" + contextName + "] not found");
                        }
                    }
                }

                CSDataProvider db = _globalDbMap[contextName];

                db = db.Clone();

                _threadDbMap[contextName] = db;

                return(db);
            }
Ejemplo n.º 19
0
        internal CSTransaction(CSDataProvider dataProvider, IsolationLevel isolationLevel)
        {
            _database = dataProvider;

            _database.BeginTransaction(isolationLevel);
        }
Ejemplo n.º 20
0
        public CSTransaction(IsolationLevel isolationLevel)
        {
            _database = CSConfig.GetDB(CSConfig.DEFAULT_CONTEXTNAME);

            _database.BeginTransaction(isolationLevel);
        }
Ejemplo n.º 21
0
		internal CSTransaction(CSSchema schema, IsolationLevel isolationLevel)
		{
			_database = schema.DB;

			_database.BeginTransaction(isolationLevel);
		}
Ejemplo n.º 22
0
            internal CSDataProvider GetDB(string contextName)
            {
                lock (_globalDbMap)
                {
                    if (_globalDbMapChanged.ContainsKey(contextName) && _globalDbMapChanged[contextName])
                    {
                        _globalDbMapChanged[contextName] = false;

                        if (_threadDbMap.ContainsKey(contextName))
                        {
                            _threadDbMap[contextName].Dispose();
                            _threadDbMap.Remove(contextName);
                        }
                    }
                }

                if (_threadDbMap.ContainsKey(contextName))
                {
                    return(_threadDbMap[contextName]);
                }

                lock (_globalDbMap)
                {
                    if (!_globalDbMap.ContainsKey(contextName))
                    {
#if !MONOTOUCH && !WINDOWS_PHONE && !SILVERLIGHT && !MONO4ANDROID
                        NameValueCollection configurationSection = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("CoolStorage");

                        if (configurationSection != null)
                        {
                            string key = (contextName == DEFAULT_CONTEXTNAME) ? "Connection" : ("Connection." + contextName);

                            string value = configurationSection[key];

                            if (value.IndexOf('/') > 0)
                            {
                                string dbType     = value.Substring(0, value.IndexOf('/')).Trim();
                                string connString = value.Substring(value.IndexOf('/') + 1).Trim();

                                string typeName = "Vici.CoolStorage." + dbType;

                                Type type = Type.GetType(typeName);

                                if (type == null)
                                {
                                    throw new CSException("Unable to load type <" + typeName + ">");
                                }

                                _globalDbMap[contextName] = (CSDataProvider)Activator.CreateInstance(type, new object[] { connString });
                            }
                        }
#endif

                        if (!_globalDbMap.ContainsKey(contextName))
                        {
                            throw new CSException("GetDB(): context [" + contextName + "] not found");
                        }
                    }
                }

                CSDataProvider db = _globalDbMap[contextName];

                db = db.Clone();

                _threadDbMap[contextName] = db;

                return(db);
            }