Skip to content

Commit

Permalink
Merge branch 'OData:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pbru87 authored Jan 29, 2024
2 parents 43cae88 + 46241bb commit 3df23cf
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 73 deletions.
13 changes: 11 additions & 2 deletions src/Microsoft.OData.Cli/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ public GenerateCommand()

this.AddOption(upperCamelCase);

Option internalModifier = new Option<bool>(new[] { "--internal", "-i" })
Option internalModifier = new Option<bool>(new[] { "--enable-internal", "-i" })
{
Name = "internal",
Name = "enable-internal",
Description = "Apply the \"internal\" class modifier on generated classes instead of \"public\" thereby making them invisible outside the assembly."
};

this.AddOption(internalModifier);

Option noTimestamp = new Option<bool>(new[] { "--no-timestamp", "-nt" })
{
Name = "no-timestamp",
Description = "Omit generation timestamp in generated files.",
};
noTimestamp.SetDefaultValue(false);
this.AddOption(noTimestamp);

Option multipleFiles = new Option<bool>(new[] { "--multiple-files" })
{
Name = "multiple-files",
Expand Down Expand Up @@ -240,6 +248,7 @@ private async Task GenerateCodeForV4Clients(GenerateOptions generateOptions, ICo
serviceConfigurationV4.IgnoreUnexpectedElementsAndAttributes = generateOptions.IgnoreUnexpectedElements;
serviceConfigurationV4.EnableNamingAlias = generateOptions.UpperCamelCase;
serviceConfigurationV4.UseDataServiceCollection = generateOptions.EnableTracking;
serviceConfigurationV4.NoTimestamp = generateOptions.NoTimestamp;

Project project = ProjectHelper.CreateProjectInstance(generateOptions.OutputDir);
BaseCodeGenDescriptor codeGenDescriptor = new CodeGenDescriptorFactory().Create(
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.OData.Cli/GenerateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public class GenerateOptions
/// </summary>
public bool EnableTracking { get; set; }

/// <summary>
/// Omit generation timestamp in generated files.
/// </summary>
public bool NoTimestamp { get; set; }

/// <summary>
/// Disables/Enables upper camel casing
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public V4CodeGenDescriptor(IFileHandler fileHandler, IMessageLogger logger, IPac
{
ClientNuGetPackageName = Common.Constants.V4ClientNuGetPackage;
ClientDocUri = Common.Constants.V4DocUri;
// ServiceConfiguration = base.ServiceConfiguration as ServiceConfigurationV4;
CodeGeneratorFactory = codeGeneratorFactory;
}

Expand Down Expand Up @@ -95,7 +94,7 @@ private async Task AddT4FileAsync(string metadata, string outputDirectory, Langu
await writer.WriteLineAsync("</edmx:Edmx>");
}

await FileHandler.AddFileAsync(csdlTempFile, metadataFile, new ODataFileOptions { SuppressOverwritePrompt = true});
await FileHandler.AddFileAsync(csdlTempFile, metadataFile, new ODataFileOptions { SuppressOverwritePrompt = true });

FileHandler.SetFileAsEmbeddedResource(csdlFileName);

Expand Down Expand Up @@ -162,12 +161,13 @@ private async Task AddGeneratedCodeAsync(string metadata, string outputDirectory
t4CodeGenerator.EnableNamingAlias = serviceConfiguration.EnableNamingAlias;
t4CodeGenerator.NamespacePrefix = serviceConfiguration.NamespacePrefix;
t4CodeGenerator.MakeTypesInternal = serviceConfiguration.MakeTypesInternal;
t4CodeGenerator.NoTimestamp = serviceConfiguration.NoTimestamp;
t4CodeGenerator.GenerateMultipleFiles = serviceConfiguration.GenerateMultipleFiles;
t4CodeGenerator.ExcludedOperationImports = serviceConfiguration.ExcludedOperationImports;
t4CodeGenerator.ExcludedBoundOperations = serviceConfiguration.ExcludedBoundOperations;
t4CodeGenerator.ExcludedSchemaTypes = serviceConfiguration.ExcludedSchemaTypes;
var headers = new List<string>();
if (serviceConfiguration.CustomHttpHeaders !=null)
if (serviceConfiguration.CustomHttpHeaders != null)
{
var headerElements = serviceConfiguration.CustomHttpHeaders.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var headerElement in headerElements)
Expand All @@ -191,7 +191,7 @@ private async Task AddGeneratedCodeAsync(string metadata, string outputDirectory
// Csdl file name is this format [ServiceName]Csdl.xml
var csdlFileName = string.Concat(serviceConfiguration.ServiceName, Common.Constants.CsdlFileNameSuffix);
var metadataFile = Path.Combine(referenceFolder, csdlFileName);
await FileHandler.AddFileAsync(tempFile, metadataFile, new ODataFileOptions { SuppressOverwritePrompt = true});
await FileHandler.AddFileAsync(tempFile, metadataFile, new ODataFileOptions { SuppressOverwritePrompt = true });

FileHandler.SetFileAsEmbeddedResource(csdlFileName);
t4CodeGenerator.EmitContainerPropertyAttribute = FileHandler.EmitContainerPropertyAttribute();
Expand All @@ -213,7 +213,7 @@ private async Task AddGeneratedCodeAsync(string metadata, string outputDirectory
}

var outputFile = Path.Combine(referenceFolder, $"{this.GeneratedFileNamePrefix(serviceConfiguration.GeneratedFileNamePrefix)}{(languageOption == LanguageOption.GenerateCSharpCode ? ".cs" : ".vb")}");
await FileHandler.AddFileAsync(tempFile, outputFile, new ODataFileOptions { SuppressOverwritePrompt = true});
await FileHandler.AddFileAsync(tempFile, outputFile, new ODataFileOptions { SuppressOverwritePrompt = true });
t4CodeGenerator.MultipleFilesManager?.GenerateFiles(serviceConfiguration.GenerateMultipleFiles, FileHandler, MessageLogger, referenceFolder, true, serviceConfiguration.OpenGeneratedFilesInIDE);
await MessageLogger.WriteMessageAsync(LogMessageCategory.Information, "Client Proxy for OData V4 was generated.");
}
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.OData.CodeGen/Microsoft.OData.CodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
<Compile Include="FileHandling\ODataFileOptions.cs" />
<Compile Include="Logging\IMessageLogger.cs" />
<Compile Include="Logging\LogMessageCategory.cs" />
<Compile Include="Logging\LogMessageCategory.cs" />
<Compile Include="PackageInstallation\IPackageInstaller.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Models\BoundOperationModel.cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.OData.CodeGen/Models/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ServiceConfiguration
public string WebProxyNetworkCredentialsDomain { get; set; }
public bool IncludeCustomHeaders { get; set; }
public bool StoreCustomHttpHeaders { get; set; }
public List<string> ExcludedSchemaTypes { get; set; }
public List<string> ExcludedSchemaTypes { get; set; }

}

Expand All @@ -43,5 +43,6 @@ public class ServiceConfigurationV4 : ServiceConfiguration
public bool IncludeT4File { get; set; }
public List<string> ExcludedOperationImports { get; set; }
public List<string> ExcludedBoundOperations { get; set; }
public bool NoTimestamp { get; set; }
}
}
41 changes: 38 additions & 3 deletions src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public virtual string TransformText()
MetadataFileRelativePath = this.MetadataFileRelativePath,
MakeTypesInternal = this.MakeTypesInternal,
MultipleFilesManager = new FilesManager(null),
NoTimestamp = this.NoTimestamp,
GenerateMultipleFiles = this.GenerateMultipleFiles,
ExcludedOperationImports = this.ExcludedOperationImports,
ExcludedBoundOperations = this.ExcludedBoundOperations,
Expand Down Expand Up @@ -113,6 +114,7 @@ public virtual string TransformText()
MetadataFileRelativePath = this.MetadataFileRelativePath,
MakeTypesInternal = this.MakeTypesInternal,
MultipleFilesManager = new FilesManager(null),
NoTimestamp = this.NoTimestamp,
GenerateMultipleFiles = this.GenerateMultipleFiles,
ExcludedOperationImports = this.ExcludedOperationImports,
ExcludedBoundOperations = this.ExcludedBoundOperations,
Expand Down Expand Up @@ -204,6 +206,9 @@ public static class Configuration
// thereby making them invisible outside the assembly
public const bool MakeTypesInternal = false;

// If set to true, generation timestamps will be left out of generated files
public const bool NoTimestamp = false;

//This files indicates whether to generate the files into multiple files or single.
//If set to true then multiple files will be generated. Otherwise only a single file is generated.
public const bool GenerateMultipleFiles = false;
Expand Down Expand Up @@ -391,6 +396,15 @@ public bool MakeTypesInternal
set;
}

/// <summary>
/// true to omit generation timestamp; otherwise false.
/// </summary>
public bool NoTimestamp
{
get;
set;
}

private IEnumerable<string> excludedOperationImports = new List<string>();

/// <summary>
Expand Down Expand Up @@ -735,6 +749,7 @@ private void ApplyParametersFromConfigurationClass()
this.EnableNamingAlias = Configuration.EnableNamingAlias;
this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes;
this.MakeTypesInternal = Configuration.MakeTypesInternal;
this.NoTimestamp = Configuration.NoTimestamp;
this.MetadataFilePath = Configuration.MetadataFilePath;
this.MetadataFileRelativePath = Configuration.MetadataFileRelativePath;
this.GenerateMultipleFiles = Configuration.GenerateMultipleFiles;
Expand Down Expand Up @@ -1188,6 +1203,15 @@ public bool MakeTypesInternal
set;
}

