Exemplo n.º 1
0
        protected override void ExecuteTask(VcssTaskModel vcssTask)
        {
            string username   = vcssTask.VcssTaskInfo.auth_token.Split('-')[0];
            string password   = vcssTask.VcssTaskInfo.auth_token.Split('-')[1];
            string requestURL = String.Format(vcssTask.VcssTaskInfo.url, username, ComputeHash(password));

            HttpWebRequest  request  = (HttpWebRequest)HttpWebRequest.Create(requestURL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream stream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    var     strResponse = reader.ReadToEnd();
                    dynamic result      = JsonConvert.DeserializeObject <dynamic>(strResponse);
                    if (result.Estado.ToString() != "Error")
                    {
                        VcssTaskManagerService.UpdateBOLSARAuthToken(result.Resultado.ToString());
                    }
                    else
                    {
                        VcssTaskManagerService.Log(vcssTask.VcssTaskInfo.name, vcssTask.data, vcssTask.scheduled_time, "Running", strResponse, DateTime.Now);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool RunTask(VcssTaskModel vcssTask)
        {
            VcssTaskCanExecuteResult canExecute = VcssTaskCanExecuteResult.EMPTY;

            try
            {
                VcssTaskManagerService.Log(vcssTask.VcssTaskInfo.name, vcssTask.data, vcssTask.scheduled_time, "Run", "", DateTime.Now);
                canExecute = this.CanExecute(vcssTask);
                if (canExecute == VcssTaskCanExecuteResult.Execute)
                {
                    this.ExecuteTask(vcssTask);
                    this.UpdateTaskExecutedTime(vcssTask);
                    VcssTaskManagerService.DeleteTask(vcssTask);
                    return(true);
                }
                else
                {
                    VcssTaskManagerService.Log(vcssTask.VcssTaskInfo.name, vcssTask.data, vcssTask.scheduled_time, "Running", canExecute.ToString(), DateTime.Now);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                VcssTaskManagerService.Log(vcssTask.VcssTaskInfo.name, "Info -> CanExecute: " + canExecute.ToString() + " -> Data: " + vcssTask.data, vcssTask.scheduled_time, "Run ERROR", ex.Message, DateTime.Now);
                return(false);
            }
        }
Exemplo n.º 3
0
        public bool CreateTask(VcssTaskInfoModel vcssTaskInfo, params string[] parameters)
        {
            VcssTaskCanScheduleResult canSchedule = VcssTaskCanScheduleResult.EMPTY;
            string parametersStr = "";

            if (parameters != null)
            {
                foreach (var item in parameters)
                {
                    parametersStr += item + ";";
                }
            }

            try
            {
                VcssTaskManagerService.Log(vcssTaskInfo.name, "Last Updated->", vcssTaskInfo.last_updated, "Create", "", DateTime.Now);
                canSchedule = this.CanSchedule(vcssTaskInfo);
                if (canSchedule == VcssTaskCanScheduleResult.Schedule)
                {
                    this.ScheduleTask(vcssTaskInfo, parameters);
                    return(true);
                }
                else
                {
                    VcssTaskManagerService.Log(vcssTaskInfo.name, "Last Updated-> Params:" + parametersStr, vcssTaskInfo.last_updated, "Creating", canSchedule.ToString(), DateTime.Now);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                VcssTaskManagerService.Log(vcssTaskInfo.name, "Last Updated-> Params:" + parametersStr + " -> CanSchedule: " + canSchedule.ToString(), vcssTaskInfo.last_updated, "Create ERROR", ex.Message, DateTime.Now);
                return(false);
            }
        }
Exemplo n.º 4
0
        protected override VcssTaskCanScheduleResult CanSchedule(VcssTaskInfoModel vcssTaskInfo)
        {
            DateTime marketTime    = DateTime.UtcNow.AddHours(vcssTaskInfo.Market.utc_offset);
            DateTime lastScheduled = VcssTaskManagerService.GetLastVcssTaskScheduledTime(vcssTaskInfo).AddMinutes(vcssTaskInfo.step);

            if (marketTime >= lastScheduled)
            {
                return(VcssTaskCanScheduleResult.Schedule);
            }
            return(VcssTaskCanScheduleResult.InvalidTime);
        }
        protected override void ScheduleTask(VcssTaskInfoModel vcssTaskInfo, params string[] parameters)
        {
            Dictionary <string, int> symbols = StockService.GetStocks().Where(s => s.market_id == 2 && s.active).ToDictionary(s => s.symbol + ".US", s => s.Id);

            using (WebClient web = new WebClient())
            {
                string   quotesData = web.DownloadString(String.Format(vcssTaskInfo.url, symbols.Keys.First(), vcssTaskInfo.auth_token, String.Join(",", symbols.Keys)));
                DateTime marketTime = DateTime.UtcNow.AddHours(vcssTaskInfo.Market.utc_offset);
                VcssTaskManagerService.ScheduleTask(vcssTaskInfo.Id, quotesData, marketTime);
            }
        }
Exemplo n.º 6
0
        protected override void ScheduleTask(VcssTaskInfoModel vcssTaskInfo, params string[] parameters)
        {
            int      symbolId = int.Parse(parameters[0]);
            DateTime from     = DateTime.Parse(parameters[1]);
            DateTime to       = DateTime.Parse(parameters[2]);
            string   symbol   = StockService.GetStockSymbol(symbolId).symbol;

            using (WebClient web = new WebClient())
            {
                string data = web.DownloadString(String.Format(vcssTaskInfo.url, symbol, from.ToString("yyyy-MM-dd"), to.ToString("yyyy-MM-dd"), vcssTaskInfo.auth_token));
                data += "#" + symbolId;
                DateTime marketTime = DateTime.UtcNow.AddHours(vcssTaskInfo.Market.utc_offset);
                VcssTaskManagerService.ScheduleTask(vcssTaskInfo.Id, data, marketTime);
            }
        }
        protected override void ScheduleTask(VcssTaskInfoModel vcssTaskInfo, params string[] parameters)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(vcssTaskInfo.url);

            request.Headers["Authorization"] = vcssTaskInfo.auth_token;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream stream2 = response.GetResponseStream())
            {
                using (StreamReader reader2 = new StreamReader(stream2))
                {
                    string   data       = reader2.ReadToEnd();
                    DateTime marketTime = DateTime.UtcNow.AddHours(vcssTaskInfo.Market.utc_offset);
                    VcssTaskManagerService.ScheduleTask(vcssTaskInfo.Id, data, marketTime);
                }
            }
        }
Exemplo n.º 8
0
        protected override void ScheduleTask(VcssTaskInfoModel vcssTaskInfo, params string[] parameters)
        {
            DateTime marketTime = DateTime.UtcNow.AddHours(vcssTaskInfo.Market.utc_offset);

            VcssTaskManagerService.ScheduleTask(vcssTaskInfo.Id, "", marketTime);
        }
Exemplo n.º 9
0
 protected void UpdateTaskExecutedTime(VcssTaskModel vcssTask)
 {
     VcssTaskManagerService.UpdateExecutedTime(vcssTask.VcssTaskInfo);
 }