Skip to content

Commit

Permalink
Add used options to output of code generated, issue #35
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-hassan committed Mar 8, 2021
1 parent c8095fe commit 54b798c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 20 deletions.
24 changes: 24 additions & 0 deletions OData2Poco.CommandLine.Test/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NUnit.Framework;
using OData2Poco.TestUtility;
Expand Down Expand Up @@ -403,6 +404,29 @@ public async Task Url_test(string url, string version, int n)
Assert.IsTrue(output.Contains("public partial class Product")); //-v

}

[Test]
[Category("code_header")]
[TestCaseSource(typeof(TestSample), nameof(TestSample.FileCases))]
[TestCaseSource(typeof(TestSample), nameof(TestSample.UrlNorthwindCases))]
public async Task CodeHeaderTest(string url, string version, int n)
{
//Arrange
var a = $"-r {url} -v";
//Act
var tuble = await RunCommand(a);
var output = tuble.Item2;

//Assert
var line = $"// Service Url: {url}";
Assert.IsTrue(output.Contains(line));
line = @"
// Parameters:
// -f CodeFilename= poco.cs
// -v Verbose= True ";
Assert.IsTrue(output.Contains(line));

}

#region Name Case

Expand Down
3 changes: 3 additions & 0 deletions OData2Poco.Core/CommandLineUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public static List<string> GetOptions(Options option)
if (!string.IsNullOrEmpty(val.ToString()))
{
var text = $"{shortName} {p1.p.Name}= {val} ";
if (shortName.Equals("-p") || shortName.Equals("--password")) //hide password for security reason
text = $"{shortName} {p1.p.Name}= ***** ";
list.Add(text);
}
}
CodeHeader.SetParameters(list);
return list;
}

Expand Down
39 changes: 39 additions & 0 deletions OData2PocoLib/CodeHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using OData2Poco.TextTransform;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace OData2Poco
{
public class CodeHeader
{
static List<string> Parameters = new List<string>();
public static string GetHeader(IPocoGenerator pocoGen)
{
var comment = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated using OData2Poco System.
// Service Url: {0}
// MetaData Version: {1}
// Generated On: {2}
// Parameters:
{3}
// </auto-generated>
//------------------------------------------------------------------------------
";

//The <auto-generated> tag at the start of the file
var h = new FluentCsTextTemplate();
var pp = Parameters.Where(x => !(x.Trim().StartsWith("-r") || x.Trim().StartsWith("--url")))
.Select(x => $"// \t{x}");
h.WriteLine(comment, pocoGen.MetaData.ServiceUrl, pocoGen.MetaData.MetaDataVersion,
DateTimeOffset.Now.ToString("s"), string.Join(Environment.NewLine, pp));
return h.ToString();
}
public static void SetParameters(List<string> parameters)
{
Parameters = new List<string>(parameters);
}
}
}
1 change: 1 addition & 0 deletions OData2PocoLib/MetaDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static async Task<MetaDataInfo> LoadMetadataAsync(OdataConnectionString o
{
var xml = await reader.ReadToEndAsync();
metaData = LoadMetaDataFromXml(xml);
metaData.ServiceUrl = odataConnString.ServiceUrl;
return metaData;
}
}
Expand Down
20 changes: 3 additions & 17 deletions OData2PocoLib/PocoClassGeneratorCs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using OData2Poco.CustAttributes;
using OData2Poco.TextTransform;
using OData2Poco;

namespace OData2Poco
{
Expand Down Expand Up @@ -169,27 +170,12 @@ internal string ReducedBaseTyp(ClassTemplate ct)
reducedName = ct.BaseType.Replace(ns, "");
return reducedName;
}

private string GetHeader()
{
var comment = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated using OData2Poco System.
// Service Url: {0}
// MetaData Version: {1}
// Generated On: {2}
// </auto-generated>
//------------------------------------------------------------------------------
//";

//The <auto-generated> tag at the start of the file
var h = new FluentCsTextTemplate();
h.WriteLine(comment, _pocoGen.MetaData.ServiceUrl, _pocoGen.MetaData.MetaDataVersion,
DateTimeOffset.Now.ToString("s"));

return h.ToString();
return CodeHeader.GetHeader(_pocoGen);
}

private string UsingAssembly(List<string> nameSpaces)
{
var h = new FluentCsTextTemplate();
Expand Down
9 changes: 9 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

## (Console: o2pgen / .Net Core: dotnet-o2pgen)


## Version 3.5.0
**Release Date:** March 8, 2021

**What is new in 3.5.0:**
- New Feature request: Add used options to the header of the code generated, issue [#35](https://github.com/moh-hassan/odata2poco/issues/35)
- Fix of displaying serviceUrl when the source is xml file, #35.
- Hide password when displaying used options for security.

## Version 3.4.2
**Release Date:** Dec 21, 2020

Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ init:
try
{
Update-AppveyorBuild -Version $ver
Write-Output "Update-AppveyorBuild Success to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Green
Write-Host "Update-AppveyorBuild Success to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Green
}
catch
{
Write-Output "Update-AppveyorBuild Fail to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Red
Write-Output "Exception Error: $PSItem.Exception.Message" -ForegroundColor Red
Write-Host "Update-AppveyorBuild Fail to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Red
Write-Host "Exception Error: $PSItem.Exception.Message" -ForegroundColor Red
$env:CAN_PUBLISH = $false
}
}
Expand Down

0 comments on commit 54b798c

Please sign in to comment.