/// <summary>
/// true to omit generation timestamp; otherwise false.
/// </summary>
public bool NoTimestamp
{
get;
set;
}

/// <summary>
/// list of operation imports to omit from the generated code
/// </summary>
Expand Down Expand Up @@ -4155,14 +4179,20 @@ internal override void WriteFileHeader()

this.Write("\r\n//\r\n// Changes to this file may cause incorrect behavior and will be lost i" +
"f\r\n// the code is regenerated.\r\n// </auto-generated>\r\n//--------------------" +
"----------------------------------------------------------\r\n\r\n// Generation date" +
": ");
"----------------------------------------------------------\r\n\r\n");


if (!this.context.NoTimestamp)
{

this.Write("// Generation date: ");

this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now.ToString(global::System.Globalization.CultureInfo.CurrentCulture)));

this.Write("\r\n");


}
}

internal override void WriteNamespaceStart(string fullNamespace)
Expand Down Expand Up @@ -6296,15 +6326,20 @@ internal override void WriteFileHeader()
Option Strict Off
Option Explicit On
");


'Generation date: ");
if (!this.context.NoTimestamp)
{

this.Write("\'Generation date: ");

this.Write(this.ToStringHelper.ToStringWithCulture(DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture)));

this.Write("\r\n");


}
}

