Skip to content

Commit

Permalink
1) Add bug fixes in "FunctionImports" generation;
Browse files Browse the repository at this point in the history
2) Add some improvements in the `FunctionImport Settings` wizard page.
  • Loading branch information
Chebotov Nikolay committed Aug 12, 2019
1 parent c9f3bb6 commit 21420f1
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 30 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

These are the changes to each version that has been released on the official [Visual Studio extension gallery](https://marketplace.visualstudio.com/items?itemName=unchase.UnchaseODataConnectedService).

## v1.0.2. `2019-08-11`
## v1.1.0 `2019-08-12`

- [x] Add bug fixes in `FunctionImports` generation
- [x] Add some improvements in the `FunctionImport Settings` wizard page

## v1.0.2 `2019-08-11`

- [x] Add bug fix: downgrade some NuGet-packages for supporting Visual Studio 2017

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.0.{build}
version: 1.1.{build}
pull_requests:
do_not_increment_build_number: true
skip_tags: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ internal static class FunctionImportsExtensions
internal static string FullNameWithNamespace(this IEdmTypeReference type, string proxyClassNamespace)
{
var definition = type?.Definition as IEdmSchemaElement;
if (definition == null && type?.IsCollection() == true)
definition = type?.AsCollection()?.ElementType()?.Definition as IEdmSchemaElement;

return definition?.FullNameWithNamespace(proxyClassNamespace);
}

Expand Down Expand Up @@ -118,9 +121,6 @@ internal static List<FunctionImportModel> GetFunctionImports(IEdmModel model, st

foreach (var modelEntityContainer in model.EntityContainers())
{
if (string.IsNullOrWhiteSpace(proxyClassNamespace))
proxyClassNamespace = modelEntityContainer.Namespace;

foreach (var functionImport in modelEntityContainer.FunctionImports())
result.Add(new FunctionImportModel(model, functionImport, endpointUri, proxyClassNamespace));
}
Expand Down
24 changes: 18 additions & 6 deletions src/Unchase.OData.ConnectedService/Models/FunctionImportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class FunctionImportModel : INotifyPropertyChanged

internal bool HasParameters => FunctionParameters.Count > 0;

internal string EntitySetName { get; }
public string EntitySetName { get; }

public string HttpMethod { get; }

Expand All @@ -42,6 +42,18 @@ public bool IsChecked
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsChecked"));
}
}

private bool _isCollectionReturnTypeChecked;
public bool IsCollectionReturnTypeChecked
{
get => _isCollectionReturnTypeChecked;
set
{
_isCollectionReturnTypeChecked = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsCollectionReturnTypeChecked"));
}
}

public string FunctionImportName { get; set; }

public string ParametersString
Expand All @@ -55,7 +67,7 @@ public string ParametersString
{
if (!first)
parametersString.Append(", ");
parametersString.Append($"{functionParameter.Type.FullNameWithNamespace(Namespace)} {functionParameter.Name}");
parametersString.Append($"{functionParameter.Type.ToCodeStringType(Namespace)} {functionParameter.Name}");
if (first)
first = false;
}
Expand All @@ -67,7 +79,6 @@ public string ParametersString
public string FunctionImportReturnTypeFullName { get; set; }

public string Separator => "|";

#endregion

