コード例 #1
0
        /// <summary>Attempts to get value from the shared cache for the specified key.</summary>
        /// <param name="key">The key.</param>
        /// <param name="value">[out] The value.</param>
        /// <returns>true if it succeeds, false if it fails.</returns>
        public bool TryGetValue(int key, out SQLNETParallelItem value)
        {
            bool found;

            try
            {
                var count = InnerList.Count;

                for (int i = 0; i < count; i++)
                {
                    if (i < InnerList.Count)
                    {
                        value = InnerList[i];
                        if (value.ParallelId == key)
                        {
                            return true;
                        }
                    }
                }

                found = false;
                value = default(SQLNETParallelItem);
               
            }
            catch
            {
                // Happen with concurrent remove
                value = default(SQLNETParallelItem);
                found = false;
            }

            if (!found)
            {
                // May happen rarely in concurrency scenario
                // We try again but with a lock
                try
                {
                    AcquireLock();
                    value = InnerList.Find(x => x.ParallelId == key);
                    return true;
                }
                catch (Exception)
                {
                    value = default(SQLNETParallelItem);
                    return false;
                }
                finally
                {
                    ReleaseLock();
                }
            }

            return true;
        }
コード例 #2
0
        /// <summary>Attempts to get value from the shared cache for the specified key.</summary>
        /// <param name="key">The key.</param>
        /// <param name="value">[out] The value.</param>
        /// <returns>true if it succeeds, false if it fails.</returns>
        public bool TryGetValue(int key, out SQLNETParallelItem value)
        {
            bool found;

            try
            {
                var count = InnerList.Count;

                for (int i = 0; i < count; i++)
                {
                    if (i < InnerList.Count)
                    {
                        value = InnerList[i];
                        if (value.ParallelId == key)
                        {
                            return(true);
                        }
                    }
                }

                found = false;
                value = default(SQLNETParallelItem);
            }
            catch
            {
                // Happen with concurrent remove
                value = default(SQLNETParallelItem);
                found = false;
            }

            if (!found)
            {
                // May happen rarely in concurrency scenario
                // We try again but with a lock
                try
                {
                    AcquireLock();
                    value = InnerList.Find(x => x.ParallelId == key);
                    return(true);
                }
                catch (Exception)
                {
                    value = default(SQLNETParallelItem);
                    return(false);
                }
                finally
                {
                    ReleaseLock();
                }
            }

            return(true);
        }
コード例 #3
0
 public void TryRemove(SQLNETParallelItem value)
 {
     try
     {
         AcquireLock();
         InnerList.Remove(value);
     }
     finally
     {
         ReleaseLock();
     }
 }
コード例 #4
0
 public void TryRemove(SQLNETParallelItem value)
 {
     try
     {
         AcquireLock();
         InnerList.Remove(value);
     }
     finally
     {
         ReleaseLock();
     }
 }
コード例 #5
0
        /// <summary>Attempts to add a value in the shared cache for the specified key.</summary>
        /// <param name="value">The value.</param>
        /// <returns>true if it succeeds, false if it fails.</returns>
        public bool TryAdd(SQLNETParallelItem value)
        {
            try
            {
                AcquireLock();

                InnerList.Add(value);

                return true;
            }
            finally
            {
                ReleaseLock();
            }
        }
コード例 #6
0
        /// <summary>Attempts to add a value in the shared cache for the specified key.</summary>
        /// <param name="value">The value.</param>
        /// <returns>true if it succeeds, false if it fails.</returns>
        public bool TryAdd(SQLNETParallelItem value)
        {
            try
            {
                AcquireLock();

                InnerList.Add(value);

                return(true);
            }
            finally
            {
                ReleaseLock();
            }
        }
コード例 #7
0
        public SQLNETParallelItem AddParallelValue(int parallelId)
        {
            var value = new SQLNETParallelItem
            {
                ParallelId = parallelId
            };

            ParallelItems.TryAdd(value);

            if (ParameterValues.Count > 0)
            {
                foreach (DictionaryEntry entry in ParameterValues)
                {
                    value.ParameterValues.Add(entry.Key, entry.Value);
                }
            }

            return(value);
        }
