Skip to content

Commit c547db5

Browse files
authored
Merge pull request #1 from krukle/dev
Release 0.0.2
2 parents 79b388f + aad3cf4 commit c547db5

File tree

9 files changed

+87
-89
lines changed

9 files changed

+87
-89
lines changed

.github/workflows/BuildAndTestOnEveryPush.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ jobs:
2424
- name: Pack release version of task
2525
run: dotnet pack --configuration Release --include-source
2626

27-
- name: Push NuGet package to the testfeed
28-
run: dotnet nuget push KalmarKommun.Datalager.Sort\bin\Release\KalmarKommun.Datalager.Sort.*.nupkg --api-key ${{ secrets.COMMUNITY_FEED_API_KEY }} --source https://www.myget.org/F/frends-community-test/api/v2/package --symbol-source https://www.myget.org/F/frends-community-test/symbols/api/v2/package

.github/workflows/PackAndPushAfterMerge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: dotnet pack --configuration Release --include-source
2525

2626
- name: Push NuGet package to the (prod) feed
27-
run: dotnet nuget push KalmarKommun.Datalager.Sort\bin\Release\KalmarKommun.Datalager.Sort.*.nupkg --api-key ${{ secrets.COMMUNITY_FEED_API_KEY }} --source https://www.myget.org/F/frendstasks-kalmarkommun/api/v2/package -sk ${{ secrets.COMMUNITY_FEED_API_KEY }} --symbol-source https://www.myget.org/F/frendstasks-kalmarkommun/symbols/api/v2/package
27+
run: dotnet nuget push KalmarKommun.Datalager.Sort\bin\Release\KalmarKommun.Datalager.Sort.*.nupkg --api-key ${{ secrets.COMMUNITY_FEED_API_KEY }} --source https://www.myget.org/F/frendstasks-kalmarkommun/api/v2/package -sk ${{ secrets.COMMUNITY_FEED_API_KEY }} --symbol-source https://www.myget.org/F/frendstasks-kalmarkommun/symbols/api/v2/package
2828

2929
- name: Create Release
3030
id: create_release
Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
1+
using Newtonsoft.Json.Linq;
12
using NUnit.Framework;
2-
using System;
3+
using System.Collections.Generic;
34

45
namespace KalmarKommun.Datalager.Sort.Tests
56
{
67
[TestFixture]
78
class TestClass
89
{
910
/// <summary>
10-
/// You need to run KalmarKommun.Datalager.Sort.SetPaswordsEnv.ps1 before running unit test, or some other way set environment variables e.g. with GitHub Secrets.
11+
/// Tests class SortAscendingByParsedIntThenDescendingByText.
1112
/// </summary>
1213
[Test]
13-
public void ThreeSorts()
14+
public void TestSortAscendingByParsedIntThenDescendingByText()
1415
{
15-
var input = new Parameters
16-
{
17-
Message = Environment.GetEnvironmentVariable("EXAMPLE_ENVIROMENT_VARIABLE")
18-
};
1916

20-
var options = new Options
17+
var input = new Parameters
2118
{
22-
Amount = 3,
23-
Delimiter = ", "
19+
ListToSort = JArray.FromObject(
20+
new List<Dictionary<string, string>>{
21+
new Dictionary<string, string> {
22+
{ "season", "autum-2023" },
23+
{ "month", "october" }
24+
},
25+
new Dictionary<string, string> {
26+
{ "season", "spring-2022" }
27+
},
28+
new Dictionary<string, string> {
29+
{ "season", "autum-2022" },
30+
{ "month", "november" }
31+
},
32+
new Dictionary<string, string> {
33+
{ "season", "spring-2023" }
34+
}
35+
}
36+
),
37+
Key = JToken.FromObject("season")
2438
};
2539

26-
var ret = Sort.SortByParsedInt(input, options, new System.Threading.CancellationToken());
40+
var ret = Sort.SortAscendingByParsedIntThenDescendingByText(input, new System.Threading.CancellationToken());
2741

28-
Assert.That(ret.Replication, Is.EqualTo("foobar, foobar, foobar"));
42+
Assert.That(ret.SortedList, Is.EqualTo(JArray.FromObject(
43+
new List<Dictionary<string, string>> {
44+
new Dictionary<string, string> {
45+
{ "season", "spring-2022" }
46+
},
47+
new Dictionary<string, string> {
48+
{ "season", "autum-2022" },
49+
{ "month", "november" }
50+
},
51+
new Dictionary<string, string> {
52+
{ "season", "spring-2023" }
53+
},
54+
new Dictionary<string, string> {
55+
{ "season", "autum-2023" },
56+
{ "month", "october" }
57+
}
58+
})));
2959
}
3060
}
3161
}

KalmarKommun.Datalager.Sort.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29613.14
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33829.357
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KalmarKommun.Datalager.Sort", "KalmarKommun.Datalager.Sort\KalmarKommun.Datalager.Sort.csproj", "{35C305C0-8108-4A98-BB1D-AFE5C926239E}"
77
EndProject
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
11
#pragma warning disable 1591
22

