Exemple #1
0
 private static async Task WCF_Loop()
 {
     while (true)
     {
         DirectoryInfo d = new DirectoryInfo(path);
         if (d.Exists)
         {
             FileInfo[] files = d.GetFiles("*." + file_extension);
             foreach (FileInfo file_info in files)
             {
                 List <String> queries = new List <string>();
                 StreamReader  sr      = new StreamReader(file_info.FullName);
                 lock (sr)
                 {
                     while (!sr.EndOfStream)
                     {
                         queries.Add(sr.ReadLine());
                     }
                 }
                 sr.Close();
                 WCFPimpMyUnicorn.Service1Client serviceClient = new WCFPimpMyUnicorn.Service1Client();
                 bool success = serviceClient.UpdateDatabase(queries.ToArray());
                 if (success)
                 {
                     file_info.Delete();
                 }
             }
         }
         await Task.Delay(timer * 1000);
     }
 }
Exemple #2
0
        private static void Fsw_Changed(object sender, FileSystemEventArgs e)
        {
            string path = e.FullPath;

            try
            {
                StreamReader sr = new StreamReader(path, Encoding.Default);

                List <string> contenu = new List <string>();
                while (!sr.EndOfStream)
                {
                    contenu.Add(sr.ReadLine());
                }
                sr.Close();

                WCFPimpMyUnicorn.Service1Client serviceClient = new WCFPimpMyUnicorn.Service1Client();
                bool success = serviceClient.UpdateDatabase(contenu.ToArray());

                if (success)
                {
                    File.Delete(path);
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }