From 5cd825304c661dfaeef8154e9d8a4d3c32102b54 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 9 Sep 2024 10:33:26 +0200 Subject: [PATCH] Version inicial --- .gitignore | 3 + SoloEnLan.sln | 25 ++++++++ SoloEnLan/App.config | 6 ++ SoloEnLan/Program.cs | 25 ++++++++ SoloEnLan/Properties/AssemblyInfo.cs | 36 ++++++++++++ SoloEnLan/Service1.Designer.cs | 37 ++++++++++++ SoloEnLan/Service1.cs | 34 +++++++++++ SoloEnLan/SoloEnLan.csproj | 65 +++++++++++++++++++++ SoloEnLan/model/monitor.cs | 72 ++++++++++++++++++++++++ SoloEnLan/service/NotificacionService.cs | 26 +++++++++ SoloEnLan/service/conexionService.cs | 17 ++++++ SoloEnLan/service/shutdownService.cs | 16 ++++++ 12 files changed, 362 insertions(+) create mode 100644 .gitignore create mode 100644 SoloEnLan.sln create mode 100644 SoloEnLan/App.config create mode 100644 SoloEnLan/Program.cs create mode 100644 SoloEnLan/Properties/AssemblyInfo.cs create mode 100644 SoloEnLan/Service1.Designer.cs create mode 100644 SoloEnLan/Service1.cs create mode 100644 SoloEnLan/SoloEnLan.csproj create mode 100644 SoloEnLan/model/monitor.cs create mode 100644 SoloEnLan/service/NotificacionService.cs create mode 100644 SoloEnLan/service/conexionService.cs create mode 100644 SoloEnLan/service/shutdownService.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2474f95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.vs/* +/SoloEnLan/bin/* +/SoloEnLan/obj/* diff --git a/SoloEnLan.sln b/SoloEnLan.sln new file mode 100644 index 0000000..0ad5762 --- /dev/null +++ b/SoloEnLan.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35013.160 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoloEnLan", "SoloEnLan\SoloEnLan.csproj", "{E15ED562-973B-41AB-B45E-3F7944570CAA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E15ED562-973B-41AB-B45E-3F7944570CAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E15ED562-973B-41AB-B45E-3F7944570CAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E15ED562-973B-41AB-B45E-3F7944570CAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E15ED562-973B-41AB-B45E-3F7944570CAA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0BE8CCF9-7EBD-46DB-B40F-AB60D03CA5A2} + EndGlobalSection +EndGlobal diff --git a/SoloEnLan/App.config b/SoloEnLan/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/SoloEnLan/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SoloEnLan/Program.cs b/SoloEnLan/Program.cs new file mode 100644 index 0000000..be137ce --- /dev/null +++ b/SoloEnLan/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceProcess; +using System.Text; +using System.Threading.Tasks; + +namespace SoloEnLan +{ + internal static class Program + { + /// + /// Punto de entrada principal para la aplicación. + /// + static void Main() + { + ServiceBase[] ServicesToRun; + ServicesToRun = new ServiceBase[] + { + new Service1() + }; + ServiceBase.Run(ServicesToRun); + } + } +} diff --git a/SoloEnLan/Properties/AssemblyInfo.cs b/SoloEnLan/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d48c4d8 --- /dev/null +++ b/SoloEnLan/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos valores de atributo para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("SoloEnLan")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SoloEnLan")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible en true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. +[assembly: Guid("e15ed562-973b-41ab-b45e-3f7944570caa")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +// utilizando el carácter "*", como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SoloEnLan/Service1.Designer.cs b/SoloEnLan/Service1.Designer.cs new file mode 100644 index 0000000..beeaf22 --- /dev/null +++ b/SoloEnLan/Service1.Designer.cs @@ -0,0 +1,37 @@ +namespace SoloEnLan +{ + partial class Service1 + { + /// + /// Variable del diseñador necesaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Limpiar los recursos que se estén usando. + /// + /// true si los recursos administrados se deben desechar; false en caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Código generado por el Diseñador de componentes + + /// + /// Método necesario para admitir el Diseñador. No se puede modificar + /// el contenido de este método con el editor de código. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.ServiceName = "Service1"; + } + + #endregion + } +} diff --git a/SoloEnLan/Service1.cs b/SoloEnLan/Service1.cs new file mode 100644 index 0000000..735101e --- /dev/null +++ b/SoloEnLan/Service1.cs @@ -0,0 +1,34 @@ +using SoloEnLan.model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.ServiceProcess; +using System.Text; +using System.Threading.Tasks; + +namespace SoloEnLan +{ + public partial class Service1 : ServiceBase + { + monitor m; + public Service1() + { + InitializeComponent(); + + m=new monitor(); + } + + protected override void OnStart(string[] args) + { + m.start(); + } + + protected override void OnStop() + { + m.fin(); + } + } +} diff --git a/SoloEnLan/SoloEnLan.csproj b/SoloEnLan/SoloEnLan.csproj new file mode 100644 index 0000000..65db86b --- /dev/null +++ b/SoloEnLan/SoloEnLan.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {E15ED562-973B-41AB-B45E-3F7944570CAA} + WinExe + SoloEnLan + SoloEnLan + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Component + + + Service1.cs + + + + + + + + + + + + \ No newline at end of file diff --git a/SoloEnLan/model/monitor.cs b/SoloEnLan/model/monitor.cs new file mode 100644 index 0000000..5b06764 --- /dev/null +++ b/SoloEnLan/model/monitor.cs @@ -0,0 +1,72 @@ +using SoloEnLan.service; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SoloEnLan.model +{ + + public class monitor + { + private Thread t; + private bool pirate; + private int tiempoComprobacion; + private int tiempoMensaje; + public monitor() + { + t = null; + pirate = false; + tiempoComprobacion = int.Parse(ConfigurationManager.AppSettings["tiempoComprovacion"]); + tiempoMensaje = int.Parse(ConfigurationManager.AppSettings["tiempoNotificacion"]); + } + + private static void runMonitor(object m) + { + + ((monitor)m).run(); + } + private void run() + { + while(!pirate) + { + //espera + Thread.Sleep(tiempoComprobacion); + //revisa lan + if (conexionService.Getestas()) + { + //manda mensaje + NotificacionService.Notifica(); + //espera despues de mensaje + Thread.Sleep(tiempoMensaje); + //apaga + shutdownService.apagaPc(); + } + Thread.Sleep(60); + + + } + } + + public void start() + { + + if (!t.IsAlive) + { + pirate = false; + t.Start(this); + } + + } + public void fin() + { + pirate = true; + t.Join(); + } + } + + +} diff --git a/SoloEnLan/service/NotificacionService.cs b/SoloEnLan/service/NotificacionService.cs new file mode 100644 index 0000000..90cc448 --- /dev/null +++ b/SoloEnLan/service/NotificacionService.cs @@ -0,0 +1,26 @@ +//using Microsoft.Toolkit.Uwp.Notifications; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoloEnLan.service +{ + internal class NotificacionService + { + public static void Notifica() + { + /*string mens = ConfigurationManager.AppSettings["MensajeAviso"]; + new ToastContentBuilder() + .AddArgument("action", "viewConversation") + .AddArgument("conversationId", 9813) + .AddText("Aviso") + .AddText(mens) + .Show(); // Not seeing the Show() method? Make sure you have version 7.0, and if you're using .NET 6 (or later), then your TFM must be net6.0-windows10.0.17763.0 or greater + } + */ + } + } +} diff --git a/SoloEnLan/service/conexionService.cs b/SoloEnLan/service/conexionService.cs new file mode 100644 index 0000000..8bde7ef --- /dev/null +++ b/SoloEnLan/service/conexionService.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoloEnLan.service +{ + internal class conexionService + { + + public static bool Getestas() + { + return true; + } + } +} diff --git a/SoloEnLan/service/shutdownService.cs b/SoloEnLan/service/shutdownService.cs new file mode 100644 index 0000000..1e0db55 --- /dev/null +++ b/SoloEnLan/service/shutdownService.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoloEnLan.service +{ + internal class shutdownService + { + public static void apagaPc() + { + + } + } +}