Skip to content

Commit

Permalink
Add MatchGenerator for Season.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanDeveloper committed Jun 21, 2017
1 parent df99210 commit 2ebde0e
Show file tree
Hide file tree
Showing 23 changed files with 1,895 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ public interface IAdminClientService {
System.Threading.Tasks.Task<bool> DeleteSeasonToTeamRelationAsync(LigaManagerAdminClient.AdminClientService.SeasonToTeamRelation seasonToTeamRelation);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAdminClientService/GenerateMatches", ReplyAction="http://tempuri.org/IAdminClientService/GenerateMatchesResponse")]
void GenerateMatches();
void GenerateMatches(LigaManagerAdminClient.AdminClientService.Season season, System.DateTime beginDateTime, System.DateTime endDateTime);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAdminClientService/GenerateMatches", ReplyAction="http://tempuri.org/IAdminClientService/GenerateMatchesResponse")]
System.Threading.Tasks.Task GenerateMatchesAsync();
System.Threading.Tasks.Task GenerateMatchesAsync(LigaManagerAdminClient.AdminClientService.Season season, System.DateTime beginDateTime, System.DateTime endDateTime);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
Expand Down Expand Up @@ -816,12 +816,12 @@ public System.Threading.Tasks.Task<bool> DeleteSeasonToTeamRelationAsync(LigaMan
return base.Channel.DeleteSeasonToTeamRelationAsync(seasonToTeamRelation);
}

public void GenerateMatches() {
base.Channel.GenerateMatches();
public void GenerateMatches(LigaManagerAdminClient.AdminClientService.Season season, System.DateTime beginDateTime, System.DateTime endDateTime) {
base.Channel.GenerateMatches(season, beginDateTime, endDateTime);
}

public System.Threading.Tasks.Task GenerateMatchesAsync() {
return base.Channel.GenerateMatchesAsync();
public System.Threading.Tasks.Task GenerateMatchesAsync(LigaManagerAdminClient.AdminClientService.Season season, System.DateTime beginDateTime, System.DateTime endDateTime) {
return base.Channel.GenerateMatchesAsync(season, beginDateTime, endDateTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@
</xs:element>
<xs:element name="GenerateMatches">
<xs:complexType>
<xs:sequence />
<xs:sequence>
<xs:element xmlns:q27="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="season" nillable="true" type="q27:Season" />
<xs:element minOccurs="0" name="beginDateTime" type="xs:dateTime" />
<xs:element minOccurs="0" name="endDateTime" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GenerateMatchesResponse">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.Windows;
using System.Windows.Data;
using LigaManagerAdminClient.AdminClientService;
using LigaManagerAdminClient.ViewModels;
using LigaManagerAdminClient.Views;
Expand Down
5 changes: 3 additions & 2 deletions LigaManagerServer/Contracts/IAdminClientService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ServiceModel;
using System;
using System.ServiceModel;
using LigaManagerServer.Models;

namespace LigaManagerServer.Contracts
Expand Down Expand Up @@ -43,6 +44,6 @@ public interface IAdminClientService : ILigaManagerService
bool DeleteSeasonToTeamRelation(SeasonToTeamRelation seasonToTeamRelation);

[OperationContract]
void GenerateMatches();
void GenerateMatches(Season season, DateTime beginDateTime, DateTime endDateTime);
}
}
Binary file modified LigaManagerServer/Database/LigaManager.db3
Binary file not shown.
107 changes: 104 additions & 3 deletions LigaManagerServer/Services/AdminClientService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentNHibernate.Conventions;
using LigaManagerServer.Contracts;
using LigaManagerServer.Interfaces;
using LigaManagerServer.Models;
using NHibernate.Event;
using NHibernate.Util;

namespace LigaManagerServer.Services
{
Expand Down Expand Up @@ -162,10 +166,107 @@ public bool AddSeasonToTeamRelation(SeasonToTeamRelation seasonToTeamRelation)
}
}

public void GenerateMatches()
public void GenerateMatches(Season season, DateTime beginDateTime, DateTime endDateTime)
{
//TODO Generate Matches for an Season
throw new System.NotImplementedException();
lock (StaticLock)
{
var seasonToTeamRelations = _seasonToTeamRelationService.GetAll();
var teamsOfSeason = seasonToTeamRelations.FindAll(x => x.Season.Equals(season));

var dateTimes = CreateDateTimes(beginDateTime, endDateTime, new List<DateTime>());
var matchesOfSeason = new List<Match>();
foreach (var seasonToTeamRelation in teamsOfSeason)
{
foreach (var teams in teamsOfSeason)
{
if (seasonToTeamRelation.Equals(teams)) continue;
var match = new Match
{
HomeTeam = seasonToTeamRelation.Team,
AwayTeam = teams.Team,
Season = seasonToTeamRelation.Season,
};

matchesOfSeason.Add(match);
}
}
var result = GenerateMatches(new List<Match>(), matchesOfSeason, dateTimes, 1);
}
}

private List<Match> GenerateMatches(List<Match> result, List<Match> matches, List<DateTime> dayOfWeeks, int matchDay)
{
if (!matches.IsEmpty())
{
foreach (var dateTime in dayOfWeeks)
{
foreach (var match in matches)
{
if (dateTime.DayOfWeek == DayOfWeek.Friday)
{
var currentMatch = match;
matches.Remove(match);
currentMatch.DateTime = dateTime;
currentMatch.MatchDay = matchDay;
result.Add(currentMatch);
// remove from group
dayOfWeeks.Remove(dateTime);
return GenerateMatches(result, matches, dayOfWeeks, matchDay);

}
else if (dateTime.DayOfWeek == DayOfWeek.Sunday)
{
var currentMatch = match;
matches.Remove(match);
currentMatch.DateTime = dateTime;
currentMatch.MatchDay = matchDay;
result.Add(currentMatch);
dayOfWeeks.Remove(dateTime);
return GenerateMatches(result, matches, dayOfWeeks, dateTime.Hour == 17 ? ++matchDay : matchDay);
}
}
}
return result;
}
else
{
return result;
}

}

/// <summary>
/// Generates all validate DateTimes during the TimeSpan of the season.
/// </summary>
/// <param name="beginn"></param>
/// <param name="end"></param>
/// <param name="result"></param>
/// <returns></returns>
private List<DateTime> CreateDateTimes(DateTime beginn, DateTime end, List<DateTime> result)
{
if (!beginn.Equals(end))
{
if (DayOfWeek.Friday == beginn.DayOfWeek)
{
result.Add(new DateTime(beginn.Year, beginn.Month, beginn.Day, 20,30,0));
}
else if (DayOfWeek.Sunday == beginn.DayOfWeek)
{
result.Add(new DateTime(beginn.Year, beginn.Month, beginn.Day, 15, 30, 0));
result.Add(new DateTime(beginn.Year, beginn.Month, beginn.Day, 17, 30, 0));
}
else if (DayOfWeek.Saturday == beginn.DayOfWeek)
{
result.Add(new DateTime(beginn.Year, beginn.Month, beginn.Day, 15, 30, 0));
}

return CreateDateTimes(beginn.AddDays(1), end, result);
}
else
{
return result;
}

}
}
}
18 changes: 18 additions & 0 deletions LigaManagerTest/AdminClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Linq;
using LigaManagerTest.AdminService;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LigaManagerTest
{
[TestClass]
public class AdminClientTest
{
[TestMethod]
public void GenerateMatchesTest()
{
var adminClient = new AdminClientServiceClient();
adminClient.GenerateMatches(adminClient.GetSeasons().First(), DateTime.Now, DateTime.Now.AddDays(60));
}
}
}
44 changes: 44 additions & 0 deletions LigaManagerTest/LigaManagerTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,68 @@
<Reference Include="System.Data.SQLite, Version=1.0.105.1, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.105.1\lib\net451\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BetTest.cs" />
<Compile Include="BettorTest.cs" />
<Compile Include="MatchTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SeasonTest.cs" />
<Compile Include="Service References\AdminService\Reference.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Reference.svcmap</DependentUpon>
</Compile>
<Compile Include="TeamTest.cs" />
<Compile Include="AdminClientTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\DataSources\LigaManagerServer.Models.Bet.datasource" />
<None Include="Properties\DataSources\LigaManagerServer.Models.Bettor.datasource" />
<None Include="Properties\DataSources\LigaManagerServer.Models.Match.datasource" />
<None Include="Properties\DataSources\LigaManagerServer.Models.Season.datasource" />
<None Include="Properties\DataSources\LigaManagerServer.Models.SeasonToTeamRelation.datasource" />
<None Include="Properties\DataSources\LigaManagerServer.Models.Team.datasource" />
<None Include="Service References\AdminService\LigaManagerServer.Models.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Service References\AdminService\service.wsdl" />
<None Include="Service References\AdminService\service.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Service References\AdminService\service1.xsd">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LigaManagerServer\LigaManagerServer.csproj">
<Project>{FE7A1F9F-CCFD-4EBB-A312-DDCD772BCD45}</Project>
<Name>LigaManagerServer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<WCFMetadataStorage Include="Service References\AdminService\" />
</ItemGroup>
<ItemGroup>
<None Include="Service References\AdminService\configuration91.svcinfo" />
</ItemGroup>
<ItemGroup>
<None Include="Service References\AdminService\configuration.svcinfo" />
</ItemGroup>
<ItemGroup>
<None Include="Service References\AdminService\Reference.svcmap">
<Generator>WCF Proxy Generator</Generator>
<LastGenOutput>Reference.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Bet" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LigaManagerServer.Models.Bet, LigaManagerServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Bettor" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LigaManagerServer.Models.Bettor, LigaManagerServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Match" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LigaManagerServer.Models.Match, LigaManagerServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Season" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LigaManagerServer.Models.Season, LigaManagerServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="SeasonToTeamRelation" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LigaManagerServer.Models.SeasonToTeamRelation, LigaManagerServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Team" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LigaManagerServer.Models.Team, LigaManagerServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Loading

0 comments on commit 2ebde0e

Please sign in to comment.