/// <summary> /// Get a list of Jobs matching the source directory from the config file /// </summary> /// <param name="configFilePath">The path to the config file</param> /// <param name="enableCaching">Optional, enable caching for the config path & source dirs</param> /// <returns></returns> public static List <Jobs> GetJobListFromEnabledService(string configFilePath, bool enableCaching = false) { var jobs = new List <Jobs>(); if (File.Exists(configFilePath)) { string json = File.ReadAllText(configFilePath); var serializerSettings = new JsonSerializerSettings() { ObjectCreationHandling = ObjectCreationHandling.Replace }; var deserializedJson = JsonConvert.DeserializeObject <JsonConfig>(json, serializerSettings); jobs = deserializedJson.Jobs.Where(x => x.Service != null && x.Service.EnableBackgroundService).ToList(); if (jobs.Count > 0) { FileLogger.Info("Found " + jobs.Count + " task(s) with enabled option \"EnableBackgroundService\""); if (enableCaching) { FileSysWatcher.SetCache(configFilePath, jobs.Select(x => x.Source).ToList()); } } else { FileLogger.Info("No task with enabled option \"EnableBackgroundService\""); } } return(jobs); }
/// <summary> /// Return the configFullPath of all users /// </summary> /// <returns></returns> public static List <string> GetConfigPathOfAllUsers() { var returnVal = new List <string>(); switch (Program.os) { case "win": var search = new ManagementObjectSearcher(new SelectQuery("Select * from Win32_UserAccount WHERE Disabled=False")); foreach (ManagementObject env in search.Get()) { var currentUserName = env["Name"].ToString(); var configPathOfUser = Regex.Replace(Json.confPathWin, @"(Users\\)(.*)(\\AppData)", m => m.Groups[1] + currentUserName + m.Groups[3]); returnVal.Add(configPathOfUser); FileSysWatcher.SetCache(currentUserName, configPathOfUser); } break; case "lin": case "fbd": // === Determine users via home directory //foreach (var homeDir in Directory.GetDirectories(enumeratePathToDetermineAllUserNames)) { // var homeDir_ = new DirectoryInfo(homeDir).Name; // var confPathLnx = Json.confPathLnx.Replace(System.Environment.UserName, homeDir_); // returnVal.Add(confPathLnx); FileLogger.Debug("Service user: "******"confPathLnx: " + Json.confPathLnx); returnVal.Add(Json.confPathLnx); FileSysWatcher.SetCache(System.Environment.UserName, Json.confPathLnx); //} break; case "mos": break; } return(returnVal); }