コード例 #8
0
        public object InternalEval()
        {
            var item       = Item;
            var lastAccess = DateTime.Now;

            // Overwrite last access
            item.LastAccess = lastAccess;
            if (item.Delegate != null)
            {
                item.Delegate.LastAccess = lastAccess;
            }

            // CHECK if the garbage collection should be invoked
            if (lastAccess > EvalManager.Configuration.ExpireCacheNextScheduled)
            {
                EvalManager.ExpireCache();
            }

            var code = item.Code;

            SQLNETParallelItem parallelValue;

            if (ValueParallel != 0)
            {
                parallelValue = item.GetParallelValue(ValueParallel);
            }
            else
            {
                parallelValue = new SQLNETParallelItem();
            }

            //var parallelValue = item;
            object result;

            if (item.IsImpersonate)
            {
                WindowsImpersonationContext impersonatedIdentity = null;

                if (SqlContext.WindowsIdentity != null)
                {
                    var currentIdentity = SqlContext.WindowsIdentity;
                    impersonatedIdentity = currentIdentity.Impersonate();
                }

                try
                {
                    if (item.Delegate == null)
                    {
                        item.Delegate   = EvalManager.Configuration.CompileSQLNET(code, item.ParameterTypes.InnerDictionary);
                        item.IsCompiled = true;
                    }

                    result = item.Delegate.Delegate(parallelValue.ParameterValues);
                }
                finally
                {
                    if (impersonatedIdentity != null)
                    {
                        impersonatedIdentity.Undo();
                    }
                }
            }
            else
            {
                if (item.Delegate == null)
                {
                    item.Delegate   = EvalManager.Configuration.CompileSQLNET(code, item.ParameterTypes.InnerDictionary);
                    item.IsCompiled = true;
                }

                result = item.Delegate.Delegate(parallelValue.ParameterValues);
            }

            // RELEASE parallel item once resolved
            if (ValueParallel != 0)
            {
                Item.ParallelItems.TryRemove(parallelValue);
            }


            if (Item.IsAutoDispose)
            {
                Dispose();
            }

            return(result);


            //            if (item.ParameterTables.Count > 0)
            //            {
            //                var s = @"
            //using (SqlConnection connection = new SqlConnection(""context connection = true""))
            //{
            //    using (SqlCommand command = new SqlCommand())
            //	{
            //		command.Connection = connection;
            //        connection.Open();
            //        [SQLNET_Code]
            //    }
            //}
            //";
            //                //var list = new List<string>();
            //                //foreach (DictionaryEntry parameterTable in item.ParameterTables)
            //                //{
            //                //    list.Add(string.Concat("command.CommandText = 'SELECT * FROM ", parameterTable.Value, "';"));
            //                //    list.Add(string.Concat(parameterTable.Key, " = command.ExecuteDataTable();"));
            //                //    list.Add(parameterTable.Key + ".ExtendedProperties['ZZZ_Select'] = command.CommandText");
            //                //}

            //                //code = s.Replace("[SQLNET_Code]", string.Join(Environment.NewLine, list)) + code;

            //                //throw new Exception(code);
            //            }
        }
コード例 #9
0
        public SQLNETParallelItem AddParallelValue(int parallelId)
        {
            var value = new SQLNETParallelItem
            {
                ParallelId = parallelId
            };

            ParallelItems.TryAdd(value);

            if (ParameterValues.Count > 0)
            {
                foreach (DictionaryEntry entry in ParameterValues)
                {
                    value.ParameterValues.Add(entry.Key, entry.Value);
                }
            }

            return value;
        }
コード例 #10
0
        public object InternalEval()
        {
            var item = Item;
            var lastAccess = DateTime.Now;

            // Overwrite last access
            item.LastAccess = lastAccess;
            if (item.Delegate != null)
            {
                item.Delegate.LastAccess = lastAccess;
            }

            // CHECK if the garbage collection should be invoked
            if (lastAccess > EvalManager.Configuration.ExpireCacheNextScheduled)
            {
                EvalManager.ExpireCache();
            }

            var code = item.Code;

            SQLNETParallelItem parallelValue;
            if (ValueParallel != 0)
            {
                parallelValue = item.GetParallelValue(ValueParallel);
            }
            else
            {
                parallelValue = new SQLNETParallelItem();
            }

            //var parallelValue = item;
            object result;

            if (item.IsImpersonate)
            {
                WindowsImpersonationContext impersonatedIdentity = null;

                if (SqlContext.WindowsIdentity != null)
                {
                    var currentIdentity = SqlContext.WindowsIdentity;
                    impersonatedIdentity = currentIdentity.Impersonate();
                }

                try
                {
                    if (item.Delegate == null)
                    {
                        item.Delegate = EvalManager.Configuration.CompileSQLNET(code, item.ParameterTypes.InnerDictionary);
                        item.IsCompiled = true;
                    }

                    result = item.Delegate.Delegate(parallelValue.ParameterValues);
                }
                finally
                {
                    if (impersonatedIdentity != null)
                    {
                        impersonatedIdentity.Undo();
                    }
                }
            }
            else
            {
                if (item.Delegate == null)
                {
                    item.Delegate = EvalManager.Configuration.CompileSQLNET(code, item.ParameterTypes.InnerDictionary);
                    item.IsCompiled = true;
                }

                result = item.Delegate.Delegate(parallelValue.ParameterValues);
            }

            // RELEASE parallel item once resolved
            if (ValueParallel != 0)
            {
                Item.ParallelItems.TryRemove(parallelValue);
            }
   

            if (Item.IsAutoDispose)
            {
                Dispose();
            }

            return result;


            //            if (item.ParameterTables.Count > 0)
            //            {
            //                var s = @"
            //using (SqlConnection connection = new SqlConnection(""context connection = true""))
            //{
            //    using (SqlCommand command = new SqlCommand()) 
            //	{
            //		command.Connection = connection;
            //        connection.Open();
            //        [SQLNET_Code]
            //    }
            //}
            //";
            //                //var list = new List<string>();
            //                //foreach (DictionaryEntry parameterTable in item.ParameterTables)
            //                //{
            //                //    list.Add(string.Concat("command.CommandText = 'SELECT * FROM ", parameterTable.Value, "';"));
            //                //    list.Add(string.Concat(parameterTable.Key, " = command.ExecuteDataTable();"));
            //                //    list.Add(parameterTable.Key + ".ExtendedProperties['ZZZ_Select'] = command.CommandText");
            //                //}

            //                //code = s.Replace("[SQLNET_Code]", string.Join(Environment.NewLine, list)) + code;

            //                //throw new Exception(code);
            //            }
        }