Example #1
0
        public MachineFile(ITextFile textFile, History machineHistory, int nextBlobId)
        {
            _textFile   = textFile ?? throw new ArgumentNullException(nameof(textFile));
            _nextBlobId = nextBlobId;

            History = machineHistory;
        }
Example #2
0
        public BarrierLimitedModeCharacterCounter(ITextFile textFile, Barrier barrier)
        {
            this.barrier = barrier;
            barrier.AddParticipant();

            charCounts = new Lazy <IReadOnlyDictionary <char, int> >(() => BufferAndCount(textFile));
        }
Example #3
0
 /// <summary>
 /// Notifies to the text editor service that all previous line change notifications for a file have to be discarded
 /// </summary>
 /// <param name='textFile'>
 /// Text file.
 /// </param>
 public static void NotifyLineCountChangesReset(ITextFile textFile)
 {
     if (LineCountChangesReset != null)
     {
         LineCountChangesReset(textFile, new TextFileEventArgs(textFile));
     }
 }
Example #4
0
        /// <summary>
        /// Rewrites the machine file according to the current in-memory representation of the timeline.
        /// </summary>
        /// <param name="diffsEnabled">Enable calculation of diffs. Setting this to true can cause compacting to take a long time.</param>
        /// <remarks>
        /// This is useful for compacting the size of the machine file, due to the fact that bookmark and timeline deletions don't actually
        /// remove anything from the machine file, but simply log the fact they happened.
        /// </remarks>
        ///
        public void Compact(IFileSystem fileSystem)
        {
            // Only allow closed machines to compact!
            if (!CanCompact())
            {
                throw new Exception("Can't compact an open machine!");
            }

            string oldFilepath = PersistantFilepath;
            string newFilepath = oldFilepath + ".tmp";

            MachineFileInfo info = null;

            using (ITextFile textFile = fileSystem.OpenTextFile(oldFilepath))
            {
                info = MachineFile.Read(textFile);
            }

            using (ITextFile textFile = fileSystem.OpenTextFile(newFilepath))
                using (MachineFile writer = new MachineFile(textFile, info.History))
                {
                    writer.WriteHistory(info.Name);
                }

            fileSystem.ReplaceFile(oldFilepath, newFilepath);
        }
Example #5
0
        public bool Persist(IFileSystem fileSystem, string filepath)
        {
            using (AutoPause())
            {
                if (File != null)
                {
                    // We already are persisted!
                    throw new InvalidOperationException("This machine is already persisted!");
                }

                if (String.IsNullOrEmpty(filepath))
                {
                    throw new ArgumentException("Invalid filepath.", nameof(filepath));
                }

                ITextFile   textFile    = fileSystem.OpenTextFile(filepath);
                MachineFile machineFile = new MachineFile(textFile, _history);

                machineFile.WriteHistory(_name);

                File = machineFile;

                PersistantFilepath = filepath;

                return(true);
            }
        }
 private void Process(ITextFile textFile)
 {
     foreach (string line in textFile.ReadLines())
     {
         textLineQueue.Add(line);
     }
 }
Example #7
0
        private IReadOnlyDictionary <char, int> BufferAndCount(ITextFile textFile)
        {
            IReadOnlyCollection <string> allLines = ReadAllLines(textFile);

            barrier.SignalAndWait();
            return(ComputeCharCounts(allLines));
        }
Example #8
0
 public static void FireResetCountChanges(ITextFile textFile)
 {
     if (ResetCountChanges != null)
     {
         ResetCountChanges(textFile, new TextFileEventArgs(textFile));
     }
 }
Example #9
0
 private static IReadOnlyCollection <string> ReadAllLines(ITextFile textFile)
 {
     using (SystemMode.Reader) // don't remove this - that's cheating!
     {
         return(textFile.ReadLines().ToList());
     }
 }
 private static IReadOnlyCollection<string> ReadAllLines(ITextFile textFile)
 {
     using (SystemMode.Reader) // don't remove this - that's cheating!
     {
         return textFile.ReadLines().ToList();
     }
 }
Example #11
0
        public DiffResult ProcessDiff(ITextFile source, ITextFile dest)
        {
            O = source;
            N = dest;

            return(GenerateDiffResult());
        }
