Exemple #1
0
 public virtual void Link(ILinkResolver root)
 {
     foreach (var link in GetLinks().Where(lnk => lnk.Direction == enLinkDirection.Input))
     {
         link.Link(root);
     }
 }
Exemple #2
0
        /// <summary>
        /// Populates a Content List (of Teasers) by executing the query it specifies.
        /// </summary>
        /// <param name="contentList">The Content List which specifies the query and is to be populated.</param>
        /// <param name="localization">The context Localization.</param>
        public virtual void PopulateDynamicList <T>(ContentList <T> contentList, Localization localization) where T : EntityModel
        {
            using (new Tracer(contentList, localization))
            {
                BrokerQuery query = new BrokerQuery
                {
                    Start         = contentList.Start,
                    PublicationId = Int32.Parse(localization.LocalizationId),
                    PageSize      = contentList.PageSize,
                    SchemaId      = MapSchema(contentList.ContentType.Key, localization),
                    Sort          = contentList.Sort.Key
                };

                // TODO: For now BrokerQuery always returns Teasers
                IEnumerable <Teaser> queryResults = query.ExecuteQuery();

                ILinkResolver linkResolver = SiteConfiguration.LinkResolver;
                foreach (Teaser item in queryResults)
                {
                    item.Link.Url = linkResolver.ResolveLink(item.Link.Url);
                }

                contentList.ItemListElements = queryResults.Cast <T>().ToList();
                contentList.HasMore          = query.HasMore;
            }
        }
 public WebhooksClient(
     IHalClient halClient,
     ILinkFactory linkFactory)
 {
     _halClient    = halClient;
     _linkFactory  = linkFactory;
     _linkResolver = new LinkResolver();
 }
Exemple #4
0
        public OAuth2Client(IHttpConnection connection, IGogoKitConfiguration configuration)
        {
            Requires.ArgumentNotNull(connection, nameof(connection));
            Requires.ArgumentNotNull(configuration, nameof(configuration));

            _connection    = connection;
            _configuration = configuration;
            _linkResolver  = new LinkResolver();
        }
Exemple #5
0
 private static HalClient CreateClient(IHttpConnection conn        = null,
                                       IHalKitConfiguration config = null,
                                       ILinkResolver resolver      = null)
 {
     return(new HalClient(
                config ?? new HalKitConfiguration(new Uri("http://foo.api.io")),
                conn ?? new FakeHttpConnection(),
                resolver ?? new Mock <ILinkResolver>(MockBehavior.Loose).Object));
 }
        public DefaultRichTextResolver(ILinkResolver linkResolver, ILogger logger, IDD4TConfiguration configuration)
        {
            Contract.ThrowIfNull(linkResolver, nameof(linkResolver));
            Contract.ThrowIfNull(logger, nameof(logger));
            Contract.ThrowIfNull(configuration, nameof(configuration));

            _linkResolver  = linkResolver;
            _logger        = logger;
            _configuration = configuration;
        }
