public static void Main(string[] args) { var action = DynamicSelectionActionWithCondition.CreateNew(ctx => { if (Station.CheckFreeSlots(out var countFreeSlots)) { return(SelectionAction .CreateNew($"Количество свободных мест для стоянки - {countFreeSlots}") .AddAction("1", "Принять самолёт", DataInputAction.CreateNew("Укажите номер борта самолёта", "airNum") .SetDescendantAction(WorkAction.CreateNew(ctx1 => { var id = ctx1["airNum"]; Console.WriteLine(Station.TryTakeAircraft(id) ? $"Самолёт с номером борта '{id}' принят" : $"Самолёт с номером борта '{id}' не удалось принять"); }))) .AddAction("2", "Отправить самолёт", SendAircraftAction())); } return(SelectionAction .CreateNew("Свободных мест для самолётов нет") .AddAction("1", "Отправить самолёт", SendAircraftAction())); }); var worker = new ConsoleActionsWorker(action, new WorkerSettings { SelectDescription = "Введите номер действия", ReselectDescriptionIfUnknownAction = "Указанное действие не найдено. Повторите выбор" }); worker.Start(); }
private char FindChar(char current, WorkAction action) { char resp = _empty; int ref1; switch (action) { case WorkAction.EncodeDToB: ref1 = _dRefTable.IndexOf(current); resp = ref1 != -1 ? _bRefTable[ref1] : _empty; break; case WorkAction.EncodeBToF: ref1 = _bRefTable.IndexOf(current); resp = ref1 != -1 ? _fRefTable[ref1] : _empty; break; case WorkAction.DecodeFToB: ref1 = _fRefTable.IndexOf(current); resp = ref1 != -1 ? _bRefTable[ref1] : _empty; break; case WorkAction.DecodeBToD: ref1 = _bRefTable.IndexOf(current); resp = ref1 != -1 ? _dRefTable[ref1] : _empty; break; } return(resp); }
/// <summary> /// This methods records the exception to be included in the work report /// </summary> /// <param name="exception">The caught exception</param> /// <param name="action">What was happening at the time</param> public void ProcessException(Exception exception, WorkAction action) { if (action == WorkAction.Execute) { _exeCaughtException = exception; } else { _undoCaughtException = exception; } }
public static void Main(string[] args) { var enterAction = DataInputAction.CreateNew($"Введите логин:", "login") .SetDescendantAction(DynamicSelectionActionWithCondition.CreateNew(ctx => { var login = ctx["login"]; if (RegistrationStorage.ContainsKey(login)) { Console.WriteLine($"Здравствуйте, {RegistrationStorage[login]}"); return(new WorkAction(ctx1 => { })); } Console.WriteLine("Пользователь не найден. Зарегистрируйтесь..."); return(DataInputAction.CreateNew("Введите логин:", "newLogin") .SetDescendantAction(DataInputAction.CreateNew("Введите имя:", "newName") .SetDescendantAction(new WorkAction(ctx1 => { var newLogin = ctx1["newLogin"]; if (RegistrationStorage.ContainsKey(newLogin)) { Console.WriteLine($"Логин {newLogin} занят"); return; } var newName = ctx1["newName"]; RegistrationStorage.Add(newLogin, newName); Console.WriteLine($"Прошла регистрация логин - {newLogin}, имя - {newName}"); })))); })); var action = SelectionAction.CreateNew() .AddAction("1", "Ввести учетную запись", enterAction) .AddAction("2", "Показать имена всех пользователей", WorkAction.CreateNew(ctx => { foreach (var name in RegistrationStorage.Values) { Console.WriteLine(name); } })); var worker = new ConsoleActionsWorker(action, new WorkerSettings { SelectDescription = "Введите номер действия", ReselectDescriptionIfUnknownAction = "Указанное действие не найдено. Повторите выбор" }); worker.Start(); }
public void ExecuteTurn() { SleepAction.CalculateScore(); EatAction.CalculateScore(); WorkAction.CalculateScore(); FreeAction.CalculateScore(); Result = new PlayerTurnResult(); Result.MoneyEarned = WorkAction.MoneyEarned; if (!WorkAction.TargetMet) { Result.WarningStrikesEarned++; } Result.SelfEsteemChange -= SleepAction.LostSelfEsteem; Result.SelfEsteemChange -= EatAction.LostSelfEsteem; }
public string Decode(string encodedText) { encodedText = encodedText.Trim().ToUpper(); string decodedStr = ""; WorkAction action = encodedText[0] == 'F' ? WorkAction.DecodeFToB : WorkAction.DecodeBToD; if (action == WorkAction.DecodeFToB) { decodedStr += 'B'; } for (var i = 1; i < encodedText.Length; i++) { decodedStr += FindChar(encodedText[i], action); } return(decodedStr); }
public ParallelFor(long from, long to, byte threads, int timeout, WorkAction work) { this.from = from; this.to = to; this.threads = new Worker[threads]; this.timeout = timeout; this.work = work; this.active = threads; lock (this) { for (byte i = 0; i < threads; i++) { var t = this.threads[i] = new Worker(this, i); t.Start(); } } }
public string Encode(string plainText) { plainText = plainText.Trim().ToUpper(); string encodedStr = ""; WorkAction action = plainText[0] == 'B' ? WorkAction.EncodeBToF : WorkAction.EncodeDToB; if (action == WorkAction.EncodeDToB) { encodedStr += 'B'; } else { encodedStr += 'F'; } for (var i = (action == WorkAction.EncodeDToB ? 0 : 1); i < plainText.Length; i++) { encodedStr += FindChar(plainText[i], action); } return(encodedStr); }
private bool doWork( WorkAction workAction ) { int job = -1; while( true ) { lock( lockObj ) { if( _jobStartedCount < _jobCount ) { job = _jobList[ _jobStartedCount ]; ++_jobStartedCount; } break; } } if( job >= 0 ) { workAction( job, _jobCount ); while( true ) { lock( lockObj ) { ++_jobCompletedCount; break; } } return true; } return false; }
public static IFilter Filter(Context context, string mask, WorkAction action) { return(Work.Filter(context, mask, null, false, action)); }
public static IFilter Filter(Context context, string mask, string toExt, bool recurse, WorkAction action) { Worklist work = new Worklist(); work.Mask = mask; work.context = context; work.ToExt = toExt; work.Action = action; work.Recurse = recurse; return(work); }
/// <summary> /// Loops through the items using multiple threads /// </summary> /// <param name="from">Start index, inclusive</param> /// <param name="to">End index, exclusive</param> /// <param name="threads">Number of threads to use</param> /// <param name="timeout">The duration a task can run for before being aborted, if > 0</param> /// <param name="work">Work to run</param> public static ILoop For(long from, long to, byte threads, int timeout, WorkAction work) { return(new ParallelFor(from, to, threads, timeout, work)); }