示例#1
0
        public IList <TxtFileSetting> CreateOpenedFilesSetting()
        {
            var result = new List <TxtFileSetting>();

            foreach (var edt in Editors)
            {
                if (string.IsNullOrEmpty(edt.File.Text))
                {
                    continue;
                }

                var setting = new TxtFileSetting {
                    Name              = edt.Title,
                    BackColor         = ColorTranslator.ToWin32(edt.BackColor),
                    CurrentLine       = edt.CurrentLineIndex,
                    FilePath          = edt.File.Path,
                    FontName          = edt.Font.Name,
                    FontSize          = edt.Font.Size,
                    ForeColor         = ColorTranslator.ToWin32(edt.ForeColor),
                    IsRtl             = edt.Rtl,
                    Saved             = edt.File.SavedToHard,
                    HasPendingChanges = edt.File.Changed
                };
                if (edt.File.Changed)
                {
                    setting.TempFilePath = $"{_directory}\\{Guid.NewGuid()}.ats";
                    TxtProcessor.WriteToFile(setting.TempFilePath, edt.Text);
                }
                result.Add(setting);
            }

            return(result);
        }
        public void TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile()
        {
            TxtProcessor txtProcessor = new TxtProcessor();
            string       testFile     = Path.Combine
                                        (
                Directory.GetCurrentDirectory(),
                @"TestFiles\TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile\TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile.txt"
                                        );

            tempFile = Path.Combine
                       (
                Directory.GetCurrentDirectory(),
                @"TestFiles\TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile\Expected_TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile_Temp.txt"
                       );
            string expectedFile = Path.Combine
                                  (
                Directory.GetCurrentDirectory(),
                @"TestFiles\TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile\Expected_TxtProcessor_ProcessFile_TxtFile_SuccessedProcessedFile.txt"
                                  );

            File.Copy(testFile, tempFile, true);
            txtProcessor.ProcessFile(tempFile);

            var tempFileBytes     = File.ReadAllBytes(tempFile);
            var expectedFileBytes = File.ReadAllBytes(expectedFile);

            Assert.AreEqual(expectedFileBytes, tempFileBytes);
        }
示例#3
0
文件: TxtEditor.cs 项目: imaun/farcin
 public TxtEditor(TabPage tabPage,
                  int index,
                  string filePath,
                  int lastEditorsCount = 0)
 {
     initialize(tabPage, index, lastEditorsCount);
     File = TxtProcessor.ReadFile(filePath);
 }
示例#4
0
 public void Run(TxtEditor editor)
 {
     if (!editor.File.SavedToHard)
     {
         var record = new AutoSaveRecord {
             CreateDate    = DateTime.Now,
             FileName      = editor.File.Name,
             FilePath      = editor.File.Path,
             SavedFileName = $"{_directory}\\{Guid.NewGuid()}.ats"
         };
         TxtProcessor.WriteToFile(
             record.SavedFileName,
             editor.File.Text);
     }
 }
示例#5
0
 public void Run(IEnumerable <TxtEditor> editors)
 {
     Records = new List <AutoSaveRecord>();
     foreach (var edt in editors)
     {
         if (edt.AutoSave && edt.File.SavedToHard)
         {
             TxtProcessor.WriteToFile(edt.File.Path, edt.File.Text);
             continue;
         }
         else if (edt.AutoSave && !edt.File.SavedToHard)
         {
             var record = new AutoSaveRecord {
                 CreateDate    = DateTime.Now,
                 FileName      = edt.File.Name,
                 FilePath      = edt.File.Path,
                 SavedFileName = $"{_directory}\\{Guid.NewGuid()}.ats"
             };
             TxtProcessor.WriteToFile(record.SavedFileName, edt.File.Text);
             Records.Add(record);
         }
     }
 }