Advertisement
Squito

Mozgatás

Feb 7th, 2020
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.85 KB | None | 0 0
  1. if(File.Exists(sourceBonySemFile) && File.Exists(sourceBonyFile) && !File.Exists(destinationBonyFile) && !File.Exists(destinationBonySemFile))
  2.                     {
  3.                         FileStream lockSemFile = null;
  4.                         FileStream lockLabFile = null;
  5.                         DateTime now = DateTime.Now;
  6.                         try
  7.                         {
  8.                             lockSemFile = new FileStream(sourceBonySemFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Delete);
  9.                         }
  10.                         catch(Exception locksem)
  11.                         {
  12.                             string lockerrormsg = now.Hour + ":" + now.Minute + " - Sem fájl lockolása sikertelen - Hiba: " + locksem.ToString() + Environment.NewLine;
  13.                             logger.AppendText(lockerrormsg);
  14.                         }
  15.                         finally
  16.                         {
  17.                             try
  18.                             {
  19.                                 lockLabFile = new FileStream(sourceBonySemFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Delete);
  20.                             }
  21.                             catch(Exception locklab)
  22.                             {
  23.                                 string lockerrormsg = now.Hour + ":" + now.Minute + " - Lab fájl lockolása sikertelen - Hiba: " + locklab.ToString() + Environment.NewLine;
  24.                                 logger.AppendText(lockerrormsg);
  25.                                
  26.                             }
  27.                             finally
  28.                             {
  29.                                 try
  30.                                 {
  31.                                     File.Move(sourceBonyFile, destinationBonyFile);
  32.                                 }
  33.                                 catch(Exception labmoveex)
  34.                                 {
  35.                                     string lockerrormsg = now.Hour + ":" + now.Minute.ToString().PadLeft(2, '0') + " - Lab fájl mozgatása sikertelen - Hiba: " + labmoveex.ToString() + Environment.NewLine;
  36.                                     logger.AppendText(lockerrormsg);
  37.                                 }
  38.                                 finally
  39.                                 {
  40.                                     string successmsg = now.Hour + ":" + now.Minute + " -  A labor kérő fájl mozgatása sikeres." + Environment.NewLine;
  41.                                     logger.AppendText(successmsg);
  42.                                 }
  43.                                 try
  44.                                 {
  45.                                     File.Move(sourceBonySemFile, destinationBonySemFile);
  46.                                 }
  47.                                 catch (Exception labsemmoveex)
  48.                                 {
  49.                                     string movesemerrormsg = now.Hour + ":" + now.Minute.ToString().PadLeft(2, '0') + " - Lab fájl mozgatása sikertelen - Hiba: " + labsemmoveex.ToString() + Environment.NewLine;
  50.                                     logger.AppendText(movesemerrormsg);
  51.                                 }
  52.                                 finally
  53.                                 {
  54.                                     string successsemmsg = now.Hour + ":" + now.Minute + " -  A labor kérő semafor fájl mozgatása sikeres." + Environment.NewLine;
  55.                                     logger.AppendText(successsemmsg);
  56.                                 }
  57.                             }
  58.                         }
  59.                         if(lockSemFile!=null)
  60.                         {
  61.                             lockSemFile.Dispose();
  62.                         }
  63.                         if(lockLabFile!=null)
  64.                         {
  65.                             lockLabFile.Dispose();
  66.                         }
  67.                     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement