-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* some new properties * create lpx plugin arch after build project * info view of actions (functions) for odata service
- Loading branch information
Showing
14 changed files
with
407 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,137 @@ | ||
using LINQPad.Extensibility.DataContext; | ||
using OData4.UI; | ||
|
||
namespace OData4 | ||
{ | ||
public static class Extensions | ||
{ | ||
public static ConnectionProperties GetConnectionProperties(this IConnectionInfo connectionInfo) | ||
{ | ||
return new ConnectionProperties(connectionInfo); | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml; | ||
using LINQPad.Extensibility.DataContext; | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.Edm.Csdl; | ||
using OData4.UI; | ||
|
||
namespace OData4 | ||
{ | ||
public static class Extensions | ||
{ | ||
public static ConnectionProperties GetConnectionProperties(this IConnectionInfo connectionInfo) | ||
{ | ||
return new ConnectionProperties(connectionInfo); | ||
} | ||
|
||
public static IEdmModel GetModel(this ConnectionProperties properties) | ||
{ | ||
var uri = properties.Uri; | ||
uri += uri.EndsWith("/") ? "$metadata" : "/$metadata"; | ||
|
||
IEdmModel model; | ||
|
||
var settings = new XmlReaderSettings | ||
{ | ||
XmlResolver = new XmlUrlResolver | ||
{ | ||
Credentials = properties.GetCredentials(), | ||
Proxy = properties.GetWebProxy() | ||
} | ||
}; | ||
|
||
using (var reader = XmlReader.Create(uri, settings)) | ||
{ | ||
model = EdmxReader.Parse(reader); | ||
} | ||
|
||
return model; | ||
} | ||
|
||
public static List<ExplorerItem> GetSchema(this IEdmModel model) | ||
{ | ||
var schema = new List<ExplorerItem>(); | ||
|
||
var sets = model.EntityContainer | ||
.EntitySets() | ||
.OrderBy(o => o.Name) | ||
.Select(o => new ExplorerItem(o.Name, ExplorerItemKind.QueryableObject, ExplorerIcon.Table) | ||
{ | ||
IsEnumerable = true, | ||
ToolTipText = o.EntityType().Name, | ||
DragText = o.Name, | ||
|
||
Tag = o.EntityType() | ||
}) | ||
.ToList(); | ||
|
||
foreach (var set in sets) | ||
{ | ||
var parentType = (IEdmEntityType)set.Tag; | ||
var children = new List<ExplorerItem>(); | ||
|
||
for (; parentType != null; parentType = parentType.BaseEntityType()) | ||
{ | ||
children.AddRange(parentType.DeclaredStructuralProperties().Select(o => GetStructuralChildItem(parentType, o))); | ||
children.AddRange(parentType.DeclaredNavigationProperties().Select(o => GetNavigationChildItem(o, sets))); | ||
} | ||
|
||
set.Children = children; | ||
} | ||
|
||
schema.AddRange(sets); | ||
|
||
var actions = model.SchemaElements | ||
.OfType<IEdmAction>() | ||
.Select(o => new ExplorerItem(o.Name, ExplorerItemKind.QueryableObject, ExplorerIcon.ScalarFunction)); | ||
|
||
schema.AddRange(actions); | ||
|
||
return schema; | ||
} | ||
|
||
private static ExplorerItem GetStructuralChildItem(IEdmEntityType parentType, IEdmStructuralProperty property) | ||
{ | ||
var icon = parentType.HasDeclaredKeyProperty(property) | ||
? ExplorerIcon.Key | ||
: ExplorerIcon.Column; | ||
|
||
var name = $"{property.Name} ({property.Type.GetTypeName()})"; | ||
var item = new ExplorerItem(name, ExplorerItemKind.Property, icon) | ||
{ | ||
DragText = property.Name | ||
}; | ||
|
||
return item; | ||
} | ||
|
||
private static ExplorerItem GetNavigationChildItem(IEdmNavigationProperty property, List<ExplorerItem> schema) | ||
{ | ||
var partnerType = property.ToEntityType(); | ||
|
||
var backReferenceType = partnerType.DeclaredNavigationProperties() | ||
.FirstOrDefault(o => o.ToEntityType() == property.DeclaringEntityType()); | ||
|
||
var isCollection = property.Type.IsCollection(); | ||
var kind = isCollection ? ExplorerItemKind.CollectionLink : ExplorerItemKind.ReferenceLink; | ||
ExplorerIcon icon; | ||
|
||
if (backReferenceType == null) | ||
icon = ExplorerIcon.Column; | ||
else if (isCollection) | ||
icon = backReferenceType.Type.IsCollection() ? ExplorerIcon.ManyToMany : ExplorerIcon.OneToMany; | ||
else | ||
icon = backReferenceType.Type.IsCollection() ? ExplorerIcon.ManyToOne : ExplorerIcon.OneToOne; | ||
|
||
var item = new ExplorerItem(property.Name, kind, icon) | ||
{ | ||
ToolTipText = partnerType.Name, | ||
HyperlinkTarget = schema.FirstOrDefault(a => (IEdmEntityType)a.Tag == partnerType), | ||
DragText = property.Name | ||
}; | ||
|
||
return item; | ||
} | ||
|
||
private static string GetTypeName(this IEdmTypeReference type) | ||
{ | ||
var edmCollectionType = type.Definition as IEdmCollectionType; | ||
if (edmCollectionType == null) | ||
return (type.Definition as IEdmNamedElement)?.Name; | ||
|
||
var element1 = edmCollectionType.ElementType.Definition as IEdmNamedElement; | ||
return element1 == null ? null : $"Collection({element1.Name})"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Dmitry Smirnov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
The MIT License (MIT) | ||
Copyright (c) Dmitrii Smirnov | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.23107.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQPadOData4", "LINQPadOData4.csproj", "{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQPadOData4", "LINQPadOData4.csproj", "{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FFB7EA2C-6A45-4F37-BC89-3F34775C588D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.