Example #1
0
 /// <summary>
 /// Prints a simple "Hello World" unless the function is provided with a message to display; also supports encryption.
 /// </summary>
 /// <param name="message">The text to display in the console.</param>
 /// <param name="encrypt">Flag determining whether the message should be encrypted or not.</param>
 public void PrintGreeting(string message = "Hello World!", bool encrypt = false)
 {
     // Print our message based on if we have a custom greeting and if we should encrypt it or not.
     if (encrypt)
     {
         try { XConsole.Print(EncryptMessage(message, 1024), true, true, false, MessageStyle.Success); }
         catch (CryptographicException ex)
         {
             Errors.Add(ex);
             XConsole.Print("Your message was unable to be encrypted.", true, true, true, MessageStyle.Error);
         }
         catch (IOException ex)
         {
             Errors.Add(ex);
             XConsole.Print("The console is unable to print your message.", true, true, true, MessageStyle.Error);
         }
         catch (Exception ex)
         {
             Errors.Add(ex);
             XConsole.Print("There was an error printing your message.", true, true, true, MessageStyle.Error);
         }
     }
     else
     {
         try { XConsole.Print(message, true, true, false, MessageStyle.Success); }
         catch (IOException ex)
         {
             Errors.Add(ex);
             XConsole.Print("The console is unable to print your message.", true, true, true, MessageStyle.Error);
         }
     }
 }
Example #2
0
        static void Main(string[] args)
        {
            // Print some application details.
            XConsole.Print("================================", false, false, true, MessageStyle.General);
            XConsole.Print("Welcome to HelloWorldAPI v0.0.1!", false, false, true, MessageStyle.Notice);
            XConsole.Print("Written By: Jason Tanner", false, false, true, MessageStyle.Notice);
            XConsole.Print("================================", false, false, true, MessageStyle.General);

            // Spawn a new API object so we can print, store, and do whatever else we need.
            HelloWorldAPI api = new HelloWorldAPI();

            // Print "Hello World".
            api.PrintGreeting();

            // Print a custom message without encryption.
            api.PrintGreeting("Hola! Mi nombre es Jason.");

            // Print a custom message with encryption.
            api.PrintGreeting("Este es muy importante!", true);

            // Store our message using a specified method.
            api.StoreData("Test data to store...", HelloWorldAPI.StorageType.File);
            api.StoreData("Some more test data...", HelloWorldAPI.StorageType.Container);
            api.StoreData("This is even more data to be stored...", HelloWorldAPI.StorageType.Database);

            // Pause the console to read output.
            XConsole.Print("\nPress any key to continue...", false, false, true, MessageStyle.General);
            Console.Read();
        }
Example #3
0
        /// <summary>
        /// Stores the provided data using a specified method of storage; data can be stored in a plaintext file,
        /// an encrypted container file, or in a local or remote database.
        /// </summary>
        /// <param name="data">The data to be stored.</param>
        /// <param name="type">The method of storage to be used.</param>
        public void StoreData(string data, StorageType type)
        {
            //Store our provided data into our selected storage type(file, database, etc.)
            try
            {
                switch (type)
                {
                case StorageType.File:
                    // Store our data into an XML file - can be updated to be an .ini or whatever.
                    XDocument file = Configuration(data);
                    file.Save(FilePath);
                    XConsole.Print("Stored data into a file!", true, true, false, MessageStyle.Success);
                    break;

                case StorageType.Container:
                    // Store our data into an encrypted XML file.
                    XDocument    container = Configuration(data);
                    MemoryStream ms        = new MemoryStream();
                    container.Save(ms);
                    byte[] plainbytes  = ms.ToArray();
                    byte[] cipherbytes = EncryptBytes(plainbytes, "ThisIsOurSuperSecretPassword");
                    File.WriteAllBytes(ContainerPath, cipherbytes);
                    XConsole.Print("Stored data into an encrypted container!", true, true, false, MessageStyle.Success);
                    break;

                case StorageType.Database:
                    // Create a query to our database for storage.

                    /* This case is undefined at the moment because of the requirement of making the class
                     * extensible. So, we'll leave it blank until we've decided what type of database to use
                     * or until we get around to extending this method in general. */
                    XConsole.Print("No database could be found to store data!", true, true, false, MessageStyle.Warning);
                    break;
                }
            }
            catch (Exception ex)
            {
                Errors.Add(ex);
                XConsole.Print(("The provided data could not be stored into a " + type.ToString().ToLower() + "."), true, true, true, MessageStyle.Error);
            }
        }