Example #1
0
        public void Run()
        {
            while (true)
            {
                int value;
                var res = _io.Ask(FACTOR_QUESTION);
                if (string.IsNullOrEmpty(res))
                {
                    break;
                }

                if (!int.TryParse(res, out value))
                {
                    _io.Write(string.Format(FACTOR_VALIDATION));
                    continue;
                }

                var result = _primeFactorService.Generate(value);
                _io.Write(string.Format(PRIME_FACTORS_FORMAT, string.Join(" ", result)));
                if (TryAskAgain())
                {
                    continue;
                }
                break;
            }
        }
Example #2
0
        public string GetTan(FinService aService)
        {
            if (m_vList.Count == 0)
            {
                throw new InvalidOperationException("Keine TAN-Nummern in Liste!");
            }

            FinTanProcessParameters aTanProc       = aService.TanProcess;
            FinChallengeInfo        aChallengeInfo = aService.ChallengeInfo;

            // If this is not a 2-step TAN procedure then we always just return the very first
            // TAN of the list.

            if ((aTanProc == null) || (aChallengeInfo == null))
            {
                Tan aTan = (Tan)m_vList[0];
                return(aTan.TAN);
            }

            string sChallenge = aChallengeInfo.Challenge;
            int    nIndex     = GetIndexFromChallenge(sChallenge);

            if (nIndex >= 0)
            {
                string sTAN = FindTan(nIndex);
                if (sTAN != null)
                {
                    return(sTAN);
                }
            }

            io.Write("Keine TAN für " + sChallenge + "in TAN-Datei gefunden!");
            return(null);
        }
Example #3
0
 public void Print()
 {
     foreach (var todo in Todos)
     {
         IO.Write(todo);
     }
 }
Example #4
0
        public string GetTan(FinService aService)
        {
            FinTanProcessParameters tanProcess     = aService.TanProcess;
            FinChallengeInfo        aChallengeInfo = aService.ChallengeInfo;

            if ((tanProcess != null) && (aChallengeInfo != null))
            {
                io.Write(tanProcess.ChallengeLabel + ": ");
                io.Write(aChallengeInfo.Challenge);
            }

            io.Write("TAN:");

            string sTAN = io.Read();

            return(!string.IsNullOrEmpty(sTAN) ? sTAN : null);
        }
Example #5
0
        public IGameState Handle()
        {
            Game.MakeMove(Context);
            Game.SwitchPlayer();

            IO.Write(Game.Board.ToString());

            return(Game.IsOver() ? new GameEndedState() : GetNextPlayerState());
        }
Example #6
0
        private string Guess()
        {
            _tries = _tries + 1;

            _inout.Write("Take a guess: ");
            var guess = _inout.ReadLine();

            if (guess.Length == 4)
            {
                return(guess.ToUpper());
            }

            // Password guess was wrong size - Error Message
            _inout.WriteLine("Password length is 4.");
            return(Guess());
        }
Example #7
0
        public ushort GetNumericInput(string message, ushort min, ushort max)
        {
            while (true)
            {
                _inputOutput.Write(message);

                ushort userInput;

                ushort.TryParse(_inputOutput.ReadLine(), out userInput);

                bool validUserInput = userInput >= min && userInput <= max;

                if (validUserInput)
                {
                    return(userInput);
                }
            }
        }
        public static void RunFactorial(IInputOutput io, IMathOperations math)
        {
            io.WriteLine("Michael Wright");
              io.WriteLine("CS 2450\n");

              io.Write("Enter a number to get a factorial: ");
              int factorialNumber = 0;
              bool parseSucceeded = int.TryParse(io.ReadLine(), out factorialNumber);
              if (!parseSucceeded)
              {
            return;
              }

              int sum = math.Factorial(factorialNumber);

              io.WriteLine("Factorial Value is {0}", sum);
              io.ReadLine();
        }