Exemple #7
0
        public CatalogMenuItemProvider(
            ICommonServices services,
            ICategoryService categoryService,
            ILinkResolver linkResolver)
        {
            _services        = services;
            _categoryService = categoryService;
            _linkResolver    = linkResolver;

            T = NullLocalizer.Instance;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OctopusServerEndpoint" /> class.
        /// </summary>
        /// <param name="octopusServer">The resolver that should be used to turn relative links into full URIs.</param>
        /// <param name="apiKey">
        /// The API key to use when connecting to the Octopus server. For more information on API keys, please
        /// see the API documentation on authentication
        /// (https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/sections/authentication.md).
        /// </param>
        /// <param name="credentials">
        /// Additional credentials to use when communicating to servers that require integrated/basic
        /// authentication.
        /// </param>
        public OctopusServerEndpoint(ILinkResolver octopusServer, string apiKey, ICredentials credentials)
        {
            if (string.IsNullOrWhiteSpace(apiKey))
            {
                throw new ArgumentException("An API key was not specified. Please set an API key using the ApiKey property. This can be gotten from your user profile page under the Octopus web portal.");
            }

            this.octopusServer = octopusServer;
            this.apiKey        = apiKey;
            this.credentials   = credentials ?? CredentialCache.DefaultNetworkCredentials;
        }
Exemple #9
0
        public CatalogMenuItemProvider(
            IStoreContext storeContext,
            ICategoryService categoryService,
            ILinkResolver linkResolver)
        {
            _storeContext    = storeContext;
            _categoryService = categoryService;
            _linkResolver    = linkResolver;

            T = NullLocalizer.Instance;
        }
Exemple #10
0
        public void Link(ILinkResolver root)
        {
            if (__LinkedToID == Guid.Empty)
            {
                return;
            }

            var lnk = root.GetLink(__LinkedToID, __LinkedTOLinkName);

            LinkTo(lnk);
        }
Exemple #11
0
        public OctopusSession(Uri serverBaseUri, ICredentials credentials, string apiKey, ILog log, ILinkResolver linkResolver = null)
        {
            this.credentials  = credentials;
            this.apiKey       = apiKey;
            this.log          = log;
            this.linkResolver = linkResolver ?? new DefaultLinkResolver(serverBaseUri);

            serializerSettings = new JsonSerializerSettings();
            serializerSettings.Converters.Add(new IsoDateTimeConverter());

            rootDocument = new Lazy <RootDocument>(EstablishSession);
        }
Exemple #12
0
 public BatchClient(
     IHttpConnection connection,
     IApiResponseFactory responseFactory,
     IJsonSerializer jsonSerializer,
     ILinkResolver linkResolver)
 {
     _responseFactory = responseFactory;
     _httpConnection  = connection;
     _configuration   = connection.Configuration;
     _jsonSerializer  = jsonSerializer;
     _linkResolver    = linkResolver;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OctopusServerEndpoint" /> class.
        /// </summary>
        /// <param name="octopusServerAddress">
        /// The URI of the Octopus Server. Ideally this should end with <c>/api</c>. If it ends with any other segment, the
        /// client
        /// will assume Octopus runs under a virtual directory.
        /// </param>
        /// <param name="apiKey">
        /// The API key to use when connecting to the Octopus server. For more information on API keys, please
        /// see the API documentation on authentication
        /// (https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/sections/authentication.md).
        /// </param>
        /// <param name="credentials">
        /// Additional credentials to use when communicating to servers that require integrated/basic
        /// authentication.
        /// </param>
        public OctopusServerEndpoint(string octopusServerAddress, string apiKey, ICredentials credentials)
        {
            if (string.IsNullOrWhiteSpace(octopusServerAddress))
                throw new ArgumentException("An Octopus server URI was not specified.");

            Uri uri;
            if (!Uri.TryCreate(octopusServerAddress, UriKind.Absolute, out uri) || !uri.Scheme.StartsWith("http"))
                throw new ArgumentException("The Octopus server URI given was invalid. The URI should start with http:// or https:// and be a valid URI.");

            octopusServer = new DefaultLinkResolver(new Uri(octopusServerAddress));
            this.apiKey = apiKey;
            this.credentials = credentials ?? CredentialCache.DefaultNetworkCredentials;
        }
Exemple #14
0
        //private readonly IBinaryFactory _binaryFactory;


        public DefaultRichTextResolver(ILinkResolver linkResolver, ILogger logger, IDD4TConfiguration configuration)
        {
            //binaryFactory.ThrowIfNull(nameof(binaryFactory));
            //linkFactory.ThrowIfNull(nameof(linkFactory));
            Contract.ThrowIfNull(linkResolver, nameof(linkResolver));
            Contract.ThrowIfNull(logger, nameof(logger));
            Contract.ThrowIfNull(configuration, nameof(configuration));

            //_binaryFactory = binaryFactory;
            //_linkFactory = linkFactory;
            _linkResolver  = linkResolver;
            _logger        = logger;
            _configuration = configuration;
        }
 public TopicController(
     SmartDbContext db,
     ILocalizedEntityService localizedEntityService,
     IStoreMappingService storeMappingService,
     IAclService aclService,
     ILinkResolver linkResolver,
     IUrlService urlService)
 {
     _db = db;
     _localizedEntityService = localizedEntityService;
     _storeMappingService    = storeMappingService;
     _aclService             = aclService;
     _linkResolver           = linkResolver;
     _urlService             = urlService;
 }
Exemple #16
0
        public HalClient(IHalKitConfiguration configuration,
                         IHttpConnection httpConnection,
                         ILinkResolver linkResolver)
        {
            Requires.ArgumentNotNull(httpConnection, nameof(httpConnection));
            Requires.ArgumentNotNull(configuration, nameof(configuration));
            Requires.ArgumentNotNull(linkResolver, nameof(linkResolver));
            if (configuration.RootEndpoint == null)
            {
                throw new ArgumentException($"{nameof(configuration)} must have a RootEndpoint");
            }

            HttpConnection = httpConnection;
            Configuration  = configuration;
            _linkResolver  = linkResolver;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OctopusServerEndpoint" /> class.
        /// </summary>
        /// <param name="octopusServerAddress">
        /// The URI of the Octopus Server. Ideally this should end with <c>/api</c>. If it ends with any other segment, the
        /// client
        /// will assume Octopus runs under a virtual directory.
        /// </param>
        /// <param name="apiKey">
        /// The API key to use when connecting to the Octopus Server. For more information on API keys, please
        /// see the API documentation on authentication
        /// (https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/sections/authentication.md).
        /// </param>
        /// <param name="credentials">
        /// Additional credentials to use when communicating to servers that require integrated/basic
        /// authentication.
        /// </param>
        public OctopusServerEndpoint(string octopusServerAddress, string apiKey, ICredentials credentials)
        {
            if (string.IsNullOrWhiteSpace(octopusServerAddress))
            {
                throw new ArgumentException("An Octopus Server URI was not specified.");
            }

            if (!Uri.TryCreate(octopusServerAddress, UriKind.Absolute, out var uri) || !uri.Scheme.StartsWith("http"))
            {
                throw new ArgumentException($"The Octopus Server URI '{octopusServerAddress}' is invalid. The URI should start with http:// or https:// and be a valid URI.");
            }

            octopusServer    = new DefaultLinkResolver(new Uri(octopusServerAddress));
            this.apiKey      = apiKey;
            this.credentials = credentials ?? CredentialCache.DefaultNetworkCredentials;
        }
Exemple #18
0
        static TridionHelper()
        {
            //this is Anti-Pattern, there is no other way to inject dependencies into this class.
            //This helper should not be used in views, this logic should get executed by the controller.

            var config = DependencyResolver.Current.GetService <IDD4TConfiguration>();
            //var linkFactory = DependencyResolver.Current.GetService<ILinkFactory>();
            var logger       = DependencyResolver.Current.GetService <ILogger>();
            var renderer     = DependencyResolver.Current.GetService <IComponentPresentationRenderer>();
            var linkResolver = DependencyResolver.Current.GetService <ILinkResolver>();

            //_linkFactory = linkFactory;
            _configuration = config;
            _logger        = logger;
            _renderer      = renderer;
            _linkResolver  = linkResolver;
        }
Exemple #19
0
        static TridionHelper()
        {
            //this is Anti-Pattern, there is no other way to inject dependencies into this class.
            //This helper should not be used in views, this logic should get executed by the controller.

            var config = DependencyResolver.Current.GetService<IDD4TConfiguration>();
            //var linkFactory = DependencyResolver.Current.GetService<ILinkFactory>();
            var logger = DependencyResolver.Current.GetService<ILogger>();
            var renderer = DependencyResolver.Current.GetService<IComponentPresentationRenderer>();
            var linkResolver = DependencyResolver.Current.GetService<ILinkResolver>();

            //_linkFactory = linkFactory;
            _configuration = config;
            _logger = logger;
            _renderer = renderer;
            _linkResolver = linkResolver;
        }
Exemple #20
0
 public TopicController(
     ITopicService topicService,
     ILanguageService languageService,
     ILocalizedEntityService localizedEntityService,
     IStoreMappingService storeMappingService,
     IUrlRecordService urlRecordService,
     IAclService aclService,
     IMenuStorage menuStorage,
     ILinkResolver linkResolver)
 {
     _topicService           = topicService;
     _languageService        = languageService;
     _localizedEntityService = localizedEntityService;
     _storeMappingService    = storeMappingService;
     _urlRecordService       = urlRecordService;
     _aclService             = aclService;
     _menuStorage            = menuStorage;
     _linkResolver           = linkResolver;
 }
        public AssetHandler(
            IContentRepository contentRepository,
            IBlobFactory blobFactory,
            IContextResolver contextResolver,
            ILinkResolver linkResolver,
            IContentTypeRepository contentTypeRepository,
            ContentMediaResolver contentMediaResolver)
        {
            Guard.ValidateObject(contentRepository);
            Guard.ValidateObject(blobFactory);
            Guard.ValidateObject(contextResolver);
            Guard.ValidateObject(linkResolver);
            Guard.ValidateObject(contentTypeRepository);
            Guard.ValidateObject(contentMediaResolver);

            _contentRepository     = contentRepository;
            _blobFactory           = blobFactory;
            _contextResolver       = contextResolver;
            _linkResolver          = linkResolver;
            _contentTypeRepository = contentTypeRepository;
            _contentMediaResolver  = contentMediaResolver;
        }
        public override void Link(ILinkResolver root)
        {
            base.Link(root);

            JoystickConfig joy;

            if (__CurrentConfig == null)
            {
                joy = fmMain.JoyInfos.FirstOrDefault(j => j.ID == __PreMapConfigID) ??
                      fmMain.JoyInfos.FirstOrDefault();
            }
            else
            {
                joy = fmMain.JoyInfos.FirstOrDefault(j => j.ID == __CurrentConfig.ID) ??
                      fmMain.JoyInfos.FirstOrDefault();
            }

            if (joy == null)
            {
                throw new ArgumentException("Wrong joystick ID or no joystick in configuration file");
            }

            InitializePanels(joy);
        }
Exemple #23
0
 public MetaDataViewModel(IPageMetaDataProperties model, ILinkResolver linkResolver)
 {
     Current       = model;
     _linkResolver = linkResolver;
 }
Exemple #24
0
 public CatalogHelper(
     SmartDbContext db,
     ICommonServices services,
     IMenuService menuService,
     IManufacturerService manufacturerService,
     IProductService productService,
     //IProductTemplateService productTemplateService,
     IProductAttributeService productAttributeService,
     IProductAttributeMaterializer productAttributeMaterializer,
     IProductAttributeFormatter productAttributeFormatter,
     ITaxService taxService,
     ICurrencyService currencyService,
     IMediaService mediaService,
     IPriceCalculationService priceCalculationService,
     //IPriceFormatter priceFormatter,
     //ISpecificationAttributeService specificationAttributeService,
     IDateTimeHelper dateTimeHelper,
     //IBackInStockSubscriptionService backInStockSubscriptionService,
     IDownloadService downloadService,
     MediaSettings mediaSettings,
     CatalogSettings catalogSettings,
     CustomerSettings customerSettings,
     CaptchaSettings captchaSettings,
     IMeasureService measureService,
     //IQuantityUnitService quantityUnitService,
     MeasureSettings measureSettings,
     TaxSettings taxSettings,
     PerformanceSettings performanceSettings,
     IDeliveryTimeService deliveryTimeService,
     Lazy <IDataExporter> dataExporter,
     ICatalogSearchService catalogSearchService,
     ICatalogSearchQueryFactory catalogSearchQueryFactory,
     IUrlHelper urlHelper,
     ProductUrlHelper productUrlHelper,
     ILocalizedEntityService localizedEntityService,
     IUrlService urlService,
     ILinkResolver linkResolver)
 {
     _db                  = db;
     _services            = services;
     _workContext         = services.WorkContext;
     _storeContext        = services.StoreContext;
     _cache               = services.Cache;
     _menuService         = menuService;
     _manufacturerService = manufacturerService;
     _productService      = productService;
     //_productTemplateService = productTemplateService;
     _productAttributeService      = productAttributeService;
     _productAttributeMaterializer = productAttributeMaterializer;
     _productAttributeFormatter    = productAttributeFormatter;
     _taxService              = taxService;
     _currencyService         = currencyService;
     _mediaService            = mediaService;
     _localizationService     = _services.Localization;
     _priceCalculationService = priceCalculationService;
     //_priceFormatter = priceFormatter;
     //_specificationAttributeService = specificationAttributeService;
     _dateTimeHelper = dateTimeHelper;
     //_backInStockSubscriptionService = backInStockSubscriptionService;
     _downloadService = downloadService;
     _measureService  = measureService;
     //_quantityUnitService = quantityUnitService;
     _measureSettings           = measureSettings;
     _taxSettings               = taxSettings;
     _performanceSettings       = performanceSettings;
     _deliveryTimeService       = deliveryTimeService;
     _mediaSettings             = mediaSettings;
     _catalogSettings           = catalogSettings;
     _customerSettings          = customerSettings;
     _captchaSettings           = captchaSettings;
     _dataExporter              = dataExporter;
     _catalogSearchService      = catalogSearchService;
     _catalogSearchQueryFactory = catalogSearchQueryFactory;
     _urlHelper              = urlHelper;
     _productUrlHelper       = productUrlHelper;
     _localizedEntityService = localizedEntityService;
     _urlService             = urlService;
     _linkResolver           = linkResolver;
     _httpRequest            = _urlHelper.ActionContext.HttpContext.Request;
 }
Exemple #25
0
 public virtual void Link(ILinkResolver root)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OctopusServerEndpoint" /> class.
        /// </summary>
        /// <param name="octopusServer">The resolver that should be used to turn relative links into full URIs.</param>
        /// <param name="apiKey">
        /// The API key to use when connecting to the Octopus server. For more information on API keys, please
        /// see the API documentation on authentication
        /// (https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/sections/authentication.md).
        /// </param>
        /// <param name="credentials">
        /// Additional credentials to use when communicating to servers that require integrated/basic
        /// authentication.
        /// </param>
        public OctopusServerEndpoint(ILinkResolver octopusServer, string apiKey, ICredentials credentials)
        {
            if (string.IsNullOrWhiteSpace(apiKey))
                throw new ArgumentException("An API key was not specified. Please set an API key using the ApiKey property. This can be gotten from your user profile page under the Octopus web portal.");

            this.octopusServer = octopusServer;
            this.apiKey = apiKey;
            this.credentials = credentials ?? CredentialCache.DefaultNetworkCredentials;
        }
 public MetaDataViewModel(IPageMetaDataProperties model, ILinkResolver linkResolver)
 {
     Current = model;
     _linkResolver = linkResolver;
 }
Exemple #28
0
        public EntityMenuItemProvider(ILinkResolver linkResolver)
        {
            _linkResolver = linkResolver;

            T = NullLocalizer.Instance;
        }
Exemple #29
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiRichView));

            string defaultFont        = file["Font"] as string;
            int    defaultFontSize    = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0);
            int    defaultFontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], int.MaxValue);

            for (int idx = 0; idx < (int)FontType.Count; ++idx)
            {
                FontType type    = (FontType)idx;
                string   font    = string.Format("{0}.Font", type);
                string   spacing = string.Format("{0}.FontSpacing", type);
                string   resize  = string.Format("{0}.FontResize", type);

                string fontName    = file[font] as string;
                int    fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file[spacing], defaultFontSpacing == int.MaxValue ? 0 : defaultFontSpacing);
                int    fontResize  = DefinitionResolver.Get <int>(Controller, Binding, file[resize], 0);

                if (fontName == null)
                {
                    fontName = defaultFont;
                }

                FontFace fontObj = FontManager.Instance.FindFont(fontName);

                if (defaultFont == null)
                {
                    defaultFont = fontName;
                }

                if (defaultFontSpacing == int.MaxValue)
                {
                    defaultFontSpacing = fontSpacing;
                }

                _fonts[idx] = new FontInfo()
                {
                    Font        = fontObj,
                    FontSpacing = (float)fontSpacing / 1000.0f,
                    FontResize  = fontResize
                };
            }

            for (int idx = 0; idx < (int)SizeType.Count; ++idx)
            {
                SizeType type = (SizeType)idx;
                string   size = string.Format("{0}.FontSize", type);

                int fontSize = DefinitionResolver.Get <int>(Controller, Binding, file[size], defaultFontSize);

                if (defaultFontSize == 0)
                {
                    defaultFontSize = fontSize;
                }

                _sizes[idx] = fontSize;
            }

            _bulletText = DefinitionResolver.GetString(Controller, Binding, file["BulletText"]) ?? "* ";
            //_bulletText = _bulletText.Replace(" ", ((char)0xa0).ToString());

            _horizontalRulerHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["HorizontalRulerHeight"], new Length(0, 0, 1));
            _indentSize            = DefinitionResolver.Get <Length>(Controller, Binding, file["Indent"], Length.Zero);
            _paragraphSpacing      = DefinitionResolver.Get <Length>(Controller, Binding, file["ParagraphSpacing"], Length.Zero);
            _imageNotLoaded        = DefinitionResolver.Get <Texture2D>(Controller, Binding, file["ImageNotLoaded"], AdvancedDrawBatch.OnePixelWhiteTexture);
            _lineHeight            = (float)DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100) / 100.0f;
            _justify = DefinitionResolver.Get <bool>(Controller, Binding, file["Justify"], false);

            _linkResolver = DefinitionResolver.Get <ILinkResolver>(Controller, Binding, file["LinkResolver"], this);

            _baseLineCorrection = DefinitionResolver.Get <bool>(Controller, Binding, file["EnableBaseLineCorrection"], false);

            Type processorType = file["Processor"] as Type;

            if (processorType != null)
            {
                _richProcessor = Activator.CreateInstance(processorType) as IRichProcessor;
            }

            Text = DefinitionResolver.GetString(Controller, Binding, file["Text"]);

            _colorNormal          = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? UiLabel.DefaultTextColor;
            _colorClickable       = DefinitionResolver.GetColorWrapper(Controller, Binding, file["LinkColor"]) ?? UiLabel.DefaultTextColor;
            _colorClickableActive = DefinitionResolver.GetColorWrapper(Controller, Binding, file["ActiveLinkColor"]) ?? _colorClickable;
            _colorRuler           = DefinitionResolver.GetColorWrapper(Controller, Binding, file["HorizontalRulerColor"]) ?? UiLabel.DefaultTextColor;

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top);

            _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);

            _clickMargin = DefinitionResolver.Get <Length>(Controller, Binding, file["ClickMargin"], Length.Zero);

            RegisterDelegate("UrlClick", file["UrlClick"]);

            EnabledGestures = (GestureType.Down | GestureType.Up | GestureType.Move | GestureType.Tap);

            return(true);
        }
