public void Dispose() { if (_isDisposed) { return; } Factotum.DisposeAndNull(ref _reader); _isDisposed = true; }
/// <summary> /// Executes a wrapper for the command's logic. /// </summary> /// <param name="parameter"> /// The parameter to pass to the command's logic. /// </param> /// <param name="executeAsynchronously"> /// A <see cref="bool"/> value that indicates whether the command's logic should be /// executed asynchronously. /// </param> protected void ExecuteInternal(object parameter, bool executeAsynchronously) { lock (_syncLock) { _dispatcher.VerifyAccess(); if (IsExecuting) { return; } } if (executeAsynchronously) { lock (_syncLock) { Factotum.DisposeAndNull(ref _cancellationTokenSource); _cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = _cancellationTokenSource.Token; var task = new Task(() => _execute(parameter, cancellationToken), cancellationToken); task.ContinueWith( t => _dispatcher.Invoke( new Action(() => CleanUpAfterExecution(t.Exception)), DispatcherPriority.Send), CancellationToken.None); IsExecuting = true; task.Start(); } } else { Exception exception = null; IsExecuting = true; try { _execute(parameter, CancellationToken.None); } catch (Exception ex) when(!ex.IsFatal()) { exception = ex; } finally { CleanUpAfterExecution(exception); } } }
internal SquareBridgeKey(Square first, Square second) { if (first == second) { throw new ArgumentException("Squares cannot be the same."); } if (first.SquareIndex > second.SquareIndex) { Factotum.Exchange(ref first, ref second); } First = first; Second = second; _hashCode = (First.SquareIndex << 8) | second.SquareIndex; }
private void CleanUpAfterExecution([CanBeNull] Exception exception) { _dispatcher.VerifyAccess(); try { if (exception != null && !exception.IsFatal()) { _handleException(exception); } } finally { lock (_syncLock) { IsExecuting = false; Factotum.DisposeAndNull(ref _cancellationTokenSource); } } }
public static OverallMatchKind ComputeOverallMatchKind( this OverallMatchKind baseOverallMatchKind, [NotNull] ICollection <OverallMatchKind> innerOverallMatchKinds) { if (innerOverallMatchKinds == null) { throw new ArgumentNullException(nameof(innerOverallMatchKinds)); } var result = baseOverallMatchKind; var computedInnerOverallMatchKind = innerOverallMatchKinds.ComputeOverallMatchKind(); if (computedInnerOverallMatchKind.HasValue) { result = Factotum.Max(result, computedInnerOverallMatchKind.Value); } return(result); }
public static DependencyPropertyKey RegisterReadOnlyDependencyProperty <TObject, TProperty>( Expression <Func <TObject, TProperty> > propertyGetterExpression, PropertyMetadata typeMetadata = null, ValidateValueCallback validateValueCallback = null) { var propertyInfo = Factotum.GetPropertyInfo(propertyGetterExpression); if (propertyInfo.DeclaringType != typeof(TObject)) { throw new ArgumentException( @"Inconsistency between property expression and declaring object type.", "propertyGetterExpression"); } return(DependencyProperty.RegisterReadOnly( propertyInfo.Name, propertyInfo.PropertyType, propertyInfo.DeclaringType.EnsureNotNull(), typeMetadata, validateValueCallback)); }
private PolyglotOpeningBook InitializeBook([NotNull] Expression <Func <byte[]> > streamDataGetter) { PolyglotOpeningBook openingBook; var currentMethodName = MethodBase.GetCurrentMethod().GetQualifiedName(); var bookName = Factotum.GetPropertyName(streamDataGetter); var data = streamDataGetter.Compile().Invoke(); _logger.Audit($"[{currentMethodName}] Initializing the opening book {bookName.ToUIString()}..."); var stopwatch = Stopwatch.StartNew(); using (var stream = new MemoryStream(data)) { openingBook = new PolyglotOpeningBook(stream); } stopwatch.Stop(); _logger.Audit($@"[{currentMethodName}] The opening book {bookName.ToUIString()} has been initialized in {stopwatch.Elapsed}."); return(openingBook); }
public static string GenerateObjectId() => Factotum.GenerateIdString(2 * Factotum.MinimumGeneratedIdPartSize, IdGenerationModes.UniqueAndRandom);