Skip to content

Commit

Permalink
Update for VS2022, and net4.8 / netstandard2.0+2.1. Version 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
danik authored and danik committed Dec 22, 2021
1 parent 81c2f1b commit e286e11
Show file tree
Hide file tree
Showing 40 changed files with 242 additions and 442 deletions.
2 changes: 1 addition & 1 deletion tik4net.console/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<add key="pass" value=""/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
6 changes: 3 additions & 3 deletions tik4net.console/ConsoleProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ static void Main(string[] args)
rows.AddRange(row.Split('|').Where(r => !string.IsNullOrEmpty(r)));
}
var result = connection.CallCommandSync(rows.ToArray());
foreach (var resultItem in result)
foreach(var word in resultItem.Words)
Console.WriteLine(word);
//foreach (var resultItem in result)
// foreach(var word in resultItem.Words)
// Console.WriteLine($"{word.Key}={word.Value}");

commandRows.Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion tik4net.console/tik4net.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>tik4net.console</RootNamespace>
<AssemblyName>tik4net.console</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down
7 changes: 4 additions & 3 deletions tik4net.coreconsole/CoreConsoleProgram.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;
using System.IO;
using Microsoft.Extensions.Configuration;

namespace tik4net.coreconsole
{
Expand All @@ -18,7 +18,7 @@ static void Main(string[] args)
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
IConfiguration configuration = builder.Build();
var configuration = builder.Build();

connection.Open(configuration["host"], configuration["user"], configuration["pass"]);

Expand All @@ -43,7 +43,8 @@ static void Main(string[] args)
}
var result = connection.CallCommandSync(rows.ToArray());
foreach (var resultItem in result)
Console.WriteLine(resultItem.Words);
foreach (var word in resultItem.Words)
Console.WriteLine($"{word.Key}={word.Value}");

commandRows.Clear();
}
Expand Down
14 changes: 9 additions & 5 deletions tik4net.coreconsole/tik4net.coreconsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ApplicationIcon />
<StartupObject></StartupObject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\tik4net\tik4net.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion tik4net.examples/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<add key="user" value="admin"/>
<add key="pass" value=""/>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
2 changes: 1 addition & 1 deletion tik4net.examples/tik4net.examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>tik4net.examples</RootNamespace>
<AssemblyName>tik4net.examples</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down
4 changes: 2 additions & 2 deletions tik4net.objects/Ip/Firewall/FirewallNat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class FirewallNat
/// <seealso cref="DstPortStr"/>
public long DstPort
{
get { return StringHelper.IsNullOrWhiteSpace(DstPortStr) ? 0 : long.Parse(DstPortStr); }
get { return string.IsNullOrWhiteSpace(DstPortStr) ? 0 : long.Parse(DstPortStr); }
set { DstPortStr = value.ToString(); }
}

Expand All @@ -124,7 +124,7 @@ public long DstPort
/// <seealso cref="SrcPortStr"/>
public long SrcPort
{
get { return StringHelper.IsNullOrWhiteSpace(SrcPortStr) ? 0 : long.Parse(SrcPortStr); }
get { return string.IsNullOrWhiteSpace(SrcPortStr) ? 0 : long.Parse(SrcPortStr); }
set { SrcPortStr = value.ToString(); }
}

