Ejemplo n.º 1
0
        // Check Last Refresh time & if past 3 minutes then login
        // Even if someone else acquired login Session by weblogin etc.
        // Still this should work as the LastLoginRefreshTime becomes stale eventually and
        // resulting into relogin trigger

        // Keep calling this in a separate thread
        public BrokerErrorCode CheckAndLogInIfNeeded(bool bForceLogin, bool bCheckRemoteControl = false)
        {
            TimeSpan        maxTimeWithoutRefresh = new TimeSpan(0, 3, 0);
            BrokerErrorCode errorCode             = TouchServer();

            lock (lockLoginMethod)
            {
                if (bForceLogin || (errorCode != BrokerErrorCode.Success) || ((DateTime.Now - LastLoginRefreshTime) > maxTimeWithoutRefresh))
                {
                    ProgramRemoteControl remoteControlValue = ProgramRemoteControl.RUN;

                    if (bCheckRemoteControl)
                    {
                        remoteControlValue = RemoteUtils.GetProgramRemoteControlValue();
                    }
                    // keep looping until PAUSE status is reset
                    if (remoteControlValue.Equals(ProgramRemoteControl.PAUSE) ||
                        remoteControlValue.Equals(ProgramRemoteControl.STOP) ||
                        remoteControlValue.Equals(ProgramRemoteControl.HIBERNATE))
                    {
                        string traceString = string.Format("CheckAndLogInIfNeeded: Remote Control {0} the LOGIN\n", remoteControlValue.ToString());
                        FileTracing.TraceOut(traceString);
                        errorCode = BrokerErrorCode.RemotePausedOrStopped;
                    }
                    else
                    {
                        string traceString = string.Format("CheckAndLogInIfNeeded: Need to do actual LogIn. ");
                        errorCode    = LogIn();
                        traceString += "LogIn() returned: " + errorCode.ToString();
                        FileTracing.TraceOut(traceString);
                    }
                }
            }
            return(errorCode);
        }
Ejemplo n.º 2
0
        public static ProgramRemoteControl GetProgramRemoteControlValue()
        {
            string pageData = HttpHelper.GetWebPageResponse("http://sites.google.com/site/munishgoyal/",
                                                            null,
                                                            null,
                                                            new CookieContainer());

            ProgramRemoteControl controlValue = ProgramRemoteControl.RUN;

            if (!string.IsNullOrEmpty(pageData))
            {
                if (pageData.Contains("StopKalaPudinaStockTraderPause"))
                {
                    controlValue = ProgramRemoteControl.PAUSE;
                }
                else if (pageData.Contains("StopKalaPudinaStockTraderStop"))
                {
                    controlValue = ProgramRemoteControl.STOP;
                }
                else if (pageData.Contains("StopKalaPudinaStockTraderHibernate"))
                {
                    controlValue = ProgramRemoteControl.HIBERNATE;
                }
                else if (pageData.Contains("StopKalaPudinaStockTraderAtEndHibernate"))
                {
                    controlValue = ProgramRemoteControl.HIBERNATEATEND;
                }
            }
            string traceString = string.Format("GetProgramRemoteControlValue: {0}, {1}", controlValue.ToString(),
                                               string.IsNullOrEmpty(pageData) ? "Failed Fetch" : "Succesful Contact");

            FileTracing.TraceOut(traceString);

            return(controlValue);
        }
Ejemplo n.º 3
0
        // Not used currently
        public static bool IsSendSystemInHibernation()
        {
            ProgramRemoteControl remoteControlValue = RemoteUtils.GetProgramRemoteControlValue();

            // If Hibernate control specified return true
            return(remoteControlValue.Equals(ProgramRemoteControl.HIBERNATE) ||
                   remoteControlValue.Equals(ProgramRemoteControl.HIBERNATEATEND));
        }
Ejemplo n.º 4
0
        // Not used currently
        public static ProgramRemoteControl CheckRemoteControlInAlgo(ref bool bChecked)
        {
            // TEMPTEMP: this check is currently temporary , need to place it properly to provide pause algo functionality
            // Check after every 5 minutes
            int    minutes = DateTime.Now.Minute;
            int    seconds = DateTime.Now.Second;
            string traceString;
            ProgramRemoteControl remoteControlValue = ProgramRemoteControl.RUN;

            if (minutes % 5 == 1)
            {
                bChecked = false;
            }
            if ((minutes >= 5) && (minutes % 5 == 0) && !bChecked)
            {
                bChecked           = true;
                remoteControlValue = RemoteUtils.GetProgramRemoteControlValue();
                // keep looping until PAUSE status is reset
                while (remoteControlValue.Equals(ProgramRemoteControl.PAUSE))
                {
                    traceString = string.Format("AlgoRunner: Remote Control PAUSED the Algo, sleeping for 30 seconds before rechecking\n");
                    FileTracing.TraceOut(traceString);
                    // sleep 60 seconds
                    Thread.Sleep(60000);
                    remoteControlValue = RemoteUtils.GetProgramRemoteControlValue();
                }
                if (remoteControlValue.Equals(ProgramRemoteControl.STOP) ||
                    remoteControlValue.Equals(ProgramRemoteControl.HIBERNATE))
                {
                    traceString = string.Format("AlgoRunner: Remote Control issued STOP/HIBERNATE command to the Algo\n");
                    FileTracing.TraceOut(traceString);
                }
            }

            return(remoteControlValue);
        }