Example #9
0
        public virtual IActionResult Execute(FinService service, ITanSource tanSource)
        {
            order = OnCreateOrder(service);
            if (order == null)
            {
                return(new ActionResult(Status.CouldNotCreateOrder));
            }

            FinServiceResult result = service.SendOrder(order);

            if (result == FinServiceResult.NeedTan)
            {
                string tan = tanSource.GetTan(service);
                if (tan == null)
                {
                    return(new ActionResult(Status.CouldNotCreateOrder));
                }

                result = service.SendTan(tan);
            }

            if (result == FinServiceResult.NeedTanMediaName)
            {
                Io.Write("Bezeichnung des TAN-Mediums erforderlich!");
                FinTanMedia[] vTanMedias = service.TanMedias;
                if (vTanMedias != null)
                {
                    Io.Write("Bitte geben Sie einen der folgenden Parameter an:");
                    foreach (FinTanMedia t in vTanMedias)
                    {
                        Io.Write("-tanmedianame \"" + t.TanMediaName + "\"");
                    }
                }

                return(new ActionResult(Status.NeedTanMediaName));
            }

            if (result == FinServiceResult.Fatal)
            {
                return(new ActionResult(Status.FatalResult));
            }

            // Als Rückgabewert wird der höchste Rückmeldecode aus dem HIRMS genommen.
            // Wurde kein HIRMS übermittelt wird als Rückgabewert 0 eingesetzt.
            int orderStatusCode = 0;

            if (order.StatusSegment != null)
            {
                int nIndex = order.StatusSegment.FindMax();
                orderStatusCode = order.StatusSegment.GetStatusCode(nIndex);
            }

            if (result == FinServiceResult.Error)
            {
                return(new ActionResult(Status.ErrorResult, orderStatusCode));
            }

            if (result == FinServiceResult.Success)
            {
                return(new ActionResult(Status.Success, orderStatusCode));
            }

            throw new Exception("The enum FinServiceResult has been changed! " +
                                "Known states: NeedTan, NeedTanMediaName, Fatal, Error, Success " +
                                "New: " + result);
        }
Example #10
0
 public void SepConditionOccured(object sender, SepCondEventArgs e)
 {
     inputoutputtype.Write(e, FileName);
 }
Example #11
0
        public IActionResult DoAction(string action, StringDictionary arguments)
        {
            // In jedem Fall wird die PIN oder der Dialogkontext zur Fortführung benötigt.
            string pin    = arguments[Arguments.Pin];
            string resume = arguments[Arguments.Resume];

            // Optional kann eine TAN oder eine TAN-Liste mitgegeben werden.
            // Wird beides nicht mitgegeben, so wird die TAN auf der Kommandozeile abgefragt.
            ITanSource tanSource = tanSourceFactory.GetTanSource(arguments);

            // Optional kann eine Datei für den HBCI-FinTsTrace angegeben werden.
            string traceFile = arguments[Arguments.Trace];

            // Wird der Schalter -suspend angegeben, so wird nach der Aktion keine
            // Dialogbeendigung durchgeführt, sondern einfach der Zustand in die angegebene Datei gespeichert.
            string suspend = arguments[Arguments.Suspend];

            // Die IAction Implementierung für die gewünschte Aktion erstellen.
            IAction cmd = actionFactory.GetAction(action);

            if (!cmd.Parse(action, arguments))
            {
                throw new ArgumentException("Wrong arguments for the given action!");
            }

            FinContact contact;
            FinDialog  dialog = null;

            if (resume != null)
            {
                dialog = new FinDialog();
                dialog.Load(resume);
                contact = dialog.Contact;
            }
            else
            {
                contact = FinContactCreator.GetFinContact(arguments);
            }

            FinService    service = FinServiceCreator.GetFinService(contact, dialog, arguments);
            IActionResult result  = new ActionResult(Status.Unknown);

            try
            {
                service.ClearDocket();

                if (!service.Online)
                {
                    // Hinweis: eine erforderliche Synchronisierung wird von LogOn immer automatisch durchführt.
                    if (!service.LogOn(pin))
                    {
                        result = new ActionResult(Status.CouldNotLogOn);
                        goto _done;
                    }
                }

                if (service.Online)
                {
                    result = cmd.Execute(service, tanSource);

                    if (suspend != null)
                    {
                        service.Dialog.SaveAs(suspend);
                    }
                    else
                    {
                        service.LogOff();
                    }
                }

_done:

                // Falls der Bankkontakt aus einer Datei geladen wurde, so muss diese nun noch
                // gespeichert werden, damit auch alle am Bankkontakt erfolgten Änderungen
                // erhalten bleiben.
                string sContactFile = arguments[Arguments.ContactFile];
                if (sContactFile != null)
                {
                    contact.SaveAs(sContactFile);
                }

                // Wurde eine Tracedatei angegeben, so wird der komplette HBCI FinTsTrace in diese
                // Datei geschrieben.
                if (traceFile != null)
                {
                    StreamWriter sw = File.CreateText(traceFile);
                    sw.Write(service.Trace);
                    sw.Close();
                }

                // Auftrag ausgeführt. Zuerst geben wir den gesammelten Laufzettel aus,
                // danach die Antwortdaten, sofern welche vorhanden sind.
                io.Write(service.Docket);

                if (result.Status != Status.CouldNotLogOn)
                {
                    ResponseData responseData = cmd.GetResponseData(service);
                    if (responseData.Formatted != null)
                    {
                        io.Write(responseData.Formatted);
                    }
                    result.Response = responseData;
                }
            }
            catch (Exception x)
            {
                throw new ActionException(x, service.Trace);
            }
            finally
            {
                service.Dispose();
            }

            return(result);
        }