// log notes:
        // Editing codebase to allow calls passing and receiving structures
        // miktek 8.15.2011

        public static void Main(string[] args)
        {
            int iRet = 999;

            // ErrorMEssage will be used to access error message
            // from the mt4 wrapper.
            String ErrorMessage = "none received";

            Console.WriteLine("testing 8.28.12");

            iRet = myManager.ManagerFactory();

            // hardwire the server name for short term.
            // put into a config.xml file for longer term sanity

            String ServerName = "mtdem01.primexm.com:443";

            // connect to the server
            iRet = myManager.Connect(ServerName);

            // get errorMessage from the CMTManager
            ErrorMessage = myManager.ErrorDescription(iRet);
            Console.WriteLine("Connect ErrMsg: {0}", ErrorMessage);

            // login in credentials. Don't dawdle here.
            // you have aprox. 15 seconds between connecting to the server
            // to enter your creds. Otherwise, say after 15 seconds, the server
            // drops your connection

            iRet         = myManager.Login(900, "!FQS123!!");
            ErrorMessage = myManager.ErrorDescription(iRet);
            Console.WriteLine("Login ErrMsg: {0}", ErrorMessage);

            if (iRet != 0)
            {
                return;
            }

            int choice = 0;

            do
            {
                Console.WriteLine("\nEnter your choice(1,2,3,4,5) to:\n1. Add the User.\n2. Update the User." +
                                  "\n3. History of closed trades.\n4. TradesRequest.\n5. TradesGet.\n6. Exit.\n");
                string sChoice = Console.ReadLine();
                choice = int.Parse(sChoice);
                switch (choice)
                {
                case 1:
                    UserRecordNET user = new UserRecordNET();
                    user.group = "FQ-IB-One";
                    Console.WriteLine("\nEnter Login:"******"\nEnter Name:");
                    user.name     = Console.ReadLine();
                    user.password = "******";
                    iRet          = myManager.UserRecordNew(user);
                    if (iRet == 0)
                    {
                        Console.WriteLine("\nUser Added Successfully.\n");
                    }
                    else
                    {
                        Console.WriteLine("\nUser cannot added successfully.\n");
                        ErrorMessage = myManager.ErrorDescription(iRet);
                        Console.WriteLine("Login ErrMsg: {0}", ErrorMessage);
                    }

                    break;

                case 2:
                    UserRecordNET existingUser = new UserRecordNET();
                    existingUser.group = "FQ-IB-One";
                    Console.WriteLine("\nEnter Login to update:");
                    string tempLogin = Console.ReadLine();
                    existingUser.login = int.Parse(tempLogin);
                    Console.WriteLine("\nEnter Name:");
                    existingUser.name     = Console.ReadLine();
                    existingUser.password = "******";
                    iRet = myManager.UserRecordUpdate(existingUser);

                    if (iRet == 0)
                    {
                        Console.WriteLine("\nUser Modified Successfully.\n");
                    }
                    else
                    {
                        Console.WriteLine("\nUser cannot Modified successfully.\n");
                        ErrorMessage = myManager.ErrorDescription(iRet);
                        Console.WriteLine("ErrMsg: {0}", ErrorMessage);
                    }
                    break;

                case 3:

                    TimeZone tZone     = TimeZone.CurrentTimeZone;
                    DateTime baseTime  = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    TimeSpan fromSpan  = baseTime - startTime + tZone.GetUtcOffset(baseTime);
                    DateTime endTime   = new DateTime(2012, 12, 28, 0, 0, 0, 0);
                    TimeSpan toSpan    = baseTime - endTime + tZone.GetUtcOffset(baseTime);
                    Int64    from      = Convert.ToInt64(Math.Abs(fromSpan.TotalSeconds));
                    Int64    to        = Convert.ToInt64(Math.Abs(toSpan.TotalSeconds));
                    Console.WriteLine("\nEnter Login:"******"Deals: " + TradeInfo[0].order + " Login: "******" Type: " + TradeInfo[0].cmd + "\nSymbol: " + TradeInfo[0].symbol +
                                          " TradeInfo[0].conv_rates[1]: " + TradeInfo[0].conv_rates[1] +
                                          "Closed Price: " + TradeInfo[0].close_price);
                    }
                    else
                    {
                        Console.WriteLine("No trade Info.\n");
                    }

                    break;

                case 4:
                    int val = 0;
                    TradeInfo = myManager.TradesRequest(ref val);
                    if (TradeInfo != null)
                    {
                        Console.WriteLine("Deals: " + TradeInfo[0].order + " Login: "******" Type: " + TradeInfo[0].cmd + "\nSymbol: " + TradeInfo[0].symbol +
                                          " TradeInfo[0].conv_rates[1]: " + TradeInfo[0].conv_rates[1] +
                                          "\nTotal No. of Trades: " + val);
                    }

                    break;

                case 5:
                    val       = 0;
                    TradeInfo = myManager.TradesGet(ref val);
                    if (TradeInfo != null)
                    {
                        Console.WriteLine("Deals: " + TradeInfo[0].order + " Login: "******" Type: " + TradeInfo[0].cmd + "\nSymbol: " + TradeInfo[0].symbol +
                                          " TradeInfo[0].conv_rates[1]: " + TradeInfo[0].conv_rates[1]);
                    }
                    else
                    {
                        Console.Write("No Trade Info.\n");
                    }

                    break;

                default:
                    break;
                }
            } while (choice > 0 && choice < 6);

            // declare a PumpFuncDelegate and then create an instance
            // of it. This will be used to start up the pumping asnycn
            // call back mechanism from the mtmanapi.dll, up through
            // the c++/cli wrapper to the C# client code here.

            MT4ManLibraryNETv03.PumpFuncDelegate myPumpFunc =
                new MT4ManLibraryNETv03.PumpFuncDelegate(miktekCSConAppTestHarness.CallBackMethod);

            // now we pass the delegate named myPumpFunc which acutally
            // is a function pointer the CallBackMethod declared
            iRet = myManager.PassMeADelegate(myPumpFunc);


            // enable the pumping switch
            myManager.PumpingSwitch();


            ExposureValueNET ExposureInfo = new ExposureValueNET();
            SymbolSummaryNET SummaryInfo  = new SymbolSummaryNET();

            int iCnt;

            // SummaryGet is passed a ref to a SymbolSummaryNET record
            // which will be populated by the SummaryGet call
            // and returned. miktek 9.10.12

            string symbol = "AUDCAD"; // FROM MTSampleAPI exec'ing.

            iCnt = myManager.SummaryGet(symbol, ref SummaryInfo);

            SymbolSummaryNET[] SymbolSummaryArray;

            // pass in and return a array Symbol Summary records
            SymbolSummaryArray = myManager.SummaryGetAll(ref iCnt); // risk mgmt call #4

            int       iResult  = 0;
            String    cur      = "AUD ";
            const int maxchars = 256;

            iResult = myManager.SummaryCurrency(cur, maxchars);

            // for testing what value should this be?
            const int sectype = 10;

            iResult = myManager.SummaryGetByType(sectype, ref SummaryInfo);

            const int symbolType = 10;

            iResult = myManager.SummaryGetByCount(symbolType, ref SummaryInfo);

            iResult = myManager.ExposureValueGet(cur, ref ExposureInfo);

            ExposureValueNET[] ExposedArray; // miktek 9.9.12

            int iRecCount = 0;
            int iLoopCtr  = 0;

            while (iLoopCtr < 4)
            {
                ExposedArray = myManager.ExposureGet(ref iRecCount);
                Console.WriteLine("ExposureGet attempt: {0} Recs Gotten: ", iLoopCtr, iRecCount);
                iLoopCtr++;
            }

            int iKey = 0;

            iKey = Console.Read();
            myManager.Disconnect();

            Console.WriteLine("End of test run 9.10.12");

            iKey = Console.Read();
        }
        public static void Main(string[] args)
        {
            int iRet = 999;

            // ErrorMEssage will be used to access error message
            // from the mt4 wrapper.
            String ErrorMessage = "none received";

            Console.WriteLine("testing 8.28.12");

            iRet = myManager.ManagerFactory();

            // hardwire the server name for short term.
            // put into a config.xml file for longer term sanity

            String ServerName = "mtdem01.primexm.com:443";

            // connect to the server
            iRet = myManager.Connect(ServerName);

            // get errorMessage from the CMTManager
            ErrorMessage = myManager.ErrorDescription(iRet);
            Console.WriteLine("Connect ErrMsg: {0}", ErrorMessage);

            // login in credentials. Don't dawdle here.
            // you have aprox. 15 seconds between connecting to the server
            // to enter your creds. Otherwise, say after 15 seconds, the server
            // drops your connection

            iRet         = myManager.Login(900, "!FQS123!!");
            ErrorMessage = myManager.ErrorDescription(iRet);
            Console.WriteLine("Login ErrMsg: {0}", ErrorMessage);

            if (iRet != 0)
            {
                return;
            }

            int choice = 0;

            do
            {
                Console.WriteLine("\nEnter your choice(1,2,3,4,5) to:\n1. Add the User.\n2. Update the User." +
                                  "\n3. History of closed trades.\n4. TradesRequest.\n5. Delete User.\n6. Users Request." +
                                  "\n7. User Records Request \n8. Symbol Refresh\n9. UserPasswordSet.\n10. Exit.\n");
                string sChoice = Console.ReadLine();
                choice = int.Parse(sChoice);
                switch (choice)
                {
                case 1:
                    UserRecordNET user = new UserRecordNET();
                    user.group = "FQ-IB-One";
                    Console.WriteLine("\nEnter Name:");
                    user.name     = Console.ReadLine();
                    user.password = "******";
                    user.enable   = 1;
                    user.enable_change_password = 1;
                    iRet = myManager.UserRecordNew(user);
                    if (iRet == 0)
                    {
                        Console.WriteLine("\nUser Added Successfully.");
                        Console.WriteLine("User Login value: " + user.login);
                    }
                    else
                    {
                        Console.WriteLine("\nUser cannot added successfully.");
                        ErrorMessage = myManager.ErrorDescription(iRet);
                        Console.WriteLine("Login ErrMsg: {0}", ErrorMessage);
                    }

                    break;

                case 2:
                    UserRecordNET existingUser = new UserRecordNET();
                    existingUser.group = "FQ-IB-One";
                    Console.WriteLine("\nEnter Login to update:");
                    string tempLogin = Console.ReadLine();
                    existingUser.login = int.Parse(tempLogin);
                    Console.WriteLine("\nEnter Name:");
                    existingUser.name   = Console.ReadLine();
                    existingUser.enable = 1;

                    iRet = myManager.UserRecordUpdate(existingUser);

                    if (iRet == 0)
                    {
                        Console.WriteLine("\nUser Modified Successfully.\n");
                    }
                    else
                    {
                        Console.WriteLine("\nUser cannot Modified successfully.\n");
                        ErrorMessage = myManager.ErrorDescription(iRet);
                        Console.WriteLine("ErrMsg: {0}", ErrorMessage);
                    }
                    break;

                case 3:

                    TimeZone tZone     = TimeZone.CurrentTimeZone;
                    DateTime baseTime  = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    TimeSpan fromSpan  = baseTime - startTime + tZone.GetUtcOffset(baseTime);
                    DateTime endTime   = new DateTime(2012, 12, 28, 0, 0, 0, 0);
                    TimeSpan toSpan    = baseTime - endTime + tZone.GetUtcOffset(baseTime);
                    Int64    from      = Convert.ToInt64(Math.Abs(fromSpan.TotalSeconds));
                    Int64    to        = Convert.ToInt64(Math.Abs(toSpan.TotalSeconds));
                    Console.WriteLine("\nEnter Login:"******"Deals: " + TradeInfo[0].order + " Login: "******" Type: " + TradeInfo[0].cmd + "\nSymbol: " + TradeInfo[0].symbol +
                                          " TradeInfo[0].conv_rates[1]: " + TradeInfo[0].conv_rates[1] +
                                          "Closed Price: " + TradeInfo[0].close_price);
                    }
                    else
                    {
                        Console.WriteLine("No trade Info.\n");
                    }

                    break;

                case 4:
                    int val = 0;
                    TradeInfo = myManager.TradesRequest(ref val);
                    if (TradeInfo != null)
                    {
                        Console.WriteLine("Deals: " + TradeInfo[0].order + " Login: "******" Type: " + TradeInfo[0].cmd + "\nSymbol: " + TradeInfo[0].symbol +
                                          " TradeInfo[0].conv_rates[1]: " + TradeInfo[0].conv_rates[1] +
                                          "\nTotal No. of Trades: " + val);
                    }

                    break;

                case 5:

                    GroupCommandInfoNET info = new GroupCommandInfoNET();
                    info.command = (int)GroupOperation.GROUP_DELETE;

                    //set the leverage accordingly..
                    info.leverage = 0;
                    Console.WriteLine("Enter the number of login values to be entered:");
                    string strUserAccountsLength = Console.ReadLine();
                    int    nUserAcctLength       = int.Parse(strUserAccountsLength);

                    //info.len consist the number of user accounts..
                    info.len = nUserAcctLength;

                    int[] logins = new int[nUserAcctLength];
                    Console.WriteLine();

                    for (int i = 0; i < nUserAcctLength; i++)
                    {
                        Console.Write(" " + (i + 1) + ". Enter Login value: ");
                        logins[i] = int.Parse(Console.ReadLine());
                        Console.WriteLine();
                    }

                    iRet         = myManager.UsersGroupOp(info, ref logins[0]);
                    ErrorMessage = myManager.ErrorDescription(iRet);
                    Console.WriteLine("ErrMsg: {0}", ErrorMessage);
                    break;

                case 6:
                    int             nNoOfUserAcct = 0;
                    UserRecordNET[] userInfo;
                    userInfo = myManager.UsersRequest(ref nNoOfUserAcct);
                    break;

                case 7:

                    int[] log = new int[4];
                    log[0] = 123456;
                    log[1] = 10020;
                    log[2] = 10021;
                    log[3] = 123423;

                    int nNoOfUsers = log.Length;
                    userInfo = myManager.UserRecordsRequest(ref log[0], ref nNoOfUsers);

                    break;

                case 8:
                    iRet = myManager.SymbolsRefresh();
                    break;

                case 9:
                    iRet = myManager.UserPasswordSet(10021, "Testing", 0, 0);
                    break;

                default:
                    break;
                }
            } while (choice > 0 && choice < 10);

            Console.WriteLine("\nChoose which pumping you want to activate:\n1. PumpingSwitch.\n2. PumpingSwitchEx.");
            string pumpChoice = Console.ReadLine();

            choice = int.Parse(pumpChoice);

            if (choice == 1)
            {
                // declare a PumpFuncDelegate and then create an instance
                // of it. This will be used to start up the pumping asnycn
                // call back mechanism from the mtmanapi.dll, up through
                // the c++/cli wrapper to the C# client code here.

                MT4ManLibraryNETv03.PumpFuncDelegate myPumpFunc =
                    new MT4ManLibraryNETv03.PumpFuncDelegate(miktekCSConAppTestHarness.CallBackMethod);

                // now we pass the delegate named myPumpFunc which actually
                // is a function pointer the CallBackMethod declared
                iRet = myManager.PassMeADelegate(myPumpFunc);

                // enable the pumping switch
                myManager.PumpingSwitch();
            }
            else if (choice == 2)
            {
                MT4ManLibraryNETv03.PumpFuncExDelegate myPumpEx =
                    new MT4ManLibraryNETv03.PumpFuncExDelegate(miktekCSConAppTestHarness.CallBackMethodEx);

                UserRecordNET exUser = new UserRecordNET();
                exUser.group = "FQ-IB-One";
                exUser.login = 123;

                Object param = exUser;

                int flags = ((int)PumpingFlags.CLIENT_FLAGS_HIDEMAIL) | ((int)PumpingFlags.CLIENT_FLAGS_HIDENEWS) | ((int)PumpingFlags.CLIENT_FLAGS_HIDETICKS);

                iRet = myManager.PassMeAnExDelegate(myPumpEx);

                iRet = myManager.PumpingSwitchEx(flags, param);
            }

            ExposureValueNET ExposureInfo = new ExposureValueNET();
            SymbolSummaryNET SummaryInfo  = new SymbolSummaryNET();

            int iCnt;

            // SummaryGet is passed a ref to a SymbolSummaryNET record
            // which will be populated by the SummaryGet call
            // and returned. miktek 9.10.12

            string symbol = "AUDCAD"; // FROM MTSampleAPI exec'ing.

            iCnt = myManager.SummaryGet(symbol, ref SummaryInfo);

            SymbolSummaryNET[] SymbolSummaryArray;

            // pass in and return a array Symbol Summary records
            SymbolSummaryArray = myManager.SummaryGetAll(ref iCnt); // risk mgmt call #4

            int       iResult  = 0;
            String    cur      = "AUD ";
            const int maxchars = 256;

            iResult = myManager.SummaryCurrency(cur, maxchars);

            // for testing what value should this be?
            const int sectype = 10;

            iResult = myManager.SummaryGetByType(sectype, ref SummaryInfo);

            const int symbolType = 10;

            iResult = myManager.SummaryGetByCount(symbolType, ref SummaryInfo);

            iResult = myManager.ExposureValueGet(cur, ref ExposureInfo);

            ExposureValueNET[] ExposedArray; // miktek 9.9.12

            int iRecCount = 0;
            int iLoopCtr  = 0;

            while (iLoopCtr < 4)
            {
                ExposedArray = myManager.ExposureGet(ref iRecCount);
                Console.WriteLine("ExposureGet attempt: {0} Recs Gotten: ", iLoopCtr, iRecCount);
                iLoopCtr++;
            }

            int iKey = 0;

            iKey = Console.Read();
            myManager.Disconnect();

            Console.WriteLine("End of test run 9.10.12");

            iKey = Console.Read();
        }