Example #12
0
        public void OpenTextFile()
        {
            // Setup
            string     filepath = TestHelpers.GetTempFilepath("test.txt");
            FileSystem fs       = new FileSystem();

            fs.DeleteFile(filepath);

            // Act
            using (ITextFile textFile = fs.OpenTextFile(filepath))
            {
                textFile.WriteLine("abc");
                textFile.WriteLine("123");
            }

            List <string> lines = new List <string>();

            using (ITextFile textFile = fs.OpenTextFile(filepath))
            {
                lines.Add(textFile.ReadLine());
                lines.Add(textFile.ReadLine());
                lines.Add(textFile.ReadLine());
            }

            // Verify
            Assert.AreEqual("abc", lines[0]);
            Assert.AreEqual("123", lines[1]);
            Assert.Null(lines[2]);

            fs.DeleteFile(filepath);
        }
Example #13
0
 public LineCountEventArgs(ITextFile textFile, int lineNumber, int lineCount, int column)
     : base(textFile)
 {
     this.lineNumber = lineNumber;
     this.lineCount  = lineCount;
     this.column     = column;
 }
 public void Add(ITextFile textFile)
 {
     foreach (string line in textFile.ReadLines())
     {
         totaliser.Add(line);
     }
 }
 public void Add(ITextFile textFile)
 {
     foreach (string line in textFile.ReadLines())
     {
         totaliser.Add(line);
     }
 }
Example #16
0
        /// <summary>
        /// Notifies to the text editor service that there has been a line count change in a file being edited
        /// </summary>
        /// <param name='textFile'>
        /// File that changed
        /// </param>
        /// <param name='lineNumber'>
        /// Line number
        /// </param>
        /// <param name='lineCount'>
        /// Number of lines added (or removed if negative)
        /// </param>
        /// <param name='column'>
        /// Column.
        /// </param>
        public void NotifyLineCountChanged(ITextFile textFile, int lineNumber, int lineCount, int column)
        {
            foreach (var ext in GetFileLineExtensions(textFile.Name).Where(ex => ex.TrackLinePosition).ToList())
            {
                if (ext.Line > lineNumber)
                {
                    if (ext.Line + lineCount < lineNumber)
                    {
                        ext.NotifyDeleted();
                    }
                    if (ext.OriginalLine == -1)
                    {
                        ext.OriginalLine = ext.Line;
                    }
                    ext.Line += lineCount;
                    ext.Refresh();
                }
                else if (ext.Line == lineNumber && lineCount < 0)
                {
                    ext.NotifyDeleted();
                    if (ext.OriginalLine == -1)
                    {
                        ext.OriginalLine = ext.Line;
                    }
                    ext.Line += lineCount;
                    ext.Refresh();
                }
            }

            if (LineCountChanged != null)
            {
                LineCountChanged(textFile, new LineCountEventArgs(textFile, lineNumber, lineCount, column));
            }
        }
 private void Process(ITextFile textFile)
 {
     foreach (string line in textFile.ReadLines())
     {
         textLineQueue.Add(line);
     }
 }
Example #18
0
 public static void FireCommitCountChanges(ITextFile textFile)
 {
     if (CommitCountChanges != null)
     {
         CommitCountChanges(textFile, new TextFileEventArgs(textFile));
     }
 }
Example #19
0
        private bool LoadTextFile(ITextFile textFile)
        {
            bool isLoadSuccessful = true;

            try
            {
                if (textFile.Load())
                {
                    this.log.Debug(textFile.FileName, "Loaded successfully.");
                }
                else
                {
                    this.log.Debug(textFile.FileName, "Needs to be analyzed first.");
                }
            }
            catch (SystemException exc)
            {
                this.log.Error(textFile.FileName, "Error: " + exc.Message);
                isLoadSuccessful = false;
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    throw;
                }
            }

            return(isLoadSuccessful);
        }
        public BarrierLimitedModeCharacterCounter(ITextFile textFile, Barrier barrier)
        {
            this.barrier = barrier;
            barrier.AddParticipant();

            charCounts = new Lazy<IReadOnlyDictionary<char, int>>(() => BufferAndCount(textFile));
        }