#region Constructors
Expand All @@ -76,14 +87,15 @@ internal FunctionImportModel(IEdmModel model, IEdmFunctionImport functionImport,
FunctionImport = functionImport;
FunctionImportName = functionImport.Name;
EndpointUri = endpointUri;
HttpMethod = model.GetHttpMethod(functionImport) ?? "POST";
HttpMethod = model.GetHttpMethod(functionImport) ?? "POST"; //ToDo: if null, then - UNKNOWN
FunctionParameters = functionImport.Parameters.ToList();
BindableParameter = FunctionParameters.FirstOrDefault(fp => fp.Type.IsEntity() || fp.Type.IsCollection() && fp.Type.AsCollection().ElementType().IsEntity());
BindableParameter = functionImport.IsBindable ? FunctionParameters.FirstOrDefault(fp => fp.Type.IsEntity() || fp.Type.IsCollection() && fp.Type.AsCollection().ElementType().IsEntity()) : null;
EntitySetName = functionImport.IsBindable && BindableParameter != null
? (BindableParameter.Type.IsCollection() ? BindableParameter.Type.AsCollection().ElementType().FullNameWithNamespace(proxyClassNamespace).Split('.').Last() : BindableParameter.Type.FullNameWithNamespace(proxyClassNamespace).Split('.').Last())
: string.Empty;
FunctionReturnType = functionImport.ReturnType;
FunctionImportReturnTypeFullName = FunctionReturnType.FullNameWithNamespace(proxyClassNamespace) ?? "void";
FunctionImportReturnTypeFullName = functionImport.ReturnType?.ToCodeStringType(proxyClassNamespace) ?? "void";
IsCollectionReturnTypeChecked = functionImport.ReturnType?.IsCollection() ?? false;
Namespace = proxyClassNamespace;
IsChecked = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Unchase.OData.ConnectedService/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: NeutralResourcesLanguage("en")]

2 changes: 1 addition & 1 deletion src/Unchase.OData.ConnectedService/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Provider()
BitmapSizeOptions.FromWidthAndHeight(32, 32)
);
CreatedBy = Constants.Author;
Version = new Version(0, 4, 0, 0);
Version = new Version(1, 1, 0, 0);
Version = typeof(Provider).Assembly.GetName().Version;
MoreInfoUri = new Uri(Constants.Website);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal class FunctionImportsViewModel : ConnectedServiceWizardPage
public UserSettings UserSettings { get; }

public List<FunctionImportModel> FunctionImports { get; set; }

public int FunctionImportsCount { get; set; } = 0;
#endregion

#region Constructors
Expand All @@ -25,6 +27,7 @@ public FunctionImportsViewModel(UserSettings userSettings) : base()
this.Description = "Function Imports Settings for select the necessary methods that will be added after generation";
this.Legend = "Function Imports Settings";
this.FunctionImports = new List<FunctionImportModel>();
this.FunctionImportsCount = FunctionImports.Count;
this.UserSettings = userSettings;
}
#endregion
Expand All @@ -37,6 +40,7 @@ public override async Task OnPageEnteringAsync(WizardEnteringArgs args)
await base.OnPageEnteringAsync(args);

this.View = new FunctionImports {DataContext = this};
this.FunctionImportsCount = this.FunctionImports.Count;
PageEntering?.Invoke(this, EventArgs.Empty);
}

Expand Down
48 changes: 37 additions & 11 deletions src/Unchase.OData.ConnectedService/Views/FunctionImports.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,76 @@
d:DesignWidth="500"
mc:Ignorable="d">
<StackPanel>
<TextBlock
Margin="0,0,0,5"
FontWeight="Bold"
Text="{Binding FunctionImportsCount, StringFormat='FunctionImports count: {0}'}" />
<TextBlock
x:Name="Label"
Margin="0,0,0,5"
TextWrapping="WrapWithOverflow">
You can select the necessary methods that will be added after generation:
</TextBlock>
<TextBlock
Margin="0,0,0,5"
FontSize="10"
TextWrapping="WrapWithOverflow">
Add? | Http-Method | ReturnType is Collection | [ReturnType] [EntitySet][FunctionImport Name] ([parameters list])
</TextBlock>
<ListBox
MinHeight="345"
MinHeight="300"
ItemsSource="{Binding FunctionImports}"
VerticalContentAlignment="Center"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<CheckBox
Width="18"
Width="16"
VerticalContentAlignment="Center"
VerticalAlignment="Center"
Margin="0,5,8,0"
IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock
Width="2"
Margin="0,3,8,0"
Text="{Binding Separator}" />
<TextBlock
Width="30"
Margin="0,5,8,0"
FontWeight="Bold"
Text="{Binding HttpMethod}" />
<TextBlock
Width="5"
Width="2"
Margin="0,3,8,0"
Text="{Binding Separator}" />
<CheckBox
Width="16"
Margin="0,5,8,0"
IsEnabled="False"
IsChecked="{Binding IsCollectionReturnTypeChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock
Width="2"
Margin="0,3,8,0"
Text="{Binding Separator}" />
<TextBlock
Margin="0,5,8,0"
FontSize="10"
Foreground="CornflowerBlue"
Text="{Binding FunctionImportReturnTypeFullName}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</TextBlock.Style>
</TextBlock>
<TextBlock
Margin="0,5,8,0"
Margin="0,3,0,0"
FontWeight="Bold"
Foreground="Coral"
Text="{Binding EntitySetName}" />
<TextBlock
Margin="0,3,8,0"
FontWeight="Bold"
Foreground="Coral"
Text="{Binding FunctionImport.Name}" />
<TextBlock Margin="0,5,8,0" Text="{Binding ParametersString}" />
<TextBlock Margin="0,3,8,0" Text="{Binding ParametersString}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Expand Down
19 changes: 16 additions & 3 deletions src/Unchase.OData.ConnectedService/Wizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -114,7 +115,8 @@ public Wizard(ConnectedServiceProviderContext context)
}
};

