Ejemplo n.º 1
0
        public ISchedulerDalInitResult Init(ISchedulerDalInitParams paramInit)
        {
            var result = new SchedulerDalJsonInitResult();

            _rootFolder = paramInit.Params["RootFolder"];
            _jobs       = new Dictionary <string, ISchedulerJob>();

            ReadJobsData();
            result.Success = true;

            if (_jobs.Count == 0)
            {
                result.Errors.Add(new Interfaces.Error()
                {
                    Code    = EErrorCodes.SchedulerJobsNotFound,
                    Type    = EErrorType.Warning,
                    Message = "SchedulerDAL was initialized but no jobs were read. Please verify that corresponding json-s exist and configuration is correct."
                });
            }

            return(result);
        }
Ejemplo n.º 2
0
        private IResult PrepareJobsList()
        {
#if DEBUG
            Thread.Sleep(12000);
#endif
            if (_dal == null)
            {
                string dalType = ConfigurationManager.AppSettings["SchedulerDal"];

                var dal = Global.Container.GetExport <ISchedulerDal>(dalType);
                ISchedulerDalInitParams initParams = dal.Value.CreateInitParams();

                string   dalParams = ConfigurationManager.AppSettings["SchedulerDalParams"];
                string[] kvs       = dalParams.Split(new char[] { ';' });
                foreach (var kv in kvs)
                {
                    if (!string.IsNullOrEmpty(kv))
                    {
                        string[] param = kv.Split(new char[] { '=' });

                        // TODO: BAD! need to fix this to compose the data automatically
                        if (dalType == "JSON" && param[0] == "RootFolder")
                        {
                            param[1] = Path.Combine(Global.Container.GetExportedValue <string>("ServiceRootFolder"), param[1]);
                        }

                        initParams.Params[param[0].Trim()] = param[1].Trim();
                    }
                }

                ISchedulerDalInitResult initResult = dal.Value.Init(initParams);
                if (!initResult.Success)
                {
                    return(initResult);
                }

                _dal = dal.Value;
            }

            ISchedulerDalGetJobsParams jobsParams = _dal.CreateGetJobsParams();
            ISchedulerDalGetJobsResult jobsResult = _dal.GetJobs(jobsParams);
            if (!jobsResult.Success)
            {
                return(jobsResult);
            }

            _jobs.AddRange(jobsResult.Jobs);

            return(null);

            #region deprecated

            /*
             * // TODO: need to have a separate DB for the jobs and schedules
             * // for now we just pushing importer every night
             * SchedulerJob importerJob = new SchedulerJob();
             * importerJob.Name = "Daily Filings Importing";
             * importerJob.LastRun = DateTime.MinValue;
             * importerJob.Interval = TimeSpan.FromDays(1);
             * importerJob.Hour = 0;
             * importerJob.JobUrl = ConfigurationManager.AppSettings["ImporterJobUrl"];
             *
             * // performing DB sanitization
             * SchedulerJob sanitizeJob = new SchedulerJob();
             * sanitizeJob.Name = "Daily Sanitization Tasks";
             * sanitizeJob.LastRun = DateTime.MinValue;
             * sanitizeJob.Interval = TimeSpan.FromDays(1);
             * sanitizeJob.Hour = 0;
             * sanitizeJob.JobUrl = ConfigurationManager.AppSettings["SanitizerJobUrl"];
             *
             * _jobs.Add(importerJob);
             * _jobs.Add(sanitizeJob);
             */
            #endregion
        }