Beispiel #1
0
        /// <summary>
        /// Get Uniform format of symbols
        /// </summary>
        /// <returns>List of Uniform format symbols</returns>
        public Dictionary <string, string> ListSymbolKeyAndValue()
        {
            string pathPairList = NaneMainDir.GetFileDir() + "PairList/";
            string pathKey      = pathPairList + "keyList.txt";
            string pathValue    = pathPairList + "valueList.txt";

            string[] listKey   = File.ReadAllLines(pathKey);
            string[] listValue = File.ReadAllLines(pathValue);

            Dictionary <string, string> list_SymbolKeyAndValue = new Dictionary <string, string> {
                { "", "" }
            };

            for (int i = 0; i < listKey.Length; i++)
            {
                if (!(listKey[i] == ""))
                {
                    try
                    {
                        list_SymbolKeyAndValue.Add(listKey[i], listValue[i]);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(list_SymbolKeyAndValue);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            DateTime localDate = DateTime.Now;

            Console.WriteLine("\ntime program start {0}  {1} ", localDate, localDate.ToLongDateString());
            string path   = NaneMainDir.GetFileDir();
            string input  = path + "input/";
            string output = path + "output/";;

            MakeCritrogrfiFile.GetFiles(input, output);
            Console.WriteLine("\nPress any key to close the program");
            Console.Read();
        }
Beispiel #3
0
        public void WaitToProceed()
        {
            if (numberSessionsMinute == -1)  // Unlimited option by using -1
            {
                return;
            }

            if (numberCallsMinute == 0)      // Reset times if set to 0
            {
                timeStartNumberCallsMinute = timeEndNumberCallsMinute = DateTime.Now;
            }

            NotCriticaMode = (!(OneOpportunity || sequenceOpportunities));  // A result of true if both are false

            if (NotCriticaMode)
            {
                if (numberSessionsWas == 0)     //  The first call does not wait because the wait will begin only before the next call
                {
                    numberSessionsWas = 1;
                    timeLast          = DateTime.Now;   // Reset the last call time after the wait (which is actually the time of calling execution)
                    timePast          = 0;              // Resetting the time just now for safety
                    reservedTime      = 0;              // Reset the time that has just accumulated to be on the safe side
                    numberCallsMinute = 0;              // Reset call counter. Right now for safety
                    return;
                }
                else
                {
                    timeNow       = DateTime.Now;
                    timePast      = timeNow.Subtract(timeLast).Milliseconds; // Check how long it took in milliseconds. From the last call
                    timeReduction = reservedTime + timePast;

                    totalWait = secondWait * numberSessionsWas;

                    if (timeReduction < totalWait)
                    {
                        totalWaitReduce = Convert.ToInt32(totalWait - timeReduction);
                        Thread.Sleep(totalWaitReduce);

                        numberCallsMinute = 0;
                        timeLast          = DateTime.Now;
                        timePast          = 0;
                        reservedTime      = 0;
                        numberSessionsWas = 1;
                        return;
                    }
                    else if (numberCallsMinute <= numberSessionsMinute)
                    {
                        numberCallsMinute++;
                        reservedTime += (timePast - secondWait);

                        timePast          = 0;
                        timeLast          = DateTime.Now;
                        numberSessionsWas = 1;
                        return;
                    }
                    else
                    {
                        timeEndNumberCallsMinute = DateTime.Now;
                        if (timeEndNumberCallsMinute.Subtract(timeStartNumberCallsMinute).Milliseconds < 60000)
                        {
                            Thread.Sleep(timeEndNumberCallsMinute.Subtract(timeStartNumberCallsMinute).Milliseconds);

                            numberCallsMinute = 0;

                            timeLast          = DateTime.Now;
                            timePast          = 0;
                            reservedTime      = 0;
                            numberSessionsWas = 0;
                            return;
                        }
                        else if (timePast < secondWait)
                        {
                            numberCallsMinute = 0;

                            totalWaitReduce = Convert.ToInt32(totalWait - timePast);
                            Thread.Sleep(totalWaitReduce);
                            timeLast          = DateTime.Now;
                            timePast          = 0;
                            reservedTime      = 0;
                            numberSessionsWas = 1;
                            return;
                        }
                        else
                        {
                            numberCallsMinute = 0;

                            timeLast          = DateTime.Now;
                            timePast          = 0;
                            reservedTime      = 0;
                            numberSessionsWas = 1;
                            return;
                        }
                    }
                }
            }
            else if (OneOpportunity)
            {
                numberCallsMinute++;

                if (numberSessionsWas >= numCallUnbrokenAPI)
                {
                    DateTime localDate = DateTime.Now;
                    using (StreamWriter sw = File.AppendText(NaneMainDir.GetMainDir() + "ExceptionOneOpportunity.txt"))
                    {
                        sw.WriteLine("To see how we got into such a situation \n" + localDate);
                    }

                    timeNow         = DateTime.Now;
                    timePast        = timeNow.Subtract(timeLast).Milliseconds;
                    totalWait       = secondWait;
                    totalWaitReduce = Convert.ToInt32(totalWait - timePast);

                    if (totalWaitReduce > 0)
                    {
                        Thread.Sleep(totalWaitReduce);
                        timeLast = DateTime.Now;
                        return;
                    }
                    else
                    {
                        timeLast = DateTime.Now;
                        numberSessionsWas++;
                        return;
                    }
                }
                else
                {
                    numberSessionsWas++;
                }
            }
            else if (sequenceOpportunities)
            {
                numberCallsMinute++;

                if ((numberSessionsWas + 2) >= numCallUnbrokenAPI)
                {
                    numberSessionsWas++;    // Add to reduce current call as well
                    timeNow         = DateTime.Now;
                    timePast        = timeNow.Subtract(timeLast).Milliseconds;
                    totalWait       = numberSessionsWas * secondWait;
                    totalWaitReduce = Convert.ToInt32(totalWait - timePast);

                    Thread.Sleep(totalWaitReduce);
                    timeLast = DateTime.Now;

                    timePast          = 0;
                    reservedTime      = 0;
                    numberSessionsWas = 0;
                    numberCallsMinute = 0;
                    return;
                }
                else
                {
                    numberSessionsWas++;
                }
            }
// TODO enable
//#if DEBUG
//            using (StreamWriter sw = File.AppendText(NaneMainDir.GetMainDir() + "DebugRateGateLog.txt"))
//            {
//                sw.WriteLine("timeNow               - {0}", timeNow);
//                sw.WriteLine("timeLast              - {0}", timeLast);
//                sw.WriteLine("timePast              - {0}", timePast);
//                sw.WriteLine("totalWait             - {0}", totalWait);
//                sw.WriteLine("totalWaitReduce       - {0}", totalWaitReduce);
//                sw.WriteLine("numberSessionsMinute  - {0}", numberSessionsMinute);
//                sw.WriteLine("numberSessionsWas     - {0}", numberSessionsWas);
//                sw.WriteLine("secondWait            - {0}", secondWait);
//                sw.WriteLine("NotCriticaMode        - {0}", NotCriticaMode);
//                sw.WriteLine("OneOpportunity        - {0}", OneOpportunity);
//                sw.WriteLine("sequenceOpportunities - {0}", sequenceOpportunities);
//                sw.WriteLine("\n\n");
//            }
//#endif
        }