internal override void WriteNamespaceStart(string fullNamespace)
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.tt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static class Configuration
// thereby making them invisible outside the assembly
public const bool MakeTypesInternal = false;

// If set to true, generation timestamps will be left out of generated files
public const bool NoTimestamp = false;

//This files indicates whether to generate the files into multiple files or single.
//If set to true then multiple files will be generated. Otherwise only a single file is generated.
public const bool GenerateMultipleFiles = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
MetadataFileRelativePath = this.MetadataFileRelativePath,
MakeTypesInternal = this.MakeTypesInternal,
MultipleFilesManager = new FilesManager(null),
NoTimestamp = this.NoTimestamp,
GenerateMultipleFiles = this.GenerateMultipleFiles,
ExcludedOperationImports = this.ExcludedOperationImports,
ExcludedBoundOperations = this.ExcludedBoundOperations,
Expand Down Expand Up @@ -92,6 +93,7 @@
MetadataFileRelativePath = this.MetadataFileRelativePath,
MakeTypesInternal = this.MakeTypesInternal,
MultipleFilesManager = new FilesManager(null),
NoTimestamp = this.NoTimestamp,
GenerateMultipleFiles = this.GenerateMultipleFiles,
ExcludedOperationImports = this.ExcludedOperationImports,
ExcludedBoundOperations = this.ExcludedBoundOperations,
Expand Down Expand Up @@ -249,6 +251,15 @@ public bool MakeTypesInternal
set;
}

/// <summary>
/// true to omit generation timestamp; otherwise false.
/// </summary>
public bool NoTimestamp
{
get;
set;
}

private IEnumerable<string> excludedOperationImports = new List<string>();

