/// <summary> /// Calculates the harmonic mean of the given numbers. /// The harmonic mean is defined as zero if at least one of the numbers is zero. /// </summary> /// <param name="numbers">The numbers whose harmonic mean is to be calculated.</param> /// <returns>The harmonic mean of the given numbers.</returns> /// <exception cref="System.InvalidOperationException"> /// The specified collection must not contain negative numbers and must not be empty. /// </exception> /// <exception cref="System.ArgumentNullException"> /// The specified collection must not be null. /// </exception> public static double HarmonicMean(IEnumerable<double> numbers) { if (numbers == null) { throw ArgumentNullException; } if (!numbers.Any()) { throw EmptyNumbersCollectionException; } if (numbers.Any(number => number < 0)) { throw CollectionContainingNegativeNumbersException; } if (numbers.Contains(0)) { // If one of the values strives against zero the limiting value of the harmonic mean does, too. // Therefore, it is sensible to define the harmonic mean as being zero if at least one of the values is zero. return 0; } double sumOfReciprocalValues = numbers.Sum(number => 1.0 / number); double harmonicMean = numbers.Count() / sumOfReciprocalValues; return harmonicMean; }
/// <summary> /// Gets the common prefix. /// </summary> /// <param name="values">The values.</param> /// <returns></returns> public static string GetCommonPrefix(IEnumerable<string> values) { if (values == null) { throw new ArgumentNullException("values"); } if (!values.Any()) { return null; } string commonPrefix = string.Empty; char[] firstValueChars = values.First().ToCharArray(); foreach (var currentChar in firstValueChars) { string currentPrefix = commonPrefix + currentChar; if (values.Any(v => !v.StartsWith(currentPrefix))) { return commonPrefix; } else { commonPrefix = currentPrefix; } } return commonPrefix; }
/// <summary> /// Gets whether a feature path is valid for the features in the feature set /// </summary> /// <param name="features">Top-level features</param> /// <param name="featurePath">Feature path to the highest-level feature</param> /// <returns>Value indicating whether the feature path is valid for a feature in <paramref name="features"/></returns> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="features"/> or <paramref name="featurePath"/> is null</exception> /// <exception cref="System.InvalidOperationException">Thrown when <paramref name="featurePath"/> is empty</exception> public static bool IsEnabled(IEnumerable<IFeature> features, IEnumerable<string> featurePath) { Ensure.Argument.NotNull(features, "features"); Ensure.Argument.NotNull(featurePath, "featurePath"); Ensure.That<InvalidOperationException>(featurePath.Any(), "Feature Path must contain at least one top-level feature"); // feature names are case insensitive IFeature current = FindFeature(features, featurePath.First()); // skip the first value featurePath = featurePath.Skip(1); // loop through the entire path while (featurePath.Any()) { // path was not found if (current == null) return false; // see if the feature has subfeatures (Complex) var asComplex = current as IComplexFeature; if (asComplex == null) // feature doesn't have subfeatures, it passes return true; current = FindFeature(asComplex.SubFeatures, featurePath.First()); featurePath = featurePath.Skip(1); } return current != null; }
public TransactionDetailsViewItem(Model.Transaction transaction, IEnumerable<Model.TransactionItem> transactionItems, IEnumerable<Model.TransactionIgnoredItem> transactionIgnoredItems, IEnumerable<Model.License> domainlessLicenseQuery, IEnumerable<Model.License> customerapplessLicenseQuery) : base(transaction) { PurchaserEmail = transaction.PurchaserEmail; PurchaserName = (transactionItems.Any(l => l.License != null)) ? transactionItems.FirstOrDefault().License.PurchasingCustomer.Name : transaction.PurchaserName; OwnerName = (transactionItems.Any(l => l.License != null)) ? transactionItems.FirstOrDefault().License.OwningCustomer.Name : "None"; SKUSummary = (from x in transactionItems select x.Sku).ToSummary(x => x.SkuCode, 99, ", "); IgnoredSummary = (from x in transactionIgnoredItems select x.Description).ToSummary(x => x, 99, ", "); StatusName = transaction.Status.GetDescription<Model.TransactionStatus>(); DomainlessLicenses = (from x in domainlessLicenseQuery select x.ObjectId).ToList(); CustomerapplessLicenses = (from x in customerapplessLicenseQuery select x.ObjectId).ToList(); }
private static IEnumerable<LaneModel> GetOrderedLanes(IEnumerable<LaneModel> laneStats) { var orderedLaneStats = new List<LaneModel>(); Func<LaneModel, bool> backLogPred = x => x.ClassType == LaneClassType.Backlog && x.Relation != "child"; Func<LaneModel, bool> activePred = x => x.ClassType == LaneClassType.Active; Func<LaneModel, bool> archivePred = x => x.ClassType == LaneClassType.Archive && x.Relation != "child"; if (laneStats.Any(backLogPred)) { orderedLaneStats.AddRange(laneStats.Where(backLogPred).OrderBy(x => x.Index)); } if (laneStats.Any(activePred)) { orderedLaneStats.AddRange(laneStats.Where(activePred).OrderBy(x => x.Index)); } if (laneStats.Any(archivePred)) { orderedLaneStats.AddRange(laneStats.Where(archivePred).OrderBy(x => x.Index)); } return orderedLaneStats; }
public bool ConflictsWith(Type eventToCheck, IEnumerable<Type> previousEvents) { var boundConflicts = false; var unboundConflicts = false; if (_conflictRegister.ContainsKey(eventToCheck)) { boundConflicts = previousEvents.Any( previousEvent => _conflictRegister[eventToCheck].Any(et => et == previousEvent)); } if (eventToCheck.GetTypeInfo().IsGenericType && _conflictRegister.ContainsKey(eventToCheck.Unbind())) { var unboundEventToCheck = eventToCheck.Unbind(); var eventToCheckGenericType = eventToCheck.GenericTypeArguments[0]; unboundConflicts = previousEvents.Any( previousEvent => _conflictRegister[unboundEventToCheck].Any( et => et.MakeGenericType(eventToCheckGenericType) == previousEvent)); } return boundConflicts || unboundConflicts; }
public TryStatementAst(IScriptExtent extent, StatementBlockAst body, IEnumerable<CatchClauseAst> catchClauses, StatementBlockAst @finally) : base(extent) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if (((catchClauses == null) || !catchClauses.Any<CatchClauseAst>()) && (@finally == null)) { throw PSTraceSource.NewArgumentException("catchClauses"); } this.Body = body; base.SetParent(body); if ((catchClauses != null) && catchClauses.Any<CatchClauseAst>()) { this.CatchClauses = new ReadOnlyCollection<CatchClauseAst>(catchClauses.ToArray<CatchClauseAst>()); base.SetParents((IEnumerable<Ast>) this.CatchClauses); } else { this.CatchClauses = EmptyCatchClauses; } if (@finally != null) { this.Finally = @finally; base.SetParent(@finally); } }
public static IEnumerable<TestDefinition> Generate(IEnumerable<NodeBase> nodes) { if (nodes == null) return null; var nodeIds = nodes.Select(n => n.Id); var distinctNodeIds = nodeIds.Distinct(); if (nodeIds.Count() != distinctNodeIds.Count()) throw new ArgumentException("Duplicate Node IDs detected"); if (nodes.Any(n => n.EntranceEdges.Count == 0 && n.ExitEdges.Count == 0)) { // TODO: Log warning } if (nodes.Any(n => n.EntranceEdges.Any(ee => !nodes.Any(n2 => n2.Id == ee.Key)))) throw new ArgumentException("Entrance edge found with ID, but no node with matching ID found"); if (nodes.Any(n => n.ExitEdges.Any(ee => !nodes.Any(n2 => n2.Id == ee.Key)))) throw new ArgumentException("Exit edge found with ID, but no node with matching ID found"); var testDefinitions = new List<TestDefinition>(); foreach (var node in nodes.Where(n => n.IsStartingPoint)) { testDefinitions.AddRange(GetTestDefinitions(node, nodes, new List<NodeBase>())); } return testDefinitions; }
/// <summary> /// Adds specific destinations to a claim. /// </summary> /// <param name="claim">The <see cref="Claim"/> instance.</param> /// <param name="destinations">The destinations.</param> public static Claim SetDestinations(this Claim claim, IEnumerable<string> destinations) { if (claim == null) { throw new ArgumentNullException(nameof(claim)); } if (destinations == null || !destinations.Any()) { claim.Properties.Remove(Properties.Destinations); return claim; } if (destinations.Any(destination => destination.Contains(" "))) { throw new ArgumentException("Destinations cannot contain spaces.", nameof(destinations)); } //claim.Properties[Properties.Destinations] = // string.Join(" ", destinations.Distinct(StringComparer.Ordinal)); //TODO chage destination with destinations in rc 2 claim.Properties[Properties.Destination] = string.Join(" ", destinations.Distinct(StringComparer.Ordinal)); return claim; }
public static void RequireArgumentNotEmptyAndNonEmptyItems( string argumentName, IEnumerable<string> argumentValue) { if (!argumentValue.Any()) { throw new ArgumentException("Cannot be empty", argumentName); } if (argumentValue.Any(item => string.IsNullOrWhiteSpace(item))) { throw new ArgumentException("Items cannot be empty", argumentName); } }
public static IEnumerable<string> GetRootPaths(IEnumerable<string> directoryNames) { if ((directoryNames == null) || !directoryNames.Any() || directoryNames.Any(dn => string.IsNullOrEmpty(dn))) throw new ArgumentNullException("fileNames"); var fullDirectoryNames = directoryNames.Select(dn => Path.GetFullPath(dn)); if (fullDirectoryNames.Any(fn => Path.GetPathRoot(fn) == null)) throw new ArgumentException("all file names must contain a root path", "fileNames"); // IEnumerable<IGrouping<string, string>> var fullDirectoryNamesByRoot = fullDirectoryNames .GroupBy(fn => Path.GetPathRoot(fn).ToLower()) .OrderBy(g => g.Key) .ToList(); var result = new List<string>(); foreach (var group in fullDirectoryNamesByRoot) { var rootResult = group.Key; int minLength = group.Min(dn => dn.Length); for (int i = group.Key.Length; i < minLength; i++) { if (!group.All(dn => string.Equals(dn.Substring(0, i), group.First().Substring(0, i), StringComparison.InvariantCultureIgnoreCase))) break; char c = group.First()[i]; if (c == Path.DirectorySeparatorChar) rootResult = group.First().Substring(0, i + 1); } result.Add(rootResult); } return result; }
public static void ProcessCompilerResults(IEnumerable<CompilerResult> results) { var errors = results.Where(r => r.HasErrors).SelectMany(r => r.Errors); var clean = results.Where(r => !r.HasErrors).Select(r => r.FileName); if (errors.Any()) { TableDataSource.Instance.AddErrors(errors); } if (results.Any(r => r.HasErrors)) { if (results.Any(r => r.Errors.Any(e => !e.IsWarning))) { WebCompilerPackage._dte.StatusBar.Text = "Error compiling. See Error List for details"; TableDataSource.Instance.BringToFront(); } else { WebCompilerInitPackage.StatusText($"Compiled with warnings"); } } else { WebCompilerInitPackage.StatusText($"Compiled successfully"); } TableDataSource.Instance.CleanErrors(clean); }
/// <summary> /// Gets the longest common directory of the given paths. /// </summary> /// <param name="files">The files.</param> /// <returns>The longest common directory of the given paths.</returns> internal static string GetCommonDirectory(IEnumerable<string> files) { if (files == null) { throw new ArgumentNullException("files"); } if (!files.Any()) { return null; } string commonPrefix = string.Empty; char[] firstValueChars = files.First().ToCharArray(); foreach (var currentChar in firstValueChars) { string currentPrefix = commonPrefix + currentChar; if (files.Any(v => !v.StartsWith(currentPrefix, StringComparison.OrdinalIgnoreCase))) { return commonPrefix; } else { commonPrefix = currentPrefix; } } return commonPrefix.Substring(0, commonPrefix.LastIndexOf('\\') + 1); }
/// <summary> /// Calculates the geometric mean of the given numbers. /// </summary> /// <param name="numbers">The numbers whose geometric mean is to be calculated.</param> /// <returns>The geometric mean of the given numbers.</returns> /// <exception cref="System.InvalidOperationException"> /// The collection must not contain negative numbers and must not be empty. /// </exception> /// <exception cref="System.ArgumentNullException"> /// The specified collection must not be null. /// </exception> public static double GeometricMean(IEnumerable<double> numbers) { if (numbers == null) { throw ArgumentNullException; } if (!numbers.Any()) { throw EmptyNumbersCollectionException; } if (numbers.Any(number => number < 0)) { throw CollectionContainingNegativeNumbersException; } double productOfNumbers = 1; foreach (double number in numbers) { productOfNumbers *= number; } double numbersCount = numbers.Count(); double exponent = 1.0 / numbersCount; double geometricMean = Math.Pow(productOfNumbers, exponent); return geometricMean; }
public IHttpActionResult Batch(IEnumerable<Recipe> recipes) { if (!recipes.Any()) return StatusCode(HttpStatusCode.NotModified); if (_shellSettings.Name != ShellSettings.DefaultName && recipes.Any(recipe => recipe.TenantName != _shellSettings.Name)) { return BadRequest(T("You can't execute recipes for other tenants on other than the Default tenant.").Text); } try { foreach (var recipe in recipes) { _recipeExecutor.ExecuteRecipe(recipe); } } catch (Exception ex) { if (ex.IsFatal()) throw; return InternalServerError(ex); } return Ok(); }
public static bool IsPotentialBindingClass(IEnumerable<string> attributeTypeNames) { #if WINRT return attributeTypeNames.Any(attr => attr.Equals(BINDING_ATTR, StringComparison.Ordinal)); #else return attributeTypeNames.Any(attr => attr.Equals(BINDING_ATTR, StringComparison.InvariantCulture)); #endif }
private IEnumerable<IDbDataParameter> CreateParameters(IDbCommand command, IEnumerable<object> parameterValues) { if (!parameterValues.Any(pv => pv != null)) return Enumerable.Empty<IDbDataParameter>(); return parameterValues.Any(o => o is IEnumerable && !(o is string)) || parameterValues.Any(o => o is IRange) ? parameterValues.SelectMany((v,i) => CreateParameters(command, _parameters[i], v)) : parameterValues.Select((v, i) => CreateParameter(command, _parameters[i], v)); }
public static IQueryable<EventOccurrenceDate> FilterByKeywords(this IQueryable<EventOccurrenceDate> objectSet, IEnumerable<string> keywords) { if (keywords != null && keywords.Any()) { objectSet = objectSet.Where(e => keywords.Any(k => e.EventOccurrence.Event.Keywords.Contains(k))); } return objectSet; }
public static bool ContainsAny(this string haystack, IEnumerable<string> needles) { if (haystack == null) throw new ArgumentNullException("haystack"); if (!string.IsNullOrEmpty(haystack) || needles.Any()) { return needles.Any(haystack.Contains); } return false; }
public static bool ContainsAny(this string haystack, StringComparison comparison, IEnumerable<string> needles) { if (haystack == null) throw new ArgumentNullException("haystack"); if (!string.IsNullOrEmpty(haystack) || needles.Any()) { return needles.Any(value => haystack.IndexOf(value, comparison) >= 0); } return false; }
public FunctionExportProvider(Assembly assembly, IEnumerable<Type> delegateTypes) { if (assembly == null) throw new ArgumentNullException("assembly"); if (delegateTypes == null) throw new ArgumentNullException("delegateTypes"); if (!delegateTypes.Any()) throw new ArgumentException("Must specify at least one delegate type."); if (delegateTypes.Any(t => !typeof(Delegate).IsAssignableFrom(t))) throw new NotSupportedException("Only delegate types are supported."); _assembly = assembly; _delegateTypes = delegateTypes; }
private bool IsRegionAvailable(string value, IEnumerable<RegionResponse> regions) { // ReSharper disable PossibleMultipleEnumeration if (regions.Any(x => x.Name.Is(value))) return true; if (regions.Any(x => IsRegionAvailable(value, x.Regions))) return true; return false; // ReSharper restore PossibleMultipleEnumeration} }
internal ForeignKeyConstraintConfiguration(IEnumerable<PropertyInfo> dependentProperties) { DebugCheck.NotNull(dependentProperties); Debug.Assert(dependentProperties.Any()); Debug.Assert(!dependentProperties.Any(p => p == null)); _dependentProperties.AddRange(dependentProperties); _isFullySpecified = true; }
public void Any(IEnumerable<int> source, Func<int, bool> predicate, bool expected) { if (predicate == null) { Assert.Equal(expected, source.Any()); } else { Assert.Equal(expected, source.Any(predicate)); } }
public void Create(IEnumerable<IBenchmark> benchmarks, IEnumerable<BenchmarkResult> benchmarkResults) { using (var fileStream = new FileStream("../../../README.md", FileMode.Create)) { using (var writer = new StreamWriter(fileStream)) { writer.WriteLine("Ioc Performance"); writer.WriteLine("==============="); writer.WriteLine(string.Empty); writer.WriteLine("Source code of my performance comparison of the most popular .NET IoC containers: "); writer.WriteLine("[www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison](http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison)"); writer.WriteLine(string.Empty); writer.WriteLine("Author: Daniel Palme "); writer.WriteLine("Blog: [www.palmmedia.de](http://www.palmmedia.de) "); writer.WriteLine("Twitter: [@danielpalme](http://twitter.com/danielpalme) "); writer.WriteLine(string.Empty); writer.WriteLine("Results"); writer.WriteLine("-------"); writer.WriteLine("### Explantions"); writer.WriteLine("**First value**: Time of single-threaded execution in [ms] "); writer.WriteLine("**Second value**: Time of multi-threaded execution in [ms] "); if (benchmarkResults.Any(b => b.SingleThreadedResult.ExtraPolated || b.MultiThreadedResult.ExtraPolated)) { writer.WriteLine("**_*_**: Benchmark was stopped after 3 minutes and result is extrapolated. "); } if (benchmarkResults.Any(b => b.SingleThreadedResult.Error == "OoM" || b.MultiThreadedResult.Error == "OoM")) { writer.WriteLine("**OoM**: Benchmark was stopped after an *OutOfMemoryException* was thrown. "); } if (benchmarkResults.Any(b => b.SingleThreadedResult.Error == "OoM" || b.MultiThreadedResult.Error == "OoM")) { writer.WriteLine("**Error**: Benchmark was stopped after an *Exception* was thrown. "); } writer.WriteLine("### Basic Features"); this.WriteBenchmarks(writer, benchmarks.Where(b => b.GetType().FullName.Contains("Basic")), benchmarkResults); writer.WriteLine("### Advanced Features"); this.WriteBenchmarks(writer, benchmarks.Where(b => b.GetType().FullName.Contains("Advanced")), benchmarkResults); writer.WriteLine("### Prepare"); this.WriteBenchmarks(writer, benchmarks.Where(b => b.GetType().FullName.Contains("Prepare")), benchmarkResults); writer.WriteLine("### Charts"); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(""); } } }
private static void CheckPatterns(IEnumerable<string> patterns) { if (patterns.Any(s => s.Contains('\\'))) { Logger.LogInfo("NOTE that `\\` in glob pattern is used as Escape character. DONOT use it as path separator."); } if (patterns.Any(s => s.Contains("../"))) { Logger.LogWarning("NOTE that `../` is currently not supported in glob pattern, please use `../` in `src` option instead."); } }
public static bool BetweenXCheck(Chuzzle chuzzle, IEnumerable<Chuzzle> allChuzzles) { var firstChuzzle = chuzzle; var secondChuzzle = allChuzzles.FirstOrDefault( ch => ch.Current.Y == firstChuzzle.Current.Y && ch.Current.X == firstChuzzle.Current.X + 2 && IsSameColor(ch, firstChuzzle)); if (secondChuzzle == null || allChuzzles.Any(x => x.Current.X == firstChuzzle.Current.X + 1 && IsLock(x))) return false; return allChuzzles.Any(x => x.Current.X == firstChuzzle.Current.X + 1 && IsSameColor(x, firstChuzzle) && !IsLock(x)); }
public void PopulateContextEntries(IEnumerable<string> contexts, List<CacheContextEntry> entries) { // User is a more generic dependency if (contexts.Any(ctx => String.Equals(ctx, "user", StringComparison.OrdinalIgnoreCase))) { return; } if (contexts.Any(ctx => String.Equals(ctx, "user.roles", StringComparison.OrdinalIgnoreCase))) { // TODO: Add actual roles entries.Add(new CacheContextEntry("administrator", "0")); } }
public static IEnumerable<string> Tokenize(string actionExpr, IEnumerable<Tuple<char, char>> depthOpenCloses, IEnumerable<string> keywords) { int depth = 0; int lastIndex = 0; List<string> ret = new List<string>(); for (int i = 0; i < actionExpr.Length; i++) { char c = actionExpr[i]; if (depthOpenCloses.Any(x => c == x.item1)) { if (depth == 0) { ret.AddRange(CutFront(actionExpr, ref lastIndex, i, 1)); } ++depth; } else if (depthOpenCloses.Any(x => c == x.item2)) { --depth; if (depth == 0) { ret.AddRange(CutFront(actionExpr, ref lastIndex, i, 1)); } } else { if (depth == 0) { foreach (var entity in keywords) { if (i + entity.Length <= actionExpr.Length) { if (actionExpr.Substring(i, entity.Length) == entity) { ret.AddRange(CutFront(actionExpr, ref lastIndex, i, entity.Length)); break; } } } } } } return ret.Select(x => x.Trim()).Where(x => x.Length > 0); }
public static IEnumerable<NamedRoute> GetRoutesForCurrentRequest(RouteCollection routes,IEnumerable<INavigationRouteFilter> routeFilters) { var navigationRoutes = routes.OfType<NamedRoute>().Where(r=> !r.IsChild).ToList(); if (routeFilters.Any()) { foreach (var route in navigationRoutes.ToArray()) { if (routeFilters.Any(filter => filter.ShouldRemove(route))) { navigationRoutes.Remove(route); } } } return navigationRoutes; }
private static string FormatBuildMetadataSemVerV1(IEnumerable <string> identifiers) => (identifiers?.Any() ?? false) ? "-" + string.Join("-", identifiers) : string.Empty;
public static bool AnyOrNotNull <T>(this IEnumerable <T> source) { return(source?.Any() == true); }
private static bool ListContainsEntity(MetaTable table, IEnumerable <object> list, object entity) { return(list.Any(e => AreEntitiesEqual(table, e, entity))); }
private static int getKeyDomainSize(IEnumerable <Command> commands) { commands = commands.Where(x => x.type != CmdType.CREATE && x.type != CmdType.CLEAR); return(commands.Any() ? commands.Max(x => x.arg) + 1 : 0); }
/// <summary> /// Check if any of the SolutionSets in this solution depend on x. /// </summary> /// <param name="x"></param> /// <returns></returns> public bool DependsOn(Expression x) { return solutions.Any(i => i.DependsOn(x)); }
static string Each <T>(IEnumerable <T> values, Func <T, string> formatter) { return(values.Any() ? values.Select(formatter).Aggregate((a, b) => a + b) : ""); }
private static Func <int, bool> IsMultiple(IEnumerable <int> multiples) { return(num => multiples.Any(mult => num % mult == 0)); }
/// <summary> /// /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="connection"></param> /// <param name="entities"></param> /// <param name="dbFields"></param> /// <param name="tableName"></param> /// <param name="qualifiers"></param> /// <param name="batchSize"></param> /// <param name="fields"></param> /// <param name="hints"></param> /// <param name="transaction"></param> /// <param name="statementBuilder"></param> /// <returns></returns> private static MergeAllExecutionContext <TEntity> CreateInternal <TEntity>(IDbConnection connection, IEnumerable <TEntity> entities, IEnumerable <DbField> dbFields, string tableName, IEnumerable <Field> qualifiers, int batchSize, IEnumerable <Field> fields, string hints = null, IDbTransaction transaction = null, IStatementBuilder statementBuilder = null) where TEntity : class { var typeOfEntity = typeof(TEntity); var dbSetting = connection.GetDbSetting(); var identity = (Field)null; var inputFields = (IEnumerable <DbField>)null; var identityDbField = dbFields?.FirstOrDefault(f => f.IsIdentity); // Check the fields if (fields?.Any() != true) { fields = dbFields?.AsFields(); } // Check the qualifiers if (qualifiers?.Any() != true) { var primary = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary == true); qualifiers = primary?.AsField().AsEnumerable(); } // Set the identity field if (typeOfEntity.IsClassType()) { identity = IdentityCache.Get <TEntity>()?.AsField() ?? FieldCache .Get <TEntity>()? .FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), identityDbField?.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) ?? identityDbField?.AsField(); } // Filter the actual properties for input fields inputFields = dbFields? .Where(dbField => fields.FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), dbField.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null) .AsList(); // Exclude the fields not on the actual entity if (typeof(TEntity).IsClassType() == false) { var entityFields = Field.Parse(entities?.FirstOrDefault()); inputFields = inputFields? .Where(field => entityFields.FirstOrDefault(f => string.Equals(f.Name.AsUnquoted(true, dbSetting), field.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null) .AsList(); } // Variables for the context var multipleEntitiesFunc = (Action <DbCommand, IList <TEntity> >)null; var singleEntityFunc = (Action <DbCommand, TEntity>)null; var identitySetterFunc = (Action <TEntity, object>)null; // Get if we have not skipped it if (typeOfEntity.IsClassType() == true && identity != null) { identitySetterFunc = FunctionCache.GetDataEntityPropertySetterCompiledFunction <TEntity>(identity); } // Identity which objects to set if (batchSize <= 1) { singleEntityFunc = FunctionCache.GetDataEntityDbParameterSetterCompiledFunction <TEntity>( string.Concat(typeof(TEntity).FullName, StringConstant.Period, tableName, ".MergeAll"), inputFields?.AsList(), null, dbSetting); } else { multipleEntitiesFunc = FunctionCache.GetDataEntityListDbParameterSetterCompiledFunction <TEntity>( string.Concat(typeof(TEntity).FullName, StringConstant.Period, tableName, ".MergeAll"), inputFields?.AsList(), null, batchSize, dbSetting); } // Identify the requests var mergeAllRequest = (MergeAllRequest)null; var mergeRequest = (MergeRequest)null; // Create a different kind of requests if (batchSize > 1) { mergeAllRequest = new MergeAllRequest(tableName, connection, transaction, fields, qualifiers, batchSize, hints, statementBuilder); } else { mergeRequest = new MergeRequest(tableName, connection, transaction, fields, qualifiers, hints, statementBuilder); } // Return the value return(new MergeAllExecutionContext <TEntity> { CommandText = batchSize > 1 ? CommandTextCache.GetMergeAllText(mergeAllRequest) : CommandTextCache.GetMergeText(mergeRequest), InputFields = inputFields, BatchSize = batchSize, SingleDataEntityParametersSetterFunc = singleEntityFunc, MultipleDataEntitiesParametersSetterFunc = multipleEntitiesFunc, IdentityPropertySetterFunc = identitySetterFunc }); }
/// <summary> /// Gets a value indicating whether the current collection is null or empty. /// </summary> /// <param name="value">The target type.</param> /// <typeparam name="T">The actual enumerable instance.</typeparam> /// <returns>A value indicating whether the collection is null or empty.</returns> public static bool IsNullOrEmpty <T>(this IEnumerable <T> value) => !value?.Any() ?? true;
private bool ContainSomeProducts(IEnumerable <string> products) { return(products?.Any() == true && !products.Any(s => string.IsNullOrWhiteSpace(s))); }
private IEnumerable <string> GetNonExistingProducts(IEnumerable <string> productsToValidate, IEnumerable <Product> matchingProducts) { return((productsToValidate?.Any() == true && matchingProducts?.Any() == true) ? productsToValidate.Except(matchingProducts.Select(a => a.Externalidentifier).Distinct()) : productsToValidate); }
private static bool IsNullOrEmpty <T>(IEnumerable <T> list) { return(!(list?.Any() ?? false)); }
internal string SubmitToYouTrack(string reportKind, string userDesc, string userEmail, bool includeBook, bool includeScreenshot, IEnumerable <string> additionalPathsToInclude) { var subject = reportKind == "User" ? "User Problem" : reportKind == "Fatal" ? "Crash Report" : "Error Report"; var issueSubmission = new YouTrackIssueSubmitter(YouTrackProjectKey); if (includeScreenshot && _reportInfo?.ScreenshotTempFile != null && RobustFile.Exists(_reportInfo.ScreenshotTempFile.Path)) { issueSubmission.AddAttachmentWhenWeHaveAnIssue(_reportInfo.ScreenshotTempFile.Path); } if (additionalPathsToInclude != null) { foreach (var path in additionalPathsToInclude) { issueSubmission.AddAttachmentWhenWeHaveAnIssue(path); } } string diagnosticInfo = GetDiagnosticInfo(includeBook, userDesc, userEmail); if (!string.IsNullOrWhiteSpace(userEmail)) { // remember their email SIL.Windows.Forms.Registration.Registration.Default.Email = userEmail; } string issueId; try { issueId = issueSubmission.SubmitToYouTrack(subject, diagnosticInfo); } catch (Exception e) { Debug.Fail("Submitting problem report to YouTrack failed with '" + e.Message + "'."); issueId = kFailureResult; } string issueLink; if (issueId == kFailureResult) { var zipPath = MakeEmailableReportFile(includeBook, includeScreenshot, userDesc, diagnosticInfo); issueLink = kFailureResult + ":" + zipPath; } else { issueLink = "https://issues.bloomlibrary.org/youtrack/issue/" + issueId; if (includeBook || _additionalPathsToInclude?.Any() == true) { try { string zipPath = CreateReportZipFile(issueId, userDesc, includeBook); if (zipPath != null) { // This could be used provided the file is not too large (about 10M as of July 2020), // but it seems simpler to do the same thing every time. //issueSubmission.AttachFileToExistingIssue(issueId, zipPath); var uploadUrl = ProblemBookUploader.UploadBook( BloomS3Client.ProblemBookUploadsBucketName, zipPath, new NullProgress()); diagnosticInfo += Environment.NewLine + "Problem book uploaded to " + uploadUrl; // We don't want to change the summary, but currently the YouTrack API requires us to set both together. issueSubmission.UpdateSummaryAndDescription(issueId, subject, diagnosticInfo); } } catch (Exception error) { Debug.WriteLine($"Attaching book to new YouTrack issue failed with '{error.Message}'."); var msg = "***Error as ProblemReportApi attempted to upload the zipped book: " + error.Message; userDesc += Environment.NewLine + msg; Logger.WriteEvent(userDesc); diagnosticInfo += Environment.NewLine + "Uploading the problem book failed with exception " + error.Message; // We don't want to change the summary, but currently the YouTrack API requires us to set both together. issueSubmission.UpdateSummaryAndDescription(issueId, subject, diagnosticInfo); } finally { _reportZipFileTemp.Detach(); } } } return(issueLink); }
public static bool IsNullOrEmpty <T>(this IEnumerable <T> list) { return(!(list?.Any() ?? false)); }
private static bool ContainsComments(IEnumerable <SyntaxTrivia> trivias) => trivias.Any(s => s.IsKind(SyntaxKind.CommentTrivia));
public CreateNewDatasetModelValidator( IDatasetRepository datasetsRepository, IPolicyRepository policyRepository) { _datasetsRepository = datasetsRepository; _policyRepository = policyRepository; RuleFor(model => model.Description) .NotEmpty() .WithMessage("You must give a description for the dataset"); RuleFor(model => model.Filename) .Custom((name, context) => { CreateNewDatasetModel model = context.ParentContext.InstanceToValidate as CreateNewDatasetModel; if (string.IsNullOrWhiteSpace(model.Filename)) { context.AddFailure("You must provide a filename"); } else if (!validExtensions.Contains(Path.GetExtension(model.Filename.ToLower()))) { context.AddFailure("Check you have the right file format"); } }); RuleFor(model => model.Name) .Custom((name, context) => { CreateNewDatasetModel model = context.ParentContext.InstanceToValidate as CreateNewDatasetModel; if (string.IsNullOrWhiteSpace(model.Name)) { context.AddFailure("Use a descriptive unique name other users can understand"); } else { IEnumerable <Dataset> datasets = _datasetsRepository.GetDatasetsByQuery(m => m.Content.Name.ToLower() == model.Name.ToLower()).Result; if (datasets != null && datasets.Any()) { context.AddFailure("Use a descriptive unique name other users can understand"); } } }); RuleFor(model => model.FundingStreamId) .Custom((name, context) => { CreateNewDatasetModel model = context.ParentContext.InstanceToValidate as CreateNewDatasetModel; if (string.IsNullOrWhiteSpace(model.FundingStreamId)) { context.AddFailure("You must give a Funding Stream Id for the dataset"); } else { IEnumerable <PoliciesApiModels.FundingStream> fundingStreams = _policyRepository.GetFundingStreams().Result; if (fundingStreams != null && !fundingStreams.Any(_ => _.Id == model.FundingStreamId)) { context.AddFailure($"Unable to find given funding stream ID: {model.FundingStreamId}"); } } }); RuleFor(model => model.DefinitionId) .Custom((name, context) => { CreateNewDatasetModel model = context.ParentContext.InstanceToValidate as CreateNewDatasetModel; if (string.IsNullOrWhiteSpace(model.DefinitionId)) { context.AddFailure("You must provide a valid dataset schema"); } else if (!string.IsNullOrWhiteSpace(model.FundingStreamId)) { IEnumerable <DatasetDefinationByFundingStream> datasetDefinitions = _datasetsRepository.GetDatasetDefinitionsByFundingStreamId(model.FundingStreamId).Result; if (datasetDefinitions?.Any(d => d.Id == model.DefinitionId) == false) { context.AddFailure($"Dataset definition not found for funding stream ID: {model.FundingStreamId}"); } } }); }
/// <summary> /// Determine if the query containes auto select expand property. /// </summary> /// <param name="responseValue">The response value.</param> /// <param name="singleResultCollection">The content as SingleResult.Queryable.</param> /// <param name="actionDescriptor">The action context, i.e. action and controller name.</param> /// <param name="request">The OData path.</param> /// <returns></returns> private static bool ContainsAutoSelectExpandProperty( object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request) { Type elementClrType = GetElementType(responseValue, singleResultCollection, actionDescriptor); IEdmModel model = GetModel(elementClrType, request, actionDescriptor); if (model == null) { throw Error.InvalidOperation(SRResources.QueryGetModelMustNotReturnNull); } ODataPath path = request.ODataFeature().Path; IEdmType edmType = model.GetTypeMappingCache().GetEdmType(elementClrType, model)?.Definition; IEdmEntityType baseEntityType = edmType as IEdmEntityType; IEdmStructuredType structuredType = edmType as IEdmStructuredType; IEdmProperty property = null; if (path != null) { string name; EdmHelpers.GetPropertyAndStructuredTypeFromPath(path, out property, out structuredType, out name); } if (baseEntityType != null) { List <IEdmEntityType> entityTypes = new List <IEdmEntityType>(); entityTypes.Add(baseEntityType); entityTypes.AddRange(EdmHelpers.GetAllDerivedEntityTypes(baseEntityType, model)); foreach (var entityType in entityTypes) { IEnumerable <IEdmNavigationProperty> navigationProperties = entityType == baseEntityType ? entityType.NavigationProperties() : entityType.DeclaredNavigationProperties(); if (navigationProperties != null) { if (navigationProperties.Any( navigationProperty => EdmHelpers.IsAutoExpand(navigationProperty, property, entityType, model))) { return(true); } } IEnumerable <IEdmStructuralProperty> properties = entityType == baseEntityType ? entityType.StructuralProperties() : entityType.DeclaredStructuralProperties(); if (properties != null) { foreach (var edmProperty in properties) { if (EdmHelpers.IsAutoSelect(edmProperty, property, entityType, model)) { return(true); } } } } } else if (structuredType != null) { IEnumerable <IEdmStructuralProperty> properties = structuredType.StructuralProperties(); if (properties != null) { foreach (var edmProperty in properties) { if (EdmHelpers.IsAutoSelect(edmProperty, property, structuredType, model)) { return(true); } } } } return(false); }
/// <summary> /// Bulk insert an instance of <see cref="DbDataReader"/> object into the database in an asynchronous way. /// </summary> /// <param name="connection">The connection object to be used.</param> /// <param name="tableName">The target table for bulk-insert operation.</param> /// <param name="reader">The <see cref="DbDataReader"/> object to be used in the bulk-insert operation.</param> /// <param name="dbFields">The list of <see cref="DbField"/> objects.</param> /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param> /// <param name="options">The bulk-copy options to be used.</param> /// <param name="bulkCopyTimeout">The timeout in seconds to be used.</param> /// <param name="batchSize">The size per batch to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <returns>The number of rows affected by the execution.</returns> internal static async Task <int> BulkInsertAsyncInternal(SqlConnection connection, string tableName, DbDataReader reader, IEnumerable <DbField> dbFields = null, IEnumerable <BulkInsertMapItem> mappings = null, SqlBulkCopyOptions?options = null, int?bulkCopyTimeout = null, int?batchSize = null, SqlTransaction transaction = null) { // Validate the objects SqlConnectionExtension.ValidateTransactionConnectionObject(connection, transaction); // Get the DB Fields dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction); if (dbFields?.Any() != true) { throw new InvalidOperationException($"No database fields found for '{tableName}'."); } // Variables needed var result = 0; var readerFields = Enumerable .Range(0, reader.FieldCount) .Select((index) => reader.GetName(index)); var mappingFields = new List <Tuple <string, string> >(); // To fix the casing problem of the bulk inserts foreach (var dbField in dbFields) { var readerField = readerFields.FirstOrDefault(field => string.Equals(field, dbField.Name, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(readerField)) { mappingFields.Add(new Tuple <string, string>(readerField, dbField.Name)); } } // Before Execution Time var beforeExecutionTime = DateTime.UtcNow; // Actual Execution using (var sqlBulkCopy = new SqlBulkCopy(connection, options.GetValueOrDefault(), transaction)) { // Set the destinationtable sqlBulkCopy.DestinationTableName = tableName; // Set the timeout if (bulkCopyTimeout != null && bulkCopyTimeout.HasValue) { sqlBulkCopy.BulkCopyTimeout = bulkCopyTimeout.Value; } // Set the batch szie if (batchSize != null && batchSize.HasValue) { sqlBulkCopy.BatchSize = batchSize.Value; } // Add the mappings if (mappings == null) { // Iterate the filtered fields foreach (var field in mappingFields) { sqlBulkCopy.ColumnMappings.Add(field.Item1, field.Item2); } } else { // Iterate the provided mappings foreach (var mapItem in mappings) { sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn); } } // Open the connection and do the operation await connection.EnsureOpenAsync(); await sqlBulkCopy.WriteToServerAsync(reader); // Hack the 'SqlBulkCopy' object var copiedField = GetRowsCopiedFieldFromSystemDataSqlBulkCopy(); // Set the return value result = copiedField != null ? (int)copiedField.GetValue(sqlBulkCopy) : reader.RecordsAffected; } // Result return(result); }
/// <summary> /// Solve the circuit for transient simulation. /// </summary> /// <param name="Analysis">Analysis from the circuit to solve.</param> /// <param name="TimeStep">Discretization timestep.</param> /// <param name="Log">Where to send output.</param> /// <returns>TransientSolution describing the solution of the circuit.</returns> public static TransientSolution Solve(Analysis Analysis, Expression TimeStep, IEnumerable<Arrow> InitialConditions, ILog Log) { Expression h = TimeStep; Log.WriteLine(MessageType.Info, "Building solution for h={0}", TimeStep.ToString()); // Analyze the circuit to get the MNA system and unknowns. List<Equal> mna = Analysis.Equations.ToList(); List<Expression> y = Analysis.Unknowns.ToList(); LogExpressions(Log, MessageType.Verbose, "System of " + mna.Count + " equations and " + y.Count + " unknowns = {{ " + String.Join(", ", y) + " }}", mna); // Evaluate for simulation functions. // Define T = step size. Analysis.Add("T", h); // Define d[t] = delta function. Analysis.Add(ExprFunction.New("d", Call.If((0 <= t) & (t < h), 1, 0), t)); // Define u[t] = step function. Analysis.Add(ExprFunction.New("u", Call.If(t >= 0, 1, 0), t)); mna = mna.Resolve(Analysis).OfType<Equal>().ToList(); // Find out what variables have differential relationships. List<Expression> dy_dt = y.Where(i => mna.Any(j => j.DependsOn(D(i, t)))).Select(i => D(i, t)).ToList(); // Find steady state solution for initial conditions. List<Arrow> initial = InitialConditions.ToList(); Log.WriteLine(MessageType.Info, "Performing steady state analysis..."); SystemOfEquations dc = new SystemOfEquations(mna // Derivatives, t, and T are zero in the steady state. .Evaluate(dy_dt.Select(i => Arrow.New(i, 0)).Append(Arrow.New(t, 0), Arrow.New(T, 0))) // Use the initial conditions from analysis. .Evaluate(Analysis.InitialConditions) // Evaluate variables at t=0. .OfType<Equal>(), y.Select(j => j.Evaluate(t, 0))); // Solve partitions independently. foreach (SystemOfEquations i in dc.Partition()) { try { List<Arrow> part = i.Equations.Select(j => Equal.New(j, 0)).NSolve(i.Unknowns.Select(j => Arrow.New(j, 0))); initial.AddRange(part); LogExpressions(Log, MessageType.Verbose, "Initial conditions:", part); } catch (Exception) { Log.WriteLine(MessageType.Warning, "Failed to find partition initial conditions, simulation may be unstable."); } } // Transient analysis of the system. Log.WriteLine(MessageType.Info, "Performing transient analysis..."); SystemOfEquations system = new SystemOfEquations(mna, dy_dt.Concat(y)); // Solve the diff eq for dy/dt and integrate the results. system.RowReduce(dy_dt); system.BackSubstitute(dy_dt); IEnumerable<Equal> integrated = system.Solve(dy_dt) .NDIntegrate(t, h, IntegrationMethod.Trapezoid) // NDIntegrate finds y[t + h] in terms of y[t], we need y[t] in terms of y[t - h]. .Evaluate(t, t - h).Cast<Arrow>() .Select(i => Equal.New(i.Left, i.Right)).Buffer(); system.AddRange(integrated); LogExpressions(Log, MessageType.Verbose, "Integrated solutions:", integrated); LogExpressions(Log, MessageType.Verbose, "Discretized system:", system.Select(i => Equal.New(i, 0))); // Solving the system... List<SolutionSet> solutions = new List<SolutionSet>(); // Partition the system into independent systems of equations. foreach (SystemOfEquations F in system.Partition()) { // Find linear solutions for y. Linear systems should be completely solved here. F.RowReduce(); IEnumerable<Arrow> linear = F.Solve(); if (linear.Any()) { linear = Factor(linear); solutions.Add(new LinearSolutions(linear)); LogExpressions(Log, MessageType.Verbose, "Linear solutions:", linear); } // If there are any variables left, there are some non-linear equations requiring numerical techniques to solve. if (F.Unknowns.Any()) { // The variables of this system are the newton iteration updates. List<Expression> dy = F.Unknowns.Select(i => NewtonIteration.Delta(i)).ToList(); // Compute JxF*dy + F(y0) == 0. SystemOfEquations nonlinear = new SystemOfEquations( F.Select(i => i.Gradient(F.Unknowns).Select(j => new KeyValuePair<Expression, Expression>(NewtonIteration.Delta(j.Key), j.Value)) .Append(new KeyValuePair<Expression, Expression>(1, i))), dy); // ly is the subset of y that can be found linearly. List<Expression> ly = dy.Where(j => !nonlinear.Any(i => i[j].DependsOn(NewtonIteration.DeltaOf(j)))).ToList(); // Find linear solutions for dy. nonlinear.RowReduce(ly); IEnumerable<Arrow> solved = nonlinear.Solve(ly); solved = Factor(solved); // Initial guess for y[t] = y[t - h]. IEnumerable<Arrow> guess = F.Unknowns.Select(i => Arrow.New(i, i.Evaluate(t, t - h))).ToList(); guess = Factor(guess); // Newton system equations. IEnumerable<LinearCombination> equations = nonlinear.Equations; equations = Factor(equations); solutions.Add(new NewtonIteration(solved, equations, nonlinear.Unknowns, guess)); LogExpressions(Log, MessageType.Verbose, String.Format("Non-linear Newton's method updates ({0}):", String.Join(", ", nonlinear.Unknowns)), equations.Select(i => Equal.New(i, 0))); LogExpressions(Log, MessageType.Verbose, "Linear Newton's method updates:", solved); } } Log.WriteLine(MessageType.Info, "System solved, {0} solution sets for {1} unknowns.", solutions.Count, solutions.Sum(i => i.Unknowns.Count())); return new TransientSolution( h, solutions, initial); }
/// <summary> /// Bulk insert an instance of <see cref="DataTable"/> object into the database in an asynchronous way. /// </summary> /// <param name="connection">The connection object to be used.</param> /// <param name="tableName">The target table for bulk-insert operation.</param> /// <param name="dataTable">The <see cref="DataTable"/> object to be used in the bulk-insert operation.</param> /// <param name="rowState">The state of the rows to be copied to the destination.</param> /// <param name="dbFields">The list of <see cref="DbField"/> objects.</param> /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param> /// <param name="options">The bulk-copy options to be used.</param> /// <param name="bulkCopyTimeout">The timeout in seconds to be used.</param> /// <param name="batchSize">The size per batch to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <returns>The number of rows affected by the execution.</returns> internal static async Task <int> BulkInsertAsyncInternal(SqlConnection connection, string tableName, DataTable dataTable, DataRowState?rowState = null, IEnumerable <DbField> dbFields = null, IEnumerable <BulkInsertMapItem> mappings = null, SqlBulkCopyOptions?options = null, int?bulkCopyTimeout = null, int?batchSize = null, SqlTransaction transaction = null) { // Validate the objects SqlConnectionExtension.ValidateTransactionConnectionObject(connection, transaction); // Get the DB Fields dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction); if (dbFields?.Any() != true) { throw new InvalidOperationException($"No database fields found for '{tableName}'."); } // Variables needed var result = 0; var tableFields = GetDataColumns(dataTable) .Select(column => column.ColumnName); var mappingFields = new List <Tuple <string, string> >(); // To fix the casing problem of the bulk inserts foreach (var dbField in dbFields) { var tableField = tableFields.FirstOrDefault(field => string.Equals(field, dbField.Name, StringComparison.OrdinalIgnoreCase)); if (tableField != null) { mappingFields.Add(new Tuple <string, string>(tableField, dbField.Name)); } } // Before Execution Time var beforeExecutionTime = DateTime.UtcNow; // Actual Execution using (var sqlBulkCopy = new SqlBulkCopy(connection, options.GetValueOrDefault(), transaction)) { // Set the destinationtable sqlBulkCopy.DestinationTableName = tableName; // Set the timeout if (bulkCopyTimeout != null && bulkCopyTimeout.HasValue) { sqlBulkCopy.BulkCopyTimeout = bulkCopyTimeout.Value; } // Set the batch szie if (batchSize != null && batchSize.HasValue) { sqlBulkCopy.BatchSize = batchSize.Value; } // Add the mappings if (mappings == null) { // Iterate the filtered fields foreach (var field in mappingFields) { sqlBulkCopy.ColumnMappings.Add(field.Item1, field.Item2); } } else { // Iterate the provided mappings foreach (var mapItem in mappings) { sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn); } } // Open the connection and do the operation connection.EnsureOpen(); if (rowState.HasValue == true) { await sqlBulkCopy.WriteToServerAsync(dataTable, rowState.Value); } else { await sqlBulkCopy.WriteToServerAsync(dataTable); } // Set the return value result = GetDataRows(dataTable, rowState).Count(); } // Result return(result); }
private static bool GeneratedAnyWorkbooks(IEnumerable <CompletedWorkbookInfo> completedWorkbooks) { return(completedWorkbooks?.Any(completedWorkbookInfo => completedWorkbookInfo.GeneratedSuccessfully) ?? false); }
/// <summary> /// True if the group has items that do not end with _._ /// </summary> private static bool GroupHasNonEmptyItems(IEnumerable <LockFileItem> group) { return(group?.Any(item => !item.Path.EndsWith(PackagingCoreConstants.ForwardSlashEmptyFolder)) == true); }
public virtual void Empty <T>(string collectionName, IEnumerable <T> collection) { Assert.IsFalse(collection?.Any() == true, CreateMessage($"expected '{collectionName}' to be empty, contains '{collection?.Count()}' elements")); }
/// <summary> /// True if the list contains CLEAR and non-CLEAR keywords. /// </summary> /// <remarks>CLEAR;CLEAR is considered valid.</remarks> public static bool HasInvalidClear(IEnumerable <string> values) { return(ContainsClearKeyword(values) && (values?.Any(e => !StringComparer.OrdinalIgnoreCase.Equals(e, Clear)) == true)); }
private void SetChoiceHash( int tenantId, long siteId, Dictionary <string, IEnumerable <string> > linkHash, IEnumerable <string> searchIndexes, int index, string line) { switch (line) { case "[[Depts]]": SiteInfo.TenantCaches[tenantId].DeptHash .Where(o => o.Value.TenantId == tenantId) .ForEach(o => AddToChoiceHash( o.Key.ToString(), SiteInfo.Dept(o.Key).Name)); break; case "[[Users]]": SiteInfo.SiteUsers(tenantId, siteId) .ToDictionary(o => o.ToString(), o => SiteInfo.UserName(o)) .Where(o => searchIndexes?.Any() != true || searchIndexes.All(p => o.Key.Contains(p) || o.Value.Contains(p))) .ForEach(o => AddToChoiceHash(o.Key, o.Value)); break; case "[[Users*]]": SiteInfo.TenantCaches[tenantId].UserHash .Where(o => o.Value.TenantId == tenantId) .ToDictionary(o => o.Key.ToString(), o => o.Value.Name) .Where(o => searchIndexes?.Any() != true || searchIndexes.All(p => o.Key.Contains(p) || o.Value.Contains(p))) .ForEach(o => AddToChoiceHash(o.Key, o.Value)); break; case "[[TimeZones]]": TimeZoneInfo.GetSystemTimeZones() .ForEach(o => AddToChoiceHash( o.Id, o.StandardName)); break; default: if (linkHash != null && linkHash.ContainsKey(line)) { linkHash[line].ForEach(value => AddToChoiceHash(value)); } else if (TypeName != "bit") { if (searchIndexes == null || searchIndexes.All(o => line.Contains(o))) { AddToChoiceHash(line); } } else { AddToChoiceHash((index == 0).ToOneOrZeroString(), line); } break; } }
public static bool IsEmpty <T>(this IEnumerable <T> enumerable) => enumerable?.Any() != true;
public bool Check(AnimationController controller) { return(_conditions.Any(c => c(controller))); }
private bool IsStraight(IEnumerable <Card> cards, out List <Card> straightCards) { straightCards = new List <Card>(); var lowStraightValues = new List <CardValue> { CardValue.Five, CardValue.Four, CardValue.Three, CardValue.Two, CardValue.Ace }; var highStraightValues = new List <CardValue> { CardValue.Ace, CardValue.King, CardValue.Queen, CardValue.Jack, CardValue.King }; var isStraight = true; foreach (var v in highStraightValues) { if (!cards.Any(x => x.Value == v)) { isStraight = false; break; } else { straightCards.Add(cards.First(x => x.Value == v)); } } if (isStraight) { return(true); } straightCards = new List <Card>(); foreach (var v in lowStraightValues) { if (!cards.Any(x => x.Value == v)) { isStraight = false; break; } else { straightCards.Add(cards.First(x => x.Value == v)); } } if (isStraight) { return(true); } //not a high or low straight straightCards = new List <Card>(); var ordered = cards.OrderByDescending(a => a.Value).ToList(); for (var i = 0; i < ordered.Count - 5; i++) { var skipped = ordered.Skip(i); var possibleStraight = skipped.Take(5); if (IsStraight(possibleStraight)) { straightCards = possibleStraight.ToList(); return(true); } } return(false); }
private static HtmlBuilder Table( this HtmlBuilder hb, SiteSettings ss, Dictionary <string, ControlData> choicesX, Dictionary <string, ControlData> choicesY, string aggregateType, Column value, bool daily, IEnumerable <string> columns, IEnumerable <CrosstabElement> data) { var max = data.Any() && columns == null ? data.Select(o => o.Value).Max() : 0; return(hb.Table( css: "grid fixed", action: () => hb .THead(action: () => hb .Tr(css: "ui-widget-header", action: () => { if (choicesY != null) { hb.Th(); } choicesX.ForEach(choice => hb .Th(action: () => hb .HeaderText( ss: ss, aggregateType: aggregateType, value: value, showValue: columns?.Any() != true, data: data.Where(o => o.GroupByX == choice.Key), choice: choice))); })) .TBody(action: () => { choicesY?.ForEach(choiceY => { var column = columns?.Any() != true ? value : ss.GetColumn(choiceY.Key); hb.Tr(css: "crosstab-row", action: () => { var row = data.Where(o => o.GroupByY == choiceY.Key).ToList(); hb.Th(action: () => hb .HeaderText( ss: ss, aggregateType: aggregateType, value: column, showValue: true, data: row, choice: choiceY)); if (columns != null) { max = row.Any() ? row.Max(o => o.Value) : 0; } choicesX.ForEach(choiceX => hb .Td(ss: ss, aggregateType: aggregateType, daily: daily, value: column, x: choiceX.Key, max: max, data: data.FirstOrDefault(o => o.GroupByX == choiceX.Key && o.GroupByY == choiceY.Key)?.Value ?? 0)); }); }); }))); }
public static bool Exist <T>(this IEnumerable <T> obj) where T : class { return(obj?.Any() == true); }