示例#1
0
 public bool Read()
 {
     try
     {
         using (BinaryReader b = new BinaryReader(File.Open(Path, FileMode.Open)))
         {
             CurrentAccount.AccountNumber = b.ReadInt32();
             Cinstance.Out($"Account Number: {CurrentAccount.AccountNumber}", Color.HotPink);
             if (Cinstance.AccountTitle)
             {
                 InitialTitle  = Console.Title;
                 Console.Title = CurrentAccount.AccountNumber.ToString();
             }
             CurrentAccount.AccountName = b.ReadString();
             Cinstance.Out($"Account name: {CurrentAccount.AccountName}", Color.HotPink);
             CurrentAccount.AccountEquity = b.ReadDouble();
             Cinstance.Out($"Account equity: {CurrentAccount.AccountEquity}", Color.HotPink);
             CurrentAccount.Currency = b.ReadChar();
             Cinstance.Out($"Account currency: {CurrentAccount.Currency}", Color.HotPink, 1);
         }
         IsValid = true;
         return(true);
     }
     catch (Exception)
     {
         Cinstance.Out("Could not read the binary file, either it is corrupt or it was created using an older version of TradeMonitor", Color.IndianRed);
         return(false);
     }
 }
示例#2
0
 public static bool Init(ref bool _initComplete)
 {
     Thread.Sleep(1000);
     string[] savedAccounts = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.fx", SearchOption.TopDirectoryOnly);
     if (savedAccounts.Length >= 1)
     {
         Cinstance.Out($"Found {savedAccounts.Length} accounts", Color.BlueViolet, 1, _prefixWithNewLines: 1);
         _initComplete = true;
         //User file exists
         foreach (var account in savedAccounts)
         {
             Cinstance.Out(Path.GetFileNameWithoutExtension(account), Color.BlueViolet);
         }
         return(true);
     }
     else
     {
         _initComplete = true;
         Pause();
         Cinstance.Out("No saved accounts could not be found, to ensure they are found on startup, ensure they are in the root directory, setup is loading", Color.HotPink, 1, _prefixWithNewLines: 1);
         Pause(1000);
         Console.Clear();
         Setup.Run();
         return(false);
     }
 }
示例#3
0
 public static void DisplayTitle()
 {
     Console.WindowWidth = Convert.ToInt32(Console.WindowWidth * 1.2);
     Console.WriteAscii("Trade Monitor by Weii", Color.DarkSlateBlue);
     Utils.Pause();
     Cinstance.Out("This program was written for personal use, do not distribute without direct permission", Color.DarkSlateBlue, 1);
 }
示例#4
0
        //public static FX_Parser _AccountInstance;

        static void Main(string[] args)
        {
            DisplayPages.DisplayTitle();

            if (args.Length != 0)
            {
                Cinstance.Out($"cmd line arg found", Color.ForestGreen, 1);
                Cinstance.Out($"Attempting to load from {args[0]}", Color.LightSeaGreen, 1);
                var account = new FX_Parser(args[0]);
                if (account.Read())
                {
                    account.Use();
                }
                else
                {
                    account.Dispose();
                    Cinstance.Out("Returning to menu", Color.IndianRed);
                    Utils.Pause();
                    Console.Clear();
                    Main(new string[0]);
                }
            }

            if (DisplayPages.Init())
            {
                DisplayPages.PrintMenu();
            }

            while (true)
            {
                Console.ReadKey();
            }
        }
示例#5
0
 public static void PrintMenu()
 {
     Utils.Pause();
     Cinstance.Out(@"""d"" for database functions (e.x search)", Color.CadetBlue, _prefixWithNewLines: 1); Utils.Pause(100);
     Cinstance.Out(@"""n"" to create new entry", Color.CadetBlue); Utils.Pause(100);
     Cinstance.Out(@"""d"" to delete entry", Color.CadetBlue); Utils.Pause(100);
     Cinstance.Out(@"""s"" to edit settings", Color.CadetBlue); Utils.Pause(100);
 }
示例#6
0
        public static bool Init()
        {
            bool _initComplete     = false;
            bool _initTaskComplete = false;

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Cinstance.InitDisplay(ref _initComplete, ref _initTaskComplete, _manuallyClearLastLine: 0);
            }).Start();
            return(Utils.Init(ref _initComplete));
        }
示例#7
0
        //Run this function from a new thread created when it is called, code runs on default thread by default
        public static void InitDisplay(ref bool _taskComplete, ref bool _initLoopComplete, string loadText = "Init", int _manuallyClearLastLine = 0)
        {
            Console.CursorVisible = false;
            int _dotCount = 3;

            while (!_taskComplete)
            {
                if (_dotCount == 3)
                {
                    Utils.ClearCurrentConsoleLine();
                    Cinstance.Out($"{loadText}.", Color.DarkSlateBlue, _disableSound: true);
                    _dotCount = 1;
                    Utils.Pause(100);
                }
                else if (_dotCount == 2)
                {
                    Utils.ClearCurrentConsoleLine();
                    Cinstance.Out($"{loadText}...", Color.DarkSlateBlue, _disableSound: true);
                    _dotCount = 3;
                    Utils.Pause(100);
                }
                else if (_dotCount == 1)
                {
                    Utils.ClearCurrentConsoleLine();
                    Cinstance.Out($"{loadText}..", Color.DarkSlateBlue, _disableSound: true);
                    _dotCount = 2;
                    Utils.Pause(100);
                }
            }
            if (_manuallyClearLastLine != 0)
            {
                for (int i = 0; i < _manuallyClearLastLine; i++)
                {
                    Utils.ClearCurrentConsoleLine();
                }
            }
            Utils.Pause();
            Console.CursorVisible = true;
            _taskComplete         = true;
        }