Example #21
0
        private bool SaveTextFile(ITextFile textFile)
        {
            bool isModified = false;

            try
            {
                if (textFile.Save())
                {
                    this.log.Info(textFile.FileName, "Saved successfully.");
                    isModified = true;
                }
                else
                {
                    this.log.Debug(textFile.FileName, "Has not been modified.");
                }
            }
            catch (SystemException exc)
            {
                this.log.Error(textFile.FileName, "Error: " + exc.Message);
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    throw;
                }
            }

            return(isModified);
        }
Example #22
0
 /// <summary>
 /// Notifies to the text editor service that there has been a line count change in a file being edited
 /// </summary>
 /// <param name='textFile'>
 /// File that changed
 /// </param>
 /// <param name='lineNumber'>
 /// Line number
 /// </param>
 /// <param name='lineCount'>
 /// Number of lines added (or removed if negative)
 /// </param>
 /// <param name='column'>
 /// Column.
 /// </param>
 public static void NotifyLineCountChanged(ITextFile textFile, int lineNumber, int lineCount, int column)
 {
     if (LineCountChanged != null)
     {
         LineCountChanged(textFile, new LineCountEventArgs(textFile, lineNumber, lineCount, column));
     }
 }
Example #23
0
 public TextEditModel(IConfiguration configuration, IToken _token, ITextFile _textfile)
 {
     textfile      = _textfile;
     Configuration = configuration;
     token         = _token;
     TextList      = textfile.listtext;
 }
Example #24
0
 /// <summary>
 /// Notifies to the text editor service that all previous line change notifications for a file have to be committed
 /// </summary>
 /// <param name='textFile'>
 /// Text file.
 /// </param>
 public static void NotifyLineCountChangesCommitted(ITextFile textFile)
 {
     if (LineCountChangesCommitted != null)
     {
         LineCountChangesCommitted(textFile, new TextFileEventArgs(textFile));
     }
 }
 public void Add(ITextFile textFile)
 {
     Task task = new Task(() => ProduceFrom(textFile));
     task.ContinueWith(HandleFileProcessed);
     producerTasks.TryAdd(task, textFile);
     task.Start();
 }
Example #26
0
        ///////////////////////////////////////////////TEXT IN DOC : EMBEDD : LOGIC ///////////////////////////////////////////////
        private void button2_Click(object sender, EventArgs e)
        {
            //Checking for validation.
            if (loadedFilePath == "")
            {
                MessageBox.Show("File Path cannot be blank...!");
                textBox1.Text = "";
                textBox2.Text = "";
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("Your Msg Should not be blank.");
            }
            else if (textBox2.Text.Length > secretmsgsize)
            {
                MessageBox.Show("You can Embedd Maximum " + secretmsgsize + " characters.");
                textBox2.Text = "";
            }
            else
            {
                Cursor.Current = Cursors.WaitCursor;

                SimpleObjectFactory sof      = new SimpleObjectFactory();
                ITextFile           textFile = sof.getTextFile();
                string text = textFile.getTextFromFile(loadedFilePath);

                string msg = textBox2.Text;

                ITextInDoc textInDoc = sof.getTextInDoc();
                text = textInDoc.Embedd(text, msg);

                string path = loadedFilePath.Remove(loadedFilePath.Length - fileNameSize) + justFName(loadedFilePath).Remove(fileNameSize - 4) + "1.txt";

                if (!File.Exists(path))
                {
                    File.Create(path).Dispose();
                    using (TextWriter tw = new StreamWriter(path))
                    {
                        tw.Write("" + text + "");
                        tw.Close();
                    }
                    label33.Text = "Output File : " + path;
                }
                else if (File.Exists(path))
                {
                    using (TextWriter tw = new StreamWriter(path))
                    {
                        MessageBox.Show(justFName(loadedFilePath).Remove(fileNameSize - 4) + "1.txt File already exist...!");
                        label33.Text = "";
                    }
                }

                Cursor.Current = Cursors.Arrow;
                textBox1.Text  = "";
                textBox2.Text  = "";
                msg            = "";
                loadedFilePath = "";
            }
        }
