private string GetInputFolderPath() { string inputFolderPath = ""; if (ConfigurationManager.AppSettings.Get("InputFolder") == "") { inputFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"\FolderWatcherService\Input"); MyLogger.Log.Info($"Path to folder Input not set in App.config, path to Input folder {inputFolderPath}"); } else { inputFolderPath = ConfigurationManager.AppSettings.Get("InputFolder"); DirectoryCheckerTest.CreateDirectoryIfNotExist(inputFolderPath); } return(inputFolderPath); }
public static void FileToGarbage(string fileFullPath, string fileName) { MyLogger.Log.Info($"Sending file {fileName} to Grabage folder"); string garbageFolderPath = ""; if (ConfigurationManager.AppSettings.Get("GarbageFolder") == "") { garbageFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"\FolderWatcherService\Garbage"); MyLogger.Log.Info($"Path to folder Garbage not set in App.config, path to Garbage folder {garbageFolderPath}"); } else { garbageFolderPath = ConfigurationManager.AppSettings.Get("GarbageFolder"); } DirectoryCheckerTest.CreateDirectoryIfNotExist(garbageFolderPath); MoveFile(fileFullPath, garbageFolderPath, fileName); }
/// <summary> /// записывает последние чеки в файл. Сделал для наглядности /// </summary> private void WriteCheques(Cheque[] cheques) { string writePath; if (ConfigurationManager.AppSettings.Get("SavedChequesFolder") == "") { writePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"\SavedCheqes\LastCheqes.txt"); MyLogger.Log.Info($"Path to folder SavedCheqes not set in App.config, path to SavedCheqes folder {writePath}"); } else { writePath = Path.Combine(ConfigurationManager.AppSettings.Get("SavedChequesFolder"), @"LastCheques.txt"); } foreach (var e in cheques) { try { DirectoryCheckerTest.CreateDirectoryIfNotExist(ConfigurationManager.AppSettings.Get("SavedChequesFolder")); using (StreamWriter streamWriter = new StreamWriter(writePath, true, System.Text.Encoding.Default)) { StringBuilder articles = new StringBuilder(); foreach (var val in e.Articles) { articles.Append(val + ';'); } streamWriter.WriteLine($"Id = {e.Id}, Number = {e.Number}, Simm = {e.Summ}, Descount = {e.Discount}, Articles = {articles}"); MyLogger.Log.Info($"Cheque added to file {writePath}"); } } catch (IOException ex) { MyLogger.Log.Error($"Cant write cheques collecttion, {ex}"); } catch (Exception ex) { MyLogger.Log.Error($"Cant write cheques collecttion, {ex}"); } } AddDelimetr(writePath); MyLogger.Log.Info($"Cheques pack added to file {writePath}"); }