public ImmutableArray <ObjectListItem> GetProjectListItems(Solution solution, string languageName, uint listFlags, CancellationToken cancellationToken) { var projectIds = solution.ProjectIds; if (!projectIds.Any()) { return(ImmutableArray <ObjectListItem> .Empty); } var projectListItemBuilder = ImmutableArray.CreateBuilder <ObjectListItem>(); var referenceListItemBuilder = ImmutableArray.CreateBuilder <ObjectListItem>(); HashSet <AssemblyIdentity> assemblyIdentitySet = null; var visitedAssemblies = new Dictionary <string, AssemblyIdentity>(); foreach (var projectId in projectIds) { var project = solution.GetProject(projectId); if (project.Language != languageName) { continue; } if (project.IsVenus()) { continue; } projectListItemBuilder.Add(new ProjectListItem(project)); if (Helpers.IsObjectBrowser(listFlags)) { if (assemblyIdentitySet == null) { assemblyIdentitySet = new HashSet <AssemblyIdentity>(); } foreach (var reference in project.MetadataReferences) { if (reference is PortableExecutableReference portableExecutableReference) { var assemblyIdentity = visitedAssemblies.GetOrAdd(portableExecutableReference.FilePath, filePath => AssemblyIdentityUtils.TryGetAssemblyIdentity(filePath)); if (assemblyIdentity != null && !assemblyIdentitySet.Contains(assemblyIdentity)) { assemblyIdentitySet.Add(assemblyIdentity); var referenceListItem = new ReferenceListItem(projectId, assemblyIdentity.Name, reference); referenceListItemBuilder.Add(referenceListItem); } } } } } projectListItemBuilder.AddRange(referenceListItemBuilder); return(projectListItemBuilder.ToImmutable()); }
private void BuildReference(ReferenceListItem referenceListItem) { AddText(ServicesVSResources.Assembly); AddName(referenceListItem.DisplayText); AddEndDeclaration(); AddIndent(); if (referenceListItem.MetadataReference is PortableExecutableReference portableExecutableReference) { AddText(portableExecutableReference.FilePath); } }
private void BuildReference(ReferenceListItem referenceListItem) { AddText(ServicesVSResources.Library_Assembly); AddName(referenceListItem.DisplayText); AddEndDeclaration(); AddIndent(); var portableExecutableReference = referenceListItem.MetadataReference as PortableExecutableReference; if (portableExecutableReference != null) { AddText(portableExecutableReference.FilePath); } }
private async Task DoProcess() { var lists = _typeFinder .Find(type => type != null && type.IsPublic && type.IsEnum && type.HasAttribute <ReferenceListAttribute>()) .Select(e => new { Enum = e, Attribute = e.GetAttribute <ReferenceListAttribute>() }) .ToList(); if (!lists.Any()) { return; } foreach (var list in lists) { try { var listInCode = new List <ListItemInfo>(); var values = Enum.GetValues(list.Enum); foreach (var value in values) { var intValue = Convert.ToInt64(value); var internalName = Enum.GetName(list.Enum, intValue); var memberInfo = list.Enum.GetMember(internalName).FirstOrDefault(); var displayAttribute = memberInfo != null ? memberInfo.GetAttribute <DisplayAttribute>() : null; var descriptionAttribute = memberInfo != null ? memberInfo.GetAttribute <DescriptionAttribute>() : null; if (displayAttribute != null && displayAttribute.GetAutoGenerateField() == false) { continue; } listInCode.Add(new ListItemInfo { Name = displayAttribute != null ? displayAttribute.Name : descriptionAttribute != null ? descriptionAttribute.Description : internalName.ToFriendlyName(), Description = descriptionAttribute?.Description, Value = intValue, OrderIndex = displayAttribute?.GetOrder() ?? intValue }); } var listInDb = await _listRepo.GetAll() .FirstOrDefaultAsync(l => l.Name == list.Attribute.ReferenceListName && l.Namespace == list.Attribute.Namespace); if (listInDb == null) { listInDb = new ReferenceList() { Name = list.Attribute.ReferenceListName, Namespace = list.Attribute.Namespace }; await _listRepo.InsertAsync(listInDb); } var itemsInDb = await _listItemRepo.GetAll() .Where(i => i.ReferenceList == listInDb) .ToListAsync(); var toAdd = listInCode.Where(i => !itemsInDb.Any(iv => iv.ItemValue == i.Value)).ToList(); foreach (var item in toAdd) { var newItem = new ReferenceListItem() { ItemValue = item.Value, Item = item.Name, Description = item.Description, OrderIndex = item.OrderIndex, ReferenceList = listInDb }; newItem.SetHardLinkToApplication(true); await _listItemRepo.InsertOrUpdateAsync(newItem); } var toInactivate = itemsInDb.Where(ldb => ldb.HardLinkToApplication && !listInCode.Any(i => i.Value == ldb.ItemValue)).ToList(); foreach (var item in toInactivate) { await _listItemRepo.DeleteAsync(item); } var toUpdate = itemsInDb.Select(idb => new { ItemInDB = idb, UpdatedItemInCode = listInCode.FirstOrDefault(i => i.Value == idb.ItemValue && (i.Name != idb.Item || !idb.HardLinkToApplication)) }) .Where(i => i.UpdatedItemInCode != null) .ToList(); foreach (var item in toUpdate) { item.ItemInDB.Item = item.UpdatedItemInCode.Name; item.ItemInDB.SetHardLinkToApplication(true); await _listItemRepo.InsertOrUpdateAsync(item.ItemInDB); } await _listRepo.InsertOrUpdateAsync(listInDb); await _unitOfWorkManager.Current.SaveChangesAsync(); } catch (Exception e) { throw new Exception($"An error occured during bootstrapping of the referenceList {list.Attribute.ReferenceListName}.{list.Attribute.Namespace}", e); } } }