private LoadedFile GetLF(string path, string name) { LoadedFile lf; string file = System.IO.Path.Combine(_base, path, name); if (!_files.TryGetValue(file, out lf)) { lf = new LoadedFile(); lf.Handle = Wrap.CreateFile(file.Replace('/', '\\'), System.IO.FileAccess.Read, System.IO.FileShare.Read, IntPtr.Zero, System.IO.FileMode.Open, System.IO.FileAttributes.Normal, IntPtr.Zero); if (lf.Handle == IntPtr.Zero || lf.Handle == new IntPtr(-1)) { lf.Missing = true; lf.Tag = DateTime.MaxValue; System.Diagnostics.Debug.WriteLine("Passing through {0}, no override file", file, lf); } else { System.Diagnostics.Debug.WriteLine("Overriding data for {0}", file, lf); //System.Threading.Thread.Sleep(10000); //System.Diagnostics.Debugger.Break(); } _files[file] = lf; } return(lf); }
public void MaximumScrollChangesBasedOnDataOffset() { var loadedFile = new LoadedFile("test", new byte[26]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; // initial condition: given 4 data per row, there should be 7 rows (0-6) because 7*4=28 viewPort.Width--; Assert.Equal(6, viewPort.MaximumScroll); viewPort.Width++; viewPort.ScrollValue++; // scroll down one line viewPort.Width--; // decrease the width so that there is data 2 lines above // Example of what it should look like right now: // .. .. .. 00 // 00 00 00 00 // 00 00 00 00 <- this is the top line in view // 00 00 00 00 // 00 00 00 00 // 00 00 00 00 // 00 00 00 00 <- this is the bottom line in view // 00 .. .. .. // notice from the diagram above that there should now be _8_ rows (0-7). Assert.Equal(7, viewPort.MaximumScroll); }
public void ChangingWidthUpdatesScrollValueIfNeeded() { // ScrollValue=0 is always the line that contains the first byte of the file. var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; viewPort.ScrollValue++; // scroll down one line viewPort.Width--; // decrease the width so that there is data 2 lines above // Example of what it should look like: // .. .. .. .. // .. .. .. 00 // 00 00 00 00 // 00 00 00 00 <- this is the top line in view // 00 00 00 00 // 00 00 00 00 // 00 00 00 00 // 00 00 00 00 <- this is the bottom line in view // .. .. .. .. Assert.Equal(2, viewPort.ScrollValue); Assert.Equal(6, viewPort.MaximumScroll); }
public LoadedFile import(String path) { if (File.Exists(path)) { try { using (StreamReader fReader = new StreamReader(path)) { String content = fReader.ReadToEnd(); LoadedFile newFile = new LoadedFile { FilePath = path, FileContent = content, Index = int.MaxValue }; addFile(newFile); return(newFile); } } catch (Exception e) { MessageBox.Show("Error importing file:\n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("File does not exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } return(null); }
private void SaveFileAtPath(string filePath) { if (LoadedFile == null) { throw new InvalidOperationException("No file loaded to save as!"); } string folderName = Path.GetDirectoryName(filePath); string fileName = Path.GetFileName(filePath); LoadedFile.FileName = fileName; LoadedFile.FolderPath = folderName; UpdateWindowTitle(); ApplicationStatus = string.Format("Saving file {0}...", fileName); try { using (EndianBinaryWriter writer = new EndianBinaryWriter(File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite), Endian.Big)) { LoadedFile.Save(writer); } } catch (Exception ex) { ApplicationStatus = string.Format("Exception while saving: {0}", ex.ToString()); } LoadedFile.FileName = fileName; ApplicationStatus = string.Format("Saved file {0}", LoadedFile.FileName); }
public static void loadFile(string path) { log = new Dictionary <string, List <float> >(); List <string> name_lookup = new List <string>(); using (TextFieldParser parser = new TextFieldParser(path)) { parser.TextFieldType = FieldType.Delimited; string separator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; parser.SetDelimiters(separator); //create columns string[] col_names = parser.ReadFields(); foreach (string name in col_names) { log.Add(name, new List <float>()); name_lookup.Add(name); } while (!parser.EndOfData) { //Processing row string[] fields = parser.ReadFields(); for (int i = 0; i < fields.Length; i++) { log[name_lookup[i]].Add(float.Parse(fields[i])); } } } columns = name_lookup.ToArray(); Console.WriteLine("Opened file: " + path); LoadedFile?.Invoke(); }
public void ResizingCannotLeaveTotallyBlankLineAtTop() { var loadedFile = new LoadedFile("test", new byte[36]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 6, Height = 6 }; viewPort.ScrollValue++; // scroll down one line viewPort.Width--; // decrease the width so that there is data 2 lines above // Example of what it should look like right now: // .. .. .. .. // .. .. .. 00 // 00 00 00 00 // 00 00 00 00 <- this is the top line in view // 00 00 00 00 // 00 00 00 00 // 00 00 00 00 // 00 00 00 00 <- this is the bottom line in view // .. .. .. .. viewPort.ScrollValue = viewPort.MinimumScroll; // scroll up to top viewPort.Width--; // decrease the width to hide the last visible byte in the top row // expected: viewPort should auto-scroll here to make the top line full of data again Assert.Equal(0, viewPort.ScrollValue); Assert.NotEqual(HexElement.Undefined, viewPort[0, 0]); }
public ActionResult Delete(Guid id, System.Web.Mvc.FormCollection collection) { using (MyLoadsConnection myLoads = new MyLoadsConnection()) { int myUserLoads = myLoads.LoadedFiles.ToList().Where(x => x.UserID == User.Identity.GetUserId()).Where((x => x.LoadedFileID == id)).Count(); if (User.IsInRole("Admin") || myUserLoads > 0) { string tableName = null; try { // TODO: Add delete logic here LoadedFile loadedfile = myLoads.LoadedFiles.Where(x => x.LoadedFileID == id).FirstOrDefault(); myLoads.LoadedFiles.Remove(loadedfile); tableName = loadedfile.LoadedFileID.ToString(); myLoads.Database.ExecuteSqlCommand("Drop Table [dbo].table_load_" + tableName.Replace("-", "_")); myLoads.SaveChanges(); //myLoads.Database.ExecuteSqlCommand("Delete From [dbo].Analysis WHERE [LoadedFileID] = " + id ); //myLoads.SaveChanges(); return(RedirectToAction("Index")); } catch { ViewBag.Message = "Table not droped"; return(View()); } } } return(RedirectToAction("Index")); }
protected override void CloneTextBox_LostFocus(object sender, EventArgs e) { base.CloneTextBox_LostFocus(sender, e); var mouseEventArgs = e as MouseEventExtArgs; if (!IsValid) { if (mouseEventArgs != null) { mouseEventArgs.Handled = true; } return; } if (e != null && mouseEventArgs == null) { return; } if (e != null) { System.Windows.Point absolutePoint = CloneTextBox.PointToScreen(new System.Windows.Point(0d, 0d)); var absoluteRectangle = new Rectangle((int)absolutePoint.X, (int)absolutePoint.Y, CloneTextBoxLocation.Width, CloneTextBoxLocation.Height); if (absoluteRectangle.Contains(mouseEventArgs.X, mouseEventArgs.Y)) { return; } } if (CloneTextBox.Tag.ToString() != CloneTextBox.Text) { if (!ChangedFileName) { RenameProject(CloneTextBox.Tag.ToString(), CloneTextBox.Text); } else { LoadedFile file = null; foreach (var proj in Notes) { foreach (var f in proj.Value.Files) { if (f.Path == CloneTextBox.Tag.ToString()) { file = f; break; } } } if (file == null) { return; } string directoryPath = Path.GetDirectoryName(file.Path) + "\\"; RenameFileInProject(Directory.GetParent(directoryPath).Parent.Name, file, CloneTextBox.Text); IsChangeFileName = false; } } // MainProjectList.Items.Refresh(); EndChangingDynamicItem(); }
public void ViewPortScrollStartsAtTopRow() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; Assert.Equal(0, viewPort.ScrollValue); }
public void addFile(LoadedFile file) { if (fileExists(Path.GetFileName(file.FilePath))) { MessageBox.Show($"A file with the name {Path.GetFileName(file.FilePath)} already exists in the current project", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } files.Add(file); resaveXml = true; }
public override bool TryDestroy(LoadedFile runtimeFileObject, ICollection <LoadedFile> allFileObjects) { if (allFileObjects.Contains(runtimeFileObject)) { var runtimeObject = runtimeFileObject.RuntimeObject; return(DestroyRuntimeObject(runtimeObject)); } return(false); }
public void ViewPortScrollingDoesNotAllowEmptyScreen() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; Assert.Equal(0, viewPort.MinimumScroll); Assert.Equal(4, viewPort.MaximumScroll); }
/* * Compile a single file into a ZerothDictionary */ public ZerothDictionary BuildFile(LoadedFile file) { logger?.log($"[Compiler] Building '{file.FileName}'"); ZerothCompilerState state = new ZerothCompilerState { }; return(null); }
public void CannotSelectFarAfterLastByte() { var loadedFile = new LoadedFile("test", new byte[20]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(4, 4); Assert.Equal(new Point(0, 4), viewPort.SelectionStart); }
public override bool AddToManagers(LoadedFile loadedFile) { if (loadedFile.RuntimeObject is LayeredTileMap) { ((LayeredTileMap)loadedFile.RuntimeObject).AddToManagers(); return(true); } else { return(false); } }
internal LoadedFile GetFile(string fullFileNameWithPath) { LoadedFile file = new LoadedFile { Filename = GetFileName(fullFileNameWithPath), FileBytes = File.ReadAllBytes(fullFileNameWithPath), FileExtension = fullFileNameWithPath.Split('.').Last() }; return(file); }
public void ViewPortCannotScrollLowerThanMinimumScroll() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; viewPort.ScrollValue = int.MinValue; Assert.Equal(viewPort.MinimumScroll, viewPort.ScrollValue); }
public void swapFiles(LoadedFile f1, LoadedFile f2) { int i1 = files.IndexOf(f1), i2 = files.IndexOf(f2); if (i1 < 0 || i2 < 0) { return; } files[i1] = f2; files[i2] = f1; resaveXml = true; }
public void EditMovesSelection() { var loadedFile = new LoadedFile("test", new byte[30]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(2, 2); viewPort.Edit("FF"); Assert.Equal(new Point(3, 2), viewPort.SelectionStart); }
public void BackSelectionWorks() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(3, 3); viewPort.SelectionEnd = new Point(2, 1); Assert.True(viewPort.IsSelected(new Point(4, 2))); }
public void ChangingWidthKeepsSameDataSelected() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; viewPort.SelectionEnd = new Point(2, 2); // 13 cells selected viewPort.Width += 1; Assert.Equal(new Point(0, 2), viewPort.SelectionEnd); // 13 cells selected }
public void RequestingOutOfRangeDataReturnsUndefinedFormat() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; Assert.Equal(HexElement.Undefined, viewPort[0, -1]); Assert.Equal(HexElement.Undefined, viewPort[5, 0]); Assert.Equal(HexElement.Undefined, viewPort[0, 5]); Assert.Equal(HexElement.Undefined, viewPort[-1, 0]); }
public void MovingCursorDownFromBottomRowScrolls() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 4 }; viewPort.SelectionStart = new Point(0, 3); viewPort.MoveSelectionStart.Execute(Direction.Down); Assert.Equal(1, viewPort.ScrollValue); }
public void EmptyPatch_TryApply_NoMetadataChange() { var sourceData = new byte[0x200].Fluent(array => array[1] = 1); var destinationData = new byte[0x200].Fluent(array => array[2] = 2); var patch = Patcher.BuildUpsPatch(sourceData, destinationData); var patchFile = new LoadedFile("patch.ups", patch); FileSystem.ShowOptions = (_, _, _, _) => 1; ViewPort.TryImport(patchFile, FileSystem); Assert.True(ViewPort.ChangeHistory.IsSaved); Assert.False(ViewPort.ChangeHistory.HasDataChange); }
public void SingleCharacterEditChangesToUnderEditFormat() { var loadedFile = new LoadedFile("test", new byte[30]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(0, 2); viewPort.Edit("F"); Assert.IsType <UnderEdit>(viewPort[0, 2].Format); Assert.Equal("F", ((UnderEdit)viewPort[0, 2].Format).CurrentText); }
public void CanEnterDataAfterLastByte() { var loadedFile = new LoadedFile("test", new byte[20]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(0, 4); viewPort.Edit("00"); Assert.NotEqual(Undefined.Instance, viewPort[0, 4].Format); Assert.Equal(new Point(1, 4), viewPort.SelectionStart); }
public void CanUndoEdit() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(2, 2); viewPort.Edit("AD"); viewPort.Undo.Execute(); Assert.Equal(0x00, viewPort[2, 2].Value); }
public void CursorCannotMoveAboveTopRow() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(3, 0); viewPort.MoveSelectionStart.Execute(Direction.Up); Assert.Equal(new Point(0, 0), viewPort.SelectionStart); // coerced to first byte }
public void MovingCursorRightFromRightEdgeMovesToNextLine() { var loadedFile = new LoadedFile("test", new byte[25]); var viewPort = new ViewPort(loadedFile) { PreferredWidth = -1, Width = 5, Height = 5 }; viewPort.SelectionStart = new Point(4, 0); viewPort.MoveSelectionStart.Execute(Direction.Right); Assert.Equal(new Point(0, 1), viewPort.SelectionStart); }