Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
unchase committed Feb 12, 2020
2 parents 9b9441a + 5d751dd commit 1ec0dee
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private async Task AddGeneratedCodeAsync()
{
MetadataDocumentUri = MetadataUri,
UseDataServiceCollection = this.ServiceConfiguration.UseDataServiceCollection,
UseAsyncDataServiceCollection = this.ServiceConfiguration.UseAsyncDataServiceCollection,
TargetLanguage = this.ServiceConfiguration.LanguageOption == LanguageOption.GenerateCSharpCode ? ODataT4CodeGenerator.LanguageOption.CSharp : ODataT4CodeGenerator.LanguageOption.VB,
IgnoreUnexpectedElementsAndAttributes = this.ServiceConfiguration.IgnoreUnexpectedElementsAndAttributes,
EnableNamingAlias = this.ServiceConfiguration.EnableNamingAlias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ internal class ServiceConfiguration
public string NamespacePrefix { get; set; }

public bool UseDataServiceCollection { get; set; }
/// <summary>
/// Change the INotifyPropertyChanged Implementation to support async operations with synchronous event callbacks
/// </summary>
/// <remarks>This should only be set to true if the <see cref="UseDataServiceCollection"/> is also true.</remarks>
public bool UseAsyncDataServiceCollection { get; set; }

public bool OpenGeneratedFilesOnComplete { get; set; }

Expand Down
9 changes: 9 additions & 0 deletions src/Unchase.OData.ConnectedService/Models/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@ internal class UserSettings
[DataMember]
public LanguageOption LanguageOption { get; set; }

/// <summary>
/// Implement INotifyPropertyChanged in generated proxies to support change tracking
/// </summary>
[DataMember]
public bool UseDataServiceCollection { get; set; }
/// <summary>
/// Change the INotifyPropertyChanged Implementation to support async operations with synchronous event callbacks
/// </summary>
/// <remarks>This should only be set to true if the <see cref="UseDataServiceCollection"/> is also true.</remarks>
[DataMember]
public bool UseAsyncDataServiceCollection { get; set; }

[DataMember]
public string GeneratedFileNamePrefix { get; set; }
Expand Down
237 changes: 189 additions & 48 deletions src/Unchase.OData.ConnectedService/Templates/ODataT4CodeGenerator.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Templates\ODataT4CodeGenerator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>ODataT4CodeGenerator1.cs</LastGenOutput>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Templates\ODataV3ExtensionsT4CodeGenerator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>ODataV3ExtensionsT4CodeGenerator.cs</LastGenOutput>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,41 @@ public bool UseDataServiceCollection
_useDataServiceCollection = value;
UserSettings.UseDataServiceCollection = value;
OnPropertyChanged(nameof(UseDataServiceCollection));
OnPropertyChanged(nameof(ShowAsyncDataServiceCollectionOption));
}
}
#endregion

#region UseAsyncDataServiceCollection
private bool _useAsyncDataServiceCollection;

/// <summary>
/// Change the INotifyPropertyChanged Implementation to support async operations with synchronous event callbacks
/// </summary>
/// <remarks>This should only be set to true is the <see cref="UseDataServiceCollection"/> is also true.</remarks>
public bool UseAsyncDataServiceCollection
{
get => _useAsyncDataServiceCollection;
set
{
_useAsyncDataServiceCollection = value;
UserSettings.UseAsyncDataServiceCollection = value;
OnPropertyChanged(nameof(UseAsyncDataServiceCollection));
}
}
#endregion

#region ShowAsyncDataServiceCollectionOption
/// <summary>
/// Show the advanced option for INotifyPropertyChanged notification that generates async and await compatible bindings
/// only available in C# and when <see cref="UseDataServiceCollection"/> is enabled.
/// </summary>
public bool ShowAsyncDataServiceCollectionOption
{
get => this.UserSettings.LanguageOption == LanguageOption.GenerateCSharpCode && UseDataServiceCollection;
}
#endregion

#region UseNamespacePrefix
private bool _useNamespacePrefix;
public bool UseNamespacePrefix
Expand Down Expand Up @@ -235,6 +266,7 @@ public override async Task OnPageEnteringAsync(WizardEnteringArgs args)

this.View = new AdvancedSettings(this.InternalWizard);
this.UseDataServiceCollection = UserSettings.UseDataServiceCollection;
this.UseAsyncDataServiceCollection = UserSettings.UseAsyncDataServiceCollection;
this.UseNamespacePrefix = UserSettings.UseNameSpacePrefix;
this.NamespacePrefix = UserSettings.NamespacePrefix ?? Constants.DefaultNamespacePrefix;
this.EnableNamingAlias = UserSettings.EnableNamingAlias;
Expand Down
16 changes: 14 additions & 2 deletions src/Unchase.OData.ConnectedService/Views/AdvancedSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,25 @@
VerticalAlignment="Center"
Text="{Binding UserSettings.NamespacePrefix, Mode=TwoWay}"
TextWrapping="Wrap" />
<CheckBox
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<CheckBox
x:Name="UseDsc"
Margin="0,5,0,0"

HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Enable entity and property tracking."
IsChecked="{Binding UserSettings.UseDataServiceCollection, Mode=TwoWay}" />
<TextBlock Margin="10,0,0,0">-</TextBlock>
<CheckBox
x:Name="UseAsyncDsc"
Margin="10,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Implement async binding base. (c# only)"
Visibility="{Binding UserSettings.UseDataServiceCollection}"
IsEnabled="{Binding UserSettings.ShowAsyncDataServiceCollectionOption}"
IsChecked="{Binding UserSettings.UseAsyncDataServiceCollection, Mode=TwoWay}" />
</StackPanel>
<CheckBox
x:Name="SelectOperationImports"
Width="450"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private void OpenConnectedServiceJsonFileButton_Click(object sender, RoutedEvent
this.UserSettings.ExcludedOperationImportsNames = microsoftConnectedServiceData.ExtendedData?.ExcludedOperationImportsNames ?? this.UserSettings.ExcludedOperationImportsNames;
this.UserSettings.UseNameSpacePrefix = microsoftConnectedServiceData.ExtendedData?.UseNameSpacePrefix ?? this.UserSettings.UseNameSpacePrefix;
this.UserSettings.UseDataServiceCollection = microsoftConnectedServiceData.ExtendedData?.UseDataServiceCollection ?? this.UserSettings.UseDataServiceCollection;
this.UserSettings.UseAsyncDataServiceCollection = microsoftConnectedServiceData.ExtendedData?.UseAsyncDataServiceCollection ?? this.UserSettings.UseAsyncDataServiceCollection;
this.UserSettings.ServiceName = microsoftConnectedServiceData.ExtendedData?.ServiceName ?? this.UserSettings.ServiceName;
this.UserSettings.AcceptAllUntrustedCertificates = microsoftConnectedServiceData.ExtendedData?.AcceptAllUntrustedCertificates ?? this.UserSettings.AcceptAllUntrustedCertificates;
this.UserSettings.NamespacePrefix = microsoftConnectedServiceData.ExtendedData?.NamespacePrefix ?? this.UserSettings.NamespacePrefix;
Expand Down
3 changes: 3 additions & 0 deletions src/Unchase.OData.ConnectedService/Wizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Wizard(ConnectedServiceProviderContext context)
AdvancedSettingsViewModel.UseNamespacePrefix = serviceConfig.UseNameSpacePrefix;
AdvancedSettingsViewModel.NamespacePrefix = serviceConfig.NamespacePrefix;
AdvancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection;
AdvancedSettingsViewModel.UseAsyncDataServiceCollection = serviceConfig.UseAsyncDataServiceCollection;
AdvancedSettingsViewModel.OperationImportsGenerator = serviceConfig.OperationImportsGenerator;
AdvancedSettingsViewModel.SelectOperationImports = serviceConfig.GenerateOperationImports;
AdvancedSettingsViewModel.ExcludedOperationImportsNames = serviceConfig.ExcludedOperationImportsNames;
Expand Down Expand Up @@ -100,6 +101,7 @@ public Wizard(ConnectedServiceProviderContext context)
advancedSettingsViewModel.UseNamespacePrefix = serviceConfig.UseNameSpacePrefix;
advancedSettingsViewModel.NamespacePrefix = serviceConfig.NamespacePrefix;
advancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection;
advancedSettingsViewModel.UseAsyncDataServiceCollection = serviceConfig.UseAsyncDataServiceCollection;
advancedSettingsViewModel.OperationImportsGenerator = serviceConfig.OperationImportsGenerator;
advancedSettingsViewModel.SelectOperationImports = serviceConfig.GenerateOperationImports;
advancedSettingsViewModel.ExcludedOperationImportsNames = serviceConfig.ExcludedOperationImportsNames;
Expand Down Expand Up @@ -252,6 +254,7 @@ private ServiceConfiguration CreateServiceConfiguration()
serviceConfiguration.Endpoint = ConfigODataEndpointViewModel.UserSettings.Endpoint;
serviceConfiguration.EdmxVersion = ConfigODataEndpointViewModel.EdmxVersion;
serviceConfiguration.UseDataServiceCollection = AdvancedSettingsViewModel.UserSettings.UseDataServiceCollection;
serviceConfiguration.UseAsyncDataServiceCollection = AdvancedSettingsViewModel.UserSettings.UseAsyncDataServiceCollection;
serviceConfiguration.GeneratedFileNamePrefix = AdvancedSettingsViewModel.UserSettings.GeneratedFileNamePrefix;
serviceConfiguration.UseNameSpacePrefix = AdvancedSettingsViewModel.UserSettings.UseNameSpacePrefix;
serviceConfiguration.OpenGeneratedFilesOnComplete = ConfigODataEndpointViewModel.UserSettings.OpenGeneratedFilesOnComplete;
Expand Down

0 comments on commit 1ec0dee

Please sign in to comment.