Exemple #30
0
 public PageTypeResolver(ILinkResolver objectLinkResolver, IListLinkResolver listLinkResolver)
 {
     this.objectLinkResolver = objectLinkResolver;
     this.listLinkResolver   = listLinkResolver;
 }
Exemple #31
0
        private RichText ResolveRichText(XmlDocument doc, Localization localization)
        {
            const string xlinkNamespaceUri = "http://www.w3.org/1999/xlink";

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");
            nsmgr.AddNamespace("xlink", xlinkNamespaceUri);

            // Process/resolve hyperlinks with XLink attributes
            ILinkResolver linkResolver = SiteConfiguration.LinkResolver;

            foreach (XmlElement linkElement in doc.SelectNodes("//a[@xlink:href]", nsmgr))
            {
                // DD4T BinaryPublisher may have resolved a href attribute already (for links to MM Components)
                string linkUrl = linkElement.GetAttribute("href");
                if (string.IsNullOrEmpty(linkUrl))
                {
                    // No href attribute found. Apparently the XLink refers to a regular Component; we resolve it to a URL here.
                    string tcmUri = linkElement.GetAttribute("href", xlinkNamespaceUri);
                    if (!string.IsNullOrEmpty(tcmUri))
                    {
                        // Try to resolve directly to Binary content of MM Component.
                        linkUrl = linkResolver.ResolveLink(tcmUri, resolveToBinary: true);
                    }
                }
                if (!string.IsNullOrEmpty(linkUrl))
                {
                    // The link was resolved; set HTML href attribute
                    linkElement.SetAttribute("href", linkUrl);
                    ApplyHashIfApplicable(linkElement, localization);

                    // Remove all XLink and data- attributes
                    IEnumerable <XmlAttribute> attributesToRemove = linkElement.Attributes.Cast <XmlAttribute>()
                                                                    .Where(a => a.NamespaceURI == xlinkNamespaceUri || a.LocalName == "xlink" || a.LocalName.StartsWith("data-")).ToArray();
                    foreach (XmlAttribute attr in attributesToRemove)
                    {
                        linkElement.Attributes.Remove(attr);
                    }
                }
                else
                {
                    // The link was not resolved; remove the hyperlink.
                    XmlNode parentNode = linkElement.ParentNode;
                    foreach (XmlNode childNode in linkElement.ChildNodes)
                    {
                        parentNode.InsertBefore(childNode, linkElement);
                    }
                    parentNode.RemoveChild(linkElement);
                }
            }

            // Resolve embedded media items
            List <EntityModel> embeddedEntities = new List <EntityModel>();

            foreach (XmlElement imgElement in doc.SelectNodes("//img[@data-schemaUri]", nsmgr))
            {
                string[]       schemaTcmUriParts = imgElement.GetAttribute("data-schemaUri").Split('-');
                SemanticSchema semanticSchema    = SemanticMapping.GetSchema(schemaTcmUriParts[1], localization);

                // The semantic mapping may resolve to a more specific model type than specified here (e.g. YouTubeVideo instead of just MediaItem)
                Type      modelType = semanticSchema.GetModelTypeFromSemanticMapping(typeof(MediaItem));
                MediaItem mediaItem = (MediaItem)modelType.CreateInstance();
                mediaItem.ReadFromXhtmlElement(imgElement);
                if (mediaItem.MvcData == null)
                {
                    // In DXA 1.1 MediaItem.ReadFromXhtmlElement was expected to set MvcData.
                    // In DXA 1.2 this should be done in a GetDefaultView override (which is also used for other embedded Entities)
                    mediaItem.MvcData = mediaItem.GetDefaultView(localization);
                }
                embeddedEntities.Add(mediaItem);

                // Replace img element with marker XML processing instruction
                imgElement.ParentNode.ReplaceChild(
                    doc.CreateProcessingInstruction(EmbeddedEntityProcessingInstructionName, String.Empty),
                    imgElement
                    );
            }

            // Split the XHTML into fragments based on marker XML processing instructions.
            string xhtml = doc.DocumentElement.InnerXml;
            IList <IRichTextFragment> richTextFragments = new List <IRichTextFragment>();
            int lastFragmentIndex = 0;
            int i = 0;

            foreach (Match embeddedEntityMatch in EmbeddedEntityProcessingInstructionRegex.Matches(xhtml))
            {
                int embeddedEntityIndex = embeddedEntityMatch.Index;
                if (embeddedEntityIndex > lastFragmentIndex)
                {
                    richTextFragments.Add(new RichTextFragment(xhtml.Substring(lastFragmentIndex, embeddedEntityIndex - lastFragmentIndex)));
                }
                richTextFragments.Add(embeddedEntities[i++]);
                lastFragmentIndex = embeddedEntityIndex + embeddedEntityMatch.Length;
            }
            if (lastFragmentIndex < xhtml.Length)
            {
                // Final text fragment
                richTextFragments.Add(new RichTextFragment(xhtml.Substring(lastFragmentIndex)));
            }

            return(new RichText(richTextFragments));
        }
        /// <summary>
        /// New View Model Builder
        /// </summary>
        /// <param name="keyProvider">A View Model Key provider</param>
        public ViewModelFactory(IViewModelKeyProvider keyProvider,
                                IViewModelResolver resolver,
                                ILinkResolver linkResolver,
                                IRichTextResolver richTextResolver,
                                IContextResolver contextResolver,
                                IDD4TConfiguration configuration,
                                ILogger logger
                                )
        {
            if (keyProvider == null)
            {
                throw new ArgumentNullException("keyProvider");
            }
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }
            if (linkResolver == null)
            {
                throw new ArgumentNullException("linkResolver");
            }
            if (richTextResolver == null)
            {
                throw new ArgumentNullException("richTextResolver");
            }
            if (contextResolver == null)
            {
                throw new ArgumentNullException("contextResolver");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("DD4Tconfiguration");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            this._keyProvider       = keyProvider;
            this._resolver          = resolver;
            this._linkResolver      = linkResolver;
            this._richtTextResolver = richTextResolver;
            this._contextResolver   = contextResolver;
            this._configuration     = configuration;
            this._logger            = logger;

            // Trying to find the entry assembly to load view models from.
            // For web applications, a special trick is needed to do this (see below).
            Assembly entryAssembly = GetWebEntryAssembly();

            if (entryAssembly == null)
            {
                entryAssembly = Assembly.GetEntryAssembly();
            }
            if (entryAssembly != null)
            {
                LoadViewModels(new List <Assembly> {
                    entryAssembly
                });
            }
        }