Click here to Skip to main content
15,897,090 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
for e.g i want to store website url address in array Website URLs will be stored in the hard coded array.

For example A[1] = “www.msn.com”;
A[2]= www.gmail.com; .. .. Etc..

This program is always running and waiting for certain condition ( in this case a time) to occur,

for example when the time is 6.00 AM the program hits all the websites listed in the array and fetch the HTTP content ( the final HTML output) in a output.html file.

For example if www.msn.com returns the following HTTP content
<html> <body> This is Msn.com </body> </html>

and www.hotmail.com returns the following HTTP content
<html> <body> This is hotmail.com </body> </html>

If these are the only two website ( in the array) than the final output in form of output.html would be :
<html> <body> This is Msn.com </body>
</html> <html> <body> This is hotmail.com </body> </html>

In a first phase it will be just a simple C# application.

What would be configurable via app.config or equivalent ? ·

The time ( 6.00 AM) in hour : minute : AM/PM format, which shows when it should generate that file. The file name of the generated file · The folder where it should save the file.

Condition : I will NOT re-start the application. The changes to the app.config are immediate.
Posted
Comments
José Amílcar Casimiro 20-May-14 5:52am    
You have your requirements, what are your difficulties?
Member 10820750 20-May-14 10:12am    
My Aim Is to code a program that on a particular time for eg 6:00 Am fetches the entire list of websites from an hard coded array like a[0]="www.msm.com"; a[1]="www.fb.com"; ...... and so on and then stores the HTML output of particluar website in a particular file like for eg msm.html,fb.html........ and so on and then finally after this procedure ends combine each website outputed html file into single html file for eg output.html


Need For Coding :

1) This program is always running and waiting for certain condition ( in this case a time) to occur, for example when the time is 6.00 AM the program hits all the websites listed in the array and fetch the HTTP content ( the final HTML output) in a output.html file.

2)What would be configurable via app.config or equivalent ?
· i) The time ( 6.00 AM) in hour : minute : AM/PM format, which shows when it should generate that file.
ii) The file name of the generated file ·
iii) The folder where it should save the file.

Condition : I do NOT re-start the application. The changes to the app.config are immediate.


3)Use timer based thread or timer control.

One timer control ( times out at every 10 seconds ) reads the app.config file at every 10 seconds.

In app.config all the settings are stored including the settings of 2nd timer control.

2nd timer control has the start time and when to expire. And his settings are stored in app.config.

10 second timer control readjusts the 2nd timer control.

Upon 2nd timer control timeout it does the main work ( http aggregation ).
Stephen Hewison 20-May-14 6:07am    
You haven't actually described your problem.
Member 10820750 20-May-14 10:12am    
My Aim Is to code a program that on a particular time for eg 6:00 Am fetches the entire list of websites from an hard coded array like a[0]="www.msm.com"; a[1]="www.fb.com"; ...... and so on and then stores the HTML output of particluar website in a particular file like for eg msm.html,fb.html........ and so on and then finally after this procedure ends combine each website outputed html file into single html file for eg output.html


Need For Coding :

1) This program is always running and waiting for certain condition ( in this case a time) to occur, for example when the time is 6.00 AM the program hits all the websites listed in the array and fetch the HTTP content ( the final HTML output) in a output.html file.

2)What would be configurable via app.config or equivalent ?
· i) The time ( 6.00 AM) in hour : minute : AM/PM format, which shows when it should generate that file.
ii) The file name of the generated file ·
iii) The folder where it should save the file.

Condition : I do NOT re-start the application. The changes to the app.config are immediate.


3)Use timer based thread or timer control.

One timer control ( times out at every 10 seconds ) reads the app.config file at every 10 seconds.

In app.config all the settings are stored including the settings of 2nd timer control.

2nd timer control has the start time and when to expire. And his settings are stored in app.config.

10 second timer control readjusts the 2nd timer control.

Upon 2nd timer control timeout it does the main work ( http aggregation ).
Member 10820750 20-May-14 8:13am    
Well Sir the difficulties are that :

1) Use timer based thread or timer control.

One timer control ( times out at every 10 seconds ) reads the app.config file at every 10 seconds.So how can i do that? any code examples would help me a lot.

In app.config all the settings are stored including the settings of 2nd timer control.

2nd timer control has the start time and when to expire. And its settings are stored in app.config.

1st 10 second timer control readjusts the 2nd timer control.

Upon 2nd timer control timeout it does the main work ( http aggregation ).

This is a typical console application and not a web based application ..

so any example codes or ideas???

1 solution

Hi, its much clearer now.

Here is globaly how you can achive your goal :

