/// <summary>
        /// Creates an object from the given URI.
        /// </summary>
        /// <param name="uri">The URI that describes an object to be created.</param>
        /// <param name="attachmentSelector">The selector for acccess to attached to the given URI objects.</param>
        /// <returns>The object created from the given URI.</returns>
        public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector)
        {
            var uriBuilder = new ShellUriBuilder(uri);
            var title      = uriBuilder.Parameters["title"] ?? uri.ToString();

            return(this._entitledItemFactory(title));
        }
Exemple #2
0
        public IUriPlacementConnector Resolve(object resolved, Uri uri, UriAttachmentSelector attachmentSelector)
        {
            Contract.Requires <ArgumentNullException>(resolved != null);
            Contract.Requires <ArgumentNullException>(uri != null);
            Contract.Requires <ArgumentNullException>(attachmentSelector != null);

            return(default(IUriPlacementConnector));
        }
        public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector)
        {
            Contract.Requires <ArgumentNullException>(uri != null);
            Contract.Requires <ArgumentNullException>(attachmentSelector != null);

            Contract.Ensures(Contract.Result <object>() != null);

            return(default(object));
        }
Exemple #4
0
        /// <summary>
        /// Builds an URI, where parameter's values are replaced with generated identifiers of attached objects
        /// and provides a selector for getting this objects.
        /// </summary>
        /// <param name="uri">When this method returns, contains the URI, where parameter's values are replaced
        /// with generated identifiers of attached objects </param>
        /// <param name="attachmentSelector">When this method returns, contains the selector for getting objects
        /// attached to the URI with identifiers.</param>
        private void EmbedAttachments(out Uri uri, out UriAttachmentSelector attachmentSelector)
        {
            if (this._attachments.Length == 0)
            {
                attachmentSelector = id => null;
                uri = this._unresolvedUri;

                return;
            }

            var attachmentDictionary = new HybridDictionary(this._attachments.Length);
            var idGenerator          = new Random();

            // Replace parameter's values in the URI with identifiers.
            var uriBuilder = new ShellUriBuilder(this._unresolvedUri);

            for (int i = 0; i < uriBuilder.Parameters.Count; i++)
            {
                var value = uriBuilder.Parameters[i];

                // Detect object's placeholder by the string "{index}",
                // where index is integer from the attachment number's range.

                if (value.Length <= 2)
                {
                    continue;
                }
                if (value[0] != '{')
                {
                    continue;
                }
                if (value[value.Length - 1] != '}')
                {
                    continue;
                }

                value = value.Substring(1, value.Length - 2);

                int attachmentIndex;
                if (int.TryParse(value, out attachmentIndex))
                {
                    if (attachmentIndex >= this._attachments.Length)
                    {
                        continue;
                    }

                    value = idGenerator.Next().ToString();
                    attachmentDictionary[value] = this._attachments[attachmentIndex];
                }

                uriBuilder.Parameters[uriBuilder.Parameters.AllKeys[i]] = value;
            }

            attachmentSelector = id => id != null ? attachmentDictionary[id] : null;
            uri = uriBuilder.Uri;
        }
Exemple #5
0
        public IUriPlacementConnector Resolve(object resolved, Uri uri, UriAttachmentSelector attachmentSelector)
        {
            var builder = new ShellUriBuilder(uri);

            if (builder.Placement == "figures")
            {
                return(this._figurePlacementConnector);
            }

            return(null);
        }
        /// <summary>
        /// Determines an object's placement from the given URI.
        /// </summary>
        /// <param name="resolved">The object to be placed with the given URI.</param>
        /// <param name="uri">The URI used to determine an object's placement.</param>
        /// <param name="attachmentSelector">The selector for acccess to attached to the given URI objects.</param>
        /// <returns>The <see cref="IUriPlacementConnector"/> that allows to connect the given object to the
        /// user interface, if the placement was determined successfully; otherwise null.</returns>
        public IUriPlacementConnector Resolve(object resolved, Uri uri, UriAttachmentSelector attachmentSelector)
        {
            var builder = new ShellUriBuilder(uri);

            if (builder.Placement == "external" && resolved is Process)
            {
                return(this);
            }

            return(null);
        }
        /// <summary>
        /// Creates an object from the given URI.
        /// </summary>
        /// <param name="uri">The URI that describes an object to be created.</param>
        /// <param name="attachmentSelector">The selector for acccess to attached to the given URI objects.</param>
        /// <returns>The object created from the given URI.</returns>
        public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector)
        {
            var builder  = new ShellUriBuilder(uri);
            var fileName = builder.Parameters["fileName"];

            if (string.IsNullOrWhiteSpace(fileName))
            {
                return(null);
            }

            return(new Process
            {
                StartInfo = new ProcessStartInfo(fileName),
            });
        }
Exemple #8
0
        /// <summary>
        /// Gets the object responsible for the given URI's placement.
        /// </summary>
        /// <param name="uri">The URI of the object being resolved.</param>
        /// <param name="attachmentSelector">The selector for objects attached to the URI.</param>
        /// <param name="resolved">The object resolved via the URI.</param>
        /// <returns><see cref="IUriPlacementConnector"/> for connecting the object to an user interface.</returns>
        private IUriPlacementConnector ResolvePlacement(Uri uri, UriAttachmentSelector attachmentSelector, object resolved)
        {
            var placementConnector = this._uriResolutionCustomization
                                     .PlacementResolvers
                                     .Select(r => r.Resolve(resolved, uri, attachmentSelector))
                                     .FirstOrDefault(c => c != null);

            if (placementConnector != null)
            {
                return(placementConnector);
            }

            throw new UriResolutionException(
                      uri,
                      string.Format(Properties.Resources.UriPlacementNotFound, typeof(IUriPlacementResolver).Name));
        }
Exemple #9
0
        /// <summary>
        /// Gets the object responsible for resolution of the given URI.
        /// </summary>
        /// <param name="uri">The URI of the object being resolved.</param>
        /// <param name="attachmentSelector">The selector for objects attached to the URI.</param>
        /// <returns>The object responsible for resolution of the given URI. </returns>
        private object ResolveModuleItem(Uri uri, UriAttachmentSelector attachmentSelector)
        {
            var builder = new ShellUriBuilder(uri);
            var moduleItemResolverKey = new UriModuleItemResolverKey(builder.Module, builder.Item);

            IUriModuleItemResolver resolver;

            if (this._uriResolutionCustomization.ModuleItemResolvers.TryGetValue(moduleItemResolverKey, out resolver))
            {
                return(resolver.Resolve(uri, attachmentSelector));
            }

            throw new UriResolutionException(
                      uri,
                      string.Format(Properties.Resources.UriModuleItemResolverNotFound, typeof(IUriModuleItemResolver).Name));
        }
 public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector)
 {
     return(_factory());
 }
Exemple #11
0
 public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector)
 {
     return(this._squareViewModelFactory());
 }