public static void HandleDrop(Store store, string filename) { if (store == null || filename == null) { return; } try { StatusDisplay.Show($"Reading {filename}"); AssemblyProcessor assemblyProcessor = new AssemblyProcessor(store); TextFileProcessor textFileProcessor = new TextFileProcessor(store); textFileProcessor.LoadCache(filename); Process(store, filename, assemblyProcessor, textFileProcessor); } catch (Exception e) { ErrorDisplay.Show(e.Message); } finally { StatusDisplay.Show(string.Empty); } }
public static IEnumerable <ModelElement> HandleMultiDrop(Store store, IEnumerable <string> filenames) { List <ModelElement> newElements = new List <ModelElement>(); List <string> filenameList = filenames?.ToList(); if (store == null || filenameList == null) { return(newElements); } try { StatusDisplay.Show($"Processing {filenameList.Count} files"); AssemblyProcessor assemblyProcessor = new AssemblyProcessor(store); TextFileProcessor textFileProcessor = new TextFileProcessor(store); try { // may not work. Might not be a text file textFileProcessor.LoadCache(filenameList); } catch { // if not, no big deal. Either it's not a text file, or we'll just process suboptimally } foreach (string filename in filenameList) { newElements.AddRange(Process(store, filename, assemblyProcessor, textFileProcessor)); } } catch (Exception e) { ErrorDisplay.Show(store, e.Message); } finally { StatusDisplay.Show("Ready"); } return(newElements); }
private static void Process(Store store, string filename, AssemblyProcessor assemblyProcessor, TextFileProcessor textFileProcessor) { try { Cursor.Current = Cursors.WaitCursor; ModelRoot.BatchUpdating = true; if (IsAssembly(filename)) { using (Transaction tx = store.TransactionManager.BeginTransaction("Process dropped assembly")) { if (assemblyProcessor.Process(filename)) { StatusDisplay.Show("Creating diagram elements. This might take a while..."); tx.Commit(); ModelDisplay.LayoutDiagram(store.ModelRoot().GetActiveDiagram() as EFModelDiagram); } } } else { using (Transaction tx = store.TransactionManager.BeginTransaction("Process dropped class")) { if (textFileProcessor.Process(filename)) { StatusDisplay.Show("Creating diagram elements. This might take a while..."); tx.Commit(); } } } } finally { Cursor.Current = Cursors.Default; ModelRoot.BatchUpdating = false; StatusDisplay.Show(""); } }
private static IEnumerable <ModelElement> Process(Store store, string filename, AssemblyProcessor assemblyProcessor, TextFileProcessor textFileProcessor) { List <ModelElement> newElements; Cursor prev = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; ModelRoot.BatchUpdating = true; using (Transaction tx = store.TransactionManager.BeginTransaction("Process drop")) { bool processingResult = IsAssembly(filename) ? assemblyProcessor.Process(filename, out newElements) : textFileProcessor.Process(filename, out newElements); if (processingResult) { StatusDisplay.Show("Creating diagram elements. This might take a while..."); tx.Commit(); } else { newElements = new List <ModelElement>(); } } } finally { Cursor.Current = prev; ModelRoot.BatchUpdating = false; StatusDisplay.Show("Ready"); } return(newElements); }