Msaada: Programming Issue

Software Engineer

JF-Expert Member
Dec 20, 2014
344
137
Natumia FileSystemWatcher kwenye asp.net web application ku monitor changes zote zinazotokea kwenye folder "c:\MyDir".

Implementation
1. Nime create class MonitorDirectory ,
  • ina static method RegisterMonitor() method, ndani nime instantiate FileSystemWatcher object, kisha ni register events kama vile OnCreated(object sender, FileSystemEventArgs e)
2. Kwenye Application_Start() nime call MonitorDirectory.RegisterMonitor();

Outcome
1. Nimefanya test kupitia IDE (Visual studio) test server, behavior zote zimekuwa triggered vizuri. Naweza ku paste file na event (OnCreated) ikawa fired vizuri tuu. Development enevironment ni Windows 7 Pro.

2. Nimeweka kwenye production server (Windows 2008 R2 Enterprise) imefail ku trigger event zozote zile.

Karibu wadau tu share experience.
 
Natumia FileSystemWatcher kwenye asp.net web application ku monitor changes zote zinazotokea kwenye folder "c:\MyDir".

Implementation
1. Nime create class MonitorDirectory ,
  • ina static method RegisterMonitor() method, ndani nime instantiate FileSystemWatcher object, kisha ni register events kama vile OnCreated(object sender, FileSystemEventArgs e)
2. Kwenye Application_Start() nime call MonitorDirectory.RegisterMonitor();

Outcome
1. Nimefanya test kupitia IDE (Visual studio) test server, behavior zote zimekuwa triggered vizuri. Naweza ku paste file na event (OnCreated) ikawa fired vizuri tuu. Development enevironment ni Windows 7 Pro.

2. Nimeweka kwenye production server (Windows 2008 R2 Enterprise) imefail ku trigger event zozote zile.

Karibu wadau tu share experience.

hiyo FileSystemWatcher object ume instantiate ndani ya class au method?.. Je hiyo class inatumika kama singleton au?.. Na hiyo object umeideclare static au?
 
hebu tupia code ya hiyo class , tuione
public class DirectoryMonitor{
private static System.Object lockThis = new System.Object();

public static void RegisterWatchers()
{
if (!Directory.Exists(ConfigurationManager.AppSettings.Get("FtpMasterDirectory")) && !Directory.Exists(ConfigurationManager.AppSettings.Get("FtpSlaveDirectory")))
{
Console.WriteLine("Directories were not located check config paths");
}
else
{
var fsw = new FileSystemWatcher
{
//Filter = "*.zip",
Path = ConfigurationManager.AppSettings.Get("FtpMasterDirectory"),
EnableRaisingEvents = true,
IncludeSubdirectories = false
};

fsw.Created += new FileSystemEventHandler(OnCreated);
}
}

//
// invoked when a new file is created
static void OnCreated(object sender, FileSystemEventArgs e)
{
try {
// get file
var fileName = e.Name;
// start background task
// do ...
} catch (Exception ex) {
throw ex;
} finally
{

}
}

}
 
Kama inafanya kazi locally kutakuwa na configuration fulani inahatajika kwenye server, nakushauri Google/Stackoverflow.
 
Hapo muhimu kwanza ni kufanya elimination kwa kutumia comparison ya development na production environment.
Maana kwenye development imefaulu, ina maana tatizo lipo kwenye server, huna haja ya kubadilisha chochote kwenye code kabla hujafanya utafiti zaidi.
- Ijaribishe kwenye mazingira mengine, tumia tarakishi yoyote nyingine, aidha ofisini ama rafiki
- Ikigoma, then ina jaribu angalia dependency zozote unazofaa kuregister
- Ikifaulu kwenye computer nyingine, basi unaweza ukashushuku folder persmission kwenye hiyo server. Kawaida Windows servers huwa na kisirani sana unapothubutu kutumia folder ndani ya C:\
Hivyo jaribu folder nyingine nje ya root, labda kwenye partition ya pili
- Pia jaribu kuanzisha software yako kama administrator, right click and start as administrator ili iwe na rights za admin

Kwa kifupi, kuna mengi ya kujaribisha kabla hujagusa code yako.
 
Back
Top Bottom