コード例 #1
0
 public async Task RegisterUsersAsync(long listId, IEnumerable <long> userIds)
 {
     await WriteTaskFactory.StartNew(() =>
     {
         try
         {
             ReaderWriterLock.EnterWriteLock();
             using (var conn = this.DangerousOpenConnection())
                 using (var tran = conn.BeginTransaction(DefaultIsolationLevel))
                 {
                     foreach (var userId in userIds)
                     {
                         conn.Execute(TableInserter, new DatabaseListUser(listId, userId));
                     }
                     tran.Commit();
                 }
         }
         catch (Exception ex)
         {
             throw WrapException(ex, "RegisterUserAsync", TableInserter);
         }
         finally
         {
             ReaderWriterLock.ExitWriteLock();
         }
     });
 }
コード例 #2
0
ファイル: LdapEncoder.cs プロジェクト: matt2323/LinqToTwitter
        /// <summary>
        /// Initializes the LDAP DN safe lists.
        /// </summary>
        private static void InitialiseDistinguishedNameSafeList()
        {
            DistinguishedNameSafeListSyncLock.EnterWriteLock();
            try
            {
                if (distinguishedNameCharacterValues == null)
                {
                    distinguishedNameCharacterValues = SafeList.Generate(255, SafeList.HashThenHexValueGenerator);
                    SafeList.PunchSafeList(ref distinguishedNameCharacterValues, DistinguishedNameSafeList());

                    // Now mark up the specially listed characters from http://www.ietf.org/rfc/rfc2253.txt
                    EscapeDistinguisedNameCharacter(',');
                    EscapeDistinguisedNameCharacter('+');
                    EscapeDistinguisedNameCharacter('"');
                    EscapeDistinguisedNameCharacter('\\');
                    EscapeDistinguisedNameCharacter('<');
                    EscapeDistinguisedNameCharacter('>');
                    EscapeDistinguisedNameCharacter(';');
                }
            }
            finally
            {
                DistinguishedNameSafeListSyncLock.ExitWriteLock();
            }
        }
コード例 #3
0
            internal void ReleaseWriterLock()
            {
#if NETFX2
                locker.ReleaseWriterLock();
#else
                locker.ExitWriteLock();
#endif
            }
コード例 #4
0
 /// <summary>
 /// Releases the Session Dictionary Write Lock
 /// </summary>
 private void ReleaseWriteLock()
 {
     #if NET20
     rwl.ReleaseWriterLock();
     #else
     rwl.ExitWriteLock();
     #endif
 }
コード例 #5
0
        /// <summary>
        /// Marks characters from the specified languages as safe.
        /// </summary>
        /// <param name="lowerCodeCharts">The combination of lower code charts to use.</param>
        /// <param name="lowerMidCodeCharts">The combination of lower mid code charts to use.</param>
        /// <param name="midCodeCharts">The combination of mid code charts to use.</param>
        /// <param name="upperMidCodeCharts">The combination of upper mid code charts to use.</param>
        /// <param name="upperCodeCharts">The combination of upper code charts to use.</param>
        /// <remarks>The safe list affects all HTML and XML encoding functions.</remarks>
        public static void MarkAsSafe(
            LowerCodeCharts lowerCodeCharts,
            LowerMidCodeCharts lowerMidCodeCharts,
            MidCodeCharts midCodeCharts,
            UpperMidCodeCharts upperMidCodeCharts,
            UpperCodeCharts upperCodeCharts)
        {
            if (lowerCodeCharts == currentLowerCodeChartSettings &&
                lowerMidCodeCharts == currentLowerMidCodeChartSettings &&
                midCodeCharts == currentMidCodeChartSettings &&
                upperMidCodeCharts == currentUpperMidCodeChartSettings &&
                upperCodeCharts == currentUpperCodeChartSettings)
            {
                return;
            }

            SyncLock.EnterWriteLock();
            try
            {
                if (characterValues == null)
                {
                    characterValues = SafeList.Generate(65536, SafeList.HashThenValueGenerator);
                }

                SafeList.PunchUnicodeThrough(
                    ref characterValues,
                    lowerCodeCharts,
                    lowerMidCodeCharts,
                    midCodeCharts,
                    upperMidCodeCharts,
                    upperCodeCharts);

                ApplyHtmlSpecificValues();

                currentLowerCodeChartSettings    = lowerCodeCharts;
                currentLowerMidCodeChartSettings = lowerMidCodeCharts;
                currentMidCodeChartSettings      = midCodeCharts;
                currentUpperMidCodeChartSettings = upperMidCodeCharts;
                currentUpperCodeChartSettings    = upperCodeCharts;
            }
            finally
            {
                SyncLock.ExitWriteLock();
            }
        }
コード例 #6
0
 /// <summary>
 /// Initializes the HTML safe list.
 /// </summary>
 private static void InitialiseSafeList()
 {
     syncLock.EnterWriteLock();
     try
     {
         characterValues = SafeList.Generate(255, SafeList.PercentThenHexValueGenerator);
         SafeList.PunchSafeList(ref characterValues, UrlParameterSafeList());
     }
     finally
     {
         syncLock.ExitWriteLock();
     }
 }
