/// <summary> /// Initializes a new instance of the <see cref="ScheduleItem"/> class. /// </summary> /// <param name="setting"> /// The setting. /// </param> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="isCreated"> /// The is created. /// </param> /// <param name="isDirty"> /// The is dirty. /// </param> /// <param name="createdName"> /// The created name. /// </param> public ScheduleItem(SchedulerSetting setting, ExecutionParam parameters, bool isCreated, bool isDirty, string createdName) { this.Setting = setting; this.Parameters = parameters; if (this.Parameters.DepartureDate == DateTime.MinValue) { this.Parameters.DepartureDate = DateTime.Now.Date; } if (this.Parameters.ReturnDate == DateTime.MinValue) { this.Parameters.ReturnDate = this.Parameters.DepartureDate.Date.AddDays(this.Parameters.MaxStayDuration); } this.IsCreated = isCreated; this.CreatedName = createdName; }
/// <summary> /// The get environment. /// </summary> /// <param name="executionParam"> /// The execution param. /// </param> /// <param name="globalContext"> /// The global context. /// </param> /// <returns> /// The <see cref="MonitorEnvironment"/>. /// </returns> private MonitorEnvironment GetEnvironment(ExecutionParam executionParam, WinFormGlobalContext globalContext) { var pluginResolver = new AssemblyPluginResolver(this.Logger); pluginResolver.LoadPlugins(); var configStore = new FileConfigStore(AppUtil.GetLocalDataPath(this.ENV_CONFIG_FILENAME), pluginResolver, this.Logger); MonitorEnvironment env = configStore.LoadEnv(); if (env == null || env.ArchiveManager == null || env.FareDatabase == null || env.FareDataProvider == null) { env = new MonitorEnvironment(configStore, pluginResolver, new BackgroundServiceManager(this.Logger), this.Logger); globalContext.AddServices(env); using (var configDialog = new EnvConfiguratorDialog(env, executionParam)) { if (configDialog.ShowDialog() == DialogResult.OK) { env = configDialog.ResultEnvironment; } else { env.Close(); env = null; } } } return env; }
/// <summary>The show help.</summary> public static void ShowHelp() { StringBuilder sb = new StringBuilder(); sb.AppendLine("Specify parameters in this format: -{Parameter ConfiguredType}[{Parameter TypeConfiguration}]"); sb.AppendLine("(without the { and } characters)\n"); sb.AppendLine("If parameter key value contains space, wrap it in double-quotation mark\n"); foreach (var p in switches) { sb.AppendFormat("-{0}{1}\t{2}\n", p.IDString, p.Type == SwitchType.Simple ? string.Empty : "..", p.Description); } var example = new ExecutionParam { Departure = AirportDataProvider.FromIATA("HEL"), Destination = AirportDataProvider.FromIATA("SGN"), DepartureDate = DateTime.Now.Date, ReturnDate = DateTime.Now.Date.AddDays(7), DepartureDateRange = new DateRangeDiff(1), ReturnDateRange = new DateRangeDiff(2), IsMinimized = true, ExitAfterDone = true, MinStayDuration = 7, MaxStayDuration = 8, PriceLimit = 2000, OperationMode = OperationMode.GetFareAndSave }; var exCli = example.GenerateCommandLine(); sb.AppendLine("\nFor Example:" + Environment.NewLine + exCli); MessageBox.Show(sb.ToString(), "Parameter Information", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary>The get scheduled tasks.</summary> /// <returns>The <see cref="List" />.</returns> public List<ScheduleItem> GetScheduledTasks() { var result = new List<ScheduleItem>(); // Get the service on the local machine using (var ts = new TaskService()) { TaskCollection tc = ts.RootFolder.GetTasks(null); foreach (Task task in tc) { try { if (task.Definition.Actions.Count > 0) { var action = task.Definition.Actions[0] as ExecAction; if (action != null) { if (string.Compare( CurrentExe, Path.GetFullPath(action.Path.Replace("\"", string.Empty)), StringComparison.InvariantCultureIgnoreCase) == 0) { try { ExecutionParam param = null; try { ExecutionParam.Parse(action.Arguments.SplitCommandLine(), null, this._logger, out param); } catch { param = new ExecutionParam(); } DateTime activeTriggerDate = DateTime.MinValue; foreach (Trigger trigger in task.Definition.Triggers) { var timeTrigger = trigger as DailyTrigger; if (timeTrigger != null) { activeTriggerDate = timeTrigger.StartBoundary; break; } } var setting = new SchedulerSetting { TaskName = task.Name.Replace(AppUtil.ProductName, string.Empty), IsEnabled = task.Enabled, ScheduledStartTime = activeTriggerDate }; result.Add(new ScheduleItem(setting, param, true, false, task.Name)); } catch (Exception ex) { this._logger.Warn("Failed to get scheduled tasks: " + ex.Message); } } } } } catch (Exception ex) { this._logger.ErrorFormat("Could not load task [{0}]: {1}", task.Name, ex.Message); } } } return result; }
/// <summary> /// The parse. /// </summary> /// <param name="paramArgs"> /// The param args. /// </param> /// <param name="iniFilePath"> /// The ini file path. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="param"> /// The param. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> /// <exception cref="ApplicationException"> /// </exception> public static bool Parse(string[] paramArgs, string iniFilePath, ILogger logger, out ExecutionParam param) { paramArgs = paramArgs ?? new string[0]; var result = new ExecutionParam(); int tempI; var parser = new Parser(switches.Length); parser.ParseStrings(switches, paramArgs); if (!string.IsNullOrEmpty(iniFilePath)) { var iniParser = new ObjectIniConfig(iniFilePath, logger); iniParser.LoadINI(); iniParser.ApplyData(result); result.ConfigHandler = iniParser; } result.IsMinimized = parser[0].ThereIs; result.AutoSync = parser[1].ThereIs; DateTime tempD; if (parser[2].ThereIs) { if (!DateTime.TryParseExact(parser[2].PostStrings[0].ToString(), DATE_FORMAT_PARAM, null, DateTimeStyles.AssumeLocal, out tempD)) { throw new ApplicationException("Invalid departure date"); } result.DepartureDate = tempD; } if (parser[4].ThereIs) { if (!DateTime.TryParseExact(parser[4].PostStrings[0].ToString(), DATE_FORMAT_PARAM, null, DateTimeStyles.AssumeLocal, out tempD)) { throw new ApplicationException("Invalid return date"); } result.ReturnDate = tempD; } if (parser[6].ThereIs) { if (!int.TryParse(parser[6].PostStrings[0].ToString(), out tempI)) { throw new ApplicationException("Invalid minimum stay duration"); } result.MinStayDuration = tempI; } else { result.MinStayDuration = Settings.Default.DefaultDurationMin; } if (parser[7].ThereIs) { if (!int.TryParse(parser[7].PostStrings[0].ToString(), out tempI)) { throw new ApplicationException("Invalid maximum stay duration"); } result.MaxStayDuration = tempI; } else { result.MaxStayDuration = Settings.Default.DefaultDurationMax; } if (parser[8].ThereIs) { if (!int.TryParse(parser[8].PostStrings[0].ToString(), out tempI)) { throw new ApplicationException("Invalid price limit"); } result.PriceLimit = tempI; } else { result.PriceLimit = Settings.Default.DefaultPriceLimit; } if (parser[9].ThereIs) { result.OperationMode = (OperationMode)Enum.Parse(typeof(OperationMode), parser[9].PostStrings[0].ToString(), true); if (result.OperationMode != OperationMode.Unspecified) { result.DepartureDateRange = DateRangeDiff.Parse(parser[3].PostStrings[0].ToString()); result.ReturnDateRange = DateRangeDiff.Parse(parser[5].PostStrings[0].ToString()); } } if (parser[10].ThereIs) { result.Departure = AirportDataProvider.FromIATA(parser[10].PostStrings[0].ToString()); } if (parser[11].ThereIs) { result.Destination = AirportDataProvider.FromIATA(parser[11].PostStrings[0].ToString()); } if (parser[13].ThereIs) { result.ExitAfterDone = true; } result.Validate(); param = result; if (parser[12].ThereIs) { return false; } return true; }