예제 #1
0
        public void SendText()
        {
            try
            {
                foreach (var texter in _texterList)
                {
                    // T-Mobile blocks best buy links sent via text
                    if (_url.Host.Contains("bestbuy", StringComparison.CurrentCultureIgnoreCase) && texter.Carrier == Carrier.TMOBILE)
                    {
                        string lhs = _url.AbsoluteUri.Substring(0, (int)_url.AbsoluteUri.Length / 2);
                        string rhs = _url.AbsoluteUri.Substring((int)(_url.AbsoluteUri.Length / 2),
                                                                (int)(_url.AbsoluteUri.Length / 2));

                        texter.Send("Found Item in stock", rhs + lhs);
                    }
                    else
                    {
                        texter.Send("Found item in stock!", _url.AbsoluteUri);
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutputHelper.Write(e);
            }
        }
        public override void Scrape()
        {
            while (!FoundItemInStock)
            {
                ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread);

                try
                {
                    Html = GetHtml();

                    if (Html.Contains("add to cart", StringComparison.CurrentCultureIgnoreCase))
                    {
                        SendSuccessMessage();
                        break;
                    }

                    ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread);

                    CanScrape = true;
                }
                catch (Exception e)
                {
                    ConsoleOutputHelper.Write(StoreName, e);
                    CoolDown();
                }

                Thread.Sleep(_waitTime);
            }
        }
예제 #3
0
        public override void Scrape()
        {
            while (!FoundItemInStock)
            {
                ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread);

                try
                {
                    Html = GetHtml();

                    if (Html.Contains("<button data-selenium=\"addToCartButton\""))
                    {
                        SendSuccessMessage();
                        break;
                    }

                    CanScrape = true;

                    ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread);
                }
                catch (Exception e)
                {
                    ConsoleOutputHelper.Write(StoreName, e);
                    CoolDown();
                }

                Thread.Sleep(_waitTime);
            }
        }
        public void TableWriterColumnConstraintsPadsWithTooLargeColumn()
        {
            var mockOutputter = new Mock <IConsoleOutputter>();
            var target        = new TableWriter(mockOutputter.Object, new ViewPort(100, 100));
            int columnWidth   = 25;

            var table = new DisplayTable()
            {
                Header = new TableRow {
                    Cells = new[] { new BasicTableCell {
                                        ContentAreas = new[] { new BasicCellContent {
                                                                   Value = "TestCell"
                                                               } }
                                    } }
                },
                ColumnDetails = new[] { new ColumnDetails {
                                            columnName = "harrumph", columnWidth = columnWidth, isNullable = false, type = Data.DataType.String
                                        } },
                Rows = new[] { new TableRow {
                                   Cells = new[] { new BasicTableCell {
                                                       ContentAreas = new[] { new BasicCellContent {
                                                                                  Value = "This is a test value."
                                                                              } }
                                                   } }
                               } }
            };

            target.Draw(table);
            string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations);

            Assert.Contains("    This is a test value.", s);
        }
예제 #5
0
        internal static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var startDate    = ConsoleInputHelper.SafeRead <DateTime>(StartDatePrompt, WrongFormatError);
            var endDate      = ConsoleInputHelper.SafeRead <DateTime>(EndDatePrompt, WrongFormatError);
            var dayOfTheWeek = ConsoleInputHelper.SafeRead <DayOfWeek>(DayOfTheWeekPrompt, DayOfTheWeekErrorMessage);

            if (startDate > endDate)
            {
                var oldValue = startDate;
                startDate = endDate;
                endDate   = oldValue;
            }

            var numberOfDays = 0;

            for (var i = startDate; i != endDate; i = i.AddDays(1))
            {
                if (i.DayOfWeek == dayOfTheWeek)
                {
                    numberOfDays++;
                }
            }

            var message = string.Format(
                "The number of {0} between {1} and {2} is {3}",
                dayOfTheWeek,
                startDate.ToString("dd/MM/yyyy"),
                endDate.ToString("dd/MM/yyyy"),
                numberOfDays);

            ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
        }
        public void TableWriterMultipleRows()
        {
            var mockOutputter = new Mock <IConsoleOutputter>();
            var target        = new TableWriter(mockOutputter.Object, new ViewPort(100, 100));

            var table = new DisplayTable()
            {
                Header = new TableRow
                {
                    Cells = new[] { new BasicTableCell {
                                        ContentAreas = new ICellContent[] {
                                            new BasicCellContent {
                                                Value = "TestCell"
                                            },
                                            new BreakingRuleContentArea(),
                                            new BasicCellContent {
                                                Value = "Line2"
                                            }
                                        }
                                    } }
                },
                ColumnDetails = new[] { new ColumnDetails {
                                            columnName = "harrumph", columnWidth = 10, isNullable = false, type = Data.DataType.String
                                        } }
            };

            target.Draw(table);
            string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations);

            string[] effectiveLines = s.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
            Assert.Equal(4, effectiveLines.Length);
        }
