Beispiel #1
0
        public async Task <IDocument> OpenDocument(DocumentPointer documentPointer, string loaderName = null)
        {
            var fileName = documentPointer.FileName;

            if (!File.Exists(fileName))
            {
                return(null);
            }

            if (IsOpen(fileName))
            {
                ActivateDocument(GetDocumentByFileName(fileName));
                return(null);
            }

            var loader = _loaders.FirstOrDefault(x => x.GetType().Name == loaderName && x.CanLoad(fileName));

            if (loader == null)
            {
                return(null);
            }

            var doc = await loader.Load(documentPointer);

            if (doc != null)
            {
                OpenDocument(doc);
            }

            return(doc);
        }
Beispiel #2
0
            public DocumentPointer ToPointer()
            {
                var so = new DocumentPointer(Loader);

                foreach (var m in Metadata)
                {
                    so.Set(m.Key, m.Value);
                }
                so.FileName = FileName;
                return(so);
            }
        /// <inheritdoc />
        public async Task <IDocument> Load(DocumentPointer documentPointer)
        {
            var fileName = documentPointer.FileName;
            var envId    = documentPointer.Get <string>("Environment");

            if (String.IsNullOrWhiteSpace(fileName) || String.IsNullOrWhiteSpace(envId))
            {
                return(null);
            }

            var env = _environments.Value.GetEnvironment(envId);

            if (env?.ID == null)
            {
                return(null);
            }

            if (!File.Exists(fileName))
            {
                return(null);
            }

            using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                foreach (var provider in _providers.Where(x => CanLoad(x.Value, fileName)))
                {
                    try
                    {
                        var result = await provider.Value.Load(stream, env);

                        if (result.Map == null)
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            continue;
                        }

                        var md = new MapDocument(result.Map, env)
                        {
                            FileName = fileName
                        };
                        await ProcessAfterLoad(env, md, result);

                        return(md);
                    }
                    catch (NotSupportedException)
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                    }
                }
            }

            return(null);
        }
        /// <inheritdoc />
        public DocumentPointer GetDocumentPointer(IDocument document)
        {
            if (!(document is MapDocument doc))
            {
                return(null);
            }
            var so = new DocumentPointer(nameof(BspSourceDocumentLoader))
            {
                FileName = doc.FileName
            };

            so.Set("Environment", doc.Environment.ID);
            return(so);
        }
Beispiel #5
0
 public static T GetRelatedDocument <T>(this IDocumentSession session, DocumentPointer <T> pointer)
 {
     return(session.Load <T>(pointer.Id));
 }
Beispiel #6
0
 public static T GetRelatedDocument <T>(this IRavenRepository session, DocumentPointer <T> pointer)
 {
     return(session.GetById <T>(pointer.Id));
 }