/// <summary>
Expand Down Expand Up @@ -593,6 +604,7 @@ private void ApplyParametersFromConfigurationClass()
this.EnableNamingAlias = Configuration.EnableNamingAlias;
this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes;
this.MakeTypesInternal = Configuration.MakeTypesInternal;
this.NoTimestamp = Configuration.NoTimestamp;
this.MetadataFilePath = Configuration.MetadataFilePath;
this.MetadataFileRelativePath = Configuration.MetadataFileRelativePath;
this.GenerateMultipleFiles = Configuration.GenerateMultipleFiles;
Expand Down Expand Up @@ -1046,6 +1058,15 @@ public class CodeGenerationContext
set;
}

/// <summary>
/// true to omit generation timestamp; otherwise false.
/// </summary>
public bool NoTimestamp
{
get;
set;
}

/// <summary>
/// list of operation imports to omit from the generated code
/// </summary>
Expand Down Expand Up @@ -4014,9 +4035,14 @@ public sealed class ODataClientCSharpTemplate : ODataClientTemplate
// </auto-generated>
//------------------------------------------------------------------------------

<#+
if (!this.context.NoTimestamp)
{
#>
// Generation date: <#= DateTime.Now.ToString(global::System.Globalization.CultureInfo.CurrentCulture) #>
<#+
}
}

internal override void WriteNamespaceStart(string fullNamespace)
{
Expand Down Expand Up @@ -5211,11 +5237,14 @@ public sealed class ODataClientVBTemplate : ODataClientTemplate

Option Strict Off
Option Explicit On


<#+
if (!this.context.NoTimestamp)
{
#>
'Generation date: <#= DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture) #>
<#+
}
}

internal override void WriteNamespaceStart(string fullNamespace)
{
Expand Down
13 changes: 13 additions & 0 deletions src/ODataConnectedService.Shared/Models/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class UserSettings : INotifyPropertyChanged

private bool ignoreUnexpectedElementsAndAttributes;

private bool noTimestamp;

private bool includeT4File;

private bool includeWebProxy;
Expand Down Expand Up @@ -236,6 +238,17 @@ public bool IgnoreUnexpectedElementsAndAttributes
}
}

[DataMember]
public bool NoTimestamp
{
get { return noTimestamp; }
set
{
noTimestamp = value;
OnPropertyChanged();
}
}

[DataMember]
public bool IncludeT4File
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
using System.Threading.Tasks;
using Microsoft.OData.CodeGen.Common;
using Microsoft.OData.CodeGen.Models;
using Microsoft.OData.CodeGen;
using Microsoft.OData.ConnectedService.Common;
using Microsoft.OData.ConnectedService.ViewModels;
using Microsoft.OData.ConnectedService.Views;
using Microsoft.OData.Edm;
using Microsoft.VisualStudio.ConnectedServices;
using Microsoft.OData.ConnectedService.Common;

namespace Microsoft.OData.ConnectedService
{
Expand Down Expand Up @@ -187,6 +186,7 @@ public void AdvancedSettingsViewModel_PageEntering(object sender, EventArgs args

if (ServiceConfig.EdmxVersion == Constants.EdmxVersion4)
{
advancedSettings.NoTimestamp.IsEnabled = !Context.IsUpdating;
advancedSettings.IncludeT4File.IsEnabled = !Context.IsUpdating;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/ODataConnectedService.Shared/Views/AdvancedSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0, 5">
<TextBlock TextWrapping="Wrap" Margin="0, 0, 40, 0">Make generated types internal (Enable this if you don't want to expose the generated types outside of your assembly.)</TextBlock>
</CheckBox>
<CheckBox x:Name="NoTimestamp" IsChecked="{Binding Path=UserSettings.NoTimestamp, Mode=TwoWay}"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0, 5">
<TextBlock TextWrapping="Wrap" Margin="0, 0, 40, 0">Omit generation timestamp in generated files (Enable this if you don't need generation timestamps in generated files.)</TextBlock>
</CheckBox>
<CheckBox x:Name="IncludeT4File" Content="Add code templates (Whether to include the T4 files into this project.)" IsChecked="{Binding Path=UserSettings.IncludeT4File, Mode=TwoWay}"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0, 15" FontWeight="Medium"/>
<CheckBox x:Name="OpenGeneratedFilesInIDE" Content="Open generated files in the IDE when generation completes." IsChecked="{Binding Path=UserSettings.OpenGeneratedFilesInIDE, Mode=TwoWay}"
Expand Down
Loading

0 comments on commit 3df23cf

Please sign in to comment.