Expand Down
2 changes: 1 addition & 1 deletion tik4net.objects/MacAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MacAddress()
/// <param name="mac">MAC address in format 00:00:00:00:00:00</param>
public MacAddress(string mac)
{
if (StringHelper.IsNullOrWhiteSpace(mac))
if (string.IsNullOrWhiteSpace(mac))
mac = DEFAULT_MAC;

EnsureValidMac(mac);
Expand Down
4 changes: 2 additions & 2 deletions tik4net.objects/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.6.0.0")]
[assembly: AssemblyFileVersion("3.6.0.0")]
[assembly: AssemblyVersion("4.0.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
41 changes: 0 additions & 41 deletions tik4net.objects/PropertyInfoExtensions.cs

This file was deleted.

10 changes: 1 addition & 9 deletions tik4net.objects/TikEntityMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public bool HasIdProperty
/// <remarks>Slow operation.</remarks>
public TikEntityMetadata(Type entityType)
{
#if NET20 || NET35 || NET40
TikEntityAttribute entityAttribute = (TikEntityAttribute)entityType.GetCustomAttributes(true).FirstOrDefault(a => a is TikEntityAttribute);
#else
TikEntityAttribute entityAttribute = (TikEntityAttribute)entityType.GetTypeInfo().GetCustomAttributes(true).FirstOrDefault(a => a is TikEntityAttribute);
#endif
if (entityAttribute == null)
throw new ArgumentException("Entity class must be decorated by TikEntityAttribute attribute.");

Expand All @@ -121,11 +117,7 @@ public TikEntityMetadata(Type entityType)
IsSingleton = entityAttribute.IsSingleton;

//properties
#if NET20 || NET35 || NET40
_properties = entityType.GetProperties()
#else
_properties = entityType.GetTypeInfo().GetAllProperties()
#endif
_properties = entityType.GetTypeInfo().GetProperties()
.Where(propInfo => propInfo.GetCustomAttribute<TikPropertyAttribute>(true) != null)
.Select(propInfo => new TikEntityPropertyAccessor(this, propInfo))
.ToDictionary(propDescriptor => propDescriptor.FieldName);
Expand Down
19 changes: 0 additions & 19 deletions tik4net.objects/TikEntityPropertyAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,14 @@ public TikEntityPropertyAccessor(TikEntityMetadata owner, PropertyInfo propertyI
throw new ArgumentException("Property must be decorated by TikPropertyAttribute.", "propertyInfo");
FieldName = propertyAttribute.FieldName;
_isReadOnly =
#if NET20 || NET35 || NET40
(propertyInfo.GetSetMethod() == null)
#else
(propertyInfo.SetMethod == null)
#endif
|| (!propertyInfo.CanWrite) || (propertyAttribute.IsReadOnly);
IsMandatory = propertyAttribute.IsMandatory;
if (propertyAttribute.DefaultValue != null)
DefaultValue = propertyAttribute.DefaultValue;
else
{
#if NET20 || NET35 || NET40
if (PropertyType.IsValueType)
#else
if (PropertyType.GetTypeInfo().IsValueType)
#endif
DefaultValue = ConvertToString(Activator.CreateInstance(PropertyType)); //default value of value type. for example: (default)int
else
DefaultValue = "";
Expand Down Expand Up @@ -131,15 +123,9 @@ private object ConvertFromString(string strValue)
return byte.Parse(strValue);
else if (PropertyType == typeof(bool))
return string.Equals(strValue, "true", StringComparison.OrdinalIgnoreCase) || string.Equals(strValue, "yes", StringComparison.OrdinalIgnoreCase);
#if NET20 || NET35 || NET40
else if (PropertyType.IsEnum)
return Enum.GetNames(PropertyType)
.Where(en => string.Equals(PropertyType.GetMember(en)[0].GetCustomAttribute<TikEnumAttribute>(false).Value, strValue, StringComparison.OrdinalIgnoreCase))
#else
else if (PropertyType.GetTypeInfo().IsEnum)
return Enum.GetNames(PropertyType)
.Where(en => string.Equals(PropertyType.GetRuntimeField(en).GetCustomAttribute<TikEnumAttribute>(false).Value, strValue, StringComparison.OrdinalIgnoreCase))
#endif
.Select(en => Enum.Parse(PropertyType, en, true))
.Single(); //TODO safer implementation
//else if (PropertyType == typeof(Ipv4Address))
Expand Down Expand Up @@ -177,13 +163,8 @@ private string ConvertToString(object propValue)
return ((long)propValue).ToString();
else if (PropertyType == typeof(bool))
return ((bool)propValue) ? "yes" : "no"; //TODO add attribute definition for support true/false
#if NET20 || NET35 || NET40
else if (PropertyType.IsEnum)
return PropertyType.GetMember(propValue.ToString())[0].GetCustomAttribute<TikEnumAttribute>(false).Value; //TODO safer implementation
#else
else if (PropertyType.GetTypeInfo().IsEnum)
return PropertyType.GetRuntimeField(propValue.ToString()).GetCustomAttribute<TikEnumAttribute>(false).Value; //TODO safer implementation
#endif
//else if (PropertyType == typeof(Ipv4Address))
// return ((Ipv4Address)propValue).Address;
//else if (PropertyType == typeof(Ipv4AddressWithSubnet))
Expand Down
8 changes: 1 addition & 7 deletions tik4net.objects/tik4net.objects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net462;net35;net40;net452;netcoreapp1.1;netcoreapp2.0;netcoreapp2.2;netcoreapp3.1;netstandard1.3;netstandard1.4;netstandard1.6</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Description>Mikrotik API library - O/R mapper API</Description>
<Authors>Daniel Frantik</Authors>
<Copyright>Copyright (C) Daniel Frantik 2017</Copyright>
Expand All @@ -25,12 +25,6 @@
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net35|AnyCPU'">
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net35|AnyCPU'">
<DocumentationFile>bin\Release\net35\tik4net.objects.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\tik4net\tik4net.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tik4net.tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<add key="user" value="admin"/>
<add key="pass" value=""/>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
6 changes: 1 addition & 5 deletions tik4net.tests/ConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public void AllConnectionModes_WilWorkTheSameWay()

OpenConnectionAndExecuteSimpleCommand(TikConnectionType.Api, host, user, pass);
OpenConnectionAndExecuteSimpleCommand(TikConnectionType.ApiSsl, host, user, pass);
#pragma warning disable CS0618 // Type or member is obsolete
OpenConnectionAndExecuteSimpleCommand(TikConnectionType.Api_v2, host, user, pass);
OpenConnectionAndExecuteSimpleCommand(TikConnectionType.ApiSsl_v2, host, user, pass);
#pragma warning restore CS0618 // Type or member is obsolete
}

private static void OpenConnectionAndExecuteSimpleCommand(TikConnectionType connectionType, string host, string user, string pass)
Expand Down Expand Up @@ -197,7 +193,7 @@ public void OpenConnectionAsyncReceiveTimeoutWillThrowExceptionWhenShortTimeout(
using (var connection = ConnectionFactory.CreateConnection(DEFAULT_CONNECTION_TYPE))
{
connection.ReceiveTimeout = 1; //very short timeout + using async version
connection.OpenAsync(ConfigurationManager.AppSettings["host"], ConfigurationManager.AppSettings["user"], ConfigurationManager.AppSettings["pass"]).GetAwaiter().GetResult();
await connection.OpenAsync(ConfigurationManager.AppSettings["host"], ConfigurationManager.AppSettings["user"], ConfigurationManager.AppSettings["pass"]);
connection.Close();
}
}).GetAwaiter().GetResult();
Expand Down
2 changes: 1 addition & 1 deletion tik4net.tests/MndpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MndpTests
[TestMethod]
public void MNDP_WillWork()
{
var items = MndpHelper.Discover();
var items = MndpHelper.Discover(true);

Assert.IsTrue(items.Count() > 0);
}
Expand Down
13 changes: 6 additions & 7 deletions tik4net.tests/tik4net.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>tik4net.tests</RootNamespace>
<AssemblyName>tik4net.tests</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down Expand Up @@ -76,6 +76,11 @@
<Compile Include="ToolTests.cs" />
<Compile Include="TorchTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\tik4net.objects\tik4net.objects.csproj">
<Project>{dd32e354-19c0-4992-902b-9cdd8e53e879}</Project>
Expand All @@ -86,12 +91,6 @@
<Name>tik4net</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup />
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tik4net.torch/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<add key="pass" value=""/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
2 changes: 1 addition & 1 deletion tik4net.torch/tik4net.torch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>tik4net.torch</RootNamespace>
<AssemblyName>tik4net.torch</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down
4 changes: 2 additions & 2 deletions tik4net/Api/ApiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void EnsureConnectionSet()

private void EnsureCommandTextSet()
{
if (StringHelper.IsNullOrWhiteSpace(_commandText))
if (string.IsNullOrWhiteSpace(_commandText))
throw new InvalidOperationException("CommandText is not set.");
}

Expand Down Expand Up @@ -144,7 +144,7 @@ private string[] ConstructCommandText(TikCommandParameterFormat defaultParameter
}

string commandText = CommandText;
if (!StringHelper.IsNullOrWhiteSpace(commandText) && !commandText.Contains("\n") && !commandText.StartsWith("/"))
if (!string.IsNullOrWhiteSpace(commandText) && !commandText.Contains("\n") && !commandText.StartsWith("/"))
commandText = "/" + commandText;

List<string> result;
Expand Down
Loading

0 comments on commit e286e11

Please sign in to comment.