예제 #7
0
        static async Task Main(string[] args)
        {
            await ThreadBuilder.Start();

            ConsoleOutputHelper.Write("No more items are being monitored.\nPress any key to close application");
            System.Console.ReadKey();
        }
예제 #8
0
        internal static void Main(string[] args)
        {
            var intervalStart = ConsoleInputHelper.SafeRead <int>(IntervalStartPromt);
            var intervalEnd   = ConsoleInputHelper.SafeRead <int>(IntervalEndPromt);

            while (true)
            {
                var divisor        = ConsoleInputHelper.SafeRead <int>(DivisorChousePromt);
                var isDivisorValid = divisor == 3 ||
                                     divisor == 4 ||
                                     divisor == 9;

                if (!isDivisorValid)
                {
                    ConsoleOutputHelper.WriteMessage(InvalidDivisorPromt, ConsoleMessageType.Error);
                }
                else
                {
                    var numbers = GetAllDivisableNumbers(intervalStart, intervalEnd, divisor);
                    ConsoleOutputHelper.WriteMessage(numbers, ConsoleMessageType.Success);

                    break;
                }
            }
        }
        public void TableWriterColumnConstraintsRespectedOverallWidth()
        {
            var mockOutputter = new Mock <IConsoleOutputter>();
            var target        = new TableWriter(mockOutputter.Object, new ViewPort(100, 100));
            int columnWidth   = new Random().Next(95);

            var table = new DisplayTable()
            {
                Header = new TableRow {
                    Cells = new[] { new BasicTableCell {
                                        ContentAreas = new[] { new BasicCellContent {
                                                                   Value = "TestCell"
                                                               } }
                                    } }
                },
                ColumnDetails = new[] { new ColumnDetails {
                                            columnName = "harrumph", columnWidth = columnWidth, isNullable = false, type = Data.DataType.String
                                        } },
                Rows = new[] { new TableRow {
                                   Cells = new[] { new BasicTableCell {
                                                       ContentAreas = new[] { new BasicCellContent {
                                                                                  Value = "This is a test value."
                                                                              } }
                                                   } }
                               } }
            };

            target.Draw(table);
            string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations);

            string[] effectiveLines = s.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
            Assert.True(effectiveLines.All(l => l.Length == columnWidth + ("|".Length * 2)), GetLengths(effectiveLines));
        }
예제 #10
0
        public void TableWriterWritesExpected()
        {
            var  mockOutputter = new Mock <IConsoleOutputter>();
            var  target        = new TableWriter(mockOutputter.Object, new ViewPort(100, 100));
            Guid expectedValue = Guid.NewGuid();

            var table = new DisplayTable()
            {
                Header = new TableRow {
                    Cells = new[] { new BasicTableCell {
                                        ContentAreas = new[] { new BasicCellContent {
                                                                   Value = "TestCell"
                                                               } }
                                    } }
                },
                ColumnDetails = new[] { new ColumnDetails {
                                            columnName = "harrumph", columnWidth = expectedValue.ToString().Length + 2, isNullable = false, type = Data.DataType.String
                                        } },
                Rows = new[] { new TableRow {
                                   Cells = new[] { new BasicTableCell {
                                                       ContentAreas = new[] { new BasicCellContent {
                                                                                  Value = expectedValue.ToString()
                                                                              } }
                                                   } }
                               } }
            };

            target.Draw(table);
            string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations);

            Assert.Contains(expectedValue.ToString(), s);
        }
예제 #11
0
        internal static void Main(string[] args)
        {
            const string SampleString = "Sample <up>tagged</up> text with MANY <up>Tags</up>!";
            var          userText     = ConsoleInputHelper.SafeRead <string>(GreetingMessage);

            ConsoleOutputHelper.WriteMessage(TransformText(userText), ConsoleMessageType.Success);
        }
