Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. private void CreateDemoFile(int fileType)
  2. {
  3. var _assembly = Assembly.GetExecutingAssembly();
  4. CCriticalSection fileLock = new CCriticalSection();
  5.  
  6. try
  7. {
  8. switch (fileType)
  9. {
  10. case 1:
  11. myResource = "CommercialClients.json";
  12. break;
  13. case 2:
  14. myResource = "ResidentialClients.json";
  15. break;
  16. }
  17. using (Stream stream = _assembly.GetManifestResourceStream(myResource))
  18. using (StreamReader reader = new StreamReader(stream))
  19. {
  20. string fileString = reader.ReadToEnd();
  21. }
  22. fileLock.Enter();
  23. if (!File.Exists(FilePath))
  24. {
  25. using (FileStream fs = File.Create(FilePath))
  26. {
  27. fs.Write(fileString, Encoding.UTF8);
  28. GlobalDebugger.DebugPrint(this.ProcessorID, String.Format("File {0} has been created with Demo Data", FilePath));
  29. localFileHash = generateHash(readJson());
  30. }
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. GlobalDebugger.DebugPrint(this.ProcessorID, "Exception Occurred in FileProcessor.CreateFile : " + ex.Message);
  36. ErrorLog.Exception("Exception Occurred in FileProcessor.CreateFile", ex);
  37. }
  38. finally
  39. {
  40. fileLock.Leave();
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement