Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #86 #87

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public override async Task AddNugetPackagesAsync()
await CheckAndInstallNuGetPackageAsync(Common.Constants.NuGetOnlineRepository, nugetPackage);

await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Nuget Packages for OData V4 were installed.");

if (this.ServiceConfiguration.EmbedEdmxFile)
{
await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Adding Nuget Packages for embedded Edmx resource...");

await CheckAndInstallNuGetPackageAsync(Common.Constants.NuGetOnlineRepository, Common.Constants.MSEmbeddedResourcePackage);

await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Nuget Packages for embedded Edmx resource were installed.");
}
}

internal async Task CheckAndInstallNuGetPackageAsync(string packageSource, string nugetPackage)
Expand Down Expand Up @@ -148,6 +157,7 @@ private async Task AddGeneratedCodeAsync()
IgnoreUnexpectedElementsAndAttributes = this.ServiceConfiguration.IgnoreUnexpectedElementsAndAttributes,
EnableNamingAlias = this.ServiceConfiguration.EnableNamingAlias,
NamespacePrefix = this.ServiceConfiguration.NamespacePrefix,
EmbedEdmxFilePath = this.ServiceConfiguration.EmbedEdmxFile ? Path.Combine(this.Context.HandlerHelper.GetServiceArtifactsRootFolder(), this.Context.ServiceInstance.Name, $"{this.GeneratedFileNamePrefix}.edmx").Replace('\\', '.').Replace(' ', '_') : null,
ExcludedOperationImportsNames = this.ServiceConfiguration?.ExcludedOperationImportsNames,
GenerateDynamicPropertiesCollection = this.ServiceConfiguration.GenerateDynamicPropertiesCollection,
DynamicPropertiesCollectionName = this.ServiceConfiguration?.DynamicPropertiesCollectionName,
Expand All @@ -171,6 +181,15 @@ private async Task AddGeneratedCodeAsync()
var outputFile = Path.Combine(this.ReferenceFileFolder, $"{this.GeneratedFileNamePrefix}{(this.ServiceConfiguration.LanguageOption == LanguageOption.GenerateCSharpCode ? ".cs" : ".vb")}");
await this.Context.HandlerHelper.AddFileAsync(tempFile, outputFile, new AddFileOptions { OpenOnComplete = this.Instance.ServiceConfig.OpenGeneratedFilesOnComplete });

if (this.ServiceConfiguration.EmbedEdmxFile)
{
var projFilePath = Path.Combine(this.ReferenceFileFolder, $"{this.GeneratedFileNamePrefix}.edmx");
File.WriteAllText(projFilePath, t4CodeGenerator.Edmx);

var item = this.Project.ProjectItems.AddFromFile(projFilePath);
item.Properties.Item("ItemType").Value = "EmbeddedResource";
}

await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Client Proxy for OData V4 was generated.");
}

Expand Down
2 changes: 2 additions & 0 deletions src/Unchase.OData.ConnectedService.Shared/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal static class Constants
public const string V4EdmNuGetPackage = "Microsoft.OData.Edm";
public const string V4SpatialNuGetPackage = "Microsoft.Spatial";

public const string MSEmbeddedResourcePackage = "Microsoft.Extensions.FileProviders.Embedded";

public const string EdmxVersion1Namespace = "http://schemas.microsoft.com/ado/2007/06/edmx";
public const string EdmxVersion2Namespace = "http://schemas.microsoft.com/ado/2008/10/edmx";
public const string EdmxVersion3Namespace = "http://schemas.microsoft.com/ado/2009/11/edmx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ internal class ServiceConfigurationV4 : ServiceConfigurationV3

public bool IncludeT4File { get; set; }

public bool EmbedEdmxFile { get; set; }

public bool MakeTypesInternal { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ internal class UserSettings
[DataMember]
public bool IncludeT4File { get; set; }

[DataMember]
public bool EmbedEdmxFile { get; set; }

[DataMember]
public bool MakeTypesInternal { get; set; }

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ public abstract class ODataClientTemplate : TemplateBase
}
}

internal string GetFixedName(string originalName)
internal virtual string GetFixedName(string originalName)
{
string fixedName = originalName;

Expand Down Expand Up @@ -3442,6 +3442,19 @@ public sealed class ODataClientCSharpTemplate : ODataClientTemplate
internal override string ODataVersion { get { return "global::Microsoft.OData.ODataVersion.V4"; } }
internal override string ParameterDeclarationTemplate { get { return "{0} {1}"; } }
internal override string DictionaryItemConstructor { get { return "{{ {0}, {1} }}"; } }

internal override string GetFixedName(string originalName)
{
string fixedName = originalName;

if (this.LanguageKeywords.Contains(fixedName))
{
fixedName = string.Format(this.FixPattern, fixedName);
}

return (fixedName ?? String.Empty).Replace(' ', '_');
}

internal override HashSet<string> LanguageKeywords { get {
if (CSharpKeywords == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
using System.Threading.Tasks;
using System.Windows;
using Microsoft.VisualStudio.ConnectedServices;
using Unchase.OData.ConnectedService.Common;
using Microsoft.VisualStudio.Debugger.Interop;
using Common = Unchase.OData.ConnectedService.Common;
using Unchase.OData.ConnectedService.Models;
using Unchase.OData.ConnectedService.Views;

Expand All @@ -15,8 +16,8 @@ namespace Unchase.OData.ConnectedService.ViewModels
internal class AdvancedSettingsViewModel : ConnectedServiceWizardPage
{
#region Properties and fields
public Constants.OperationImportsGenerator[] OperationImportsGenerators =>
new[] { Constants.OperationImportsGenerator.Inner, Constants.OperationImportsGenerator.SimpleOData};
public Common.Constants.OperationImportsGenerator[] OperationImportsGenerators =>
new[] { Common.Constants.OperationImportsGenerator.Inner, Common.Constants.OperationImportsGenerator.SimpleOData};

#region UseDataServiceCollection
private bool _useDataServiceCollection;
Expand Down Expand Up @@ -183,6 +184,24 @@ public bool IncludeT4File
}
#endregion

#region EmbedEdmxFileEnabled
public bool EmbedEdmxFileEnabled { get; set; }
#endregion

#region EmbedEdmxFile
private bool _embedEdmxFile;
public bool EmbedEdmxFile
{
get => _embedEdmxFile;
set
{
_embedEdmxFile = value;
UserSettings.EmbedEdmxFile = value;
OnPropertyChanged(nameof(EmbedEdmxFile));
}
}
#endregion

#region MakeTypesInternal
private bool _makeTypesInternal;
public bool MakeTypesInternal
Expand Down Expand Up @@ -212,8 +231,8 @@ public bool IncludeExtensionsT4File
#endregion

#region OperationImportsGenerator
private Constants.OperationImportsGenerator _operationImportsGenerator;
public Constants.OperationImportsGenerator OperationImportsGenerator
private Common.Constants.OperationImportsGenerator _operationImportsGenerator;
public Common.Constants.OperationImportsGenerator OperationImportsGenerator
{
get => _operationImportsGenerator;
set
Expand Down Expand Up @@ -282,15 +301,17 @@ public override async Task OnPageEnteringAsync(WizardEnteringArgs args)
this.UseDataServiceCollection = UserSettings.UseDataServiceCollection;
this.UseAsyncDataServiceCollection = UserSettings.UseAsyncDataServiceCollection;
this.UseNamespacePrefix = UserSettings.UseNameSpacePrefix;
this.NamespacePrefix = UserSettings.NamespacePrefix ?? Constants.DefaultNamespacePrefix;
this.NamespacePrefix = UserSettings.NamespacePrefix ?? Common.Constants.DefaultNamespacePrefix;
this.EnableNamingAlias = UserSettings.EnableNamingAlias;
this.IgnoreUnexpectedElementsAndAttributes = UserSettings.IgnoreUnexpectedElementsAndAttributes;
this.GenerateDynamicPropertiesCollection = UserSettings.GenerateDynamicPropertiesCollection;
this.DynamicPropertiesCollectionName = UserSettings.DynamicPropertiesCollectionName;
this.GeneratedFileNameEnabled = true;
this.GeneratedFileNamePrefix = UserSettings.GeneratedFileNamePrefix ?? Constants.DefaultReferenceFileName;
this.GeneratedFileNamePrefix = UserSettings.GeneratedFileNamePrefix ?? Common.Constants.DefaultReferenceFileName;
this.IncludeT4FileEnabled = true;
this.IncludeT4File = UserSettings.IncludeT4File;
this.EmbedEdmxFileEnabled = true;
this.EmbedEdmxFile = UserSettings.EmbedEdmxFile;
this.MakeTypesInternal = UserSettings.MakeTypesInternal;
this.IncludeExtensionsT4File = UserSettings.IncludeExtensionsT4File;
this.OperationImportsGenerator = UserSettings.OperationImportsGenerator;
Expand Down
Loading