Skip to content

Commit

Permalink
[CastIt.Server] Updated the data methods that will be called when the…
Browse files Browse the repository at this point in the history
… server goes down
  • Loading branch information
Wolfteam committed Jun 17, 2021
1 parent 7720c4b commit 6139ea8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
12 changes: 0 additions & 12 deletions CastIt.Server/.config/dotnet-tools.json

This file was deleted.

6 changes: 5 additions & 1 deletion CastIt.Server/Common/Extensions/LoggingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CastIt.Domain.Models.Logging;
using CastIt.GoogleCast;
using CastIt.Server.Controllers;
using CastIt.Server.Hubs;
using CastIt.Server.Services;
Expand Down Expand Up @@ -26,7 +27,10 @@ public static List<FileToLog> AddServerLogs(this List<FileToLog> logs)
//Services
new FileToLog(typeof(ServerCastService), "service_cast"),
new FileToLog(typeof(AppDataService), "service_appdata"),
new FileToLog(typeof(ServerAppSettingsService), "service_appsettings")
new FileToLog(typeof(ServerAppSettingsService), "service_appsettings"),

//Others
new FileToLog(typeof(Player), "castit_player")
});
return logs;
}
Expand Down
3 changes: 3 additions & 0 deletions CastIt.Server/Common/MappingProfile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoMapper;
using CastIt.Domain.Dtos.Responses;
using CastIt.Domain.Entities;
using CastIt.GoogleCast;
using CastIt.Infrastructure.Models;

namespace CastIt.Server.Common
Expand All @@ -17,6 +18,8 @@ public MappingProfile()
CreateMap<ServerPlayList, GetAllPlayListResponseDto>();
CreateMap<ServerPlayList, PlayListItemResponseDto>();
CreateMap<ServerFileItem, FileItemResponseDto>();

CreateMap<PlayerStatus, PlayerStatusResponseDto>();
}
}
}
9 changes: 0 additions & 9 deletions CastIt.Server/Common/ServerConstants.cs

This file was deleted.

46 changes: 21 additions & 25 deletions CastIt.Server/Services/AppDataService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using CastIt.Application.Common.Utils;
using CastIt.Domain.Entities;
using CastIt.Infrastructure.Models;
using CastIt.Server.Interfaces;
using CastIt.Server.Migrations;
using FluentMigrator.Runner;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CastIt.Server.Services
Expand Down Expand Up @@ -131,12 +133,6 @@ public Task<long> GetNumberOfFiles(long playlistId)
return _db.Select<FileItem>().Where(f => f.PlayListId == playlistId).CountAsync();
}

public void SaveChangesBeforeClosingApp(Dictionary<PlayList, int> playListsPositions, List<FileItem> vms)
{
SavePlayListsPositions(playListsPositions);
SaveFileChanges(vms);
}

public Task UpdatePlayList(long id, string name, int position)
{
return _db.Update<PlayList>(id)
Expand All @@ -156,33 +152,33 @@ public Task UpdateFile(long id, string name, string description, double duration
.ExecuteAffrowsAsync();
}

private void SavePlayListsPositions(Dictionary<PlayList, int> positions)
public async Task SavePlayListChanges(List<ServerPlayList> playLists)
{
if (positions.Count == 0)
if (playLists.Count == 0)
return;

foreach (var (vm, position) in positions)
{
_db.Update<PlayList>(vm.Id)
.Set(p => p.Position, position)
.Set(p => p.Shuffle, vm.Shuffle)
.Set(p => p.Loop, vm.Loop)
.ExecuteAffrows();
}
var tasks = playLists.Select(playList => _db.Update<PlayList>(playList.Id)
.Set(p => p.Position, playList.Position)
.Set(p => p.Shuffle, playList.Shuffle)
.Set(p => p.Loop, playList.Loop)
.ExecuteAffrowsAsync()
);

await Task.WhenAll(tasks);
}

private void SaveFileChanges(List<FileItem> vms)
public async Task SaveFileChanges(List<ServerFileItem> files)
{
if (vms.Count == 0)
if (files.Count == 0)
return;

foreach (var vm in vms)
{
_db.Update<FileItem>(vm.Id)
.Set(f => f.PlayedPercentage, vm.PlayedPercentage)
.Set(f => f.Position, vm.Position)
.ExecuteAffrows();
}
var tasks = files.Select(file => _db.Update<FileItem>(file.Id)
.Set(f => f.PlayedPercentage, file.PlayedPercentage)
.Set(f => f.Position, file.Position)
.ExecuteAffrowsAsync()
);

await Task.WhenAll(tasks);
}

private void ApplyMigrations()
Expand Down

0 comments on commit 6139ea8

Please sign in to comment.