public Dictionary<string, string> Generate(List<NameNode> idNameNodes, IEnumerable<string> excludedNames) { Generator.Reset(); int varCount = idNameNodes.Count; string[] newNames = new string[varCount]; var newSubstitution = new Dictionary<string, string>(); for (int i = 0; i < varCount; i++) { string newName; do { newName = Generator.Next(); } while (excludedNames.Contains(newName) || NamesGenerator.CSharpKeywords.Contains(newName)); newNames[i] = newName; } int ind = 0; foreach (NameNode v in idNameNodes) if (!newSubstitution.ContainsKey(v.Name)) newSubstitution.Add(v.Name, newNames[ind++]); return newSubstitution; }
public IPagedList<User> GetServiceProvidersPage(int page, int itemsPerPage, IEnumerable<int> locations, IEnumerable<Guid> tags, string searchString) { IQueryable<User> users = _serviceHubEntities.Users .Include("Tags") .Include("Ratings") .Include("Locations") .Where(o => o.IsPublic); if (locations.Count() > 0) locations = _serviceHubEntities.GetLocationsHierarchy(string.Join(",", locations)).Select(o => o.Id); if (locations.Count() > 0 && tags.Count() > 0) users = users.Where(o => o.Locations.Any(i => locations.Contains(i.Id)) || o.Tags.Any(i => tags.Contains(i.Id))); else if (locations.Count() > 0) users = users.Where(o => o.Locations.Any(i => locations.Contains(i.Id))); else if (tags.Count() > 0) users = users.Where(o => o.Tags.Any(i => tags.Contains(i.Id))); if (!string.IsNullOrWhiteSpace(searchString)) { string searchStringUpperCase = searchString.ToUpper(); users = users.Where(o => o.Name.ToUpper().Contains(searchStringUpperCase)); } return users .OrderByDescending(o => o.Ratings.Average(i => i.Score)) .ToPagedList(page, itemsPerPage); }
private static void AssertGetSensorsResult(IEnumerable<string> sensors) { Assert.IsNotNull(sensors); Assert.AreEqual(2, sensors.Count()); Assert.IsTrue(sensors.Contains("Temperature Sensor")); Assert.IsTrue(sensors.Contains("Velocity Sensor")); }
/// <summary> /// Compares 2 userprofile. /// </summary> /// <param name="userProfile"></param> /// <param name="compUserProfile"></param> /// <param name="objectsToCompare"> optional (if not given, all objects will be taken into account)</param> /// <param name="networks"> optional (if not given, all networks will be added to the resulting usercomparison)</param> /// <returns></returns> internal static UserComparison CompareUserProfiles(ProfileData userProfile, ProfileData compUserProfile, IEnumerable<ProfileDataObjects> objectsToCompare = null, IEnumerable<Network> networks = null) { UserComparison userComparison = new UserComparison(); if (userProfile == null) userProfile = new ProfileData(); if (compUserProfile == null) compUserProfile = new ProfileData(); if(objectsToCompare == null) objectsToCompare = ProfileData.GetAllProfileDataObjects(); if (networks == null) networks = Network.GetAllNetworks(); userComparison.Networks = networks.ToList(); if (objectsToCompare.Contains(ProfileDataObjects.EDUCATION)) CompareEducation(ref userComparison, userProfile, compUserProfile); if(objectsToCompare.Contains(ProfileDataObjects.WORK)) CompareWork(ref userComparison, userProfile, compUserProfile); if (objectsToCompare.Contains(ProfileDataObjects.TEAM)) CompareInterests(ref userComparison, userProfile, compUserProfile, InterestType.TEAM); if (objectsToCompare.Contains(ProfileDataObjects.ATHLETE)) CompareInterests(ref userComparison, userProfile, compUserProfile, InterestType.ATHLETE); return userComparison; }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, IEnumerable<string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString, property.ConcurrencyMode); } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties(), PrincipalProperties = property.PrincipalProperties(), Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : property.Type.TypeKind() == EdmTypeKind.Entity ? property.Type.Definition as IEdmEntityType : null, TargetMultiplicity = property.TargetMultiplicity(), }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
public static GameObject[] ResolveTargets(GameObject source, IEnumerable<string> TargetIds, GameObjectCollection parent, GameConsole console, bool DeepProcess) { // If it passed, find all targets and activate them List<GameObject> foundTargets = new List<GameObject>(5); foreach (var item in parent) { if (item.Value != source && TargetIds.Contains(item.Value.GetSetting("id"))) foundTargets.Add(item.Value); } // Process all known collections if (DeepProcess) { for (int i = 0; i < console.LayeredTextSurface.LayerCount; i++) { var objects = console.GetObjectCollection(i); if (objects != parent) { foreach (var item in objects) { if (item.Value != source && TargetIds.Contains(item.Value.GetSetting("id"))) foundTargets.Add(item.Value); } } } } return foundTargets.ToArray(); }
internal static IQueryable<Agreement> VisibleTo(this IQueryable<Agreement> agreements, IPrincipal principal, IEnumerable<int> ownedTenantIds) { if (agreements == null) return null; if (principal == null) throw new ArgumentNullException("principal"); if (ownedTenantIds == null) throw new ArgumentNullException("ownedTenantIds"); // when user is not an agreement admin, filter out private agreements // and protected agreements that the user does not own if (!principal.IsInAnyRole(RoleName.AgreementManagers)) { return agreements.Where(x => Public.Equals(x.VisibilityText, StringComparison.OrdinalIgnoreCase) || ( Protected.Equals(x.VisibilityText, StringComparison.OrdinalIgnoreCase) && x.Participants.Any(y => y.IsOwner && ownedTenantIds.Contains(y.EstablishmentId)) ) ); } // when user is an agreement admin, include all agreements they own return agreements.Where(x => Public.Equals(x.VisibilityText, StringComparison.OrdinalIgnoreCase) || ( x.Participants.Any(y => y.IsOwner && ownedTenantIds.Contains(y.EstablishmentId)) ) ); }
public void String(IEnumerable<string> source, IEqualityComparer<string> comparer, string value, bool expected) { if (comparer == null) { Assert.Equal(expected, source.Contains(value)); } Assert.Equal(expected, source.Contains(value, comparer)); }
/// <summary> /// ขอข้อมูล User profile จากรหัส class room ที่ใช้งานล่าสุด /// </summary> /// <param name="classRoomId">รหัส class room ที่จะทำการขอข้อมูล</param> public IEnumerable<UserProfile> GetUserProfilesByLastActivateOnClassRoomId(IEnumerable<string> classRoomIds) { var qry = _mongoUtil.GetCollection<UserProfile>(TableName) .Find(it => !it.DeletedDate.HasValue && it.Subscriptions.Any(s => classRoomIds.Contains(s.ClassRoomId))) .ToEnumerable() .Where(it => classRoomIds.Contains(it.Subscriptions.Where(s => !s.DeletedDate.HasValue && s.LastActiveDate.HasValue).OrderBy(s => s.LastActiveDate).LastOrDefault().ClassRoomId)); return qry; }
public void DeleteDataFor(IEnumerable<string> usersToDelete) { var postsToDelete = _container.Posts.Where(x => usersToDelete.Contains(x.CreatedBy)); DeletePosts(postsToDelete.ToList()); var questionsToDelete = _container.Questions.Where(x => usersToDelete.Contains(x.CreatedBy)); DeleteQuestions(questionsToDelete.ToList()); }
protected void RemoveProperties(IEnumerable<string> paramNames, bool exclude) { var propNamesMappingsToRemove = new List<string>(PropertyMappings.Count); propNamesMappingsToRemove.AddRange(from propMapping in this.PropertyMappings where (exclude && !paramNames.Contains(propMapping.Value.PropertyName)) || (!exclude && paramNames.Contains(propMapping.Value.PropertyName)) select propMapping.Key); foreach (var propName in propNamesMappingsToRemove) { this.RemoveProperty(propName); } }
public IEnumerable<DealerManpower> FindAllDealerManpowers(IEnumerable<int> dealerIds, string dse) { IEnumerable<DealerManpower> manpowers; if (string.IsNullOrEmpty(dse)) manpowers = manpowerRepo.Fetch().Where(x => dealerIds.Contains(x.DealerId) && (x.ObjectInfo.DeletedDate == null || x.Profile.DateOfLeaving != null)).ToList(); else { manpowers = manpowerRepo.Fetch().Where(x => dealerIds.Contains(x.DealerId) && x.Type == dse && (x.ObjectInfo.DeletedDate == null || x.Profile.DateOfLeaving != null)).ToList(); } return manpowers; }
public IEnumerable<Profile> FindProfilesByManPowerLevel(IEnumerable<int> dseIds, string value) { List<Profile> profiles; if (string.IsNullOrEmpty(value)) profiles = profileRepo.Fetch().Where(x => dseIds.Contains(x.DealerManpower.Id) && x.ObjectInfo.DeletedDate == null).ToList(); else { profiles = profileRepo.Fetch().Where(x => dseIds.Contains(x.DealerManpower.Id) && x.ObjectInfo.DeletedDate == null && x.TrainingLevel == value).ToList(); } return profiles; }
public async Task<bool> AllRequiredTagsArePresent(IEnumerable<int> tagsIds) { var exactlyOneSeasonTagIsPresent = await this.tags .All() .CountAsync(t => t.Type == TagType.Season && tagsIds.Contains(t.Id)) == 1; var languageOrTechnologyTagIsPresent = await this.tags .All() .AnyAsync(t => (t.Type == TagType.Technology || t.Type == TagType.Language) && tagsIds.Contains(t.Id)); return exactlyOneSeasonTagIsPresent && languageOrTechnologyTagIsPresent; }
public IEnumerable<Package> GetUnfinishedPackages(string userKey, IEnumerable<string> userPackageIds) { if (userPackageIds == null || !userPackageIds.Any()) { return new Package[0]; } _packageAuthenticator.EnsureKeyCanAccessPackages(userPackageIds, userKey); IEnumerable<Package> existingPublishedPackages = _publishedPackageRepository.Collection.Where(pp => userPackageIds.Contains(pp.Id)).ToList() .Select(pp => new Package { Id = pp.Id, Version = pp.Version}); return _packageRepository.Collection.Where(p => userPackageIds.Contains(p.Id)) .Except(existingPublishedPackages, (x, y) => x.Id == y.Id && x.Version == y.Version); }
protected void PrintBumps(IEnumerable<Bumped> _bumps) { if (_bumps.Contains(Bumped.Left)) Console.Write(">"); if (_bumps.Contains(Bumped.Right)) Console.Write("<"); if (_bumps.Contains(Bumped.Top)) Console.Write(@"\/"); if (_bumps.Contains(Bumped.Bottom)) Console.Write(@"/\"); Console.WriteLine(); }
public ActionResult Search(string search, IEnumerable<int> selected, int? page = null) { if (page.HasValue) { const int pageSize = 6; var src = repo.GetAll().Where(o => (selected == null || !selected.Contains(o.Id)) && o.Name.Containz(search)); var rows = this.RenderView(@"Awesome\LookupList", src.Skip((page.Value - 1) * pageSize).Take(pageSize)); return Json(new { rows, more = src.Count() > page * pageSize }); } return View(@"Awesome\LookupList", repo.GetAll().Where(o => (selected == null || !selected.Contains(o.Id)) && o.Name.Containz(search))); }
private static BindableCollection<ButtonModel> ConvertToButtons(IEnumerable<Answer> possibleAnswers) { if(possibleAnswers.Contains(Answer.Yes)) { return possibleAnswers.Contains(Answer.Cancel) ? new BindableCollection<ButtonModel>{new ButtonModel("Yes"), new ButtonModel("No"), new ButtonModel("Cancel")} : new BindableCollection<ButtonModel> {new ButtonModel("Yes"), new ButtonModel("No")}; } return possibleAnswers.Contains(Answer.Cancel) ? new BindableCollection<ButtonModel> {new ButtonModel("Ok"), new ButtonModel("Cancel")} : new BindableCollection<ButtonModel> {new ButtonModel("Ok")}; }
public static List<EditorCrossSceneReference> GetCrossSceneReferencesForScenes( IEnumerable<Scene> scenes ) { // Start by logging out the cross-scene references out var crossSubSceneRefs = ComputeAllCrossSceneReferences(); // Remove all of the cross-scene references that do not pertain to our input SubScenes list crossSubSceneRefs.RemoveAll( x => { return !scenes.Contains( x.fromScene ) && !scenes.Contains( x.toScene ); } ); return crossSubSceneRefs; }
public CommandLineArguments(IEnumerable<string> args) { Verbose = args.Contains("--verbose"); TerminateOnDisconnect = args.Contains("--terminateOnDisconnect"); if (args.Contains("--port")) { // TODO: Cleanup? var arglist = (IList<string>) args; var indexOfPortParam = arglist.IndexOf("--port") + 1; Port = int.Parse(arglist[indexOfPortParam]); } else Port = DefaultPort; }
public byte[] ExtractDefaultTranslation(string sitePath, IEnumerable<string> extensionNames) { if (extensionNames == null || extensionNames.Count() == 0) { return ExtractDefaultTranslation(sitePath); } var site = Path.Get(sitePath); var zipFiles = new Dictionary<Path, StringBuilder>(); // Extract resources for module manifests site.Files("module.txt", true) .Where(p => extensionNames.Contains(p.Parent().FileName)) .Read((content, path) => { var moduleName = path.Parent().FileName; var poPath = GetModuleLocalizationPath(site, moduleName); ExtractPoFromManifest(zipFiles, poPath, content, path, site); }); // Extract resources for theme manifests site.Files("theme.txt", true) .Where(p => extensionNames.Contains(p.Parent().FileName)) .Read((content, path) => { var themeName = path.Parent().FileName; var poPath = GetThemeLocalizationPath(site, themeName); ExtractPoFromManifest(zipFiles, poPath, content, path, site); }); // Extract resources from views and cs files site.Files("*", true) .WhereExtensionIs(".cshtml", ".aspx", ".ascx", ".cs") .Where(p => { var tokens = p.MakeRelativeTo(site).Tokens; return new[] {"themes", "modules"}.Contains(tokens[0]) && extensionNames.Contains(tokens[1]); }) .Grep( ResourceStringExpression, (path, match, contents) => { var str = match.Groups[1].ToString(); DispatchResourceString(zipFiles, null, null, site, path, site, contents, str); } ) .Grep( PluralStringExpression, (path, match, contents) => { var str = match.Groups[1].ToString(); DispatchResourceString(zipFiles, null, null, site, path, site, contents, str); str = match.Groups[6].ToString(); DispatchResourceString(zipFiles, null, null, site, path, site, contents, str); } ); return ZipExtensions.Zip( new Path(zipFiles.Keys.Select(p => p.MakeRelativeTo(site))), p => Encoding.UTF8.GetBytes(zipFiles[site.Combine(p)].ToString())); }
public byte[] PackageTranslations(string cultureCode, string sitePath, IEnumerable<string> extensionNames) { var site = Path.Get(sitePath); var translationFiles = site .Files("orchard.*.po", true) .Where(p => extensionNames != null && (p.Parent().FileName.Equals(cultureCode, StringComparison.OrdinalIgnoreCase) && (extensionNames.Contains(p.MakeRelativeTo(site.Combine("Modules")).Tokens[0], StringComparer.OrdinalIgnoreCase) || extensionNames.Contains(p.MakeRelativeTo(site.Combine("Themes")).Tokens[0], StringComparer.OrdinalIgnoreCase)))) .MakeRelativeTo(site); return ZipExtensions.Zip( translationFiles, p => site.Combine(p).ReadBytes()); }
public static string GetDays(IEnumerable<string> days) { string result = days.FirstOrDefault(); if (DateTime.Today.DayOfWeek == DayOfWeek.Saturday || DateTime.Today.DayOfWeek == DayOfWeek.Sunday) { if(days.Contains("Выходные")) result = "Выходные"; } else if (DateTime.Today.DayOfWeek != DayOfWeek.Saturday && DateTime.Today.DayOfWeek != DayOfWeek.Sunday) { if (days.Contains("Рабочие")) result = "Рабочие"; } return result; }
public static string CopyName(string name, IEnumerable<string> names) { if (!names.Contains(name)) return name; int index = 1; while (true) { var newName = string.Format(CopyFormat, name, index); if (!names.Contains(newName)) return newName; index++; } }
public static string CopyFileName(string name, IEnumerable<string> names) { if (!names.Contains(name)) return name; int index = 1; while (true) { var shortName = Path.GetFileNameWithoutExtension(name); var ext = Path.GetExtension(name); var newName = string.Format(CopyFormat, shortName, index) + ext; if (!names.Contains(newName)) return newName; index++; } }
public GetDepartamentosViewModel(IEnumerable<string> codigoEmpresas, IEnumerable<string> codigoDepartamentos) : this() { AufenPortalReportesDataContext db = new AufenPortalReportesDataContext() .WithConnectionStringFromConfiguration(); if (codigoEmpresas != null && codigoEmpresas.Any(x => !String.IsNullOrEmpty(x))) { Empresas = db.EMPRESAs.Where(x => codigoEmpresas.Contains(x.Codigo)); Vw_Ubicaciones = db.vw_Ubicaciones.Where(x => codigoEmpresas.Contains(x.IdEmpresa)); } if (codigoDepartamentos != null && codigoDepartamentos.Any(x => !String.IsNullOrEmpty(x))) { CodigoDepartamentos = codigoDepartamentos; } }
public void DropColumns(string tableName, IEnumerable<string> columns) { using (var transaction = _sqLiteMigrationHelper.BeginTransaction()) { var originalColumns = _sqLiteMigrationHelper.GetColumns(tableName); var originalIndexes = _sqLiteMigrationHelper.GetIndexes(tableName); var newColumns = originalColumns.Where(c => !columns.Contains(c.Key)).Select(c => c.Value).ToList(); var newIndexes = originalIndexes.Where(c => !columns.Contains(c.Column)); CreateTable(tableName, newColumns, newIndexes); transaction.Commit(); } }
private static string[] CreateStringArrayFromCard(Card card, IEnumerable<List> lists, IEnumerable<string> fieldsToInclude) { var list = new List<string>(); if(fieldsToInclude.Contains("Name")) list.Add(card.Name); if (fieldsToInclude.Contains("Description")) list.Add(card.Desc); if (fieldsToInclude.Contains("Due Date")) list.Add(card.Due.ToString()); if (fieldsToInclude.Contains("List")) list.Add(lists.FirstOrDefault() != null ? lists.FirstOrDefault().Name : null); return list.ToArray(); }
public static void SetLayer(this Transform transform, int layer, IEnumerable<int> excludeLayers = null) { if (excludeLayers == null || !excludeLayers.Contains(transform.gameObject.layer)) transform.gameObject.layer = layer; for (int i = 0; i < transform.GetChildCount(); ++i) { Transform child = transform.GetChild(i); if (excludeLayers == null || !excludeLayers.Contains(child.gameObject.layer)) child.gameObject.layer = layer; SetLayer(child, layer, excludeLayers); } }
public IEnumerable<PropertyInfo> GetProperties( Type type, bool declaredOnly, IEnumerable<PropertyInfo> explicitlyMappedProperties = null, IEnumerable<Type> knownTypes = null, bool includePrivate = false) { DebugCheck.NotNull(type); explicitlyMappedProperties = explicitlyMappedProperties ?? Enumerable.Empty<PropertyInfo>(); knownTypes = knownTypes ?? Enumerable.Empty<Type>(); ValidatePropertiesForModelVersion(type, explicitlyMappedProperties); var propertyInfos = from p in declaredOnly ? type.GetDeclaredProperties() : type.GetNonHiddenProperties() where !p.IsStatic() && p.IsValidStructuralProperty() let m = p.Getter() where (includePrivate || (m.IsPublic || explicitlyMappedProperties.Contains(p) || knownTypes.Contains(p.PropertyType))) && (!declaredOnly || type.BaseType().GetInstanceProperties().All(bp => bp.Name != p.Name)) && (EdmV3FeaturesSupported || (!IsEnumType(p.PropertyType) && !IsSpatialType(p.PropertyType))) && (Ef6FeaturesSupported || !p.PropertyType.IsNested) select p; return propertyInfos; }