FunctionImportsViewModel.FunctionImports = serviceConfig.FunctionImports;
FunctionImportsViewModel.FunctionImports = serviceConfig.FunctionImports ?? new List<FunctionImportModel>();
FunctionImportsViewModel.FunctionImportsCount = serviceConfig.FunctionImports?.Count ?? 0;
}

AdvancedSettingsViewModel.PageEntering += (sender, args) =>
Expand All @@ -137,12 +139,23 @@ public Wizard(ConnectedServiceProviderContext context)
{
if (sender is FunctionImportsViewModel functionImportsViewModel)
{
if (FunctionImportsViewModel.FunctionImports == null || !FunctionImportsViewModel.FunctionImports.Any() || FunctionImportsViewModel.FunctionImports.Any(fi => !ConfigODataEndpointViewModel.Endpoint.Contains(fi.EndpointUri)))
if (FunctionImportsViewModel.FunctionImports == null ||
!FunctionImportsViewModel.FunctionImports.Any() ||
AdvancedSettingsViewModel.UseNamespacePrefix && FunctionImportsViewModel.FunctionImports.Any(fi => fi.Namespace != AdvancedSettingsViewModel.NamespacePrefix) ||
FunctionImportsViewModel.FunctionImports.Any(fi =>
!ConfigODataEndpointViewModel.Endpoint.Contains(fi.EndpointUri)))
{
FunctionImportsViewModel.FunctionImports = FunctionImportsHelper.GetFunctionImports(
this.CreateServiceConfiguration().GetEdmModel(),
AdvancedSettingsViewModel.UseNamespacePrefix ? AdvancedSettingsViewModel.NamespacePrefix : null,
AdvancedSettingsViewModel.UseNamespacePrefix
? AdvancedSettingsViewModel.NamespacePrefix
: null,
ConfigODataEndpointViewModel.Endpoint.Replace("$metadata", string.Empty));
FunctionImportsViewModel.FunctionImportsCount = FunctionImportsViewModel.FunctionImports?.Count ?? 0;
}

functionImportsViewModel.FunctionImports = FunctionImportsViewModel.FunctionImports;
functionImportsViewModel.FunctionImportsCount = functionImportsViewModel.FunctionImports?.Count ?? 0;
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" ?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Unchase.OData.ConnectedService.afc46f39-8c64-4e14-85d0-af6c7c4291f3" Version="1.0" Language="en-US" Publisher="Unchase" />
<DisplayName>Unchase OData ConnectedService</DisplayName>
<Identity Id="Unchase.OData.ConnectedService.afc46f39-8c64-4e14-85d0-af6c7c4291f3" Version="1.1" Language="en-US" Publisher="Unchase" />
<DisplayName>Unchase OData Connected Service</DisplayName>
<Description xml:space="preserve">OData V1-V4 connected service with extension methods for client-side proxy class.</Description>
<MoreInfo>https://github.com/unchase/Unchase.Odata.Connectedservice</MoreInfo>
<License>Resources\EULA.txt</License>
Expand Down

0 comments on commit 21420f1

Please sign in to comment.