コード例 #7
0
ファイル: LdapEncoder.cs プロジェクト: matt2323/LinqToTwitter
 /// <summary>
 /// Initializes the LDAP filter safe lists.
 /// </summary>
 private static void InitialiseFilterSafeList()
 {
     FilterSafeListSyncLock.EnterWriteLock();
     try
     {
         if (filterCharacterValues == null)
         {
             filterCharacterValues = SafeList.Generate(255, SafeList.SlashThenHexValueGenerator);
             SafeList.PunchSafeList(ref filterCharacterValues, FilterEncodingSafeList());
         }
     }
     finally
     {
         FilterSafeListSyncLock.ExitWriteLock();
     }
 }
コード例 #8
0
ファイル: CssEncoder.cs プロジェクト: matt2323/LinqToTwitter
 /// <summary>
 /// Initializes the HTML safe list.
 /// </summary>
 private static void InitialiseSafeList()
 {
     syncLock.EnterWriteLock();
     try
     {
         if (characterValues == null)
         {
             characterValues = SafeList.Generate(0xFF, SafeList.SlashThenSixDigitHexValueGenerator);
             SafeList.PunchSafeList(ref characterValues, CssSafeList());
         }
     }
     finally
     {
         syncLock.ExitWriteLock();
     }
 }
コード例 #9
0
        /// <summary>
        /// Set the result of the test
        /// </summary>
        /// <param name="resultState">The ResultState to use in the result</param>
        /// <param name="message">A message associated with the result state</param>
        /// <param name="stackTrace">Stack trace giving the location of the command</param>
        public void SetResult(ResultState resultState, string message, string stackTrace)
        {
#if PARALLEL
            RwLock.EnterWriteLock();
#endif
            try
            {
                ResultState = resultState;
                Message     = message;
                StackTrace  = stackTrace;
            }
            finally
            {
#if PARALLEL
                RwLock.ExitWriteLock();
#endif
            }
        }
コード例 #10
0
        /// <summary>
        /// Set the result of the test
        /// </summary>
        /// <param name="resultState">The ResultState to use in the result</param>
        /// <param name="message">A message associated with the result state</param>
        /// <param name="stackTrace">Stack trace giving the location of the command</param>
        public void SetResult(ResultState resultState, string message, string stackTrace)
        {
#if PARALLEL
            RwLock.EnterWriteLock();
#endif
            try
            {
                ResultState = resultState;
                Message     = message;
                StackTrace  = stackTrace;
            }
            finally
            {
#if PARALLEL
                RwLock.ExitWriteLock();
#endif
            }

            // Set pseudo-counts for a test case
            //if (IsTestCase(test))
            //{
            //    passCount = 0;
            //    failCount = 0;
            //    skipCount = 0;
            //    inconclusiveCount = 0;

            //    switch (ResultState.Status)
            //    {
            //        case TestStatus.Passed:
            //            passCount++;
            //            break;
            //        case TestStatus.Failed:
            //            failCount++;
            //            break;
            //        case TestStatus.Skipped:
            //            skipCount++;
            //            break;
            //        default:
            //        case TestStatus.Inconclusive:
            //            inconclusiveCount++;
            //            break;
            //    }
            //}
        }
コード例 #11
0
 /// <summary>
 /// Releases a write lock.
 /// </summary>
 private static void ReleaseWriteLock()
 {
     SyncLock.ExitWriteLock();
 }
コード例 #12
0
        /// <summary>
        /// Looks up the discriminator convention for a type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>A discriminator convention.</returns>
        public static IDiscriminatorConvention LookupDiscriminatorConvention(Type type)
        {
            __configLock.EnterReadLock();
            try
            {
                IDiscriminatorConvention convention;
                if (__discriminatorConventions.TryGetValue(type, out convention))
                {
                    return(convention);
                }
            }
            finally
            {
                __configLock.ExitReadLock();
            }

            __configLock.EnterWriteLock();
            try
            {
                IDiscriminatorConvention convention;
                if (!__discriminatorConventions.TryGetValue(type, out convention))
                {
                    // if there is no convention registered for object register the default one
                    if (!__discriminatorConventions.ContainsKey(typeof(object)))
                    {
                        var defaultDiscriminatorConvention = StandardDiscriminatorConvention.Hierarchical;
                        __discriminatorConventions.Add(typeof(object), defaultDiscriminatorConvention);
                        if (type == typeof(object))
                        {
                            return(defaultDiscriminatorConvention);
                        }
                    }

                    if (type.IsInterface)
                    {
                        // TODO: should convention for interfaces be inherited from parent interfaces?
                        convention = __discriminatorConventions[typeof(object)];
                        __discriminatorConventions[type] = convention;
                    }
                    else
                    {
                        // inherit the discriminator convention from the closest parent that has one
                        Type parentType = type.BaseType;
                        while (convention == null)
                        {
                            if (parentType == null)
                            {
                                var message = string.Format("No discriminator convention found for type {0}.", type.FullName);
                                throw new BsonSerializationException(message);
                            }
                            if (__discriminatorConventions.TryGetValue(parentType, out convention))
                            {
                                break;
                            }
                            parentType = parentType.BaseType;
                        }

                        // register this convention for all types between this and the parent type where we found the convention
                        var unregisteredType = type;
                        while (unregisteredType != parentType)
                        {
                            RegisterDiscriminatorConvention(unregisteredType, convention);
                            unregisteredType = unregisteredType.BaseType;
                        }
                    }
                }
                return(convention);
            }
            finally
            {
                __configLock.ExitWriteLock();
            }
        }
コード例 #13
0
ファイル: Lock.cs プロジェクト: ckurt/Its.Monitoring
 public override void Dispose()
 {
     ReaderWriterLock.ExitWriteLock();
 }