Example #27
0
        public void GetCharCounts_OnManyThreads_ShouldAlwaysGetTheSameResult([ValueSource("Files")] ITextFile file)
        {
            const int NumCalls    = 10;
            var       countedFile = new CachingFileCharacterCounter();
            var       charCounts  = Enumerable.Range(0, NumCalls).AsParallel().Select(i => countedFile.GetCharCounts(file)).ToList();

            Assert.That(charCounts.Distinct().Count(), Is.EqualTo(1));
        }
        public void LineCount_OnManyThreads_ShouldOnlyReadFileOnce([ValueSource("Files")] ITextFile file)
        {
            const int NumCalls    = 10;
            var       countedFile = new CountedTextFile(file);

            Enumerable.Range(0, NumCalls).AsParallel().Select(i => countedFile.LineCount).ToList();
            Assert.That(countedFile.NumberOfCallsToCountLines, Is.EqualTo(1));
        }
        public void Add(ITextFile textFile)
        {
            Task task = new Task(() => ProduceFrom(textFile));

            task.ContinueWith(HandleFileProcessed);
            producerTasks.TryAdd(task, textFile);
            task.Start();
        }
        public void LineCount_OnManyThreads_ShouldAlwaysGetTheSameResult([ValueSource("Files")] ITextFile file)
        {
            const int NumCalls    = 10;
            var       countedFile = new CountedTextFile(file);
            var       lineCounts  = Enumerable.Range(0, NumCalls).AsParallel().Select(i => countedFile.LineCount).ToList();

            Assert.That(lineCounts.Distinct().Count(), Is.EqualTo(1));
        }
Example #31
0
        public void GetCharCounts_TwiceOnSameThread_ShouldOnlyComputeOnce([ValueSource("Files")] ITextFile file)
        {
            var countedFile = new CachingFileCharacterCounter();

            countedFile.GetCharCounts(file);
            countedFile.GetCharCounts(file);
            Assert.That(countedFile.NumberOfCallsToComputeCharCounts, Is.EqualTo(1));
        }
Example #32
0
        /// <inheritdoc />
        /// <exception cref="ArgumentNullException">
        ///     Thrown if the passed argument is
        ///     full
        /// </exception>
        public void Parse(ITextFile file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            this.ParseLineByLine(file.ReadLines());
        }
Example #33
0
        static public MachineFileInfo Read(ITextFile textFile)
        {
            MachineFileReader reader = new MachineFileReader();

            reader.ReadFile(textFile);

            MachineFileInfo info = new MachineFileInfo(reader.Name, reader.History, reader.NextLineId);

            return(info);
        }
 public ITextFile MergeFiles(ITextFile source, IEnumerable<ITextFile> modifications)
 {
     var analysedFiles = new Dictionary<ITextFile, IFileAnalysisResult>();
     
     foreach (var modification in modifications)
     {
         analysedFiles.Add(modification, FileAnalyser.CompareFiles(source, modification)); 
     }
     return AssemblingFiles(analysedFiles);
 }
        private ICharacterCounter ComputeCharCounts(ITextFile textFile)
        {
            ++NumberOfCallsToComputeCharCounts;
            var counter = new CharacterTotaliser();
            foreach (string line in textFile.ReadLines())
            {
                counter.Add(line);
            }

            return counter;
        }
        public ICharacterCounter GetCharCounts(ITextFile textFile)
        {
            ICharacterCounter characterCounter;

            if (!cache.TryGetValue(textFile, out characterCounter))
            {
                cache.Add(textFile, characterCounter = ComputeCharCounts(textFile));
            }

            return(characterCounter);
        }
Example #37
0
        public void Dispose()
        {
            Machine = null;
            History = null;

            if (_textFile != null)
            {
                _textFile.Dispose();
                _textFile = null;
            }
        }
Example #38
0
        public JsonRobotConfiguration(ITextFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            _file = file;

            RefreshConfiguration();
        }
