コード例 #1
0
        ICreateDocumentTask IDocumentService.CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                if (uri.Scheme == Uri.UriSchemeFile)
                {
                    var path = uri.LocalPath;
                    if (path == null || !UnifiedFile.Exists(path))
                    {
                        return null;
                    }

                    var fileViewer = this.GetFileViewerService(UnifiedPath.GetExtension(path));
                    if (fileViewer == null)
                    {
                        return null;
                    }

                    return this.CreateDocument(guid, uri, fileViewer);
                }
                else if (uri.Scheme == StreamScheme)
                {
                    var streamId = uri.Host + uri.PathAndQuery;
                    StreamInfo streamInfo;
                    if (!_registeredStreams.TryGetValue(streamId, out streamInfo))
                    {
                        this.LogWarning("no registered stream with ID '{0}' found", streamId);
                        return null;
                    }

                    _registeredStreams.Remove(streamId);

                    if (!streamInfo.StreamReference.IsAlive)
                    {
                        this.LogWarning("the registered stream with ID '{0}' is no more alive", streamId);
                        return null;
                    }

                    var fileViewer = this.GetFileViewerServiceOrNotifyMissing(streamInfo.FileType);
                    if (fileViewer == null)
                    {
                        return null;
                    }


                    IFeature[] features;

                    var viewer = fileViewer.CreateViewer(streamInfo.StreamReference.Target, out features);

                    var document = DocumentInfo.CreateTemporary(streamInfo.OwnerRepository.ID, streamInfo.Title, uri, viewer, features);
                    document.Description = streamInfo.Description;

                    return document;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }));
        }