Example #1
0
        public void Display(ContainStates state)
        {
            Console.WriteLine("\n" + new string('-', 50));
            Log.Logger.Information($"Displaying state of comparing envelopes:");
            switch (state)
            {
            case ContainStates.FirstContainsSecond:
                Log.Logger.Information($"State: first can fit second");
                Console.WriteLine(UIMessages.SECOND_FITS_IN_FIRST);

                break;

            case ContainStates.SecondContainsFirst:
                Log.Logger.Information($"State: second can fit first");
                Console.WriteLine(UIMessages.FIRST_FITS_IN_SECOND);

                break;

            case ContainStates.DoesntContainsAny:
                Log.Logger.Information($"Can not fit each other");
                Console.WriteLine(UIMessages.ENVELOPES_DONT_FIT_TO_EACH_OTHER);

                break;

            default:
                Log.Logger.Information($"invalid state");
                Console.WriteLine(UIMessages.INVALID_COMPARING_STATE);

                break;
            }
            Console.WriteLine("\n" + new string('-', 50));
        }
        public void Start(string[] args)
        {
            Log.Logger.Information($"Starting app");

            double[] firstEnvelopeSizing,
            secondEnvelopeSizing;

            while (_envelopesUserInterface.IsRun())
            {
                try
                {
                    Log.Logger.Information($"User is inputting parametrs");

                    if (args.Length != 0 && args.Length == ENVELOPE_PARAMETRS)
                    {
                        if (args.Length > ENVELOPE_PARAMETRS)
                        {
                            throw new ArgumentException();
                        }

                        firstEnvelopeSizing  = ConvertUsersInput(args[0].Split(' '));
                        secondEnvelopeSizing = ConvertUsersInput(args[1].Split(' '));

                        Array.Clear(args, 0, args.Length);
                    }
                    else
                    {
                        firstEnvelopeSizing =
                            ConvertUsersInput(_envelopesUserInterface.GetEnvelopeFromUser(UIMessages.INPUT_FIRST_ENVELOPE));

                        secondEnvelopeSizing =
                            ConvertUsersInput(_envelopesUserInterface.GetEnvelopeFromUser(UIMessages.INPUT_SECOND_ENVELOPE));
                    }

                    IEnvelope firstEnvelope = SetEnvelope(firstEnvelopeSizing);

                    IEnvelope secondEnvelope = SetEnvelope(secondEnvelopeSizing);

                    ContainStates state = IsContains(firstEnvelope, secondEnvelope);

                    _envelopesUserInterface.Display(state);
                }
                catch (FormatException ex)
                {
                    _envelopesUserInterface.DisplayExeption(ex.Message);
                }
                catch (ArgumentException ex)
                {
                    _envelopesUserInterface.DisplayExeption(ex.Message);
                }
            }
        }
        private ContainStates IsContains(IEnvelope firstEnvelope, IEnvelope secondEnvelope)
        {
            Log.Logger.Information($"Checking is envelope fits to another one");

            ContainStates state = ContainStates.DoesntContainsAny;

            if (firstEnvelope.IsFits(secondEnvelope))
            {
                state = ContainStates.FirstContainsSecond;
            }
            if (secondEnvelope.IsFits(firstEnvelope))
            {
                state = ContainStates.SecondContainsFirst;
            }

            Log.Logger.Information($"Successfully checked, {state}");

            return(state);
        }