Example #39
0
 /// <inheritdoc />
 public Editor(string path)
 {
     Path = path;
     if (System.IO.Path.GetExtension(path) == ".osb")
     {
         TextFile = new StoryBoard(ReadFile(path));
     }
     else
     {
         TextFile = new Beatmap(ReadFile(path));
     }
 }
 public void Add(ITextFile textFile)
 {
     // We could possibly put the lock around just Add(), but would then incur a lot of lock-entry/exit
     // time. It could sometimes be better, but this way probably wins most times.
     readerWriterLock.EnterWriteLock();
     try
     {
         foreach (string line in textFile.ReadLines())
         {
             totaliser.Add(line);
         }
     }
     finally
     {
         readerWriterLock.ExitWriteLock();
     }
 }
 private IReadOnlyDictionary<char, int> BufferAndCount(ITextFile textFile)
 {
     IReadOnlyCollection<string> allLines = ReadAllLines(textFile);
     return ComputeCharCounts(allLines);
 }
 public CountedTextFile(ITextFile textFile)
 {
     this.textFile = textFile;
     lazyCount = new Lazy<int>(CountLines, LazyThreadSafetyMode.ExecutionAndPublication);
 }
 public LimitedModeCharacterCounter(ITextFile textFile)
 {
     charCounts = new Lazy<IReadOnlyDictionary<char, int>>(() => BufferAndCount(textFile));
 }
Example #44
0
		public static void FireResetCountChanges (ITextFile textFile)
		{
			if (ResetCountChanges != null)
				ResetCountChanges (textFile, new TextFileEventArgs (textFile));
		}
Example #45
0
		public static void FireCommitCountChanges (ITextFile textFile)
		{
			if (CommitCountChanges != null)
				CommitCountChanges (textFile, new TextFileEventArgs (textFile));
		}
		/// <summary>
		/// Notifies to the text editor service that all previous line change notifications for a file have to be committed
		/// </summary>
		/// <param name='textFile'>
		/// Text file.
		/// </param>
		public static void NotifyLineCountChangesCommitted (ITextFile textFile)
		{
			if (LineCountChangesCommitted != null)
				LineCountChangesCommitted (textFile, new TextFileEventArgs (textFile));
		}
 public abstract IFileAnalysisResult CompareFiles(ITextFile first, ITextFile second);
 public LazyInitialisedCountedTextFile(ITextFile textFile)
 {
     this.textFile = textFile;
 }
 public TextFileNameSort(ISortData sortData, ITextFile save)
 {
     _sortData = sortData;
     _textFile = save;
 }
 public ITextFile ProcessFiles(ITextFile source, IEnumerable<ITextFile> modifications)
 {
     return Merge.MergeFiles(source, modifications);
 }
 public CountedTextFile(ITextFile textFile)
 {
     this.textFile = textFile;
 }
		/// <summary>
		/// Notifies to the text editor service that there has been a line count change in a file being edited
		/// </summary>
		/// <param name='textFile'>
		/// File that changed
		/// </param>
		/// <param name='lineNumber'>
		/// Line number
		/// </param>
		/// <param name='lineCount'>
		/// Number of lines added (or removed if negative)
		/// </param>
		/// <param name='column'>
		/// Column.
		/// </param>
		public static void NotifyLineCountChanged (ITextFile textFile, int lineNumber, int lineCount, int column)
		{
			if (LineCountChanged != null)
				LineCountChanged (textFile, new LineCountEventArgs (textFile, lineNumber, lineCount, column));
		}
 public ICharacterCounter GetCharCounts(ITextFile textFile)
 {
     // Concise, huh? It's almost as if ConcurrentDictionary was designed for this...
     return cache.GetOrAdd(textFile, ComputeCharCounts);
 }
		public TextFileEventArgs (ITextFile textFile)
		{
			this.textFile = textFile;
		}
 public abstract IFileAnalysisResult CompareToSourceFile(ITextFile modification);
 public void Add(ITextFile textFile)
 {
     Task.Factory.StartNew(() => Process(textFile));
 }
 public CountedTextFile(ITextFile textFile, Func<Func<FileLineCount>, ILazy<FileLineCount>> makeLazy)
 {
     this.textFile = textFile;
     lazyCount = makeLazy(CountLines);
 }
		/// <summary>
		/// Notifies to the text editor service that all previous line change notifications for a file have to be discarded
		/// </summary>
		/// <param name='textFile'>
		/// Text file.
		/// </param>
		public static void NotifyLineCountChangesReset (ITextFile textFile)
		{
			if (LineCountChangesReset != null)
				LineCountChangesReset (textFile, new TextFileEventArgs (textFile));
		}