Esempio n. 1
0
        public FileAction AddRecord(FileContent currentFile, string visitorName, DateTime timeOfVisit)
        {
            //string[] lines = File.ReadAllLines(currentFile);
            List <AuditEntry> entries = Parse(currentFile.Content);

            if (entries.Count < _maxEntriesPerFile)
            {
                entries.Add(new AuditEntry(entries.Count + 1, visitorName, timeOfVisit));
                string[] newContent = Serialize(entries);
                return(new FileAction(currentFile.FileName, ActionType.Update, newContent));

                //int lastIndex = int.Parse(lines.Last().Split(';')[0]);
                //string newLine = (lastIndex + 1) + ";" + visitorName + ";" + timeOfVisit.ToString("s");
                //File.AppendAllLines(currentFile, new[] { newLine });
            }
            else
            {
                var      entry      = new AuditEntry(1, visitorName, timeOfVisit);
                string[] newContent = Serialize(new List <AuditEntry> {
                    entry
                });
                string newFileName = GetNewFileName(currentFile.FileName);

                return(new FileAction(newFileName, ActionType.Create, newContent));
                //string newLine = "1;" + visitorName + ";" + timeOfVisit.ToString("s");
                //string newFileName = GetNewFileName(currentFile);
                //File.WriteAllLines(newFileName, new[] { newLine });
            }
        }
Esempio n. 2
0
        public FileAction AddRecord(FileContent currentFile, string visitorName, DateTime timeOfVisit)
        {
            var entries = Parse(currentFile.Content);

            if (entries.Count < _maxEntriesPerFile)
            {
                entries.Add(new AuditEntry(entries.Count + 1, visitorName, timeOfVisit));
                var newContent = Serialize(entries);

                return(new FileAction(currentFile.FileName, ActionType.Update, newContent));
            }
            else
            {
                var entry       = new AuditEntry(1, visitorName, timeOfVisit);
                var newContent  = Serialize(new[] { entry });
                var newFileName = GetNewFileName(currentFile.FileName);

                return(new FileAction(newFileName, ActionType.Create, newContent));
            }
        }