Skip to content

Commit

Permalink
Refactor remoting services
Browse files Browse the repository at this point in the history
  • Loading branch information
fahminlb33 committed Feb 28, 2021
1 parent a6e5b99 commit 4f3ccda
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using KFlearning.Core.Services;
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace KFlearning.Core.Services
namespace KFlearning.Core.Remoting
{
public interface IKFserverService : IDisposable
public interface IKFServer : IDisposable
{
bool IsRunning { get; }

Expand All @@ -16,7 +17,7 @@ public interface IKFserverService : IDisposable
void Stop();
}

public class KFserverService : IKFserverService
public class KFServer : IKFServer
{
private const int ServerPort = 21002;
private const string KFserverProcessName = "kfserver";
Expand All @@ -26,7 +27,7 @@ public class KFserverService : IKFserverService
public bool IsRunning => Process.GetProcessesByName(KFserverProcessName).Length > 0;


public KFserverService(IPathManager pathManager)
public KFServer(IPathManager pathManager)
{
_pathManager = pathManager;
}
Expand All @@ -50,6 +51,7 @@ public void Stop()
foreach (var process in Process.GetProcessesByName(KFserverProcessName))
{
process.Kill();
process?.Dispose();
}
}
catch (Exception)
Expand Down Expand Up @@ -82,28 +84,14 @@ public ServerInfo GetInfo()

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
if (_disposedValue) return;

Stop();
_disposedValue = true;
}
Stop();
_disposedValue = true;
}

// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~KFserverService()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
// SOLUTION : KFlearning
// PROJECT : KFlearning.Core
// FILENAME : RemoteServer.cs
// AUTHOR : Fahmi Noor Fiqri, Kodesiana.com
// WEBSITE : https://kodesiana.com
// REPO : https://github.com/Kodesiana or https://github.com/fahminlb33
//
// This file is part of KFlearning, see LICENSE.
// See this code in repository URL above!

using System;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace KFlearning.Core.Services
namespace KFlearning.Core.Remoting
{
public interface IRemoteShutdownServer : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace KFlearning.Core.Services
namespace KFlearning.Core.Remoting
{
public class ServerInfo
{
Expand Down
11 changes: 11 additions & 0 deletions src/KFlearning.Core/Remoting/ShutdownRequestedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Net;

namespace KFlearning.Core.Remoting
{
public class ShutdownRequestedEventArgs : EventArgs
{
public IPAddress Address { get; set; }
public string Clusster { get; set; }
}
}
21 changes: 0 additions & 21 deletions src/KFlearning.Core/Services/ShutdownRequestedEventArgs.cs

This file was deleted.

0 comments on commit 4f3ccda

Please sign in to comment.