Exemplo n.º 1
0
        /// <summary>
        /// Gets or creates specific document and opens it.
        /// </summary>
        /// <param name="uri">The URI of the document. Can be a file path URI.</param>
        /// <param name="suppressOpen"><c>true</c> if the document should not be opened.</param>
        public static IDocument GetDocument(this IShell shell, Uri uri, bool suppressOpen)
        {
            var doc = GetDocuments(shell).FirstOrDefault(s => s.Uri == uri);
            if (doc == null)
            {
                doc = IoC.GetAllInstances(typeof(IDocumentProvider))
                    .Cast<IDocumentProvider>()
                    .Where(provider => provider.Handles(uri))
                    .Select(provider => provider.Create(uri))
                    .FirstOrDefault();

                if (doc != null && !suppressOpen)
                    shell.ActivateDocument(doc);
            }
            return doc;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a specific sink based on the uri.
        /// </summary>
        /// <param name="uri">The sink URI.</param>
        /// <param name="suppressOpen">If set to <c>true</c> sink will not be opened, but just created.</param>
        /// <returns></returns>
        public static ISink GetSink(this IShell shell, Uri uri, bool suppressOpen)
        {
            if (uri == null) throw new ArgumentNullException("uri");
            var sinks = GetSinks(shell);
            var sink = sinks.FirstOrDefault(s => s.Uri == uri);
            if (sink == null)
            {
                sink = IoC.GetAllInstances(typeof(ISinkProvider))
                    .Cast<ISinkProvider>()
                    .Where(provider => provider.Handles(uri))
                    .Select(provider => provider.Create(uri))
                    .FirstOrDefault();

                if (sink != null && !suppressOpen)
                    shell.ActivateDocument(sink);
            }
            return sink;
        }