Example #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------
        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;
            }
        }
Example #2
0
 public ExplorerItem(string text, ExplorerItemKind kind, ExplorerIcon icon)
 {
     this.Text = text;
     this.Kind = kind;
     this.Icon = icon;
 }
Example #3
0
 public ExplorerItem(string text, ExplorerItemKind kind, ExplorerIcon icon)
 {
     this.Text = text;
     this.Kind = kind;
     this.Icon = icon;
 }
Example #4
0
        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);
        }