예제 #12
0
        public override void Scrape()
        {
            while (!FoundItemInStock)
            {
                ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread);

                try
                {
                    Html = GetHtml();

                    if (!Html.Contains("<p class=\"product-out-of-stock\">Out of stock</p>"))
                    {
                        SendSuccessMessage();
                        break;
                    }

                    CanScrape = true;

                    ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread);
                }
                catch (Exception e)
                {
                    ConsoleOutputHelper.Write(StoreName, e);
                    CoolDown();
                }

                Thread.Sleep(_waitTime);
            }
        }
예제 #13
0
        public override void Scrape()
        {
            while (!FoundItemInStock)
            {
                ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread);

                try
                {
                    var doc = GetHtmlDocument();
                    Html = doc.Text;

                    var addToCartButton = doc.QuerySelector("button[class*='add-to-cart-button']")?.InnerText.Trim()
                                          .ToLower();

                    if (Html.Contains("Add to Cart", StringComparison.CurrentCultureIgnoreCase) && !String.IsNullOrEmpty(addToCartButton))
                    {
                        SendSuccessMessage();
                        break;
                    }

                    CanScrape = true;

                    ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread);
                }
                catch (Exception e)
                {
                    ConsoleOutputHelper.Write(StoreName, e);
                    CoolDown();
                }

                Thread.Sleep(_waitTime);
            }
        }
        public void TableWriterWritesSomething()
        {
            var mockOutputter = new Mock <IConsoleOutputter>();
            var target        = new TableWriter(mockOutputter.Object, new ViewPort(100, 100));

            var table = new DisplayTable()
            {
                Header = new TableRow {
                    Cells = new[] { new BasicTableCell {
                                        ContentAreas = new ICellContent[] {
                                            new BasicCellContent {
                                                Value = "TestCell"
                                            },
                                            new BreakingRuleContentArea(),
                                            new BasicCellContent {
                                                Value = "Line2"
                                            }
                                        }
                                    } }
                },
                ColumnDetails = new [] { new ColumnDetails {
                                             columnName = "harrumph", columnWidth = 10, isNullable = false, type = Data.DataType.String
                                         } }
            };

            target.Draw(table);
            string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations);

            Assert.Contains("Line2", s);
        }
예제 #15
0
        static void Main(string[] args)
        {
            var ou = new ConsoleOutputHelper();

            // First test case: we need to change to color with the {color} syntax
            ou.WriteLine("{yellow}Hello World!{}");

            // Second test case: headings
            ou.WriteLine("# This should be white as it is something important.");

            // Third test case: wrapping
            ou.WriteLine(@"This is written in multiple
lines in the source code. But a single line break should
not break the output into multiple lines. Instead, the output
should flow around the console. So this multi line
message should fit inside the console, and get wrapped
accordingly.");

            // Fourth test case: inline colors
            ou.WriteLine(@"So let's color {cyan}something{} in the middle.");

            // Fifth test case
            ou.WriteLine(@"When we are creating many text.

And I mean many.

Many {yellow}many{} many.

We want this to pause when the console is full. 

Or display.

Whatever.

More text here.

More text here.

More text here.

More text here.

More text here.

More text here.

More text here.

More text here.

More text here. More text here. More text here. More text here. More text here. More text here. More text here.
More text here. More text here. More text here. More text here. More text here. More text here. More text here.

More text here.

More text here.

");
        }
예제 #16
0
        internal static void Main(string[] args)
        {
            var rawEqation = ConsoleInputHelper.SafeRead <string>(GreetingMessage);
            var rawIndexes = rawEqation.Split(new[] { "x^2+", "x+", "=0" }, StringSplitOptions.RemoveEmptyEntries);
            var solution   = SolveQuadraticEquation(double.Parse(rawIndexes[0]), double.Parse(rawIndexes[1]), double.Parse(rawIndexes[2]));

            ConsoleOutputHelper.WriteMessage(solution, ConsoleMessageType.Success);
        }
예제 #17
0
        internal static void Main(string[] args)
        {
            int    inputNumber = ConsoleInputHelper.SafeRead <int>(GreetingMessage, ParsingErrorMessage);
            bool   isEven      = inputNumber % 2 == 0;
            string message     = string.Format(SuccessMessage, inputNumber, isEven ? "Even" : "Odd");

            ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
        }
예제 #18
0
 protected void SendSuccessMessage()
 {
     // We found an item in stock so lets send a text
     ConsoleOutputHelper.Write("[Found item in stock]: " + _url.AbsoluteUri, ConsoleColor.Green, Thread.CurrentThread);
     ConsoleOutputHelper.Write("Sending text...", Thread.CurrentThread);
     FoundItemInStock = true;
     SendText();
     ConsoleOutputHelper.Write("Sent", Thread.CurrentThread);
 }
예제 #19
0
        internal static void Main(string[] args)
        {
            var sampleArray = new int[20];

            for (int i = 0; i < sampleArray.Length; i++)
            {
                sampleArray[i] = i * 5;
            }

            ConsoleOutputHelper.WriteMessage(string.Join(", ", sampleArray), ConsoleMessageType.Success);
        }
예제 #20
0
        internal static void Main(string[] args)
        {
            var inputNumber = ConsoleInputHelper.SafeRead <int>();

            if (inputNumber % 35 == 0)
            {
                ConsoleOutputHelper.WriteMessage(SuccessMessage, ConsoleMessageType.Success);
            }
            else
            {
                ConsoleOutputHelper.WriteMessage(FailMessage, ConsoleMessageType.Warrning);
            }
        }
예제 #21
0
        public static void Main(string[] args)
        {
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("**********************************************"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("*                                            *"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("* Welcome to the Fax/Email Automation System *"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("*                                            *"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("*   Refer to C:\\Temp\\FaxLog.txt for        *"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("*           log information                  *"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("*               v1.3.1                       *"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage("**********************************************"));
            Console.WriteLine(ConsoleOutputHelper.OutputConsoleMessage(""));

            SendFaxAsync2().Wait();
        }
예제 #22
0
        internal static void Main(string[] args)
        {
            var firstArray  = new int[12];
            var secondArray = new int[12];

            if (firstArray.SequenceEqual(secondArray))
            {
                ConsoleOutputHelper.WriteMessage(AreEqualMessage, ConsoleMessageType.Success);
            }
            else
            {
                ConsoleOutputHelper.WriteMessage(AreNotEqualMessage, ConsoleMessageType.Warrning);
            }
        }
예제 #23
0
        internal static void Main(string[] args)
        {
            var inputNumber = ConsoleInputHelper.SafeRead <int>(EnterNumberPrompt);

            while (true)
            {
                var choice        = ConsoleInputHelper.SafeRead <int>(AlgorithmChoosePrompt);
                var choiseIsValid = choice == 1 || choice == 2;

                if (choiseIsValid)
                {
                    RunAlgorithm(choice, inputNumber);
                    break;
                }

                ConsoleOutputHelper.WriteMessage(InlvaidChoicePrompt, ConsoleMessageType.Error);
            }
        }
예제 #24
0
        internal static void Main(string[] args)
        {
            var sides = new double[TriangleNumberOfSides];

            for (int i = 0; i < TriangleNumberOfSides; i++)
            {
                var promtMessage = string.Format(SidePromtMessage, i + 1);
                sides[i] = ConsoleInputHelper.SafeRead <double>(promtMessage);
            }

            var perimeter = sides.Sum();
            var area      = sides.Aggregate((a, b) => a * b);

            var areaMessage      = string.Format(AreaSuccessMessage, area);
            var perimeterMessage = string.Format(PerimeterSuccessMessage, perimeter);

            ConsoleOutputHelper.WriteMessage(areaMessage, ConsoleMessageType.Success);
            ConsoleOutputHelper.WriteMessage(perimeterMessage, ConsoleMessageType.Success);
        }
예제 #25
0
        internal static void Main(string[] args)
        {
            string input = Console.ReadLine();

            if (input != null)
            {
                var sumMessage = string.Format(SumMessage, input, FindDigitSum(input));
                ConsoleOutputHelper.WriteMessage(sumMessage, ConsoleMessageType.Success);

                var reversedDigits = string.Join(string.Empty, input.Reverse());
                var reverseMessage = string.Format(ReversedMessage, input, reversedDigits);
                ConsoleOutputHelper.WriteMessage(reverseMessage, ConsoleMessageType.Success);

                var firstDigitsSwitchMessage = string.Format(FirstDigitsSwitchMessage, input, SwitchFirstDigits(input));
                ConsoleOutputHelper.WriteMessage(firstDigitsSwitchMessage, ConsoleMessageType.Success);

                var secondDigitsSwitchMessage = string.Format(SecondDigitsSwitchMessage, input, SwitchSecondDigits(input));
                ConsoleOutputHelper.WriteMessage(secondDigitsSwitchMessage, ConsoleMessageType.Success);
            }
        }
예제 #26
0
        internal static void Main(string[] args)
        {
            var firstArray          = new[] { 's', 'b', 'l', 'a' };
            var secondArray         = new[] { 's', 'b', 'l', 'a' };
            var firstArrayAsString  = string.Join(string.Empty, firstArray);
            var secondArrayAsString = string.Join(string.Empty, secondArray);
            var compareResult       = string.Compare(firstArrayAsString, secondArrayAsString, StringComparison.Ordinal);

            if (compareResult > 0)
            {
                ConsoleOutputHelper.WriteMessage(string.Format(FirstArrayMessage, 1), ConsoleMessageType.Success);
            }
            else if (compareResult < 0)
            {
                ConsoleOutputHelper.WriteMessage(string.Format(FirstArrayMessage, 2), ConsoleMessageType.Success);
            }
            else
            {
                ConsoleOutputHelper.WriteMessage(EqualArraysMessage, ConsoleMessageType.Warrning);
            }
        }
예제 #27
0
        internal static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ExtractBirthDateFormString("9204028463");

            string pinString;

            while (true)
            {
                pinString = ConsoleInputHelper.SafeRead <string>(PinInputGreeting);

                var parsedPin       = 0L;
                var isNummeric      = long.TryParse(pinString, out parsedPin);
                var isCorrectLength = pinString.Length == 10;

                if (isNummeric && isCorrectLength)
                {
                    break;
                }

                ConsoleOutputHelper.WriteMessage(InvalidPinPromt, ConsoleMessageType.Error);
            }

            var birthDay          = ExtractBirthDateFormString(pinString);
            var gender            = ExtractGender(pinString);
            var age               = ExtratAge(pinString);
            var daysUntilBirthDay = ExtractDaysUntilBirthDay(pinString);

            var message =
                string.Format(
                    "The person wtih the PIN {0} is {1} and is born on: {2}. He is {3} years old and has {4} days until his birthday.",
                    pinString,
                    gender,
                    birthDay.ToString("dd/MM/yyyy"),
                    age,
                    daysUntilBirthDay);

            ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
        }
예제 #28
0
        internal static void Main(string[] args)
        {
            var firstArraySize = ConsoleInputHelper.SafeRead <int>(FirstArraySizeMessage);
            var firstArray     = new int[firstArraySize];

            for (int i = 0; i < firstArray.Length; i++)
            {
                firstArray[i] = ConsoleInputHelper.SafeRead <int>(string.Format(EnterElementMessage, i));
            }

            var secondArraySize = ConsoleInputHelper.SafeRead <int>(SecondArraySizeMessage);
            var secondArray     = new int[secondArraySize];

            for (int i = 0; i < secondArray.Length; i++)
            {
                secondArray[i] = ConsoleInputHelper.SafeRead <int>(string.Format(EnterElementMessage, i));
            }

            var equalElements = firstArray.Where(secondArray.Contains).ToList();

            ConsoleOutputHelper.WriteMessage(string.Format(BiggestElementMessage, equalElements.Max()), ConsoleMessageType.Success);
        }
예제 #29
0
        private static void RunAlgorithm(int choice, int inputNumber)
        {
            bool result;

            if (choice == 1)
            {
                result = SquareRootPrimeAlgorithm(inputNumber);
            }
            else
            {
                result = HalfPrimeAlgorithm(inputNumber);
            }

            if (result)
            {
                var message = string.Format(IsPrimePrompt, inputNumber);
                ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
            }
            else
            {
                var message = string.Format(IsNotPrimePrompt, inputNumber);
                ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Warrning);
            }
        }
예제 #30
0
        protected void CoolDown()
        {
            // If we threw another exception after the cool down is at 0 that means we need to wait longer
            if (!CanScrape)
            {
                // If this is a new timer, it will be at 0 and we need to then set it up
                if (_currentCoolDownTime == 0)
                {
                    _currentCoolDownTime = _cooldownTime * 2;
                    _cooldownTime        = _currentCoolDownTime;
                }
            }

            CanScrape = false;

            ConsoleOutputHelper.Write($"{StoreName} {ProductName} is cooling down for {_cooldownTime} minutes...", Thread.CurrentThread);

            for (int i = _cooldownTime; i >= 0; i--)
            {
                ConsoleOutputHelper.Write($"{StoreName} {ProductName} is cooling down for {i} minutes...", Thread.CurrentThread);
                _currentCoolDownTime = i;
                Thread.Sleep(new TimeSpan(0, 1, 0));
            }
        }