示例#8
0
 public void Use()
 {
     Cinstance.Out($"Succesfully loaded {CurrentAccount.AccountName} ({CurrentAccount.AccountNumber})", Color.LightGoldenrodYellow);
     Utils.Pause(50000);
 }
示例#9
0
        public static void Run()
        {
            var _account = new AccountSetup();

            Console.WriteAscii("Setup", Color.DodgerBlue);
            Cinstance.Out("The information provided here can be changed once setup is finished", Color.CornflowerBlue, 1);

            bool   AccountNumberEntry = false;
            string AccountNumber      = "";

            while (!AccountNumberEntry)
            {
                Cinstance.Out("Account Number: ", Color.HotPink, _nextBufferOnSameLine: true);
                AccountNumber = Console.ReadLine();
                if (File.Exists(AccountNumber.ToString() + ".fx"))
                {
                    Cinstance.Out("Account file already exists, to prevent this, change the account number or delete the current file", Color.OrangeRed);
                }
                else if (!Regex.IsMatch(AccountNumber, "^[0-9]+$"))
                {
                    Cinstance.Out("Value was not numerical (regex used - ^\\d$)", Color.OrangeRed);
                }
                else
                {
                    AccountNumberEntry = true;
                }
            }
            _account.AccountNumber = Convert.ToInt32(AccountNumber);
            Cinstance.Out($"Account number bound to value ", Color.HotPink, _nextBufferOnSameLine: true);
            Cinstance.Out(_account.AccountNumber.ToString(), Color.DeepPink, 1);

            bool   AccountNameEntry = false;
            string AccountName      = "";

            while (!AccountNameEntry)
            {
                Cinstance.Out("Account Name: ", Color.HotPink, _nextBufferOnSameLine: true);
                AccountName = Console.ReadLine();
                if (AccountName.Length > 16 || !Regex.IsMatch(AccountName, "[a-zA-Z]+"))
                {
                    Cinstance.Out("Value violated input rules", Color.OrangeRed);
                    Cinstance.Out("     -16 chars max", Color.CadetBlue);
                    Cinstance.Out("     -Letters only", Color.CadetBlue);
                }
                else
                {
                    AccountNameEntry = true;
                }
            }
            _account.AccountName = AccountName;
            Cinstance.Out($"Account name bound to value ", Color.HotPink, _nextBufferOnSameLine: true);
            Cinstance.Out(_account.AccountName, Color.DeepPink, 1);

            bool AccountCurrencyEntry = false;
            char AccountCurrency      = ' ';

            while (!AccountCurrencyEntry)
            {
                Cinstance.Out("Account Currency -select index-: ", Color.HotPink);
                Cinstance.Out("     a) £ (GBP)", Color.LightPink);
                Cinstance.Out("     b) $ (USD)", Color.LightPink);
                Cinstance.Out("     c) € (EUR)", Color.LightPink);
                Cinstance.Out("     d) R (ZAR)", Color.LightPink);
                AccountCurrency = Console.ReadLine()[0];
                if (!Index2Currency.ContainsKey(AccountCurrency.ToString().ToLower()[0]))
                {
                    Cinstance.Out("Dictionary did not contain this index", Color.OrangeRed);
                }
                else
                {
                    AccountCurrencyEntry = true;
                }
            }
            _account.Currency = Index2Currency[Convert.ToChar(AccountCurrency)];
            Cinstance.Out($"Account currency bound to  ", Color.HotPink, _nextBufferOnSameLine: true);
            Cinstance.Out(Index2Description[AccountCurrency.ToString()], Color.DeepPink, 2);

            bool   AccountEquityEntry = false;
            string AccountEquity      = "";

            while (!AccountEquityEntry)
            {
                Cinstance.Out("Account Equity: ", Color.HotPink, _nextBufferOnSameLine: true);
                AccountEquity = Console.ReadLine();
                if (Regex.IsMatch(AccountEquity, "[a-zA-Z]+"))
                {
                    Cinstance.Out("Value was not numerical (regex used - ^\\d$)", Color.OrangeRed);
                }
                else
                {
                    AccountEquityEntry = true;
                }
            }
            _account.AccountEquity = Convert.ToDouble(AccountEquity);
            Cinstance.Out($"Account equity set to ", Color.HotPink, _nextBufferOnSameLine: true);
            Cinstance.Out(_account.AccountEquity.ToString(), Color.DeepPink, 2);

            Cinstance.Out($"Your account is being written to a new file -  {_account.AccountNumber}.fx", Color.ForestGreen, 1);
            Utils.Pause();

            bool _scribeComplete      = false;
            bool _initDisplayComplete = false;

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Cinstance.InitDisplay(ref _scribeComplete, ref _initDisplayComplete, loadText: "Writing");
            }).Start();

            var scribe = new FX_Scribe(_account);

            scribe.WriteToFile(ref _scribeComplete);
            Utils.Pause();
            Cinstance.Out("Account Successfully Written", Color.CadetBlue, _prefixWithNewLines: 1);
        }