コード例 #1
0
        // Lets user add an URL and give the .jpeg file a name.
        public void AddURL()
        {
            bool loop = true;

            while (loop)
            {
                Console.Clear();
                Console.Write("Enter URL (ie https://www.website.com): ");
                var url = Console.ReadLine();

                Console.Clear();
                Console.Write("Enter the name you want the screenshot file to have (only letters a-z): ");
                string urlName = Console.ReadLine();

                #region Error handling
                if (url.Contains(" "))
                {
                    Console.WriteLine("There can't be any spaces in the URL, press any key to try again...");
                    Console.ReadKey();
                }
                else if (!url.StartsWith("https://www."))
                {
                    Console.WriteLine("Don't forget the \"https://www.\" in the URL! Press any key to try again...");
                    Console.ReadKey();
                }
                else if (!Regex.IsMatch(urlName, @"^[a-zA-Z]+$"))
                {
                    Console.WriteLine("File name can only contain letters a-z, press any key to try again...");
                    Console.ReadKey();
                }
                #endregion

                else
                {
                    Lists.URLList.Add(new URL {
                        URLLink = url, URLFileName = urlName
                    });
                    var directoryFile = Directory.GetCurrentDirectory() + "\\URL.json";
                    SaveAndLoad.WriteToJsonFile(directoryFile, Lists.URLList);

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("URL succesfully added to list, press any key to continue...");
                    Console.ResetColor();
                    Console.ReadKey();
                    loop = false;
                }
            }
        }
コード例 #2
0
        public void Start()
        {
            #region Read from file
            try
            {
                var directoryFile = Directory.GetCurrentDirectory() + "\\URL.json";
                if (SaveAndLoad.ReadFromJsonFile(directoryFile) != null)
                {
                    Lists.URLList = SaveAndLoad.ReadFromJsonFile(directoryFile).ToList();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("An error occurred, restarting application...");
                System.Threading.Thread.Sleep(2000);
                Process.Start(Application.ExecutablePath);
                Environment.Exit(-1);
                Application.Exit();
            }
            #endregion

            bool loop = true;
            while (loop)
            {
                Console.Clear();
                Console.WriteLine("This program lets you add an unlimited number of URLs to a list. When you have added your");
                Console.WriteLine("URLs you have the option to get screenshots from every website.");
                Console.WriteLine("The screenshots will be saved and you can go back and inspect them whenever you wish to!");
                Console.WriteLine("You need to have Firefox installed on your computer to use this program.");
                Console.WriteLine("\nUse the number keys to navigate through the program.\n");
                Console.WriteLine("[1] URL options");
                Console.WriteLine("[2] Exit");
                var input = Console.ReadKey(true).Key;

                switch (input)
                {
                case ConsoleKey.D1:
                    ui.Menu();
                    break;

                case ConsoleKey.D2:
                    Environment.Exit(0);
                    break;
                }
            }
        }