I) Running an app at a specific time.
-the best solution : use windows tasks. windows allow you to run a specific software at a specific time (daily weekly or monthly).
=> So you will no longer have to worry about your app running at a specifc time each day.

-For the file location, you will probably specife your location in the code.
specifiying the location in the app.config is possible (i guess), but i don't now how to do it.

II) General Idea to capture webPages html code.
I am working a lot with this kind of apps. you have 2 solutions. either use WebBrowser or httpwebRequets.
the easiest is the later. httpwebRequest allow you te get the html code of a page synchronously. its perfect to start with this technique.

Here is a sample to get an url html code:

C#
public string CapturePage(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Accept = "*/*";

            request.AllowAutoRedirect = true;
            request.Timeout = 60000;
            request.UserAgent = "http_requester/0.1";
            request.Method = "GET";
            request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

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

            StreamReader sr = new StreamReader(response.GetResponseStream());
            ///copier les donnees du stream dans une variable
            string sourceCode = sr.ReadToEnd();            
            
            sr.Close();
            response.Close();

            return sourceCode;

        }

I don't think you will have to use threads for now. In the other hand, its much better to develop the app as console application, so it automatically close when the task is finished.


III) timers:
Timers don't have anything to do with threads. the idea is to instanciate one or many timers.
once the timer reach its cooldown time, an event is raised.

here is a link to understand the logic: (MSDN)
http://msdn.microsoft.com/fr-fr/library/system.timers.timer(v=vs.110).aspx[^]

Pretty Easy :) no thread needed

Don't hesitate to ask more questions.

Hope it helps.
 
Share this answer
 
Comments
Member 10820750 3-Jun-14 4:36am    
I tried the below code but actually the timer expires before the execution of the method so how can i use the timer to call the method every 10 seconds after it has executed
Member 10820750 3-Jun-14 4:38am    
using System;
using System.Threading;
using System.Configuration;
//using System.Threading;
using System.Net;
using System.IO;
using System.Text;
using System.Timers;

namespace agile.getdiyvabhaskar
{
class ApplicationSettings
{
//public static const int FileScanSettings=ConfigurationSettings.AppSettings["FileTimer"];

System.Timers.Timer FileScanSettingsTimer = new System.Timers.Timer();


public void ReadAppSettings()
{
FileScanSettingsTimer.Enabled = true;
FileScanSettingsTimer.Interval = Convert.ToDouble(ConfigurationManager.AppSettings["FileTimer"]);
FileScanSettingsTimer.Elapsed += new System.Timers.ElapsedEventHandler(FileScanSettingsTimer_Elapsed);
FileScanSettingsTimer.Start();
FileScanSettingsTimer.Dispose();

}
public void FileScanSettingsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (FileScanSettingsTimer.Enabled)
{
FileScanSettingsTimer.Enabled = false;
Thread one = new Thread(getdiyvabhaskar.HttpAggregation.HttpAggreator);

FileScanSettingsTimer.Enabled = true;
}
}

static void Main()
{
ApplicationSettings aps = new ApplicationSettings();
Thread two = new Thread(aps.ReadAppSettings);
two.Start();
two.Join();
Thread.Sleep(10000);
}


}

class HttpAggregation
{
/*public static const double timeToRun = Convert.ToDouble(ConfigurationManager.AppSettings["FileTimer"]);
public static const string WebSiteAddress = ConfigurationManager.AppSettings["WebSiteAddress"];
public static const string FilePath = ConfigurationManager.AppSettings["FilePath"];
public static const string[] WebSiteAddress_Array = WebSiteAddress.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
*/

public static void HttpAggreator()
{
StringBuilder sb = new StringBuilder();
string FilePath = ConfigurationManager.AppSettings["FilePath"];
string WebSiteAddress = ConfigurationManager.AppSettings["WebsiteAddress"];
string[] WebSiteAddress_Array = WebSiteAddress.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string geturl in WebSiteAddress_Array)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(geturl);
request.AllowAutoRedirect = true;
request.Timeout = 60000;
request.UserAgent = "http_requester/0.1";
request.Method = "GET";
request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

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

StreamReader sr = new StreamReader(response.GetResponseStream());

string sourceCode = sr.ReadToEnd();

sb.AppendLine("***********************Website Reading Stars Here*******************************");
sb.Append(sourceCode);
sb.AppendLine();
sb.AppendLine();
sb.AppendLine("***********************Website Reading Ends Here********************************");

using (StreamWriter outfile = new StreamWriter(FilePath))
{
outfile.Write(sb.ToString());
}
}
}
}


}
Member 10820750 3-Jun-14 4:38am    
I'have tried all the means but failed to execute it need help!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900