public bool Open(Iori iori) { ThingGraphContent source = null; var sinkIo = ThingGraphIoManager.GetSinkIO(iori, IoMode.Read) as ThingGraphIo; try { // TODO: check if iori already in use source = sinkIo.Open(iori); OnProgress("", -1, -1); AttachCurrent(source, iori.Name); return(true); } catch (Exception ex) { Registry.Pooled <IExceptionHandler>() .Catch(new Exception("Open failed: " + ex.Message, ex), MessageType.OK); try { if (source != null) { sinkIo.Close(source); } } catch { } return(false); } }
public void ImportRawSource() { Save(); Close(Data); bool tryIt = true; while (tryIt && MessageBoxShow("Open a new, non exisiting file", "RawImport", MessageBoxButtons.OkCancel) == DialogResult.Ok) { var fileDialog = new FileDialogMemento(); DefaultDialogValues(fileDialog, WriteFilter); DefaultDialogValues(OpenFileDialog, ReadFilter); if (FileDialogShow(fileDialog, true) == DialogResult.Ok) { var sinkFile = fileDialog.FileName; fileDialog.ResetFileName(); if (File.Exists(sinkFile)) { continue; } if (tryIt = MessageBoxShow("Open the file to import", "RawImport", MessageBoxButtons.OkCancel) == DialogResult.Ok) { if (FileDialogShow(OpenFileDialog, true) == DialogResult.Ok) { var sourceFile = OpenFileDialog.FileName; if (!File.Exists(sourceFile)) { MessageBoxShow("File does not exist", "RawImport", MessageBoxButtons.Ok); break; } tryIt = false; var sourceInfo = Iori.FromFileName(sourceFile); var sinkIo = ThingGraphIoManager.GetSinkIO(Iori.FromFileName(sinkFile), IoMode.Write) as ThingGraphIo; ThingGraphContent sink = null; try { sink = sinkIo.Open(Iori.FromFileName(sinkFile)); var repairer = Registry.Pooled <ThingGraphRepairPool>() .Find(sourceInfo.Extension, IoMode.Read) as IPipe <Iori, IThingGraph>; this.AttachProgress(repairer as IProgress); repairer.Use(Iori.FromFileName(sourceFile), sink.Data); } catch (Exception ex) { Registry.Pooled <IExceptionHandler>() .Catch(new Exception("Raw import failed: " + ex.Message, ex), MessageType.OK); sinkIo.Close(sink); File.Delete(sinkFile); } sinkIo.Close(sink); MessageBoxShow("Import successfull", "RawImport", MessageBoxButtons.Ok); this.Open(Iori.FromFileName(sinkFile)); OpenFileDialog.ResetFileName(); } } } } }
public bool IsUnsaved(ThingGraphContent data) { var sink = ThingGraphIoManager.GetSinkIO(data.ContentType, IoMode.None) as ThingGraphIo; if (sink is MemoryThingGraphIo) { if (data.Data.Count > 0) { return(true); } } return(false); }
public void ExportSceneView(Iori iori, IGraphScene <IVisual, IVisualEdge> scene) { if (scene.HasThingGraph()) { var sinkIo = ThingGraphIoManager.GetSinkIO(iori, IoMode.Write) as ThingGraphIo; if (sinkIo != null) { var source = Registry.Create <ISceneViz <IVisual, IThing, IVisualEdge, ILink> > () .CreateThingsView(scene); var sink = sinkIo.Open(iori); new ThingGraphExporter { Progress = this.Progress }.Use(source, sink.Data); sinkIo.Close(sink); } } }
protected void Close(ThingGraphContent data) { if (data == null) { return; } Mesh.RemoveBackGraph(data.Data); Mesh.ClearDisplays(); var sink = ThingGraphIoManager.GetSinkIO(data.ContentType, IoMode.Write) as ThingGraphIo; if (sink != null) { sink.Close(data); ThingGraphClosed?.Invoke(data); } }
public bool ImportFiles(IEnumerable <string> sourceFiles) { var result = true; if (sourceFiles.Count() > 0) { var progressSaved = this.Progress; var progressHandler = Registry.Pooled <IProgressHandler> (); this.Progress = (m, i, max) => progressHandler.Write(m, i, max); try { foreach (var sourceFile in sourceFiles) { if (File.Exists(sourceFile)) { progressHandler.Show("Importing file " + sourceFile); var sourceIori = Iori.FromFileName(sourceFile); var sourceIo = ThingGraphIoManager.GetSinkIO(sourceIori, IoMode.Read) as ThingGraphIo; if (sourceIo != null) { ThingGraphContent source = null; try { source = sourceIo.Open(sourceIori); new ThingGraphMerger { Progress = this.Progress }.Use(source.Data, Data.Data); } catch (Exception ex) { Registry.Pooled <IExceptionHandler> () .Catch(new Exception("Add file failed: " + ex.Message, ex), MessageType.OK); result = false; } finally { sourceIo.Close(source); } } } } Progress = null; progressHandler.Close(); } finally { Progress = progressSaved; } } return(result); }
public void Save() { if (Data == null) { return; } if (IsUnsaved(this.Data)) { SaveAs(); } else { var sinkIo = ThingGraphIoManager.GetSinkIO(Data.ContentType, IoMode.Write) as ThingGraphIo; if (sinkIo != null) { sinkIo.Flush(Data); } } }
public bool SaveAs(Iori iori) { // save current: var oldSource = ""; ThingGraphIo sinkIo = null; if (Data.Source != null) { oldSource = this.Data.Source.ToString(); sinkIo = ThingGraphIoManager.GetSinkIO(Data.ContentType, IoMode.Write) as ThingGraphIo; if (sinkIo != null) { sinkIo.Flush(Data); } } // get the new: sinkIo = ThingGraphIoManager.GetSinkIO(iori, IoMode.Write) as ThingGraphIo; if (sinkIo == null) { return(false); } var sink = sinkIo.Open(iori); // saveAs: var merger = new ThingGraphMerger { Progress = this.Progress }; merger.Use(Data.Data, sink.Data); merger.AttachThings(sink.Data); // close and reopen; flush and attach does't work in all cases sinkIo.Close(sink); sink = sinkIo.Open(iori); AttachCurrent(sink, iori.Name); OnProgress(string.Format("{0} saved as {1}", Path.GetFileNameWithoutExtension(oldSource), iori.Name), -1, -1); return(true); }
public void Open() { if (Current != null) { Trace.WriteLine(string.Format("Provider already opened {0}", Current.Description)); var conn = Current.Data as IGatewayConnection; if (conn != null) { Trace.WriteLine(string.Format("Connection already opened {0}/{1}", conn.Gateway.IsOpen, conn.Gateway.Iori.ToFileName())); } } else { var ioManager = new ThingGraphIoManager { }; var sinkIo = ioManager.GetSinkIO(Iori, IoMode.Read) as ThingGraphIo; try { var sink = sinkIo.Open(Iori); if (sink != null) { Trace.WriteLine(string.Format("DataBase opened {0}", Iori.ToFileName())); Current = sink; var graph = new SchemaThingGraph(Current.Data); PrepareGraph(graph); _thingGraph = graph; } else { throw new Exception("Database not found: " + Iori.ToString()); } } catch (Exception e) { Trace.WriteLine(e.Message); _thingGraph = new ThingGraph(); Trace.WriteLine(string.Format("Empty Graph created {0}", Iori.ToFileName())); } } }