public void LoadSettings(UserSettings userSettings, bool load) { if (!load) { return; } try { userSettings = GetLocalUserSettings(userSettings); } catch (Exception) { if (!FilesHelper.FileExists(userSettings.SettingsFileLocation)) { NotificationsHelper.DisplayMessage(Messages.Preparing); PrepareEnvironment(new UserSettings()); } else if (!CommandsHelper.ShouldExecuteTasks()) { NotificationsHelper.DisplayMessage(Messages.Ready); } else { NotificationsHelper.DisplayMessage(Messages.ErrorInSettings); } } }
/// <summary> /// Main method. /// </summary> /// <param name="args">List of arguments.</param> private static void Main(string[] args) { Console.WriteLine("Spark Words Processor"); Console.WriteLine("Parses a file with word counts for the training model."); if (args.Length < 1 || args.Length > 2) { Console.WriteLine("Arguments are: <sessionTag> [path-to-cache] where sessionTag is an integer."); return; } if (!int.TryParse(args[0], out var tag)) { Console.WriteLine($"Session tag must be an integer! Value {args[0]} is invalid!"); } if (args.Length == 2) { filesHelper = new FilesHelper(tag, cache: args[1]); } else { filesHelper = new FilesHelper(tag); } Console.WriteLine($"Initialized cache to {filesHelper.PathToCache}"); if (!filesHelper.FileExists(filesHelper.TempDataFile)) { Console.WriteLine($"Could not find input file: {filesHelper.TempDataFile}."); } var spark = SparkSession.Builder() .AppName(nameof(SparkWordsProcessor)) .GetOrCreate(); RunJob(); spark.Stop(); Console.WriteLine($"Successfully generated model training file to {filesHelper.ModelTrainingFile}."); }
private static void PrepareEnvironment(UserSettings userSettings) { try { if (!FilesHelper.FileExists(userSettings.TasksLocation)) { FilesHelper.OpenOrCreateFile(userSettings.TasksLocation); } if (!FilesHelper.FileExists(userSettings.SettingsFileLocation)) { FilesHelper.OpenOrCreateFile(userSettings.SettingsFileLocation); FilesHelper.WriteAllText(userSettings.SettingsFileLocation, JsonHelper.Serialize(userSettings)); } if (!DirectoriesHelper.DirectoryExists(userSettings.DownloadLocation)) { DirectoriesHelper.CreateDirectory(userSettings.DownloadLocation); } } catch { NotificationsHelper.DisplayMessage(Messages.ErrorInitiatingConfiguration); } }