Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Quartz.NET在执行过程中跳过步骤_C#_Quartz Scheduler_Quartz.net - Fatal编程技术网

C# Quartz.NET在执行过程中跳过步骤

C# Quartz.NET在执行过程中跳过步骤,c#,quartz-scheduler,quartz.net,C#,Quartz Scheduler,Quartz.net,我需要你在QUARTZ.NET上的宝贵建议。我使用此计划在每10秒后运行我的函数。实际上,我的代码是从json文件中获取数据,并将其与数据库SQL server进行比较。如果id与数据库匹配,那么它将不做任何事情,否则它将推送产品。某段时间代码运行成功,我没有得到重复的条目。但有时它会在数据库中插入重复的值,并且只能跳过exist=(int)cmd.ExecuteScalar();请告诉我该怎么办。因为我不能将调度时间从10秒增加到10秒以上。以及如何避免遗漏其中的一行。下面是我的代码。这将对我

我需要你在QUARTZ.NET上的宝贵建议。我使用此计划在每10秒后运行我的函数。实际上,我的代码是从json文件中获取数据,并将其与数据库SQL server进行比较。如果id与数据库匹配,那么它将不做任何事情,否则它将推送产品。某段时间代码运行成功,我没有得到重复的条目。但有时它会在数据库中插入重复的值,并且只能跳过exist=(int)cmd.ExecuteScalar();请告诉我该怎么办。因为我不能将调度时间从10秒增加到10秒以上。以及如何避免遗漏其中的一行。下面是我的代码。这将对我大有帮助。。请帮忙。谢谢

IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
                scheduler.Start();
                // scheduler.ResumeAll();

                IJobDetail job = JobBuilder.Create<SampleJob>()
                               .WithIdentity("currencyJob", "group1")
                               .Build();

                //  IJobDetail job = JobBuilder.Create<SampleJob>().Build();
                ITrigger trigger = TriggerBuilder.Create()
                         .WithIdentity("trigger1", "group1")
                         .WithSimpleSchedule(s => s.WithIntervalInSeconds(15).RepeatForever())
                         .Build();

                //ITrigger trigger = TriggerBuilder.Create()
                //              .WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
                //              .Build();

                scheduler.ScheduleJob(job, trigger);
