public void RemoveMethod(string name) { ProjectChanged = true; FileNames.Remove(name); Sources.Remove(name); Comments.Remove(name); FilesChanged.Remove(name); }
private void OnTimerElapsed(object sender, ElapsedEventArgs e) { var sources = FilesChanged.Distinct().ToArray(); var targets = sources.Select(Path.GetFileName).Select(name => Path.Combine(BUILD_DIRECTORY, name)).ToArray(); for (var i = 0; i < sources.Length; i++) { TryMoveFile(sources[i], targets[i]); } BuildRepository(); }
public void Load(string path) { _path = path; _files = LoadData(_path); FilesChanged?.Invoke(this, new FilesChangedEventArgs(_files)); foreach (var file in _files) { FileChanged?.Invoke(this, new FileChangedEventArgs(file)); } }
public void Stop() { Timer.Stop(); FilesChanged.Clear(); if (Watcher is null) { return; } Watcher.Changed -= OnDirectoryChanged; Watcher.Dispose(); Watcher = null; }
public void RenameMethod(string name, string newName) { if (!Sources.ContainsKey(name)) { throw new ArgumentException("Unknown method name"); } if (Sources.ContainsKey(newName)) { throw new ArgumentException("Method " + newName + " already exists."); } if (newName.Length != name.Length) { throw new ArgumentException("New method name must have same number of symbols as old name"); } if (newName.Length != 1 && newName.Length != 4) { throw new ArgumentException("Incorrect length of new method name"); } if (newName.Length == 1 && (!System.Text.RegularExpressions.Regex.IsMatch(newName, "[B-Za-z]") || newName == "A" || newName == "V")) { throw new ArgumentException("Incorrect method name.\nMethod name must be 1 Latin character except 'A' or 'V'"); } ProjectChanged = true; Sources.Add(newName, Sources[name]); Sources.Remove(name); FileNames.Add(newName, FileNames[name]); FileNames.Remove(name); FilesChanged.Add(newName, FilesChanged[name]); FilesChanged.Remove(name); Comments.Add(newName, Comments[name]); Comments.Remove(name); if (name.Length == 1) { char old = name[0]; char nw = newName[0]; foreach (var a in Sources.Keys) { for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (Sources[a][i, j] == old) { Sources[a][i, j] = nw; } } } } } }
/// <summary> /// Add new method with zero source code /// </summary> /// <param name="name">Name of new method</param> /// <param name="path">Path of file with source</param> public void AddMethod(string name, string path) { ProjectChanged = true; FileNames.Add(name, path); Comments.Add(name, ""); char[,] source = new char[16, 16]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { source[i, j] = '0'; } } source[0, 0] = '#';// Empty method immediately ends running Sources.Add(name, source); FilesChanged.Add(name, true); }
public static void FindContainers(string path) { var jsonFiles = Directory.EnumerateFiles(path, Settings.Default.MessagesFileNamePattern) .Select(fileName => new FileInfo(fileName)).ToArray(); var deletedContainers = MessageContainers.Where(mc => !jsonFiles.Any(jf => jf.FullName == mc.FileInfo.FullName)).ToArray(); deletedContainers.ForEach(dc => MessageContainers.Remove(dc)); bool somethingChanged = deletedContainers.Any(); foreach (var jsonFile in jsonFiles) { try { if (MessageContainers.Any(mf => mf.FileInfo.FullName == jsonFile.FullName && mf.FileInfo.LastWriteTime == jsonFile.LastWriteTime)) { continue; } somethingChanged = true; MessageContainers.RemoveAll(mf => mf.FileInfo.FullName == jsonFile.FullName); var json = File.ReadAllText(jsonFile.FullName); var container = JsonHelper.GetObjectFromString <MessageContainer>(json); container.FileInfo = jsonFile; MessageContainers.Add(container); } catch (Exception ex) { Debug.WriteLine($"{nameof(FindContainers)}: can't open json file.{Environment.NewLine}{ex}"); } } if (somethingChanged) { FilesChanged?.Invoke(MessageContainers, EventArgs.Empty); } }
void WorkLoop(object sender, EventArgs e) { while (true) { if (ShouldAbort) { return; } Stopwatch Watch = new Stopwatch(); bool EventNeedsFiring = false; FileWatcherRaised = false; try { foreach (var fileName in Directory.EnumerateFiles(FolderPath, FileExtension, SearchOption.TopDirectoryOnly).ToArray()) { if (ShouldAbort) { return; } if (GetMdoc(fileName) != null) { continue; } FileInfo Info = new FileInfo(fileName); MdocIncubatorEntry CurrentState = GetIncubating(fileName); Mdoc ParsedEntry = null; int AvailableTilts = 0; try { ParsedEntry = Mdoc.FromFile(new[] { fileName }, DefaultTiltDose); AvailableTilts = ParsedEntry.Entries.Count; } catch { } if (CurrentState == null) { Stopwatch Timer = new Stopwatch(); Timer.Start(); lock (Incubator) { Incubator.Add(new MdocIncubatorEntry(fileName, Timer, Info.Length, AvailableTilts)); if (Incubator.Count == 1) { IncubationStarted?.Invoke(); } } } else { // Check if bool CanRead = false; try { File.OpenRead(fileName).Close(); CanRead = true; } catch { } if (ParsedEntry == null || Info.Length != CurrentState.Size || CurrentState.NTilts != AvailableTilts || !CanRead) { lock (Incubator) Incubator.Remove(CurrentState); Stopwatch Timer = new Stopwatch(); Timer.Start(); lock (Incubator) Incubator.Add(new MdocIncubatorEntry(fileName, Timer, Info.Length, AvailableTilts)); } else if ((CurrentState.Lifetime.ElapsedMilliseconds > 1000 && AvailableTilts >= ExpectedNTilts) || (AcceptAnywayAfter > 0 && CurrentState.Lifetime.ElapsedMilliseconds > AcceptAnywayAfter)) { //lock (Ripe) { if (!Ripe.Exists(m => m.Path == fileName)) { while (CreationTasks.Count > 15) { Thread.Sleep(1); } Task CreationTask = new Task(() => { Mdoc Created = ParsedEntry; lock (Ripe) { // Make sure the list is sorted int InsertAt = 0; while (InsertAt < Ripe.Count && Ripe[InsertAt].Path.CompareTo(fileName) < 0) { InsertAt++; } Ripe.Insert(InsertAt, Created); } lock (CreationTasks) CreationTasks.Remove(fileName); }); lock (CreationTasks) CreationTasks.Add(fileName, CreationTask); CreationTask.Start(); } } EventNeedsFiring = true; if (!Watch.IsRunning) { Watch.Start(); } lock (Incubator) { Incubator.Remove(CurrentState); if (Incubator.Count == 0) { IncubationEnded?.Invoke(); } } } } if (EventNeedsFiring && Watch.ElapsedMilliseconds > 500) { //Task.WaitAll(CreationTasks.ToArray()); //CreationTasks.Clear(); Watch.Stop(); Watch.Reset(); EventNeedsFiring = false; FilesChanged?.Invoke(); } } } catch (Exception exc) { Debug.WriteLine("FileDiscoverer crashed:"); Debug.WriteLine(exc); if (ExceptionsLogged < 100) { using (TextWriter Writer = File.AppendText("d_filediscoverer.txt")) { Writer.WriteLine(DateTime.Now + ":"); Writer.WriteLine(exc.ToString()); Writer.WriteLine(""); ExceptionsLogged++; } } } while (CreationTasks.Count > 0) { Thread.Sleep(1); } if (EventNeedsFiring) { FilesChanged?.Invoke(); } while (!IsIncubating() && !FileWatcherRaised) { if (ShouldAbort) { return; } Thread.Sleep(50); } } }
private void RecordFileChanged(string file) => FilesChanged.Add(file);
protected virtual void OnFilesChanged(FilesChangedEventArgs e) { FilesChanged?.Invoke(this, e); }
public void ChangePath(string newPath, string newExtension) { IncubationEnded?.Invoke(); lock (Incubator) { if (DiscoveryThread != null && DiscoveryThread.IsBusy) { DiscoveryThread.RunWorkerCompleted += (sender, args) => { FileWatcher.EnableRaisingEvents = false; FileWatcherRaised = false; ShouldAbort = false; FolderPath = newPath; FileExtension = newExtension; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); }; ShouldAbort = true; } else { FolderPath = newPath; FileExtension = newExtension; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); } } }
void WorkLoop(object sender, EventArgs e) { while (true) { if (ShouldAbort) { return; } Stopwatch Watch = new Stopwatch(); bool EventNeedsFiring = false; FileWatcherRaised = false; try { foreach (var fileName in Directory.EnumerateFiles(FolderPath, FileExtension, SearchOption.TopDirectoryOnly)) { if (ShouldAbort) { return; } if (GetMovie(fileName) != null) { continue; } string NameXML = fileName.Substring(0, fileName.LastIndexOf(".")) + ".xml"; if (!File.Exists(NameXML)) { FileInfo Info = new FileInfo(fileName); Tuple <string, Stopwatch, long> CurrentState = GetIncubating(fileName); if (CurrentState == null) { Stopwatch Timer = new Stopwatch(); Timer.Start(); lock (Incubator) { Incubator.Add(new Tuple <string, Stopwatch, long>(fileName, Timer, Info.Length)); if (Incubator.Count == 1) { IncubationStarted?.Invoke(); } } } else { // Check if bool CanRead = false; try { File.OpenRead(fileName).Close(); CanRead = true; } catch { } if (Info.Length != CurrentState.Item3 || !CanRead) { lock (Incubator) Incubator.Remove(CurrentState); Stopwatch Timer = new Stopwatch(); Timer.Start(); lock (Incubator) Incubator.Add(new Tuple <string, Stopwatch, long>(fileName, Timer, Info.Length)); } else if (CurrentState.Item2.ElapsedMilliseconds > 1000) { lock (Ripe) { if (!Ripe.Exists(m => m.Path == fileName)) { // Make sure the list is sorted int InsertAt = 0; while (InsertAt < Ripe.Count && Ripe[InsertAt].Path.CompareTo(fileName) < 0) { InsertAt++; } if (!fileName.Substring(fileName.Length - 8).ToLower().Contains("tomostar")) { Ripe.Insert(InsertAt, new Movie(fileName)); } else { Ripe.Insert(InsertAt, new TiltSeries(fileName)); } } } EventNeedsFiring = true; if (!Watch.IsRunning) { Watch.Start(); } lock (Incubator) { Incubator.Remove(CurrentState); if (Incubator.Count == 0) { IncubationEnded?.Invoke(); } } } } if (EventNeedsFiring && Watch.ElapsedMilliseconds > 500) { Watch.Stop(); Watch.Reset(); EventNeedsFiring = false; FilesChanged?.Invoke(); } } else { lock (Ripe) { if (!Ripe.Exists(m => m.Path == fileName)) { // Make sure the list is sorted int InsertAt = 0; while (InsertAt < Ripe.Count && Ripe[InsertAt].Path.CompareTo(fileName) < 0) { InsertAt++; } if (!fileName.Substring(fileName.Length - 8).ToLower().Contains("tomostar")) { Ripe.Insert(InsertAt, new Movie(fileName)); } else { Ripe.Insert(InsertAt, new TiltSeries(fileName)); } } } EventNeedsFiring = true; if (!Watch.IsRunning) { Watch.Start(); } if (EventNeedsFiring && Watch.ElapsedMilliseconds > 500) { Watch.Stop(); Watch.Reset(); EventNeedsFiring = false; FilesChanged?.Invoke(); } } } } catch (Exception exc) { Debug.WriteLine("FileDiscoverer crashed:"); Debug.WriteLine(exc); } if (EventNeedsFiring) { FilesChanged?.Invoke(); } while (!IsIncubating() && !FileWatcherRaised) { if (ShouldAbort) { return; } Thread.Sleep(50); } } }
private void Query_ContentsChanged(IStorageQueryResultBase sender, object args) { FilesChanged?.Invoke(sender, EventArgs.Empty); }
public void ChangePath(string newPath) { IncubationEnded?.Invoke(); lock (Incubator) { if (DiscoveryThread != null && DiscoveryThread.IsBusy) { DiscoveryThread.RunWorkerCompleted += (sender, args) => { FileWatcher.EnableRaisingEvents = false; FileWatcherRaised = false; ShouldAbort = false; FolderPath = newPath; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Task.WaitAll(CreationTasks.Values.ToArray()); //Thread.Sleep(500); // There might still be item creation tasks running asynchro Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); }; ShouldAbort = true; } else { FolderPath = newPath; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); } } }
protected virtual void OnFilesChanged() { FilesChanged?.Invoke(this); }
void QueryContentsChanged(Windows.Storage.Search.IStorageQueryResultBase sender, object args) { FilesChanged?.Invoke(this, EventArgs.Empty); }
void WorkLoop(object sender, EventArgs e) { string[] ParticleFileNames = null; if (Directory.Exists(Path.Combine(FolderPath, "matching"))) { ParticleFileNames = Directory.EnumerateFiles(Path.Combine(FolderPath, "matching"), "*.star", SearchOption.TopDirectoryOnly).Select(p => Helper.PathToNameWithExtension(p)).ToArray(); } while (true) { if (ShouldAbort) { return; } Stopwatch Watch = new Stopwatch(); bool EventNeedsFiring = false; FileWatcherRaised = false; try { foreach (var fileName in Directory.EnumerateFiles(FolderPath, FileExtension, SearchOption.TopDirectoryOnly).ToArray()) { if (ShouldAbort) { return; } if (GetMovie(fileName) != null) { continue; } string NameXML = fileName.Substring(0, fileName.LastIndexOf(".")) + ".xml"; if (!File.Exists(NameXML)) { FileInfo Info = new FileInfo(fileName); Tuple <string, Stopwatch, long> CurrentState = GetIncubating(fileName); if (CurrentState == null) { Stopwatch Timer = new Stopwatch(); Timer.Start(); lock (Incubator) { Incubator.Add(new Tuple <string, Stopwatch, long>(fileName, Timer, Info.Length)); if (Incubator.Count == 1) { IncubationStarted?.Invoke(); } } } else { // Check if bool CanRead = false; try { File.OpenRead(fileName).Close(); CanRead = true; } catch { } if (Info.Length != CurrentState.Item3 || !CanRead) { lock (Incubator) Incubator.Remove(CurrentState); Stopwatch Timer = new Stopwatch(); Timer.Start(); lock (Incubator) Incubator.Add(new Tuple <string, Stopwatch, long>(fileName, Timer, Info.Length)); } else if (CurrentState.Item2.ElapsedMilliseconds > 1000) { //lock (Ripe) { if (!Ripe.Exists(m => m.Path == fileName)) { while (CreationTasks.Count > 15) { Thread.Sleep(1); } Task CreationTask = new Task(() => { Movie Created = null; if (!fileName.Substring(fileName.Length - 8).ToLower().Contains("tomostar")) { Created = new Movie(fileName, ParticleFileNames); } else { Created = new TiltSeries(fileName); } lock (Ripe) { // Make sure the list is sorted int InsertAt = 0; while (InsertAt < Ripe.Count && Ripe[InsertAt].Path.CompareTo(fileName) < 0) { InsertAt++; } Ripe.Insert(InsertAt, Created); } lock (CreationTasks) CreationTasks.Remove(fileName); }); lock (CreationTasks) CreationTasks.Add(fileName, CreationTask); CreationTask.Start(); } } EventNeedsFiring = true; if (!Watch.IsRunning) { Watch.Start(); } lock (Incubator) { Incubator.Remove(CurrentState); if (Incubator.Count == 0) { IncubationEnded?.Invoke(); } } } } if (EventNeedsFiring && Watch.ElapsedMilliseconds > 500) { //Task.WaitAll(CreationTasks.ToArray()); //CreationTasks.Clear(); Watch.Stop(); Watch.Reset(); EventNeedsFiring = false; FilesChanged?.Invoke(); } } else { //lock (Ripe) { if (!Ripe.Exists(m => m.Path == fileName)) { while (CreationTasks.Count > 15) { Thread.Sleep(1); } Task CreationTask = new Task(() => { Movie Created = null; if (!fileName.Substring(fileName.Length - 8).ToLower().Contains("tomostar")) { Created = new Movie(fileName, ParticleFileNames); } else { Created = new TiltSeries(fileName); } lock (Ripe) { // Make sure the list is sorted int InsertAt = 0; while (InsertAt < Ripe.Count && Ripe[InsertAt].Path.CompareTo(fileName) < 0) { InsertAt++; } Ripe.Insert(InsertAt, Created); } lock (CreationTasks) CreationTasks.Remove(fileName); }); lock (CreationTasks) CreationTasks.Add(fileName, CreationTask); CreationTask.Start(); } } EventNeedsFiring = true; if (!Watch.IsRunning) { Watch.Start(); } if (EventNeedsFiring && Watch.ElapsedMilliseconds > 500) { //Task.WaitAll(CreationTasks.ToArray()); //CreationTasks.Clear(); Watch.Stop(); Watch.Reset(); EventNeedsFiring = false; FilesChanged?.Invoke(); } } } } catch (Exception exc) { Debug.WriteLine("FileDiscoverer crashed:"); Debug.WriteLine(exc); if (ExceptionsLogged < 100) { using (TextWriter Writer = File.AppendText("d_filediscoverer.txt")) { Writer.WriteLine(DateTime.Now + ":"); Writer.WriteLine(exc.ToString()); Writer.WriteLine(""); ExceptionsLogged++; } } } while (CreationTasks.Count > 0) { Thread.Sleep(1); } if (EventNeedsFiring) { FilesChanged?.Invoke(); } while (!IsIncubating() && !FileWatcherRaised) { if (ShouldAbort) { return; } Thread.Sleep(50); } } }
internal void Clear() { m_project.CloseFiles(); New(); FilesChanged.Execute(); }