3+
using Newtonsoft.Json.Linq;
34
using System.ComponentModel;
45
using System.ComponentModel.DataAnnotations;
56

67
namespace KalmarKommun.Datalager.Sort
78
{
89
/// <summary>
9-
/// Parameters class usually contains parameters that are required.
10+
/// Parameters class contains parameters that are required.
1011
/// </summary>
1112
public class Parameters
1213
{
1314
/// <summary>
14-
/// Something that will be repeated.
15+
/// The list of dictionaries to sort.
1516
/// </summary>
16-
[DisplayFormat(DataFormatString = "Text")]
17-
[DefaultValue("Lorem ipsum dolor sit amet.")]
18-
public string Message { get; set; }
19-
}
17+
[DisplayFormat(DataFormatString = "Expression")]
18+
[DefaultValue(null)]
19+
public JArray ListToSort { get; set; }
2020

21-
/// <summary>
22-
/// Options class provides additional optional parameters.
23-
/// </summary>
24-
public class Options
25-
{
2621
/// <summary>
27-
/// Number of times input is repeated.
28-
/// </summary>
29-
[DefaultValue(3)]
30-
public int Amount { get; set; }
31-
32-
/// <summary>
33-
/// How repeats of the input are separated.
22+
/// Key of which value in dictionaries to sort list by.
3423
/// </summary>
3524
[DisplayFormat(DataFormatString = "Text")]
36-
[DefaultValue(" ")]
37-
public string Delimiter { get; set; }
25+
[DefaultValue("")]
26+
public JToken Key { get; set; }
3827
}
3928

4029
public class Result
4130
{
4231
/// <summary>
43-
/// Contains the input repeated the specified number of times.
32+
/// Contains SortedList which is ListToSort, sorted by the provided Key.
4433
/// </summary>
45-
[DisplayFormat(DataFormatString = "Text")]
46-
public string Replication;
34+
[DisplayFormat(DataFormatString = "Expression")]
35+
public JArray SortedList;
4736
}
4837
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Tasks": [
33
{
4-
"TaskMethod": "KalmarKommun.Datalager.Sort.Sort.SortByParsedInt"
4+
"TaskMethod": "KalmarKommun.Datalager.Sort.Sort.SortAscendingByParsedIntThenDescendingByText"
55
}
66
]
77
}
Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.ComponentModel;
1+
using Newtonsoft.Json.Linq;
2+
using System;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
25
using System.Threading;
3-
using Microsoft.CSharp; // You can remove this if you don't need dynamic type in .NET Standard frends Tasks
46

57
#pragma warning disable 1591
68

@@ -9,31 +11,23 @@ namespace KalmarKommun.Datalager.Sort
911
public static class Sort
1012
{
1113
/// <summary>
12-
/// This is task
13-
/// Documentation: https://github.com/CommunityHiQ/KalmarKommun.Datalager.Sort
14+
/// Task for sorting a List of Dicitionaries, based on the values of a key from the Dictionaries.
15+
///
16+
/// Documentation: https://github.com/krukle/FrendsTask_KalmarKommun.Datalager.Sort
17+
///
1418
/// </summary>
15-
/// <param name="input">What to repeat.</param>
16-
/// <param name="options">Define if repeated multiple times. </param>
19+
/// <param name="input">The List to sort, and which key's values to sort by</param>
1720
/// <param name="cancellationToken"></param>
18-
/// <returns>{string Replication} </returns>
19-
public static Result SortByParsedInt(Parameters input, [PropertyTab] Options options, CancellationToken cancellationToken)
21+
/// <returns>The sorted list of dictionaries.</returns>
22+
public static Result SortAscendingByParsedIntThenDescendingByText(Parameters input, CancellationToken cancellationToken)
2023
{
21-
var repeats = new string[options.Amount];
22-
23-
for (var i = 0; i < options.Amount; i++)
24+
return new Result
2425
{
25-
// It is good to check the cancellation token somewhere you spend lot of time, e.g. in loops.
26-
cancellationToken.ThrowIfCancellationRequested();
27-
28-
repeats[i] = input.Message;
29-
}
30-
31-
var output = new Result
32-
{
33-
Replication = string.Join(options.Delimiter, repeats)
26+
SortedList = JArray.FromObject(input.ListToSort
27+
.OrderBy(x => Int32.Parse(Regex.Match(x[input.Key.ToString()].ToString(), @"\d+").Value))
28+
.ThenByDescending(x => x[input.Key.ToString()])
29+
.ToList())
3430
};
35-
36-
return output;
3731
}
3832
}
3933
}

