private void StartService() { ServiceController service = new ServiceController(NameProcess, Environment.MachineName); try { if (libConfig.Save()) { MonitorCore.MMonitor mMonitor = new MMonitor(rdbLocal.Checked, txtHost.Text); if (ValidHost(mMonitor)) { if (libConfig.Local == false) { service.Start(new string[] { libConfig.Host }); } else { service.Start(new string[] { libConfig.UserBd, libConfig.PassBd, libConfig.UrlBd, libConfig.CatalogBd }); } service.WaitForStatus(ServiceControllerStatus.Running); MessageBox.Show("Servicio iniciado", "Campos Inteligentes", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RefreshInfo() { libConfig.Refresh(); txtBd.Text = libConfig.CatalogBd; txtUrlBd.Text = libConfig.UrlBd; txtUserBd.Text = libConfig.UserBd; txtHost.Text = libConfig.Host; rdbLocal.Checked = libConfig.Local;//ConfigurationManager.AppSettings["host"]; //var p = Process.GetCurrentProcess().ProcessName; var p = Process.GetProcesses(); ListProcess = Process.GetProcessesByName(NameProcess); MonitorCore = new MMonitor(libConfig.Local, libConfig.Host); TMonitor.Elapsed += MonitorCore.Process; if (ListProcess.Count() > 0) { groupBox1.Enabled = false; contextMenuStrip1.Items[2].Enabled = false; contextMenuStrip1.Items[3].Enabled = true; btnStart.Enabled = false; btnStop.Enabled = true; btnRestart.Enabled = true; cancellationToken = new CancellationTokenSource(); txtArea.Text = "Estatus: Iniciado \r\n"; TMonitor.Start(); var d = RequestMonitor(new TimeSpan(0, 0, 0, 20, 0), cancellationToken.Token, new MMonitor(libConfig.Local, libConfig.Host), txtArea); } else { groupBox1.Enabled = true; contextMenuStrip1.Items[2].Enabled = true; contextMenuStrip1.Items[3].Enabled = false; btnStart.Enabled = true; btnStop.Enabled = false; //btnGo.Enabled = true; btnRestart.Enabled = false; //txtHost.ReadOnly = false; txtArea.Text = "Estatus: Detenido \r\n"; //timerMonitor.Stop(); TMonitor.Stop(); if (cancellationToken != null) { cancellationToken.Cancel(); } } }
static void Main(string[] args) { System.Timers.Timer MTimer = new System.Timers.Timer(5000) { AutoReset = true }; string location = System.Reflection.Assembly.GetExecutingAssembly().Location; Console.WriteLine("Version " + System.Diagnostics.FileVersionInfo.GetVersionInfo(location).FileVersion + " | Build: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(location).FileBuildPart); Console.WriteLine("================================================================================="); //Console.WriteLine("Environment: "+Libraries.Settings.Get("enviroment")+"\nSoftware version: "+Libraries.Settings.Get("prosper_version")+"\nMessages:"+ (Libraries.Settings.Get("show_messages")=="1"?"Y":"N")+"\nPROSPER: "+(Libraries.Settings.Get("open_prosper") == "1" ? "Y" : "N")); //Console.WriteLine("================================================================================="); //Console.WriteLine("No cierres esta ventana... "); var intervalTimeSpan = new TimeSpan(0, 0, 0, 5, 0); Console.WriteLine("Tipo de conexion(1=Local,2=Remoto)?: "); var local = Console.ReadLine(); string host = ""; if (local == "2") { Console.WriteLine("Host(Ejem. http://ejemplo.com/service.svc): "); host = Console.ReadLine(); } //Task Timer = TimerTask(intervalTimeSpan, cancellationToken.Token); //Console.ReadLine(); //cancellationToken.Cancel(); // FUNCIONA BIEN MMonitor mMonitor = new MMonitor(local == "1"?true:false, host); mMonitor.ModeMessage = MMonitor.Modo.console; //var d = mMonitor.Process(intervalTimeSpan, cancellationToken.Token); MTimer.Elapsed += mMonitor.Process; MTimer.Start(); Console.WriteLine("Iniciando procesos"); Console.ReadLine(); MTimer.Stop(); // cancellationToken.Cancel(); }
private bool ValidHost(MMonitor mMonitor) { try { string Prosper = null; var conn = mMonitor.Monitor(ref Prosper); if (conn.Count() > 0) { return(true); } return(false); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary>The method that calculates what seeds should dropped from mixed seeds. This is dependant on the config and installed mods.</summary> private void PopulateSeeds() { List <Seed> enabledSeeds = new List <Seed>(); // Add seeds from Stardew Valley enabledSeeds = enabledSeeds .Union(CheckModForEnabledCrops("StardewValley")) .ToList(); // Add seeds from integrated mods List <string> integratedModsInstalled = CheckIntegratedMods(); object jaApi = null; if (integratedModsInstalled.Count() != 0) { jaApi = this.Helper.ModRegistry.GetApi("spacechase0.JsonAssets"); if (jaApi != null) { foreach (string modName in integratedModsInstalled) { MMonitor.Log($"{modName} loaded"); enabledSeeds = enabledSeeds .Union(CheckModForEnabledCrops(modName)) .ToList(); } } else { MMonitor.Log("Failed to retrieve Json Assets API", LogLevel.Error); } } // Create a new collection, so no exceptions occur from changing values in the current collection loop List <Seed> updatedEnabledSeeds = new List <Seed>(); foreach (var enabledSeed in enabledSeeds) { Seed newEnabledSeed = enabledSeed; int seedIndex; // Check if the current seedName is a number, meaning it's a Stardew seed if (int.TryParse(enabledSeed.Name, out seedIndex)) { newEnabledSeed.Id = seedIndex; } else { // Get seed if the current seed is from an integrated mod seedIndex = this.Helper.Reflection.GetMethod(jaApi, "GetObjectId").Invoke <int>(enabledSeed.Name); if (seedIndex == -1) { MMonitor.Log($"Could find seed index for item: {enabledSeed.Name}", LogLevel.Error); continue; } newEnabledSeed.Id = seedIndex; } updatedEnabledSeeds.Add(newEnabledSeed); } Seeds = updatedEnabledSeeds; }
/// <summary>The method for finding which seeds are currently enabled in the specified mod.</summary> /// <param name="modName">The internal mod name that will be used for getting the list of seeds.</param> /// <returns>A list of enabled seeds.</returns> private List <Seed> CheckModForEnabledCrops(string modName) { List <Seed> seedNames = new List <Seed>(); // Get the CropMod object for the current mod from config PropertyInfo configInfo = ModConfig.GetType().GetProperty(modName); CropMod mod = (CropMod)configInfo.GetValue(ModConfig); // Get the 4 season properties for the current CropMod PropertyInfo[] modSeasonsInfo = mod.GetType().GetProperties(); // Get the seed index for finding seed names for the crops PropertyInfo seedIndexInfo = SeedIndex.GetType().GetProperty(modName); Dictionary <string, string> seedIndex = (Dictionary <string, string>)seedIndexInfo.GetValue(SeedIndex); for (int i = 0; i < 4; i++) { PropertyInfo modSeasonInfo = modSeasonsInfo[i]; Season season = (Season)modSeasonInfo.GetValue(mod); string seasonName = modSeasonInfo.Name.ToLower(); if (season == null) { continue; } foreach (Crop crop in season.Crops) { if (crop.Enabled) { string seedName = seedIndex .Where(seed => seed.Key == crop.Name) .Select(seed => seed.Value) .FirstOrDefault(); if (string.IsNullOrEmpty(seedName)) { MMonitor.Log($"Seed name for {crop.Name} couldn't be found", LogLevel.Error); continue; } // If the seed is already in the dictionary, add the season to the array if (seedNames.Where(seed => seed.Name == seedName).Any()) { // Add the season to all instances of the seed seedNames .Where(seed => seed.Name == seedName) .Select(seed => seed.Seasons.Add(seasonName)); } else { // Add the to the list [Chance] number of times, so it has an effect on the final result for (int j = 0; j < crop.Chance; j++) { seedNames.Add(new Seed(0, seedName, new string[1] { seasonName })); } MMonitor.Log($"{seedName} has been added to the seed list"); } } } } return(seedNames); }