示例#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);
        }
示例#2
0
        public async Task <RemoteInfo> GetRemote(HttpRequest request)
        {
            var ip   = RemoteUtils.IP(request);
            var isIp = RemoteUtils.IsIPAddress(ip);

            if (isIp)
            {
                var url = _host + $"?ip={ip}&position=true";

                var response = await new HttpClient().GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    var info = JsonConvert.DeserializeObject <IPInfo>(json);
                    return(new RemoteInfo()
                    {
                        Ip = info.ip,
                        Agent = request.Headers["user-agent"],
                        City = info.city,
                        Country = info.country_name,
                        Coordinate = new RemoteInfo.CoordinateInfo
                        {
                            Lat = info.lat,
                            Lng = info.lng
                        }
                    });
                }
            }
            return(null);
        }
        public IActionResult SaveContactUs(MContactUs form)
        {
            string token = GetCpatchaToken();

            string validationMessage = ValidateContactUsForm(form, token);

            if (validationMessage != null)
            {
                ViewBag.Message = validationMessage;
            }
            else
            {
                IBusinessOperationManipulate <MContactUs> operation = GetSaveContactUsOperation();
                form.IP      = RemoteUtils.GetRemoteIPAddress(ControllerContext);
                form.Name    = StringUtils.StripTagsRegex(form.Name);
                form.Subject = StringUtils.StripTagsRegex(form.Subject);
                form.Email   = StringUtils.StripTagsRegex(form.Email);
                form.Message = StringUtils.StripTagsRegex(form.Message);

                operation.Apply(form);

                bool sendResult = SendEmail(form, token);

                if (sendResult)
                {
                    ViewBag.Message = "Your message has been received and we will contact you soon.";
                }
                else
                {
                    ViewBag.Message = "Unable to send the message, internal server error.";
                }
            }

            return(View("Contact"));
        }
        public IActionResult URLCheck(String product, String group, String serial, String pin)
        {
            MRegistration param = new MRegistration();

            param.IP           = RemoteUtils.GetRemoteIPAddress(ControllerContext);
            param.Pin          = pin;
            param.SerialNumber = serial;

            return(VerifyProduct(param));
        }
        public IActionResult WebCheck(MBarcode form)
        {
            form.SerialNumber = StringUtils.StripTagsRegex(form.SerialNumber);
            form.Pin          = StringUtils.StripTagsRegex(form.Pin);
            MRegistration param = new MRegistration();

            param.IP           = RemoteUtils.GetRemoteIPAddress(ControllerContext);
            param.Pin          = form.Pin;
            param.SerialNumber = form.SerialNumber;

            return(VerifyProduct(param));
        }
示例#6
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);
        }