KalmarKommun.Datalager.Sort/KalmarKommun.Datalager.Sort.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<authors>chei100</authors>
66
<copyright>chei100</copyright>
77
<PackageLicenseExpression>MIT</PackageLicenseExpression>
8-
<PackageProjectUrl>https://github.com/CommunityHiQ/KalmarKommun.Datalager.Sort</PackageProjectUrl>
8+
<PackageProjectUrl>https://github.com/krukle/FrendsTask_KalmarKommun.Datalager.Sort/</PackageProjectUrl>
99
<IncludeSource>true</IncludeSource>
1010
<PackageTags>Frends</PackageTags>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
12-
<Version>0.0.1</Version>
12+
<Version>0.0.2</Version>
1313
</PropertyGroup>
1414

1515
<ItemGroup>
@@ -20,6 +20,7 @@
2020

2121
<ItemGroup>
2222
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
23+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2324
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
2425
</ItemGroup>
2526

README.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,50 @@
1-
# KalmarKommun.Datalager.Sort
1+
# FrendsTask_KalmarKommun.Datalager.Sort
22

3-
frends Community Task for Sort
3+
Frends task for sorting
44

5-
[![Actions Status](https://github.com/CommunityHiQ/KalmarKommun.Datalager.Sort/workflows/PackAndPushAfterMerge/badge.svg)](https://github.com/CommunityHiQ/KalmarKommun.Datalager.Sort/actions) ![MyGet](https://img.shields.io/myget/frends-community/v/KalmarKommun.Datalager.Sort) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
[![Actions Status](https://github.com/krukle/FrendsTask_KalmarKommun.Datalager.Sort/workflows/PackAndPushAfterMerge/badge.svg)](https://github.com/krukle/FrendsTask_KalmarKommun.Datalager.Sort/actions) [![MyGet](https://img.shields.io/myget/frendstasks-kalmarkommun/v/KalmarKommun.Datalager.Sort)](https://www.myget.org/feed/frendstasks-kalmarkommun/package/nuget/KalmarKommun.Datalager.Sort) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66

77
- [Installing](#installing)
88
- [Tasks](#tasks)
99
- [Sort](#Sort)
1010
- [Building](#building)
1111
- [Contributing](#contributing)
12-
- [Change Log](#change-log)
1312

1413
# Installing
1514

1615
You can install the Task via frends UI Task View or you can find the NuGet package from the following NuGet feed
17-
https://www.myget.org/F/frends-community/api/v3/index.json and in Gallery view in MyGet https://www.myget.org/feed/frends-community/package/nuget/KalmarKommun.Datalager.Sort
18-
16+
https://www.myget.org/F/frendstasks-kalmarkommun/api/v3/index.json and in Gallery view in MyGet https://www.myget.org/feed/frendstasks-kalmarkommun/package/nuget/KalmarKommun.Datalager.Sort
1917
# Tasks
2018

2119
## Sort
2220

23-
Repeats a message
21+
Task for sorting a List of Dicitionaries, based on the values of a key from the Dictionaries.
2422

2523
### Properties
2624

2725
| Property | Type | Description | Example |
2826
| -------- | -------- | -------- | -------- |
29-
| Message | `string` | Some string that will be repeated. | `foo` |
30-
31-
### Options
32-
33-
| Property | Type | Description | Example |
34-
| -------- | -------- | -------- | -------- |
35-
| Amount | `int` | Amount how many times message is repeated. | `3` |
36-
| Delimiter | `string` | Character(s) used between replications. | `, ` |
27+
| ListToSort | `List<Dictionary<string, string>>` | List of dictionaries to sort. | `new List<Dictionary<string, string>> { new Dictionary<string, string> { { "season", "autum-2023" }, { "month", "october" } } };` |
28+
| Key | `string` | Key of values in dictionaries to sort by. | `"season"` |
3729

3830
### Returns
3931

4032
A result object with parameters.
4133

4234
| Property | Type | Description | Example |
4335
| -------- | -------- | -------- | -------- |
44-
| Replication | `string` | Repeated string. | `foo, foo, foo` |
36+
| SortedList | `List<Dictionary<string, string>>` | Sorted list of dictionaries. | `new List<Dictionary<string, string>> { new Dictionary<string, string> { { "season", "autum-2023" }, { "month", "october" } } };` |
4537

4638
Usage:
4739
To fetch result use syntax:
4840

49-
`#result.Replication`
41+
`#result.SortedList`
5042

5143
# Building
5244

5345
Clone a copy of the repository
5446

55-
`git clone https://github.com/CommunityHiQ/KalmarKommun.Datalager.Sort.git`
47+
`git clone https://github.com/krukle/FrendsTask_KalmarKommun.Datalager.Sort`
5648

5749
Rebuild the project
5850

@@ -76,9 +68,3 @@ When contributing to this repository, please first discuss the change you wish t
7668
5. Submit a Pull request so that we can review your changes
7769

7870
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
79-
80-
# Change Log
81-
82-
| Version | Changes |
83-
| ------- | ------- |
84-
| 0.0.1 | Development still going on |

0 commit comments

Comments
 (0)