Ejemplo n.º 1
0
        public void Run(Quartz.IJobExecutionContext context)
        {
            //获取可用蜘蛛
            //待执行状态
            //开启状态
            //间隔时间符合条件
            var SpiderCollection = DB.Database.SqlQuery <yy_Spider>("SELECT * FROM yy_Spider WITH(NOLOCK) WHERE Status = 0 AND IsShow = 1 AND DATEADD(second,ExecutionInterval,LastStartTime) < GETDATE()").ToList();

            if (SpiderCollection.Count > 0)
            {
                foreach (var v in SpiderCollection)
                {
                    try
                    {
                        //蜘蛛开始执行任务
                        Start(v);
                    }
                    catch (Exception ex)
                    {
                        Add(ex);
                    }
                    finally
                    {
                    }
                }
            }

            //状态重置
            DB.Database.ExecuteSqlCommand("UPDATE yy_Spider SET Status=0");

            MQueue.Send("NewsSync", null);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Invoke the method via the MethodInvoker.
 /// </summary>
 /// <param name="context"></param>
 protected override void ExecuteInternal(JobExecutionContext context)
 {
     if (methodInvoker == null)
     {
         throw new JobExecutionException("Could not execute job when method invoker is null");
     }
     try
     {
         context.Result = methodInvoker.Invoke();
     }
     catch (TargetInvocationException ex)
     {
         logger.Error(errorMessage, ex.GetBaseException());
         if (ex.GetBaseException() is JobExecutionException)
         {
             // -> JobExecutionException, to be logged at info level by Quartz
             throw ex.GetBaseException();
         }
         // -> "unhandled exception", to be logged at error level by Quartz
         throw new JobMethodInvocationFailedException(methodInvoker, ex.GetBaseException());
     }
     catch (Exception ex)
     {
         // -> "unhandled exception", to be logged at error level by Quartz
         throw new JobMethodInvocationFailedException(methodInvoker, ex.GetBaseException());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 基类去实现接口,由派生类处理
 /// 这个方法里定义算法的骨架,而核心的ExcuteJob抽象方法,由各个具体类去实现
 /// </summary>
 /// <param name="context"></param>
 public void Execute(Quartz.IJobExecutionContext context)
 {
     //操作 一些公用的方法
     //    foreach (var item in context.JobDetail.JobDataMap)
     //    {
     //        Console.WriteLine("{0}.JobDataMap   key={1},value={2}", context.JobDetail.Key.Name, item.Key, item.Value);
     //    }
     ExcuteJob(context);
 }
Ejemplo n.º 4
0
        public void Execute(Quartz.IJobExecutionContext context)
        {
            //message.Subject = "Test";
            //message.Body = "Test at " + DateTime.Now;
            //using (SmtpClient client = new SmtpClient
            //{
            //    EnableSsl = true,
            //    Host = "smtp.gmail.com",
            //    Port = 587,
            //    Credentials = new NetworkCredential("*****@*****.**", "password")
            //})
            //{
            //    client.Send(message);
            //}

            //find emails with due date
            using (SubTrackerContext dc = new SubTrackerContext())
            {
                //var v = dc.ServicesTable.Where(a => a.EndDate == DateTime.Now.AddDays(1).Date).FirstOrDefault();
                DateTime tommorow = DateTime.Now.AddDays(1).Date;
                var      userMail = from a in dc.ServicesTable.Where(a => a.EndDate == tommorow)
                                    select a.User.EmailId;

                if (userMail != null)
                {
                    foreach (var email in userMail)
                    {
                        var    from   = new MailAddress("*****@*****.**", "SubTracker");
                        var    to     = new MailAddress(email);
                        var    frompw = "subscriptionTracker123";
                        string sub    = "Renew your Subscription";
                        string body   = "<br/><br/>Please renew your subscription, as it will expire tommorow inorder to continue using the service - <strong>SubTracker</strong>" +
                                        "<br/><br/> Click this link to go to your account.";
                        var smtp = new SmtpClient
                        {
                            Host                  = "smtp.gmail.com",
                            Port                  = 587,
                            EnableSsl             = true,
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials           = new NetworkCredential(from.Address, frompw)
                        };
                        using (var message = new MailMessage(from, to))
                        {
                            message.Subject    = sub;
                            message.Body       = body;
                            message.IsBodyHtml = true;

                            smtp.Send(message);
                        }
                    }
                }
            }
        }
 public void Execute(Quartz.IJobExecutionContext context)
 {
     log.Info("Execute started");
     try
     {
         this.ExecuteInternal(context);
         log.Info("Execute ended");
     }
     catch (Exception ex)
     {
         log.Fatal("Execute failed", ex);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     第一次启动时,暂停时间
        /// </summary>
        /// <param name="context">执行上下文</param>
        /// <param name="scope"></param>
        /// <param name="tiemSpan">时间间隔</param>
        /// <returns></returns>
        protected void FirstWaiter(Qz.IJobExecutionContext context, IScope scope, TimeSpan tiemSpan)
        {
            var objectCache = scope.Resolve <IObjectCache>();
            var type        = context.JobInstance;
            var cacheKey    = $"Job_{type.GetType().Name}_FirstWaiter";

            objectCache.TryGet(cacheKey, out bool sendState);
            if (sendState == false)
            {
                Thread.Sleep(tiemSpan);
                scope.Resolve <IObjectCache>().Set(cacheKey, true);
            }
        }
Ejemplo n.º 7
0
            public void Execute(Quartz.IJobExecutionContext context)
            {
                IMyJob myjob = JobFactory.Instance.Find(context.JobDetail.Key);

                myjob.Load();
                if (myjob.State != JobState.Working)
                {
                    return;
                }
                JobFactory.Instance.JobRemove(myjob);
                myjob.Excute();
                JobFactory.Instance.JobAdd(myjob);
            }
Ejemplo n.º 8
0
 public override void Execute(Quartz.IJobExecutionContext context)
 {
     try
     {
         gameEntity.makeCompleted();
     }
     catch (Exception e)
     {
         JobExecutionException je = new JobExecutionException(e);
         je.RefireImmediately = true; //do something with the exception
         throw je;                    //throw JobExecutionException
     }
 }
Ejemplo n.º 9
0
        protected override void DoJob(Quartz.IJobExecutionContext context)
        {
            var task = new T();

            /*if (task is BaseReportTask) {
             * (task as BaseReportTask).DoReportTask(Util.RPCNow);
             * } else if (task is BaseSimpleTask) {
             * (task as BaseSimpleTask).Execute();
             * } else if (task is BaseSyncTask) {
             * (task as BaseSyncTask).DoSync();
             * }*/
            task.Execute();
            log.Info(typeof(T).Name + " Job Finish");
        }
Ejemplo n.º 10
0
 /// <summary> 
 /// This implementation applies the passed-in job data map as object property
 /// values, and delegates to <code>ExecuteInternal</code> afterwards.
 /// </summary>
 /// <seealso cref="ExecuteInternal" />
 public void Execute(JobExecutionContext context)
 {
     try
     {
         ObjectWrapper bw = new ObjectWrapper(this);
         MutablePropertyValues pvs = new MutablePropertyValues();
         pvs.AddAll(context.Scheduler.Context);
         pvs.AddAll(context.MergedJobDataMap);
         bw.SetPropertyValues(pvs, true);
     }
     catch (SchedulerException ex)
     {
         throw new JobExecutionException(ex);
     }
     ExecuteInternal(context);
 }
Ejemplo n.º 11
0
 /// <summary>
 ///     执行
 /// </summary>
 /// <param name="context">执行上下文</param>
 public async Task Execute(Qz.IJobExecutionContext context)
 {
     using (var scope = Ioc.BeginScope()) {
         try {
             //get tenant and switch
             var jobDataMap = context.JobDetail.JobDataMap;
             var tenantName = jobDataMap.GetString(nameof(Tenant));
             if (!string.IsNullOrWhiteSpace(tenantName))
             {
                 TenantContext.SwitchDatabase(scope, tenantName);
             }
             //execute
             await Execute(context, scope);
         } catch (Exception ex) {
             var type = context.JobInstance;
             ExceptionLogs.Write(ex, type.GetType().Name);
         }
     }
 }
        public async Task Execute(Quartz.IJobExecutionContext context)
        {
            Console.WriteLine("start");
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var tasks = new List <Task>();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(new Task(() => writefile()));
            }

            tasks.ForEach(t => t.Start());

            await Task.WhenAll(tasks.ToArray());

            sw.Stop();
            Console.WriteLine($"all tasks done {callcount} api call in {sw.Elapsed}");
        }
        public override void Execute(Quartz.IJobExecutionContext context)
        {
            try
            {
                if (gameEntity.resolvePotentialWinners() == GameResolveStatus.OUTSTANDING)
                {
                    this.ExecuteTime = DateTime.Now.AddSeconds(10);  ///TODO is this correct?
                    schedule(context.Scheduler);
                }

                gamerule.ExcecuteTime = ExecuteTime.DateTime;
                gameEntity.db.SaveChanges();
            }
            catch (Exception e)
            {
                JobExecutionException je = new JobExecutionException(e);
                je.RefireImmediately = true; //do something with the exception
                throw je;                    //throw JobExecutionException
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// </summary>
        /// <param name="context"></param>
        public void Execute(Quartz.IJobExecutionContext context)
        {
            long now = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);

            if (timeNow != null)
            {
                long diff = (now - timeNow.Value);
                timeNow = now;

                if (diff > 0)
                {
                    logger.Debug("Scheduler job executed ... ");
                    doSomething(diff);
                }
            }
            else
            {
                timeNow = now;
            }
        }
Ejemplo n.º 15
0
        public async Task Execute(Quartz.IJobExecutionContext context)
        {
            try
            {
                JobDataMap dataMap = context.JobDetail.JobDataMap;

                string connectionString = (string)dataMap["connectionstring"];

                using (var conn = new SqlConnection(connectionString))
                    using (var Command = new SqlCommand("GenerateProjectReport_TEST", conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        conn.Open();
                        Command.ExecuteNonQuery();
                        conn.Close();
                        await Task.CompletedTask;
                    }
            }catch (SqlException e) {
                Debug.WriteLine("SQL execution exception in ReportJob, see stacktrace: \n" + e.StackTrace);
                await Task.CompletedTask;
            }
        }
Ejemplo n.º 16
0
        public void Execute(Quartz.IJobExecutionContext context)
        {
            if (AutoUpdateData._isUploading)
            {
                logger.DebugFormat("***************************Previous job is In Upload. Please wait。。。 {0}", context.PreviousFireTimeUtc.Value.DateTime);
                AutoUpdateData.jobflag("P Please wait。。。revious job is In Upload:" + context.PreviousFireTimeUtc.Value.DateTime);
                return;
            }

            DataTable    tblPicked;
            BssLineStock bssLineStock = new BssLineStock();

            AutoUpdateData._isUploading = true;
            //get sql update mode
            //1-删除后再追加 2-直接更新
            if (AutoUpdateData._updatemode.StartsWith("1"))
            {
                _is1 = true;
            }
            else if (AutoUpdateData._updatemode.StartsWith("2"))
            {
                _is1 = false;
            }
            else
            {
                _is1 = true;
            }

            logger.DebugFormat("执行更新任务!!!!!!!!!!!!!!!");
            AutoUpdateData.jobflag("Is Runing, Next Exec Job Time:" + context.NextFireTimeUtc.Value.DateTime);
            try
            {
                var _tmpOracleDBname = AutoUpdateData._DBOracle11DBname;
                //init even tInitIniToday
                AutoUpdateData.tInitIniToday(DateTime.Now.ToString("yyyyMMdd"));
                //get
                if (AutoUpdateData._tableList.Count > 0)
                {
                    logger.Debug("执行数据获取任务!!!!!!!!!!!!!!!");
                    var tmpBatch = AutoUpdateData._txt1batchNum;
                    AutoUpdateData._dsList.Clear();


                    var tmpwhereFirst = getInSql(AutoUpdateData._CONTRACT, "CONTRACT", false);
                    if (string.IsNullOrEmpty(tmpwhereFirst))
                    {
                        return;
                    }
                    var tmpwhere = tmpwhereFirst;

                    foreach (var item in AutoUpdateData._tableList)
                    {
                        try
                        {
                            //init attr
                            _typeOfTable = "0";
                            _time_start  = DateTime.Now.ToString();
                            _time_done   = DateTime.Now.ToString();
                            _sql         = "select * from ";
                            tmpwhere     = tmpwhereFirst;

                            if (item.Key.Contains('|'))
                            {
                                var td = item.Key.Split('|');

                                var tmpTableTakeDataNum = "";
                                int preNum   = 0;
                                var allCount = 0;

                                var tmpKeyname = td[0].Trim() + "_KEY";
                                var tmpKeyLast = td[0].Trim() + "." + td[1].Trim();

                                var tmpds = new DataSet();
                                //father and son
                                var isSon             = false;
                                var tmpdsForFatherSon = new DataSet();

                                tmpds.DataSetName = td[0].Trim();


                                //test
                                //if (item.Value != 3)
                                //{
                                //    continue;
                                //}

                                switch (item.Value)
                                {
                                case 1:
                                    //key: 0 table | where 1 | order by 2  | type 3
                                    var tmpInsql = getInSql(AutoUpdateData._N_OBL_PART_TYPE, td[1].Trim(), true);


                                    if (string.IsNullOrEmpty(tmpInsql))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        tmpwhere += tmpInsql;
                                    }

                                    //pre update number
                                    tmpTableTakeDataNum = AutoUpdateData._iniToday.IniReadValue("TableTakeDataNum", td[0].Trim());

                                    if (!int.TryParse(tmpTableTakeDataNum, out preNum))
                                    {
                                        preNum = 0;
                                    }
                                    //get all count form oracle db

                                    allCount = OracleDal.GetCount(_tmpOracleDBname, td[0].Trim(), tmpwhere);
                                    logger.DebugFormat("*********Table: {0},已上传:{1} ,Oracle 现在有数据:{2}.当日:{3}", td[0], preNum, allCount, DateTime.Now.ToString("yyyyMMdd"));

                                    if (preNum >= allCount)
                                    {
                                        logger.DebugFormat("*********(已上传数) {0} >= {1} (Oracle 现在有数据),无需更新.", preNum, allCount);
                                    }
                                    else
                                    {
                                        var tmptoUpdate = (allCount - preNum);
                                        logger.DebugFormat("*********需更新数:{0}.", tmptoUpdate);
                                        var tmporderby = td[2].Trim();
                                        if (td[2].Trim().ToLower().Equals("no"))
                                        {
                                            tmporderby = "";
                                        }

                                        tmpds = OracleDal.GetData(_tmpOracleDBname, td[0].Trim(), tmpwhere, tmporderby, preNum, tmptoUpdate);
                                    }

                                    tmpds.DataSetName = td[0].Trim();
                                    _typeOfTable      = td[3].Trim();
                                    break;

                                case 2:

                                    //key: 0 table | add Id 1 | order by 2 | datefrom 3 | type 4
                                    //get the last ID

                                    //get from SQL by id;
                                    //var tmpTRANSACTION_ID = AutoUpdateData._iniToday.IniReadValue("TableKeyLastValue", tmpKeyLast);
                                    var tmpTRANSACTION_ID = DbHelperSQL.GetDMaxID(td[1], td[0]);

                                    // get last where
                                    tmpwhere += " and " + td[1].Trim() + ">='" + tmpTRANSACTION_ID + "' ";

                                    //pre update number
                                    tmpTableTakeDataNum = AutoUpdateData._iniToday.IniReadValue("TableTakeDataNum", td[0].Trim());

                                    if (!int.TryParse(tmpTableTakeDataNum, out preNum))
                                    {
                                        preNum = 0;
                                    }

                                    //get all count form oracle db

                                    OracleParameter[] parameters2 = { new OracleParameter(":gxsj", OracleDbType.Varchar2, 10) };
                                    parameters2[0].Value = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd") + " 00:00:00";    // HH

                                    if (tmpTRANSACTION_ID == 1)
                                    {
                                        logger.DebugFormat("******************************{0} 初始更新,加限时间-3天。", td[0]);
                                        _time_start = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd") + " 00:00:00";
                                        tmpwhere   += " and " + td[3] + ">=to_date(:gxsj,'yyyy-MM-dd HH24:mi:ss')";
                                        allCount    = OracleDal.GetCount(_tmpOracleDBname, td[0].Trim(), tmpwhere, parameters2);
                                    }
                                    else
                                    {
                                        allCount = OracleDal.GetCount(_tmpOracleDBname, td[0].Trim(), tmpwhere);
                                    }

                                    logger.DebugFormat("*********Table: {0},已上传:{1} ,Oracle 现在有数据:{2}.当日:{3}", td[0], preNum, allCount, DateTime.Now.ToString("yyyyMMdd"));

                                    if (preNum >= allCount)
                                    {
                                        logger.DebugFormat("*********(已上传数) {0} >= {1} (Oracle 现在有数据),无需更新.", preNum, allCount);
                                    }
                                    else
                                    {
                                        var tmptoUpdate = (allCount - preNum);
                                        logger.DebugFormat("*********需更新数:{0}.", tmptoUpdate);
                                        var tmporderby = td[2].Trim();
                                        if (td[2].Trim().ToLower().Equals("no"))
                                        {
                                            tmporderby = "";
                                        }
                                        if (tmpTRANSACTION_ID == 1)
                                        {
                                            tmpds = OracleDal.GetData(_tmpOracleDBname, td[0].Trim(), tmpwhere, tmporderby, preNum, tmptoUpdate, parameters2);
                                        }
                                        else
                                        {
                                            tmpds = OracleDal.GetData(_tmpOracleDBname, td[0].Trim(), tmpwhere, tmporderby, preNum, tmptoUpdate);
                                        }
                                    }

                                    tmpds.DataSetName = td[0].Trim();
                                    _typeOfTable      = td[4].Trim();
                                    _time_done        = OracleDal.getMaxCol(tmpds, td[3]).ToString();
                                    break;

                                case 3:

                                    //key: 0 table|1 where|2 order by  | type 3
                                    //get per last datetime

                                    var tmpLastWhere = AutoUpdateData._iniToday.IniReadValue("TableKeyLastValue", tmpKeyLast);

                                    var tmpLastWhereDateTime = DateTime.Now;
                                    if (!DateTime.TryParse(tmpLastWhere, out tmpLastWhereDateTime))
                                    {
                                        tmpLastWhereDateTime = DateTime.Now;
                                        AutoUpdateData._iniToday.IniWriteValue("TableKeyLastValue", tmpKeyLast, tmpLastWhereDateTime.ToString());
                                    }
                                    tmpwhere += " and to_char(" + td[1] + ", 'yyyymmddHH24miss') >= :gxsj";
                                    OracleParameter[] parameters3 = { new OracleParameter(":gxsj", OracleDbType.Varchar2, 10) };
                                    //no time

                                    parameters3[0].Value = DateTime.Now.ToString("yyyyMMdd000000");

                                    //for N_AIS_SHOP_LIST_PICKED_ACT_TAB
                                    var tmpnewDateTime = DateTime.Now.ToString("yyyyMMdd000000");
                                    if (td[0].Trim().ToUpper().Equals("N_AIS_SHOP_LIST_PICKED_ACT_TAB".ToUpper()))
                                    {
                                        tmpnewDateTime       = DbHelperSQL.GetTableFieldDateTime("AISPICK_UPD_DATE", "M_CONTOROL", " [KEY-ID]='01'");
                                        parameters3[0].Value = tmpnewDateTime;
                                        logger.DebugFormat("**************{0},{1} change to new value:{2}.", td[0], td[1], tmpnewDateTime);
                                    }

                                    //pre update number
                                    tmpTableTakeDataNum = AutoUpdateData._iniToday.IniReadValue("TableTakeDataNum", td[0].Trim());

                                    if (!int.TryParse(tmpTableTakeDataNum, out preNum))
                                    {
                                        preNum = 0;
                                    }

                                    allCount = OracleDal.GetCount(_tmpOracleDBname, td[0].Trim(), tmpwhere, parameters3);
                                    logger.DebugFormat("*********Table: {0},已上传:{1} ,Oracle 现在有数据:{2}.当日:{3}", td[0], preNum, allCount, DateTime.Now.ToString("yyyyMMdd"));

                                    if (preNum >= allCount)
                                    {
                                        logger.DebugFormat("*********(已上传数) {0} >= {1} (Oracle 现在有数据),无需更新.", preNum, allCount);
                                    }
                                    else
                                    {
                                        var tmptoUpdate = (allCount - preNum);
                                        logger.DebugFormat("*********需更新数:{0}.", tmptoUpdate);
                                        var tmporderby = td[2].Trim();
                                        if (td[2].Trim().ToLower().Equals("no"))
                                        {
                                            tmporderby = "";
                                        }
                                        tmpds = OracleDal.GetData(_tmpOracleDBname, td[0].Trim(), tmpwhere, tmporderby, preNum, tmptoUpdate, parameters3);
                                    }

                                    tmpds.DataSetName = td[0].Trim();
                                    _typeOfTable      = td[3].Trim();
                                    _time_done        = OracleDal.getMaxCol(tmpds, td[1]).ToString();

                                    #region new update 2015-12-02
                                    if (tmpds.Tables.Count > 0 && td[0].Trim().ToUpper().Equals("N_AIS_SHOP_LIST_PICKED_ACT_TAB".ToUpper()))
                                    {
                                        logger.DebugFormat("*******开始更新{0}的相关表[M_PARTS_STOCK,M_LINE_PARTS_STOCK]", td[0].Trim());
                                        //AIS配膳リストピッキング実績-> AIS配膳リストピッキング実績
                                        tblPicked = tmpds.Tables[0];    // bssLineStock.GetPickedActData();
                                        //更新ライン在庫マス数据
                                        if (bssLineStock.SetLinePartsStockData(tblPicked) <= 0)
                                        {
                                            //TODO: 更新失败
                                            logger.ErrorFormat("******* {0} 的相关表[M_PARTS_STOCK,M_LINE_PARTS_STOCK] 更新失败", td[0].Trim());
                                        }
                                        else
                                        {
                                            logger.DebugFormat("******* {0} 的相关表[M_PARTS_STOCK,M_LINE_PARTS_STOCK] 更新Success", td[0].Trim());

                                            var tmpExist = DbHelperSQL.GetCount("M_CONTOROL", "[KEY-ID]='01'");
                                            var tmpsql   = "";
                                            if (tmpExist > 0)
                                            {
                                                tmpsql = string.Format("UPDATE M_CONTOROL set [AISPICK_UPD_DATE]='{0}' where [KEY-ID]='01'", _time_done);
                                            }
                                            else
                                            {
                                                tmpsql = string.Format("INSERT INTO M_CONTOROL([KEY-ID],[AISPICK_UPD_DATE])  VALUES('{0}','{1}')", "01", _time_done);
                                            }

                                            var tmpdd = DbHelperSQL.ExecuteSql(tmpsql);

                                            if (tmpdd > 0)
                                            {
                                                logger.DebugFormat("*******Success M_CONTOROL 更新时间 AISPICK_UPD_DATE success", td[0].Trim());
                                            }
                                            else
                                            {
                                                logger.DebugFormat("*******Error M_CONTOROL 更新时间 AISPICK_UPD_DATE Error", td[0].Trim());
                                            }
                                        }
                                    }


                                    #endregion

                                    break;

                                case 4:
                                    //key: P 0|where 1| order by 2 | C 3 | type 4
                                    //get P:父,C: 子 根据P的Key得到C.的数据。
                                    //get the last ID

                                    // set tmpwhere
                                    tmpwhere += " and " + td[1] + ">=to_date(:gxsj,'yyyy-MM-dd HH24:mi:ss')";
                                    OracleParameter[] parameters4 = { new OracleParameter(":gxsj", OracleDbType.Varchar2, 10) };

                                    //set time
                                    parameters4[0].Value = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";    // HH


                                    logger.DebugFormat("****TESTFKG:{0},ORG_START_DATE:{1}   【0:の場合 PCの日付を抽出条件にする。1:の場合 環境ファイル内の日付(yyyy-mm-dd)を設定し、その日付を抽出条件にする】", AutoUpdateData._TESTFKG, AutoUpdateData._ORG_START_DATE);
                                    if (AutoUpdateData._TESTFKG.Equals("1"))
                                    {
                                        logger.DebugFormat("****使用配置文件中的日期。{0}", AutoUpdateData._ORG_START_DATE);
                                        parameters4[0].Value = AutoUpdateData._ORG_START_DATE + " 00:00:00";    // HH
                                    }
                                    var trytmpDD  = DateTime.Now;
                                    var chedkdate = DateTime.TryParse(parameters4[0].Value.ToString(), out trytmpDD);
                                    if (!chedkdate)
                                    {
                                        logger.DebugFormat("**配置文件提供ORG_START_DATE的值不符合要求(yyyy-MM-dd),value:{0}.则使用当天日期。", AutoUpdateData._ORG_START_DATE, DateTime.Now.ToString("yyyy-MM-dd"));
                                        logger.ErrorFormat("**配置文件提供ORG_START_DATE的值不符合要求(yyyy-MM-dd),value:{0}.则使用当天日期。", AutoUpdateData._ORG_START_DATE, DateTime.Now.ToString("yyyy-MM-dd"));
                                        parameters4[0].Value = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";    // HH
                                    }

                                    // parameters4[0].Value = tmpORG_START_DATE.ToString("yyyy-MM-dd") + " 00:00:00";// HH

                                    //pre update number
                                    tmpTableTakeDataNum = AutoUpdateData._iniToday.IniReadValue("TableTakeDataNum", td[0].Trim());

                                    if (!int.TryParse(tmpTableTakeDataNum, out preNum))
                                    {
                                        preNum = 0;
                                    }

                                    //get all count form oracle db

                                    allCount = OracleDal.GetCount(_tmpOracleDBname, td[0].Trim(), tmpwhere, parameters4);

                                    logger.DebugFormat("*********Table: {0},已上传:{1} ,Oracle 现在有数据:{2}.>=条件日期:{3}", td[0], preNum, allCount, trytmpDD.ToString("yyyy-MM-dd"));

                                    if (preNum >= allCount)
                                    {
                                        logger.DebugFormat("*********(已上传数) {0} >= {1} (Oracle 现在有数据),无需更新.", preNum, allCount);
                                    }
                                    else
                                    {
                                        var tmptoUpdate = (allCount - preNum);
                                        logger.DebugFormat("*********需更新数:{0}.", tmptoUpdate);
                                        var tmporderby = td[2].Trim();
                                        if (td[2].Trim().ToLower().Equals("no"))
                                        {
                                            tmporderby = "";
                                        }
                                        tmpds = OracleDal.GetData(_tmpOracleDBname, td[0].Trim(), tmpwhere, tmporderby, preNum, tmptoUpdate, parameters4);
                                    }

                                    tmpds.DataSetName = td[0].Trim();

                                    //to Get C
                                    if (!AutoUpdateData._tableKeyList.ContainsKey(tmpKeyname))
                                    {
                                        isSon = false;
                                        logger.DebugFormat("*************************表:{0} 没有设置主键,无法更新子表:{1}。", td[0], td[3]);
                                    }
                                    else
                                    {
                                        //var tmpkeyValue = AutoUpdateData._tableKeyList[tmpKeyname];
                                        //var tmpkeys = tmpkeyValue.Split(',');
                                        //logger.DebugFormat("*************************表:{0} 的主键:{1}。", td[0], tmpkeyValue);
                                        isSon = true;
                                    }
                                    tmpds.DataSetName = td[0].Trim();
                                    _typeOfTable      = td[4].Trim();
                                    _time_done        = OracleDal.getMaxCol(tmpds, td[1]).ToString();
                                    break;

                                default:

                                    tmpds.DataSetName = td[0].Trim();
                                    if (td[0].IndexOf('.') > 0)
                                    {
                                        tmpds.DataSetName = td[0].Trim().Split('.')[1];
                                    }
                                    break;
                                }
                                _sql += td[0].Trim() + " where " + tmpwhere;
                                //**************************同步表
                                OracleDal.StartToMSSQL(_is1, false, tmpds, tmpKeyLast);

                                //for father and son
                                if (isSon)
                                {
                                    var tmpallSonCount = 0;
                                    if (tmpds.Tables.Count > 0)
                                    {
                                        var tmpkeyValue = AutoUpdateData._tableKeyList[tmpKeyname];
                                        var tmpkeys     = tmpkeyValue.Split(',');
                                        if (tmpkeys.Count() <= 0)
                                        {
                                            logger.DebugFormat("*************************表:{0} 的主键 为空:{1}。", td[0], tmpkeyValue);
                                        }
                                        else
                                        {
                                            logger.DebugFormat("*************************表:{0} 的主键:{1}。", td[0], tmpkeyValue);
                                            logger.DebugFormat("*************************开始更新表:{0},子表:{1}。", td[0], td[3]);
                                            string sonTmpsonwhereAll = "";
                                            foreach (DataRow p in tmpds.Tables[0].Rows)
                                            {
                                                string sonTmpsonwhere = "";
                                                try
                                                {
                                                    var tmpsonwhere = "";

                                                    tmpsonwhere = "SELECT * FROM " + td[3].Trim() + " where ";

                                                    if (!string.IsNullOrEmpty(_tmpOracleDBname))
                                                    {
                                                        tmpsonwhere = "SELECT * FROM " + _tmpOracleDBname + "." + td[3].Trim() + " where ";
                                                    }
                                                    if (tmpkeys.Count() > 0)
                                                    {
                                                        if (tmpkeys.Count() == 1)
                                                        {
                                                            tmpsonwhere += tmpkeys[0] + "='" + p[tmpkeys[0]].ToString().Trim() + "'";
                                                        }
                                                        else
                                                        {
                                                            for (int i = 0; i < tmpkeys.Count(); i++)
                                                            {
                                                                if (i == 0)
                                                                {
                                                                    tmpsonwhere += tmpkeys[0] + "='" + p[tmpkeys[0]].ToString().Trim() + "'";
                                                                }
                                                                else
                                                                {
                                                                    tmpsonwhere += " and " + tmpkeys[i] + "='" + p[tmpkeys[i]].ToString().Trim() + "'";
                                                                }
                                                            }
                                                        }
                                                    }
                                                    //
                                                    sonTmpsonwhere     = tmpsonwhere;
                                                    sonTmpsonwhereAll += sonTmpsonwhere + "\n";
                                                    //get data
                                                    var tmpSon = OracleDal.Query(tmpsonwhere);

                                                    tmpSon.DataSetName = td[3].Trim();
                                                    //**************************同步子表
                                                    tmpallSonCount += OracleDal.StartToMSSQL(_is1, true, tmpSon, "");
                                                }
                                                catch (Exception ex)
                                                {
                                                    logger.ErrorFormat("****************************更新主表:{0},记录:{1}  -->的子表失败。{2}", td[0], (p[0].ToString() + "," + p[1].ToString() + "," + p[2].ToString()), ex.Message);
                                                    //OracleDal.ilog(td[3].Trim(), allCount, AutoUpdateData._CONTRACT + ",Fail," + AutoUpdateData._updatemode, "AutoUpdateOracleMSSQL: SQL:" + sonTmpsonwhere + " Fail. Error:" + ex.Message, AutoUpdateData._ipAddMac);

                                                    OracleDal.ilog("error", updateJob._typeOfTable, updateJob._time_start, updateJob._time_done, sonTmpsonwhere, allCount, AutoUpdateData._ipAddMac, AutoUpdateData._CONTRACT + "|" + AutoUpdateData._updatemode);

                                                    continue;
                                                }
                                            }
                                            //OracleDal.ilog(td[3].Trim(), tmpallSonCount, AutoUpdateData._CONTRACT + ",Success," + AutoUpdateData._updatemode, "AutoUpdateOracleMSSQL:Update Count:" + tmpallSonCount + " Success.", AutoUpdateData._ipAddMac);
                                            OracleDal.ilog("success", updateJob._typeOfTable, updateJob._time_start, updateJob._time_done, sonTmpsonwhereAll, tmpallSonCount, AutoUpdateData._ipAddMac, AutoUpdateData._CONTRACT + "|" + AutoUpdateData._updatemode);
                                        }
                                    }
                                    else
                                    {
                                        logger.DebugFormat("*************************表:{0} 的数据 为空。", td[0]);
                                    }
                                }
                            }
                            else
                            {
                                var tmpTableTakeDataNum = AutoUpdateData._iniToday.IniReadValue("TableTakeDataNum", item.Key.Trim());
                                int preNum = 0;
                                if (!int.TryParse(tmpTableTakeDataNum, out preNum))
                                {
                                    preNum = 0;
                                }

                                var allCount = OracleDal.GetCount(_tmpOracleDBname, item.Key, "");

                                logger.DebugFormat("*********Table: {0},已上传:{1} ,Oracle 现在有数据:{2}.", item.Key, preNum, allCount);

                                if (preNum >= allCount)
                                {
                                    logger.DebugFormat("*********(已上传数) {0} >= {1} (Oracle 现在有数据),无需更新.", preNum, allCount);
                                }
                                else
                                {
                                    var tmptoUpdate = (allCount - preNum);
                                    logger.DebugFormat("*********需更新数:{0}", tmptoUpdate);

                                    var tmpds = OracleDal.GetData(_tmpOracleDBname, item.Key, "", "", preNum, tmptoUpdate);
                                    tmpds.DataSetName = item.Key;

                                    OracleDal.StartToMSSQL(_is1, false, tmpds, "");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            AutoUpdateData.jobflag("Error:" + ex.Message);
                            logger.ErrorFormat("{0}表同步有问题,开始同步下个表。Error:{1}.", item.Key, ex.Message);
                            continue;
                        }
                    }
                }
                else
                {
                    logger.Error("no Table,Please check Set.ini,and add Table.");
                }
            }
            catch (Exception ex)
            {
                AutoUpdateData.jobflag("Error:" + ex.Message);
                logger.Error(ex);
            }
            finally
            {
                AutoUpdateData._isUploading = false;
            }
            AutoUpdateData.jobflag("Notice: Current Job is Run Over, Next Exec Job Time:" + context.NextFireTimeUtc.Value.DateTime);
        }
Ejemplo n.º 17
0
 /// <summary> 
 /// Execute the actual job. The job data map will already have been
 /// applied as object property values by execute. The contract is
 /// exactly the same as for the standard Quartz execute method.
 /// </summary>
 /// <seealso cref="Execute" />
 protected abstract void ExecuteInternal(JobExecutionContext context);
Ejemplo n.º 18
0
        public Task Execute(Quartz.IJobExecutionContext context)
        {
            //MailModel email = new MailModel();
            //email.Body = "tess";
            //// TODO ambil email to
            ////email.Recipient = emailto;
            //email.Recipient = "*****@*****.**";
            //email.RecipientList = null;
            //email.Subject = "Notifikasi Checklist User";
            //await _exchangeManagedService.SendMail(email, null, "");
            //using (var baseContext = new BaseContext())
            //{
            //    ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 360;
            //    string commandText = "[dbo].[GetALLCategory] ";
            //    var listModel = baseContext.Database.SqlQuery<CategoryVM>(commandText).ToListAsync();

            //}

            //_logger.Information(@"Oh Hai \o/");
            var           koneksi = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlConnection con     = new SqlConnection(koneksi);
            SqlCommand    command = new SqlCommand("GetEngineOverdue", con);

            command.CommandType = CommandType.StoredProcedure;
            con.Open();
            command.ExecuteNonQuery();
            SqlDataAdapter adp = new SqlDataAdapter(command);
            DataTable      dt  = new DataTable();

            DataSet ds = new DataSet();

            adp.Fill(ds);
            dt = ds.Tables[0];
            string a = string.Empty;
            string b = string.Empty;

            //using (MailMessage mail = new MailMessage())
            //{
            //    mail.From = new MailAddress("*****@*****.**");
            //    mail.To.Add("*****@*****.**");
            //    mail.Subject = a;
            //    mail.Body = b;//"<a href='http://lonsumimac'>tesssss</a>";//emailto.Body;
            //    mail.IsBodyHtml = true;

            //    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
            //    {
            //        smtp.Credentials = new NetworkCredential("*****@*****.**", "dian081193");
            //        smtp.EnableSsl = true;
            //        smtp.Send(mail);
            //    }
            //}
            var username = ConfigurationManager.AppSettings["Username"];
            var password = ConfigurationManager.AppSettings["Password"];
            var domain   = ConfigurationManager.AppSettings["Domain"];
            var email    = ConfigurationManager.AppSettings["Email"];

            this._exchangeService = new ExchangeService(ExchangeVersion.Exchange2013)
            {
                Credentials = new WebCredentials(username, password, domain)
            };

            _exchangeService.AutodiscoverUrl(email, RedirectionCallback);


            try
            {
                //var msgBody = new MessageBody
                //{
                //    BodyType = BodyType.HTML,
                //    Text = mailModel.Body
                //};
                foreach (DataRow rw in dt.Rows)
                {
                    var message = new EmailMessage(_exchangeService)
                    {
                        Subject = rw["Subject"].ToString(),
                        Body    = new MessageBody(BodyType.HTML, rw["Body"].ToString()),
                    };
                    message.ToRecipients.Add(rw["Email"].ToString());

                    Task.Run(() => {
                        message.SendAndSaveCopy();
                    });
                }

                //return true;
            }
            catch (Exception e)
            {
                throw e;
            }
            return(Task.CompletedTask);
        }
Ejemplo n.º 19
0
 ///<summary>
 /// Executes this job instance.
 ///</summary>
 ///<param name="jobExecutionContext"></param>
 public void Execute(JobExecutionContext jobExecutionContext)
 {
     count++;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 具体业务层的JOB
 /// 派生类实现这个方法,这类似于模版方法里的具体方法
 /// </summary>
 protected abstract void ExcuteJob(Quartz.IJobExecutionContext context);
Ejemplo n.º 21
0
 public async System.Threading.Tasks.Task Execute(Quartz.IJobExecutionContext context)
 {
     // await System.IO.File.AppendAllLinesAsync(@"c:\temp\job2.txt", new[] { System.DateTime.Now.ToLongTimeString() });
     System.Console.WriteLine("Job Two");
     await System.Threading.Tasks.Task.CompletedTask;
 }
Ejemplo n.º 22
0
 public void JobExecutionVetoed(JobExecutionContext context)
 {
 }
Ejemplo n.º 23
0
 /// <summary> 
 /// Execute the actual job. The job data map will already have been
 /// applied as object property values by execute. The contract is
 /// exactly the same as for the standard Quartz execute method.
 /// </summary>
 protected override void ExecuteInternal(JobExecutionContext jobExecutionContext)
 {
     count++;
 }
Ejemplo n.º 24
0
 public bool VetoJobExecution(Trigger trigger, JobExecutionContext context)
 {
     return false;
 }
Ejemplo n.º 25
0
 public void JobToBeExecuted(JobExecutionContext context)
 {
 }
Ejemplo n.º 26
0
 /// <summary> 
 /// Delegates execution to the underlying ThreadStart.
 /// </summary>
 public virtual void Execute(JobExecutionContext context)
 {
     delegateInstance.Invoke();
 }
Ejemplo n.º 27
0
 public void Execute(Quartz.IJobExecutionContext context)
 {
     //GenerarAPK();
 }
Ejemplo n.º 28
0
 public void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
 {
 }
Ejemplo n.º 29
0
 /// <summary>
 ///     执行
 /// </summary>
 /// <param name="context">上下文</param>
 /// <param name="scope">作用域</param>
 protected abstract Task Execute(Qz.IJobExecutionContext context, IScope scope);
Ejemplo n.º 30
0
 public void TriggerComplete(Trigger trigger, JobExecutionContext context,
     SchedulerInstruction triggerInstructionCode)
 {
 }
Ejemplo n.º 31
0
        public override void Execute(Quartz.IJobExecutionContext context)
        {
            gameEntity.makeCompleted();

            gameEntity.db.SaveChanges();
        }
Ejemplo n.º 32
0
 public void TriggerFired(Trigger trigger, JobExecutionContext context)
 {
 }