Пример #1
0
        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);
            }
        }
Пример #2
0
        protected override ThingGraphContent OpenInternal(Iori source)
        {
            var gateway = new Limaki.Data.db4o.Gateway();

            try {
                gateway.Open(source);

                var sink = new ThingGraphContent {
                    Data        = new ThingGraph(gateway),
                    Source      = source,
                    ContentType = Db4oThingGraphSpot.Db4oThingGraphContentType,
                };
                return(sink);
            } catch (DatabaseFileLockedException ex) {
                throw;
            } catch (Exception ex) {
                if (ex.InnerException != null && ex.InnerException is DatabaseFileLockedException)
                {
                    throw ex.InnerException;
                }
                else
                {
                    var olderVersion = ProveIfOlderVersion(gateway);
                    if (olderVersion != null)
                    {
                        throw new NotSupportedException(olderVersion, ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Пример #3
0
 public virtual void Close()
 {
     if (ThingGraphIo != null)
     {
         ThingGraphIo.Close(GraphContent);
         this.GraphContent = null;
     }
 }
Пример #4
0
 public void Close()
 {
     if (Current != null)
     {
         Close(Current);
         Trace.WriteLine(string.Format("DataBase closed {0}", Iori.ToFileName()));
         Current = null;
     }
 }
Пример #5
0
        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();
                        }
                    }
                }
            }
        }
Пример #6
0
        public override void Close(ThingGraphContent sink)
        {
            Flush(sink);
            var graph = sink.Data as ThingGraph;

            if (graph != null)
            {
                graph.Close();
            }
        }
Пример #7
0
        public override Iori Use(ThingGraphContent source)
        {
            var result     = base.Use(source);
            var thingGraph = source.Data as ThingGraph;

            if (thingGraph != null)
            {
                result = thingGraph.Gateway.Iori;
            }
            return(result);
        }
Пример #8
0
 public override void Flush(ThingGraphContent sink)
 {
     if (sink.Data != null)
     {
         var graph = sink.Data as ThingGraph;
         if (graph != null)
         {
             graph.Flush();
         }
     }
 }
Пример #9
0
        public static Iori GetIori(IGraph <IThing, ILink> g)
        {
            var graphContent = new ThingGraphContent {
                Data = g.UnWrapped() as IThingGraph
            };

            return(Registry.Pooled <ThingGraphIoPool> ()
                   .OfType <ThingGraphIo> ()
                   .Select(io => io.Use(graphContent))
                   .Where(i => i != null)
                   .FirstOrDefault());
        }
Пример #10
0
        public virtual ThingGraphContent Use(Iori source, ThingGraphContent sink)
        {
            var result = Open(source);

            if (sink.Data == null)
            {
                return(result);
            }
            else
            {
                throw new NotImplementedException("Merging not implemented");
            }
        }
Пример #11
0
        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);
        }
Пример #12
0
        protected void Close(ThingGraphContent data)
        {
            if (data == null)
            {
                return;
            }
            var sinkIo = new ThingGraphIoManager {
            }.GetSinkIO(data.ContentType, IoMode.Write) as ThingGraphIo;

            if (sinkIo != null)
            {
                sinkIo.Close(data);
            }
        }
Пример #13
0
        public bool AttachCurrent(ThingGraphContent source, string message)
        {
            Close(Data);

            Data = source;

            ThingGraphIn?.Invoke(source);

            Mesh.ApplyBackGraph(source.Data);

            DataBound?.Invoke();

            DataPostProcess?.Invoke(message);

            return(true);
        }
Пример #14
0
        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);
            }
        }
Пример #15
0
        public virtual void Save(ThingGraphContent source, Iori sinkInfo)
        {
            if (source == null)
            {
                return;
            }

            using (var sink = new FileStream(sinkInfo.ToFileName(), FileMode.Create)) {
                var serializer = new ThingXmlSerializer {
                    Graph = source.Data, Things = source.Data.Elements().ToList()
                };

                serializer.Write(sink);

                sink.Flush();
                sink.Close();
            }
            source.Source = sinkInfo;
        }
Пример #16
0
        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);
        }
Пример #17
0
        public static ThingGraphContent GetContent(IGraph <IThing, ILink> g)
        {
            var graphContent = new ThingGraphContent {
                Data = g.UnWrapped() as IThingGraph
            };
            var iog = Registry.Pooled <ThingGraphIoPool>()
                      .OfType <ThingGraphIo>()
                      //.Select(io => io.Use(graphContent))
                      .Where(io => io.Use(graphContent) != null)
                      .FirstOrDefault();

            if (iog == null)
            {
                return(graphContent);
            }

            var iori = iog.Use(graphContent);
            var ct   = iog.Use(iori);

            graphContent.Source      = iori;
            graphContent.ContentType = ct.ContentType;
            return(graphContent);
        }
Пример #18
0
 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()));
         }
     }
 }
Пример #19
0
 public virtual Iori Use(ThingGraphContent source)
 {
     // Close(source);
     return(source.Source as Iori);
 }
Пример #20
0
 public abstract void Close(ThingGraphContent sink);
Пример #21
0
 public abstract void Flush(ThingGraphContent sink);
Пример #22
0
 public virtual Iori Use(ThingGraphContent source, Iori sink)
 {
     source.Source = sink;
     // Close(source);
     return(sink);
 }
Пример #23
0
 public override void Flush(ThingGraphContent sink)
 {
 }
Пример #24
0
 public override void Close(ThingGraphContent sink)
 {
 }
Пример #25
0
        public override void Close(ThingGraphContent sink)
        {
            var sinkIo = ThingGraphIoManager.GetSinkIO(sink.Source as Iori, IoMode.Write) as ThingGraphIo;

            Close(sink);
        }
Пример #26
0
 public override void Flush(ThingGraphContent sink)
 {
     Save(sink, sink.Source as Iori);
 }