Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
Zexuz committed Apr 8, 2019
1 parent f41f626 commit a49f3e1
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 50 deletions.
1 change: 0 additions & 1 deletion Mpv.JsonIpc/Manager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.IO.Pipes;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

Expand Down
3 changes: 1 addition & 2 deletions Mpv.JsonIpc/Response.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace Mpv.JsonIpc
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SnackTime.Core.Episodes.proto.gen;
using SnackTime.Core.Media.Episodes.proto.gen;
using SonarrSharp;
using SonarrSharp.Enum;

namespace SnackTime.Core.Episodes
namespace SnackTime.Core.Media.Episodes
{
public class EpisodeProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using pb = global::Google.Protobuf;
using pbr = global::Google.Protobuf.Reflection;

namespace SnackTime.Core.Episodes.proto.gen {
namespace SnackTime.Core.Media.Episodes.proto.gen {

/// <summary>Holder for reflection information generated from types.proto</summary>
public static partial class TypesReflection {
Expand All @@ -31,7 +31,7 @@ static TypesReflection() {
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::SnackTime.Core.Episodes.proto.gen.Episode), global::SnackTime.Core.Episodes.proto.gen.Episode.Parser, new[]{ "SeriesId", "EpisodeFileId", "SeasonNumber", "EpisideNumber", "Title", "Overview" }, null, null, null)
new pbr::GeneratedClrTypeInfo(typeof(global::SnackTime.Core.Media.Episodes.proto.gen.Episode), global::SnackTime.Core.Media.Episodes.proto.gen.Episode.Parser, new[]{ "SeriesId", "EpisodeFileId", "SeasonNumber", "EpisideNumber", "Title", "Overview" }, null, null, null)
}));
}
#endregion
Expand All @@ -46,7 +46,7 @@ public sealed partial class Episode : pb::IMessage<Episode> {

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::SnackTime.Core.Episodes.proto.gen.TypesReflection.Descriptor.MessageTypes[0]; }
get { return global::SnackTime.Core.Media.Episodes.proto.gen.TypesReflection.Descriptor.MessageTypes[0]; }
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SnackTime.Core.Series.proto.gen;
using SnackTime.Core.Media.Series.proto.gen;
using SonarrSharp;
using SonarrSharp.Enum;

