public static bool TryGenerateExplorerIcon(File file) { string path = file.GetAbsolutePath(); if (!F.Exists(path)) { return(false); } try { string ext = P.GetExtension(path).Replace(".", string.Empty); if (file.IsFolder) { //string guid = GetGuidFromString("folder").ToString(); ////文件夹,统一图标 //if (!F.Exists(GetExplorerIconPath(guid))) //{ // var iconPath = GetExplorerIconPath(guid); // ExplorerIcon.GetBitmapFromFolderPath(path, ExplorerIcon.IconSizeEnum.ExtraLargeIcon).Save(iconPath, ImageFormat.Png); //} //file.IconGUID = guid; } else if (FileUtility.IsExecutable(path)) { //程序文件,每个图标都不同 string guid = Guid.NewGuid().ToString(); var iconPath = GetExplorerIconPath(file); ExplorerIcon.GetBitmapFromFilePath(path, ExplorerIcon.IconSizeEnum.ExtraLargeIcon) .Save(iconPath, ImageFormat.Png); } else { var iconPath = GetExplorerIconPath(file); //其他文件,同一个格式的用同一个图标 if (F.Exists(iconPath)) { } else { string tempPath = P.GetTempFileName(); ExplorerIcon.GetBitmapFromFilePath(path, ExplorerIcon.IconSizeEnum.ExtraLargeIcon).Save(tempPath, ImageFormat.Png); try { F.Move(tempPath, iconPath); } catch { } }; } } catch (Exception ex) { } return(false); }
public static BitmapImage GetFolderIcon() { string folderIconPath = Path.Combine(ThumbnailFolderPath, "folder.png"); if (!F.Exists(folderIconPath)) { ExplorerIcon.GetBitmapFromFolderPath("C:\\Windows", ExplorerIcon.IconSizeEnum.ExtraLargeIcon) .Save(folderIconPath, ImageFormat.Png); } return(new BitmapImage(new Uri(Path.GetFullPath(folderIconPath), UriKind.Absolute))); }
ExplorerItem GetTables(string header, ExplorerIcon icon, IEnumerable <TableInfo> tableSource) { var tables = tableSource.ToList(); var dic = tables.ToDictionary(t => t.Type, t => new { table = t, item = GetTable(icon, t) }); var items = new ExplorerItem(header, ExplorerItemKind.Category, icon) { Children = dic.Values.OrderBy(t => t.table.Name).Select(t => t.item).ToList() }; foreach (var table in dic.Values) { var entry = table.item; var typeAccessor = table.table.TypeAccessor; foreach (var ma in typeAccessor.Members) { var aa = ma.MemberInfo.GetCustomAttributeLike <AssociationAttribute>(); if (aa != null) { var relationship = Extensions.HasProperty(aa, "Relationship") ? aa.Relationship : Relationship.OneToOne; var otherType = relationship == Relationship.OneToMany ? ma.Type.GetItemType() ! : ma.Type; var otherTable = dic.ContainsKey(otherType) ? dic[otherType] : null; var typeName = relationship == Relationship.OneToMany ? $"List<{otherType.Name}>" : otherType.Name; entry.Children.Add( new ExplorerItem( ma.Name, relationship == Relationship.OneToMany ? ExplorerItemKind.CollectionLink : ExplorerItemKind.ReferenceLink, relationship == Relationship.OneToMany ? ExplorerIcon.OneToMany : relationship == Relationship.ManyToOne ? ExplorerIcon.ManyToOne : ExplorerIcon.OneToOne) { DragText = ma.Name, ToolTipText = typeName + (aa.IsBackReference == true ? " // Back Reference" : ""), SqlName = aa.KeyName, IsEnumerable = ma.Type.MaybeChildOf(typeof(IEnumerable <>)) && !ma.Type.MaybeEqualTo(typeof(string)), HyperlinkTarget = otherTable?.item, }); } } } return(items); }
static int GetIconDisplayOrder(ExplorerIcon icon) { switch (icon) { case ExplorerIcon.Column: return(0); case ExplorerIcon.OneToOne: return(1); case ExplorerIcon.OneToMany: return(2); case ExplorerIcon.Table: return(3); case ExplorerIcon.ScalarFunction: return(4); default: return(10); } }
ExplorerItem GetTable(ExplorerIcon icon, TableInfo table) { var columns = ( from ma in table.TypeAccessor.Members let aa = ma.MemberInfo.GetCustomAttributeLike <AssociationAttribute>() where aa == null let ca = ma.MemberInfo.GetCustomAttributeLike <ColumnAttribute>() let id = ma.MemberInfo.GetCustomAttributeLike <IdentityAttribute>() let pk = ma.MemberInfo.GetCustomAttributeLike <PrimaryKeyAttribute>() where ca != null && ca.IsColumn || pk != null || id != null || ca == null && !table.IsColumnAttributeRequired && MappingSchema.Default.IsScalarType(ma.Type) select new ExplorerItem( ma.Name, ExplorerItemKind.Property, pk != null || ca != null && ca.IsPrimaryKey ? ExplorerIcon.Key : ExplorerIcon.Column) { Text = $"{ma.Name} : {GetTypeName(ma.Type)}", // ToolTipText = $"{sqlName} {column.ColumnType} {(column.IsNullable ? "NULL" : "NOT NULL")}{(column.IsIdentity ? " IDENTITY" : "")}", DragText = ma.Name, // SqlName = sqlName, // SqlTypeDeclaration = $"{column.ColumnType} {(column.IsNullable ? "NULL" : "NOT NULL")}{(column.IsIdentity ? " IDENTITY" : "")}", } ).ToList(); var ret = new ExplorerItem(table.Name, ExplorerItemKind.QueryableObject, icon) { DragText = table.Name, // ToolTipText = $"ITable<{t.TypeName}>", IsEnumerable = true, Children = columns.ToList(), }; return(ret); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void SetPropertyItemStyle( IEdmEntityType entityType, IEdmProperty property, out string itemText, out string tooltipText, out ExplorerItemKind itemKind, out ExplorerIcon itemIcon) { var navigationProperty = (property as IEdmNavigationProperty); var structuralProperty = (property as IEdmStructuralProperty); var isCollection = property.Type.IsCollection(); if ( navigationProperty != null ) { itemText = property.Name; tooltipText = property.Type.Definition.FullTypeName(); itemKind = (isCollection ? ExplorerItemKind.CollectionLink : ExplorerItemKind.ReferenceLink); switch (navigationProperty.TargetMultiplicity()) { case EdmMultiplicity.One: itemIcon = (isCollection ? ExplorerIcon.ManyToOne : ExplorerIcon.OneToOne); break; case EdmMultiplicity.Many: itemIcon = (isCollection ? ExplorerIcon.ManyToMany : ExplorerIcon.OneToMany); break; default: itemIcon = ExplorerIcon.Column; break; } } else if (structuralProperty != null && entityType.DeclaredKey.Contains(structuralProperty)) { itemText = string.Format("{0} : {1}", property.Name, property.Type.Definition.FullTypeName()); tooltipText = "Contained in entity key"; itemKind = ExplorerItemKind.Property; itemIcon = ExplorerIcon.Key; } else { itemText = string.Format("{0} : {1}", property.Name, property.Type.Definition.FullTypeName()); tooltipText = string.Empty; itemKind = ExplorerItemKind.Property; itemIcon = ExplorerIcon.Column; } }
public ExplorerItem(string text, ExplorerItemKind kind, ExplorerIcon icon) { this.Text = text; this.Kind = kind; this.Icon = icon; }
ExplorerItem GetTables(string header, ExplorerIcon icon, IEnumerable <TableSchema> tableSource) { var tables = tableSource.ToList(); var dic = new Dictionary <TableSchema, ExplorerItem>(); var items = new ExplorerItem(header, ExplorerItemKind.Category, icon) { Children = tables .Select(t => { var memberName = _contextMembers[t]; Code.AppendLine($" public ITable<@{t.TypeName}> @{memberName} {{ get {{ return this.GetTable<@{t.TypeName}>(); }} }}"); CodeTable(_classCode, t, true); var tableSqlName = _sqlBuilder.BuildTableName( new StringBuilder(), null, t.SchemaName == null ? null : (string)_sqlBuilder.Convert(t.SchemaName, ConvertType.NameToOwner), (string)_sqlBuilder.Convert(t.TableName, ConvertType.NameToQueryTable)).ToString(); //Debug.WriteLine($"Table: [{t.SchemaName}].[{t.TableName}] - ${tableSqlName}"); var ret = new ExplorerItem(memberName, ExplorerItemKind.QueryableObject, icon) { DragText = memberName, ToolTipText = $"ITable<{t.TypeName}>", SqlName = tableSqlName, IsEnumerable = true, Children = t.Columns.Select(GetColumnItem).ToList() }; dic[t] = ret; return(ret); }) .OrderBy(t => t.Text) .ToList() }; foreach (var table in tables.Where(t => dic.ContainsKey(t))) { var entry = dic[table]; foreach (var key in table.ForeignKeys) { var typeName = key.AssociationType == AssociationType.OneToMany ? $"List<{key.OtherTable.TypeName}>" : key.OtherTable.TypeName; entry.Children.Add( new ExplorerItem( key.MemberName, key.AssociationType == AssociationType.OneToMany ? ExplorerItemKind.CollectionLink : ExplorerItemKind.ReferenceLink, key.AssociationType == AssociationType.OneToMany ? ExplorerIcon.OneToMany : key.AssociationType == AssociationType.ManyToOne ? ExplorerIcon.ManyToOne : ExplorerIcon.OneToOne) { DragText = key.MemberName, ToolTipText = typeName + (key.BackReference == null ? " // Back Reference" : ""), SqlName = key.KeyName, IsEnumerable = key.AssociationType == AssociationType.OneToMany, HyperlinkTarget = dic.ContainsKey(key.OtherTable) ? dic[key.OtherTable] : null, }); } } return(items); }
ExplorerItem GetProcedures(string header, ExplorerIcon icon, List <ProcedureSchema> procedures) { var results = new HashSet <TableSchema>(); var items = new ExplorerItem(header, ExplorerItemKind.Category, icon) { Children = procedures .Select(p => { var sprocSqlName = _sqlBuilder.BuildTableName( new StringBuilder(), null, p.SchemaName == null ? null : (string)_sqlBuilder.Convert(p.SchemaName, ConvertType.NameToOwner), (string)_sqlBuilder.Convert(p.ProcedureName, ConvertType.NameToQueryTable)).ToString(); var memberName = p.MemberName; if (p.IsFunction && !p.IsTableFunction) { var res = p.Parameters.FirstOrDefault(pr => pr.IsResult); if (res != null) { memberName += $" -> {res.ParameterType}"; } } var ret = new ExplorerItem(memberName, ExplorerItemKind.QueryableObject, icon) { DragText = $"{p.MemberName}(" + p.Parameters .Where(pr => !pr.IsResult) .Select(pr => $"{(pr.IsOut ? pr.IsIn ? "ref " : "out " : "")}{pr.ParameterName}") .Join(", ") + ")", SqlName = sprocSqlName, IsEnumerable = p.ResultTable != null, Children = p.Parameters .Where(pr => !pr.IsResult) .Select(pr => new ExplorerItem( $"{pr.ParameterName} ({pr.ParameterType})", ExplorerItemKind.Parameter, ExplorerIcon.Parameter)) .Union(p.ResultTable?.Columns.Select(GetColumnItem) ?? new ExplorerItem[0]) .ToList(), }; if (p.ResultTable != null && !results.Contains(p.ResultTable)) { results.Add(p.ResultTable); CodeTable(Code, p.ResultTable, false); } CodeProcedure(Code, p, sprocSqlName); return(ret); }) .OrderBy(p => p.Text) .ToList(), }; return(items); }
static int GetIconDisplayOrder(ExplorerIcon icon) { switch (icon) { case ExplorerIcon.Column: return 0; case ExplorerIcon.OneToOne: return 1; case ExplorerIcon.OneToMany: return 2; case ExplorerIcon.Table: return 3; case ExplorerIcon.ScalarFunction: return 4; default: return 10; } }
public ExplorerItem(string text, ExplorerItemKind kind, ExplorerIcon icon) { this.Text = text; this.Kind = kind; this.Icon = icon; }
internal static List <ExplorerItem> GetSchemaAndBuildAssembly(ICsvDataContextDriverProperties csvDataContextDriverProperties, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName) { const ExplorerItemKind errorExplorerItemKind = ExplorerItemKind.ReferenceLink; const ExplorerIcon errorExplorerIcon = ExplorerIcon.Box; var csvDatabase = CsvDataModelGenerator.CreateModel(csvDataContextDriverProperties); var(code, tableCodeGroups) = CsvCSharpCodeGenerator.GenerateCode(csvDatabase, ref nameSpace, ref typeName, csvDataContextDriverProperties); var compileErrors = BuildAssembly(code, assemblyToBuild); var hasCompilationErrors = compileErrors.Any(); var schema = GetSchema(csvDatabase); var index = 0; if (hasCompilationErrors || csvDataContextDriverProperties.DebugInfo) { schema.Insert(index++, new ExplorerItem("Data context source code", ExplorerItemKind.Schema, ExplorerIcon.Schema) { ToolTipText = "Drag&drop context source code to text window", DragText = code }); } var exceptions = csvDatabase.Exceptions; if (exceptions.Any()) { var fileOrFolder = $"{exceptions.Pluralize("file")} or {exceptions.Pluralize("folder")}"; schema.Insert(index++, new ExplorerItem($"{exceptions.Count} {fileOrFolder} {exceptions.Pluralize("was", "were")} not processed", errorExplorerItemKind, errorExplorerIcon) { ToolTipText = $"Drag&drop {fileOrFolder} processing {exceptions.Pluralize("error")} to text window", DragText = exceptions.Select(exception => exception.Message).JoinNewLine() }); } if (hasCompilationErrors) { schema.Insert(0, new ExplorerItem("Data context compilation failed", errorExplorerItemKind, errorExplorerIcon) { ToolTipText = "Drag&drop data context compilation errors to text window", DragText = compileErrors.JoinNewLine() }); } else { foreach (var tableCodeGroup in tableCodeGroups.Where(codeGroup => codeGroup.Count() > 1)) { var codeNames = tableCodeGroup.Select(typeCodeResult => typeCodeResult.CodeName).ToImmutableList(); var similarFilesSize = tableCodeGroup.Select(typeCodeResult => typeCodeResult.FilePath).GetHumanizedFileSize(); var filePaths = new HashSet <string>(codeNames); var similarFilesCount = codeNames.Count; schema.Insert(index++, new ExplorerItem($"{codeNames.First()} similar files joined data ({similarFilesCount}/{csvDatabase.Files.Count} files {similarFilesSize})", ExplorerItemKind.QueryableObject, ExplorerIcon.View) { Children = schema.Where(IsSimilarFile).ToList(), IsEnumerable = true, ToolTipText = $"Drag&drop {similarFilesCount} similar files joined data to text window".JoinNewLine( string.Empty, $"{string.Join(Environment.NewLine, similarFilesCount <= 3 ? codeNames : codeNames.Take(2).Concat(new []{ "..." }).Concat(codeNames.Skip(similarFilesCount - 1)))}"), DragText = $@"new [] {{ {string.Join(Environment.NewLine, codeNames.Select(n => $"\t{n},"))} }}.SelectMany(_ => _) " }); if (!csvDataContextDriverProperties.ShowSameFilesNonGrouped) { schema.RemoveAll(IsSimilarFile); } bool IsSimilarFile(ExplorerItem explorerItem) => filePaths !.Contains(explorerItem.Tag); } } if (!csvDatabase.Tables.Any()) { schema.Insert(0, new ExplorerItem("No files found", ExplorerItemKind.Schema, ExplorerIcon.Box)); } return(schema); }