Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.SessionState;
- using System.Threading;
- using System.Data.SqlClient;
- using System.Data;
- using FM.WebSync.Core;
- using System.IO;
- using System.Configuration;
- namespace DBPolling
- {
- public class Global : System.Web.HttpApplication
- {
- private bool Running;
- static string res;
- void Application_Start(object sender, EventArgs e)
- {
- // Code that runs on application startup
- Running = true;
- Thread t = new Thread(new ThreadStart(PublishLoop));
- t.IsBackground = true;
- t.Start();
- }
- void Application_End(object sender, EventArgs e)
- {
- // Code that runs on application shutdown
- Running = false;
- }
- void Application_Error(object sender, EventArgs e)
- {
- // Code that runs when an unhandled error occurs
- }
- void Session_Start(object sender, EventArgs e)
- {
- // Code that runs when a new session is started
- }
- void Session_End(object sender, EventArgs e)
- {
- // Code that runs when a session ends.
- // Note: The Session_End event is raised only when the sessionstate mode
- // is set to InProc in the Web.config file. If session mode is set to StateServer
- // or SQLServer, the event is not raised.
- }
- private void PublishLoop()
- {
- String prev=String.Copy("");
- String next=String.Copy("");
- String ConnectionString = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
- SqlConnection connection = new SqlConnection(ConnectionString);
- SqlCommand command = connection.CreateCommand();
- command.CommandText = "select ID from Tab1";
- command.Notification = null;
- while (Running)
- {
- connection.Open();
- using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
- {
- StreamWriter sw1 = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\next.txt");
- while ((reader.Read()))
- {
- //Response.Write(reader[0].ToString());
- next = String.Concat(next,reader[0].ToString());
- sw1.WriteLine(next);
- }
- sw1.Close();
- if (!prev.Equals(next))
- {
- Publisher publisher = new Publisher(new PublisherArgs
- {
- DomainKey = "c80cb405-eb77-4574-9405-5ba51832f5e6",
- DomainName="localhost"
- });
- Publication publication = publisher.Publish("/test", JSON.Serialize(next));
- if (publication.Successful == true)
- {
- StreamWriter sw = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\error123.txt");
- sw.WriteLine("success");
- sw.WriteLine(next);
- sw.Close();
- }
- else
- {
- StreamWriter sw = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\error123.txt");
- sw.Write("failed");
- sw.Close();
- }
- prev = String.Copy(next);
- next = String.Copy("");
- }
- }
- Thread.Sleep(5000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement