Skip to content

Commit

Permalink
Merge pull request #59 from dotnet-campus/t/lindexi
Browse files Browse the repository at this point in the history
使用配置
  • Loading branch information
lindexi authored Dec 24, 2019
2 parents 7ce27aa + a1bd90f commit 5a62e3a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 114 deletions.
2 changes: 1 addition & 1 deletion build/Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.1.17759-alpha</Version>
<Version>0.1.19002-alpha</Version>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<SourceIntermediateDirectory>-i "$(SourcePackingDirectory)Package "</SourceIntermediateDirectory>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' != ''">-n "$(PackageOutputPath) "</SourcePackageOutputPath>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' == '' and $(OutputPath) != ''">-n "$(OutputPath) "</SourcePackageOutputPath>
<SourcePackageReferenceVersion>--PackageReferenceVersion $(PackageReferenceVersionFile)</SourcePackageReferenceVersion>
<SourcePackageReferenceVersion>--PackageReferenceVersion "$(PackageReferenceVersionFile)"</SourcePackageReferenceVersion>

</PropertyGroup>

Expand Down
16 changes: 0 additions & 16 deletions src/dotnetCampus.SourceYard/Properties/launchSettings.json

This file was deleted.

103 changes: 7 additions & 96 deletions src/dotnetCampus.SourceYard/Utils/BuildProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dotnetCampus.Configurations;
using dotnetCampus.Configurations.Core;

namespace dotnetCampus.SourceYard.Utils
{
Expand Down Expand Up @@ -126,107 +128,16 @@ public void SetSourcePackingDirectory(string packingDirectory)
// 这个文件里面存放使用 fkv 配置
if (File.Exists(sourceProjectPackageFile))
{
// todo 等待高性能配置发布
var configList = DeserializeFile(new FileInfo(sourceProjectPackageFile));
var fileConfigurationRepo = new FileConfigurationRepo(sourceProjectPackageFile);

if (configList.TryGetValue("RepositoryType", out var repositoryType))
{
RepositoryType = repositoryType.Trim();
}

if (configList.TryGetValue("PackageProjectUrl", out var packageProjectUrl))
{
PackageProjectUrl = packageProjectUrl.Trim();
}

if (configList.TryGetValue("RepositoryUrl", out var repositoryUrl))
{
RepositoryUrl = repositoryUrl.Trim();
}
}
}
var appConfigurator = fileConfigurationRepo.CreateAppConfigurator();

// 这里代码从Configurations复制
private Dictionary<string, string> DeserializeFile(FileInfo file)
{
// 一次性读取完的性能最好
var str = File.ReadAllText(file.FullName);
str = str.Replace("\r\n", "\n");
return Deserialize(str);
}
private static string _splitString = ">";
RepositoryType = appConfigurator.Default.GetValue("RepositoryType");

private static string _escapeString = "?";
PackageProjectUrl = appConfigurator.Default.GetValue("PackageProjectUrl");

/// <summary>
/// 反序列化的核心实现,反序列化字符串
/// </summary>
/// <param name="str"></param>
private Dictionary<string, string> Deserialize(string str)
{
var keyValuePairList = str.Split('\n');
var keyValue = new Dictionary<string, string>(StringComparer.Ordinal);
string? key = null;
var splitString = _splitString;

foreach (var temp in keyValuePairList.Select(temp => temp.Trim()))
{
if (temp.StartsWith(splitString, StringComparison.Ordinal))
{
// 分割,可以作为注释,这一行忽略
// 下一行必须是key
key = null;
continue;
}

var unescapedString = UnescapeString(temp);

if (key == null)
{
key = unescapedString;

// 文件存在多个地方都记录相同的值
// 如果有多个地方记录相同的值,使用最后的值替换前面文件
if (keyValue.ContainsKey(key))
{
keyValue.Remove(key);
}
}
else
{
if (keyValue.ContainsKey(key))
{
// key
// v1
// v2
// 返回 {"key","v1\nv2"}
keyValue[key] = keyValue[key] + "\n" + unescapedString;
}
else
{
keyValue.Add(key, unescapedString);
}
}
RepositoryUrl = appConfigurator.Default.GetValue("RepositoryUrl");
}

return keyValue;
}

/// <summary>
/// 存储的反转义
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private static string UnescapeString(string str)
{
var escapeString = _escapeString;

if (str.StartsWith(escapeString, StringComparison.Ordinal))
{
return str.Substring(1);
}

return str;
}
}
}
5 changes: 5 additions & 0 deletions src/dotnetCampus.SourceYard/dotnetCampus.SourceYard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.2.1" />
<PackageReference Include="dotnetCampus.Configurations.Source" />

</ItemGroup>

Expand All @@ -41,6 +42,10 @@
<ItemGroup>
<!--所有的 NuGet 包资产都声明成私有的-->
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
<PackageReference Update="dotnetCampus.Configurations.Source" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 5a62e3a

Please sign in to comment.