namespace SnackTime.Core.Series
namespace SnackTime.Core.Media.Series
{
public class SeriesProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using pb = global::Google.Protobuf;
using pbr = global::Google.Protobuf.Reflection;

namespace SnackTime.Core.Series.proto.gen {
namespace SnackTime.Core.Media.Series.proto.gen {

/// <summary>Holder for reflection information generated from types.proto</summary>
public static partial class TypesReflection {
Expand All @@ -31,8 +31,8 @@ static TypesReflection() {
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::SnackTime.Core.Series.proto.gen.Series), global::SnackTime.Core.Series.proto.gen.Series.Parser, new[]{ "Id", "Title", "ImagesUrl", "Overview", "Monitored" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::SnackTime.Core.Series.proto.gen.ImagesUrl), global::SnackTime.Core.Series.proto.gen.ImagesUrl.Parser, new[]{ "Banner", "Fanart", "Poster" }, null, null, null)
new pbr::GeneratedClrTypeInfo(typeof(global::SnackTime.Core.Media.Series.proto.gen.Series), global::SnackTime.Core.Media.Series.proto.gen.Series.Parser, new[]{ "Id", "Title", "ImagesUrl", "Overview", "Monitored" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::SnackTime.Core.Media.Series.proto.gen.ImagesUrl), global::SnackTime.Core.Media.Series.proto.gen.ImagesUrl.Parser, new[]{ "Banner", "Fanart", "Poster" }, null, null, null)
}));
}
#endregion
Expand All @@ -47,7 +47,7 @@ public sealed partial class Series : pb::IMessage<Series> {

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::SnackTime.Core.Series.proto.gen.TypesReflection.Descriptor.MessageTypes[0]; }
get { return global::SnackTime.Core.Media.Series.proto.gen.TypesReflection.Descriptor.MessageTypes[0]; }
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand Down Expand Up @@ -101,9 +101,9 @@ public string Title {

/// <summary>Field number for the "imagesUrl" field.</summary>
public const int ImagesUrlFieldNumber = 3;
private global::SnackTime.Core.Series.proto.gen.ImagesUrl imagesUrl_;
private global::SnackTime.Core.Media.Series.proto.gen.ImagesUrl imagesUrl_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::SnackTime.Core.Series.proto.gen.ImagesUrl ImagesUrl {
public global::SnackTime.Core.Media.Series.proto.gen.ImagesUrl ImagesUrl {
get { return imagesUrl_; }
set {
imagesUrl_ = value;
Expand Down Expand Up @@ -236,7 +236,7 @@ public void MergeFrom(Series other) {
}
if (other.imagesUrl_ != null) {
if (imagesUrl_ == null) {
imagesUrl_ = new global::SnackTime.Core.Series.proto.gen.ImagesUrl();
imagesUrl_ = new global::SnackTime.Core.Media.Series.proto.gen.ImagesUrl();
}
ImagesUrl.MergeFrom(other.ImagesUrl);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public void MergeFrom(pb::CodedInputStream input) {
}
case 26: {
if (imagesUrl_ == null) {
imagesUrl_ = new global::SnackTime.Core.Series.proto.gen.ImagesUrl();
imagesUrl_ = new global::SnackTime.Core.Media.Series.proto.gen.ImagesUrl();
}
input.ReadMessage(imagesUrl_);
break;
Expand All @@ -294,7 +294,7 @@ public sealed partial class ImagesUrl : pb::IMessage<ImagesUrl> {

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::SnackTime.Core.Series.proto.gen.TypesReflection.Descriptor.MessageTypes[1]; }
get { return global::SnackTime.Core.Media.Series.proto.gen.TypesReflection.Descriptor.MessageTypes[1]; }
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions SnackTime.Core/Process/IProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace SnackTime.Core.Process
{
public interface IProcessManager
{
void StartProcess(string path, string[] args = null);
bool IsProcessRunning(string path);
void StopProcess(string path);
void StartProcess(string path, string[] args = null);
bool IsProcessRunning(string path);
System.Diagnostics.Process GetProcessFromPath(string path);
}
}
42 changes: 21 additions & 21 deletions SnackTime.Core/Process/ProcessManager.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
using System.Collections.Generic;
using System.Linq;

namespace SnackTime.Core.Process
{
public class ProcessManager : IProcessManager
{
private readonly Dictionary<string, System.Diagnostics.Process> _process;

public ProcessManager()
{
_process = new Dictionary<string, System.Diagnostics.Process>();
}


public void StartProcess(string path, string[] args = null)
{
if (IsProcessRunning(path)) return;

var process = System.Diagnostics.Process.Start(path, string.Join(" ", args));
_process.Add(path, process);
System.Diagnostics.Process.Start(path, string.Join(" ", args));
}

public bool IsProcessRunning(string path)
{
if (!_process.ContainsKey(path))
return false;

if (!_process[path].HasExited) return true;

_process.Remove(path);
return false;
return GetProcessFromPath(path) == null;
}

public void StopProcess(string path)
public System.Diagnostics.Process GetProcessFromPath(string path)
{
if (IsProcessRunning(path))
_process[path].Kill();
var processes = System.Diagnostics.Process.GetProcesses();
return processes.Where(process =>
{
try
{
if (process.MainModule.FileName == path)
{
return true;
}
}
catch
{
// ignored
}

return false;
}).SingleOrDefault();
}
}
}
1 change: 0 additions & 1 deletion SnackTime.Core/Settings/SettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading;
using Microsoft.Extensions.Logging;

namespace SnackTime.Core.Settings
Expand Down
4 changes: 4 additions & 0 deletions SnackTime.Core/SnackTime.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Folder Include="Media" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion SnackTime.WebApi/Controllers/EpisodeController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SnackTime.Core.Episodes;
using SnackTime.Core.Media.Episodes;
using SnackTime.WebApi.Helpers;
using SonarrSharp;

Expand Down
5 changes: 2 additions & 3 deletions SnackTime.WebApi/Controllers/SeriesController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SnackTime.Core.Series;
using SnackTime.Core.Media.Series;
using SnackTime.WebApi.Helpers;
using SonarrSharp;

Expand Down
3 changes: 2 additions & 1 deletion SnackTime.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static void Main(string[] args)
.MinimumLevel.Verbose()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate:"[{Timestamp:HH:mm:ss} {Level:u3} {CustomRequestId} {Method} {Endpoint}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Console(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3} {CustomRequestId} {Method} {Endpoint}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();

CreateWebHostBuilder(args).Build().Run();
Expand Down

0 comments on commit a49f3e1

Please sign in to comment.