Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I am working on the webservices for the first time where i have to FTP the Files to a specific location. All the files are generated by another method in a single location x.The first 3 characters of the file is how we identify the file belonging to which client. Every client will have 2 files to be FTPied.

From this x location we have to get these files and also get the client specific details from the database like clientname,landingzone,ftpusername etc.,

Below is what i wrote. first i am getting all the clients from GetClientInformation method in a webservice then wrote a for loop in order to access the properties of the service.
then i am checking for the files present in the x location.

Here i have to wait for 10 hours and check every 10 mins if my required file is prsent or not.f the 2 files for the specific client are present then we will ftp the files.

Could some one please let me know what should be done next.

C#
        public bool Transmit()
        {
            try
            {
                strClientEncounterInfo = generateFile.GetClientInformation();
                foreach (var client in strClientEncounterInfo)
                {
                    strClientID=client.ClientEncounterId.ToString().Substring(0,3);
                    if (IsReportRequested == true)
                    {
                        var files = Directory.GetFiles(ConfigurationManager.AppSettings["ECG_LOCATION"], strClientID).Where(item => item.StartsWith(strClientID));
                        if (files.Count() == 2)
                        {
//FTP the files

                        }
                        else
                        {
isFilePresent(ConfigurationManager.AppSettings["ECG_LOCATION"], filename);
                        }

                    }
                }
            }
        }
        public bool isFilePresent(string path, string filename)
        {
            try
            {
                watcher = new FileSystemWatcher();
                watcher.Path = path;
                watcher.Filter = filename + "*.*";
                watcher.NotifyFilter = NotifyFilters.LastAccess |NotifyFilters.LastWrite |NotifyFilters.FileName |NotifyFilters.Size;
                watcher.Changed += new FileSystemEventHandler(OnChanged);
                watcher.Created += new FileSystemEventHandler(OnChanged);
                watcher.Deleted += new FileSystemEventHandler(OnChanged);
                //watcher.Renamed += new RenamedEventHandler(OnRenamed);
                watcher.EnableRaisingEvents = true;    
            }
            catch (Exception)
            {
                
                throw;
            }
            return true;
        }
        private static void OnChanged(object sender, FileSystemEventArgs e)
        {
            
        }
Posted

1 solution

Before thinking about next step, try to understand some basics of programming. Look at your exception handling:
C#
try
{
    //...
}
catch (Exception)
{
    throw;
}
This is obvious nonsense. Logically, this is equivalent of not handling exceptions at all (except wasting some extra resources). And this is what you really need to do. Exceptions should not be caught in every context. Just the opposite, they should be handled quite rarely, only in strategically chosen points (I call them "competence points") where you know how to handle them, and, usually, on a top stack frame of each thread, or, for UI, in special points of the main event loop. Exceptions are designed to be isolated from normal instruction flow. Re-throwing can be used in many cases, but only if the handler does something useful. Please see my past answer:
throw . .then ... rethrowing[^].

—SA
 
Share this answer
 
Comments
anupama962010 25-Mar-14 6:58am    
Hi,
I haven't yet complete writing the error handling part. I will keep in mind what you said when i am doing error handling. thanks
Sergey Alexandrovich Kryukov 25-Mar-14 11:33am    
Oh, I would understand that, but why would you write any try-catch here? If you don't care about exception at first at all, it's a good strategy, but it means that you should write no try-catch at all. You are catching too locally, already.
—SA

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