public MainWindowViewModel() { FileOpenCommand.Subscribe(() => { CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.Multiselect = true; dialog.Filters.Add(new CommonFileDialogFilter("全てのファイル", "*.*")); dialog.Filters.Add(new CommonFileDialogFilter("NBTファイル", "*.dat;*.schematic")); if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { DataStore.OpenFile(dialog.FileNames.ToArray()); } }); FolderOpenCommand.Subscribe(() => { CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.Multiselect = true; dialog.IsFolderPicker = true; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { DataStore.OpenFile(dialog.FileNames.ToArray()); } }); }
private bool IsEdited(IEnumerable <Event> loggedEvents, FileOpenCommand foc) { // Get all the events happened between this file open command, and the next one. IEnumerable <Event> subsequentEvents = loggedEvents.SkipUntil(x => x == foc).TakeUntil(x => x != foc && x is FileOpenCommand); // See if there is a document change or not. return(subsequentEvents.FirstOrDefault(x => x is DocumentChange) != null); }
private void RunCloud() { _isRunning = true; CancelCommand.RaiseCanExecuteChanged(); FileOpenCommand.RaiseCanExecuteChanged(); _cancellationToken = new CancellationTokenSource(); ThreadPool.QueueUserWorkItem(DoWork, _cancellationToken); }
/// <summary> /// Determines whether the given event is a file open command with a valid file path. /// </summary> /// <param name="anEvent">An event.</param> /// <returns>true if the given event is a valid file open command, false otherwise</returns> private bool IsValidFileOpenCommand(Event anEvent) { FileOpenCommand foc = anEvent as FileOpenCommand; if (foc == null) { return(false); } if (string.IsNullOrEmpty(foc.FilePath)) { return(false); } if (foc.FilePath == "null") { return(false); } return(true); }
private void DoWork(object state) { var cancellationToken = ((CancellationTokenSource)state).Token; // Execute the process steps var step1 = new ExecuteExcelToCsvProcessStep(_eventAggregator, _logger, 1); step1.Run(cancellationToken); var step2 = new ExecuteCreateZipFileProcessStep(_eventAggregator, _logger, 2); step2.Run(cancellationToken); // Update the UI command state Dispatcher.CurrentDispatcher.Invoke(() => { _isRunning = false; RunCloudCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); FileOpenCommand.RaiseCanExecuteChanged(); }); }
// How to merge with the previous method?? private int GetLineChartYValue(FileOpenCommand fileOpenCommand) { if (radioDocumentLength.Checked) { return(fileOpenCommand.DocumentLength); } else if (radioActiveCodeLength.Checked) { return(fileOpenCommand.ActiveCodeLength); } else if (radioExpressionCount.Checked) { return(fileOpenCommand.ExpressionCount); } else if (radioASTNodeCount.Checked) { return(fileOpenCommand.ASTNodeCount); } else { return(0); } }
/// <summary> /// Processes the file open command. /// </summary> /// <param name="foc">The file open command.</param> /// <param name="files">The files.</param> /// <param name="lastDocChanges">The last document changes.</param> /// <param name="result">The result.</param> /// <returns>The new current file path.</returns> private static string ProcessFileOpenCommand( FileOpenCommand foc, Dictionary <string, StringBuilder> files, Dictionary <string, DocumentChange> lastDocChanges, EntireSnapshot result) { string currentFile = foc.FilePath; if (!result.FilePaths.Contains(currentFile)) { result.FilePaths.Insert(0, currentFile); lastDocChanges.Add(currentFile, null); if (foc.Snapshot == null) { files.Add(currentFile, null); } else { files.Add(currentFile, new StringBuilder(foc.Snapshot)); } } else { // Bring the current file to the front result.FilePaths.Remove(currentFile); result.FilePaths.Insert(0, currentFile); // If this command has a new snapshot, replace it. if (foc.Snapshot != null) { files[currentFile] = new StringBuilder(foc.Snapshot); } } return(currentFile); }
public override IEnumerable <PatternInstance> DetectAsPatternInstances(ILogProvider logProvider) { List <Event> completeList = logProvider.LoggedEvents.ToList(); List <DocumentChange> dcList = logProvider.LoggedEvents.OfType <DocumentChange>().ToList(); List <MovePatternInstance> detectedPatterns = new List <MovePatternInstance>(); foreach (int i in Enumerable.Range(0, dcList.Count - 1)) { if (dcList[i] is Delete && dcList[i + 1] is Insert) { Delete delete = dcList[i + 0] as Delete; Insert insert = dcList[i + 1] as Insert; if (TestEquivalent(delete.Text, insert.Text)) { FileOpenCommand fromFileOpenCommand = FindClosestFileOpenCommand(completeList, delete); FileOpenCommand toFileOpenCommand = FindClosestFileOpenCommand(completeList, insert); if (fromFileOpenCommand == null || toFileOpenCommand == null) { continue; } detectedPatterns.Add(new MovePatternInstance( delete, insert, 2, "From: " + Path.GetFileName(fromFileOpenCommand.FilePath) + ", To: " + Path.GetFileName(toFileOpenCommand.FilePath) + ", \"" + delete.Text + "\"", fromFileOpenCommand.FilePath, toFileOpenCommand.FilePath )); } } } return(detectedPatterns); }
/// <summary> /// Processes the file open command. /// </summary> /// <param name="dcList">The dc list.</param> /// <param name="i">The i.</param> /// <param name="logProvider">The log provider.</param> private void ProcessFileOpenCommand(List <Event> dcList, int i, ILogProvider logProvider) { FileOpenCommand foc = (FileOpenCommand)dcList[i]; this.CurrentFile = foc.FilePath; if (foc.Snapshot != null) { if (!this.Snapshots.ContainsKey(this.CurrentFile)) { this.Snapshots.Add(this.CurrentFile, foc.Snapshot); this.InsertSegments.Add(this.CurrentFile, new List <InsertSegment>()); } else { if (foc.Snapshot == this.Snapshots[this.CurrentFile]) { // Do nothing. } else if (this.Snapshots[this.CurrentFile] == null) { this.Snapshots[this.CurrentFile] = foc.Snapshot; this.InsertSegments[this.CurrentFile] = new List <InsertSegment>(); } else { // Extracts the diffs string before = this.Snapshots[this.CurrentFile]; string after = foc.Snapshot; diff_match_patch dmp = new diff_match_patch(); List <Diff> diffs = dmp.diff_main(before, after); int curOffset = 0; int curLength = before.Length; foreach (Diff diff in diffs) { switch (diff.operation) { case Operation.INSERT: this.ProcessInsert(foc, curOffset, diff.text, logProvider); curOffset += diff.text.Length; curLength += diff.text.Length; break; case Operation.DELETE: this.ProcessDelete(foc, curOffset, diff.text.Length, logProvider); curLength -= diff.text.Length; break; case Operation.EQUAL: curOffset += diff.text.Length; break; } } } } } else { if (!this.Snapshots.ContainsKey(this.CurrentFile)) { this.Snapshots.Add(this.CurrentFile, null); this.InsertSegments.Add(this.CurrentFile, new List <InsertSegment>()); } } }