isScheduler scheduler=StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
//scheduler.ResumeAll();
IJobDetail job=JobBuilder.Create()
.WithIdentity(“currencyJob”、“group1”)
.Build();
//IJobDetail job=JobBuilder.Create().Build();
ITrigger trigger=TriggerBuilder.Create()
.WithIdentity(“触发器1”、“组1”)
.WithSimpleSchedule(s=>s.WithIntervalInSeconds(15).RepeatForever())
.Build();
//ITrigger trigger=TriggerBuilder.Create()
//.WithSimpleSchedule(x=>x.WithIntervalInSeconds(10).RepeatForever())
//.Build();
ScheduleJob(作业,触发器);
下面是Sample.cs

   public void Execute(IJobExecutionContext context)
        {


            tweetmonitor();
        }

        public void tweetmonitor()
        {
            ////////////////////////////////URLS And Proxy tables data get//////////////////////////////////
            List<UrlKeyword> employee = new List<UrlKeyword>();
            List<Proxy> proxy = new List<Proxy>();
            List<ProductsJsonModel> json = new List<ProductsJsonModel>();
            ProductsJsonModel json2 = new ProductsJsonModel();
            SqlConnection conn = new SqlConnection(strConnString);
            //SqlConnection conn = new SqlConnection(strConnString);

            SqlCommand customer = new SqlCommand("select * from customer", conn);
            SqlCommand cmdproxy = new SqlCommand("select * FROM ProxyTable", conn);

            customer.CommandType = CommandType.Text;
            try { 
            conn.Open();


            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlDataReader rdr = customer.ExecuteReader();

            while (rdr.Read())
            {

                UrlKeyword emp = new UrlKeyword();

                emp.url = rdr["ContactName"].ToString();
                emp.keywords = rdr["CompanyName"].ToString();

                employee.Add(emp);
            }
            rdr.Close();


            SqlDataReader rdrproxy = cmdproxy.ExecuteReader();

            while (rdrproxy.Read())
            {
                Proxy pr = new Proxy();

                pr.IP = rdrproxy["IP"].ToString();
                pr.Port = Convert.ToInt32(rdrproxy["Port"]);
                pr.UserName = rdrproxy["UserName"].ToString();
                pr.PassWord = rdrproxy["PassWord"].ToString();
                proxy.Add(pr);

            }
            rdrproxy.Close();

            }
            catch (Exception ex)
            {

            }
            ////////////////////////////////////////////////////////////////
            ///////////////////Checking from database/////////////////////////

            ///////////////////Checking from database/////////////////////////


            foreach (var x in employee)
            {

                foreach (var m in proxy)
                {


                    try
                    {
                        string url = x.url;
                        string keyword = x.keywords;
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(x.url);
                        WebProxy myproxy = new WebProxy(m.IP, m.Port);
                        if (m.UserName != null && m.PassWord != null && m.UserName != "" && m.PassWord != "")

                        {
                            myproxy.Credentials = new NetworkCredential(m.UserName, m.PassWord);
                        }
                        myproxy.BypassProxyOnLocal = false;

                        request.Proxy = myproxy;
                        request.Method = "GET";
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                        if (response != null)
                        {
                            Stream receiveStream = response.GetResponseStream();
                            StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
                            string mr = readStream.ReadToEnd();

                            /////////////////JSON Data///////////////////
                            if (x.url.Contains("json"))
                            {
                                //JSON files to twitter
                                try
                                {
                                    ProductsJsonModel Data = JsonConvert.DeserializeObject<ProductsJsonModel>(mr);
                                    List<Product> ProductsFromUrl = Data.products;
                                    int countofloop;
                                    countofloop = ProductsFromUrl.Count;

                                    SqlCommand cmd = new SqlCommand();
                                    SqlDataAdapter da = new SqlDataAdapter();
                                    SqlCommandBuilder cb = new SqlCommandBuilder(da);
                                    DataSet ds = new DataSet();

                                    if (conn.State != ConnectionState.Open)
                                    {
                                        conn.Open();
                                    }

                                    cmd.CommandText = "select IdJson from  dbo.JsonDataPrimary";
                                    cmd.Connection = conn;

                                    da.SelectCommand = cmd;

                                    da.Fill(ds, "JsonDataPrimary");

                                    for (int s = 0; s < countofloop; s++)
                                    {
                                        int exist = 0;
                                       // SqlCommand cmd = new SqlCommand();
                                        cmd.CommandText = @"SELECT count(*) FROM dbo.JsonDataPrimary WHERE IdJson= '" + ProductsFromUrl[s].id + "'";
                                        cmd.CommandType = System.Data.CommandType.Text;
                                        cmd.Connection = conn;
                                        exist = (int)cmd.ExecuteScalar();

                                        //////////////////////////duplicate check////////////////////////////////////


                                        //////////////////////////////////////////////////////

                                        //   if (exist > 0)
                                        if (checkDuplicateTitle(ds.Tables["JsonDataPrimary"].Rows, ProductsFromUrl[s].id.ToString()) && exist > 0)
                                        {
                                            ///exit from here
                                        }
                                        else
                                        {

                                            string logstweetout = published_at + Environment.NewLine + product_title + Environment.NewLine + newurlimage;

                                            string logsdata = published_at + Environment.NewLine + product_title + Environment.NewLine + newurlimage + Environment.NewLine + "Variants(According to size)" + Environment.NewLine + variantscheck + Environment.NewLine;
                                               cmd.CommandText = @"INSERT INTO dbo.JsonDataPrimary VALUES('" + ProductsFromUrl[s].id + "','" + ProductsFromUrl[s].published_at + "','','' ,'" + test + "')";
                                            cmd.CommandType = System.Data.CommandType.Text;
                                        if (conn.State != ConnectionState.Open)
                                        {
                                            conn.Open();
                                        }
                                        cmd.Connection = conn;



                                        }

                                        cmd.ExecuteNonQuery();

                                    }

                                }
                                catch (Exception ex)
                                {

                                }
                                conn.Close();
                            }
public void执行(IJobExecutionContext上下文)
{
tweetmonitor();
}
公共无效tweetmonitor()
{
////////////////////////////////URL和代理表数据获取//////////////////////////////////
List employee=新列表();
列表代理=新列表();
List json=new List();
ProductsJsonModel json2=新产品sJSONModel();
SqlConnection conn=新的SqlConnection(strConnString);
//SqlConnection conn=新的SqlConnection(strConnString);
SqlCommand customer=新的SqlCommand(“从客户中选择*”,conn);
SqlCommand cmdproxy=新SqlCommand(“从ProxyTable中选择*”,conn);
customer.CommandType=CommandType.Text;
试试{
conn.Open();
如果(连接状态!=连接状态打开)
{
conn.Open();
}
SqlDataReader rdr=customer.ExecuteReader();
while(rdr.Read())
{
UrlKeyword emp=新的UrlKeyword();
emp.url=rdr[“ContactName”].ToString();
emp.keywords=rdr[“CompanyName”].ToString();
employee.Add(emp);
}
rdr.Close();
SqlDataReader rdrproxy=cmdproxy.ExecuteReader();
while(rdrproxy.Read())
{
Proxy pr=新代理();
pr.IP=rdrproxy[“IP”].ToString();
pr.Port=Convert.ToInt32(rdrproxy[“端口]);
pr.UserName=rdrproxy[“UserName”].ToString();
pr.PassWord=rdrproxy[“PassWord”].ToString();
代理添加(pr);
}
rdrproxy.Close();
}
捕获(例外情况除外)
{
}
////////////////////////////////////////////////////////////////
///////////////////从数据库检查/////////////////////////
///////////////////从数据库检查/////////////////////////
foreach(员工中的风险值x)
{
foreach(代理中的var m)
{
尝试
{
字符串url=x.url;
字符串关键字=x.keywords;
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(x.url);
WebProxy myproxy=新的WebProxy(m.IP,m.Port);
如果(m.UserName!=null&&m.PassWord!=null&&m.UserName!=“”&&m.PassWord!=“”)
{
myproxy.Credentials=新的网络凭据(m.UserName,m.PassWord);
}
myproxy.BypassProxyOnLocal=false;
Proxy=myproxy;
request.Method=“GET”;
HttpWebResponse=(HttpWebResponse)request.GetResponse();
if(响应!=null)
{
Stream receiveStream=response.GetResponseStream();
StreamReader readStream=新的StreamReader(receiveStream,Encoding.UTF8);
字符串mr=readStream.ReadToEnd();
/////////////////JSON数据///////////////////
if(x.url.Contains(“json”))
{
//将JSON文件发送到twitter
尝试
{
ProductsJsonModel Data=JsonConvert.DeserializeObject(mr);
列出ProductsFromUrl=Data.products;
整数计数;
countofloop=ProductsFromUrl.Count;
SqlCommand cmd=新的SqlCommand();
SqlDataAdapter da=新的SqlDataAdapter();
SqlCommandBuilder cb=新的SqlCommandBuilder(da);
数据集ds=新数据集();
如果(连接状态!=连接状态打开)
{