Esempio n. 1
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Extension Methods
        public static ILinkBuilder <TParentBuilder> SetMeta <TParentBuilder>(this ILinkBuilder <TParentBuilder> linkBuilder, params Meta[] metaCollection)
            where TParentBuilder : class
        {
            Contract.Requires(linkBuilder != null);

            return(linkBuilder.SetMeta(metaCollection.AsEnumerable()));
        }
Esempio n. 2
0
        internal static ILinkBuilder BuildLink(NodeAdapter adapter, ContentItem item, bool selected, string target)
        {
            INode  node      = item;
            string className = node.ClassNames;

            if (selected)
            {
                className += "selected ";
            }

            ILinkBuilder builder = Link.To(node)
                                   .Target(target)
                                   .Class(className)
                                   .Href(adapter.GetPreviewUrl(item))
                                   .Text("<img src='" + adapter.GetIconUrl(item) + "'/>" + node.Contents)
                                   .Attribute("id", item.Path.Replace('/', '_'))
                                   .Attribute("title", "#" + item.ID + ": " + N2.Context.Current.Definitions.GetDefinition(item).Title)
                                   .Attribute("data-id", item.ID.ToString())
                                   .Attribute("data-type", item.GetContentType().Name)
                                   .Attribute("data-path", item.Path)
                                   .Attribute("data-url", item.Url)
                                   .Attribute("data-page", item.IsPage.ToString().ToLower())
                                   .Attribute("data-zone", item.ZoneName)
                                   .Attribute("data-permission", adapter.GetMaximumPermission(item).ToString());

            builder.Href(adapter.GetPreviewUrl(item));

            return(builder);
        }
Esempio n. 3
0
 public IgnoreRelationshipsResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                                         IIncludedResourceObjectBuilder includedBuilder, IEnumerable <IQueryConstraintProvider> constraintProviders,
                                                         IResourceContextProvider resourceContextProvider, IResourceDefinitionAccessor resourceDefinitionAccessor,
                                                         IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(linkBuilder, includedBuilder, constraintProviders, resourceContextProvider,
            resourceDefinitionAccessor, settingsProvider)
 {
 }
Esempio n. 4
0
 public BusFinder(IHttpService httpService, IDateFormatter dateFormatter, IOptions <BusConfig> options, ILinkBuilder linkBuilder)
 {
     this.httpService   = httpService;
     this.dateFormatter = dateFormatter;
     this.linkBuilder   = linkBuilder;
     config             = options.Value;
     availableStations  = GetAvailableStations().Result;
 }
Esempio n. 5
0
 public RailwayFinder(IHttpService httpService, IDateFormatter dateFormatter, IOptions <RailwayConfig> options,
                      IMapsService mapsService, ILinkBuilder linkBuilder)
 {
     this.httpService   = httpService;
     this.dateFormatter = dateFormatter;
     this.mapsService   = mapsService;
     this.linkBuilder   = linkBuilder;
     config             = options.Value;
 }
Esempio n. 6
0
 /// <summary>
 /// Adds a link item to the currently building link.
 /// </summary>
 /// <param name="linkBuilder">The link builder.</param>
 /// <param name="href">The href attribute of a link item.</param>
 /// <param name="name">The name attribute of a link item.</param>
 /// <param name="templated">The <see cref="bool"/> value which indicates if the <c>Href</c> property
 /// is a URI template.</param>
 /// <param name="type">The media type expected when dereferencing the target source.</param>
 /// <param name="deprecation">The URL which provides further information about the deprecation.</param>
 /// <param name="profile">The URI that hints about the profile of the target resource.</param>
 /// <param name="title">The <see cref="string"/> value which is intended for labelling
 /// the link with a human-readable identifier.</param>
 /// <param name="hreflang">The <see cref="string"/> value which is intending for indicating
 /// the language of the target resource.</param>
 /// <param name="additionalProperties">The additional properties.</param>
 /// <returns></returns>
 public static ILinkItemBuilder WithLinkItem(this ILinkBuilder linkBuilder, string href,
                                             string name        = null, bool?templated = null, string type  = null,
                                             string deprecation = null, string profile = null, string title = null,
                                             string hreflang    = null,
                                             IDictionary <string, object> additionalProperties = null)
 {
     return(new LinkItemBuilder(linkBuilder, linkBuilder.Rel, href, name, templated,
                                type, deprecation, profile, title, hreflang, linkBuilder.EnforcingArrayConverting, additionalProperties));
 }
Esempio n. 7
0
        internal static Control AddTo(this ILinkBuilder builder, Control container)
        {
            var c = builder.ToControl();

            if (c != null)
            {
                container.Controls.Add(c);
            }
            return(c);
        }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider resourceContextProvider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(resourceContextProvider, settingsProvider.Get())
 {
     _included          = new HashSet <ResourceObject>(ResourceIdentifierObjectComparer.Instance);
     _fieldsToSerialize = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _linkBuilder       = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
 }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider provider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(provider, settingsProvider.Get())
 {
     _included          = new HashSet <ResourceObject>(new ResourceObjectComparer());
     _fieldsToSerialize = fieldsToSerialize;
     _linkBuilder       = linkBuilder;
 }
        protected ResponseResourceObjectBuilder GetResponseResourceObjectBuilder(IEnumerable <IEnumerable <RelationshipAttribute> > inclusionChains = null,
                                                                                 ResourceLinks resourceLinks = null, RelationshipLinks relationshipLinks = null)
        {
            ILinkBuilder link = GetLinkBuilder(null, resourceLinks, relationshipLinks);
            IEnumerable <IQueryConstraintProvider> includeConstraints = GetIncludeConstraints(inclusionChains);
            IIncludedResourceObjectBuilder         includedBuilder    = GetIncludedBuilder();

            return(new ResponseResourceObjectBuilder(link, includedBuilder, includeConstraints, ResourceGraph, GetResourceDefinitionAccessor(),
                                                     GetSerializerSettingsProvider()));
        }
Esempio n. 11
0
        private IncludedResourceObjectBuilder GetBuilder()
        {
            IFieldsToSerialize fields = GetSerializableFields();
            ILinkBuilder       links  = GetLinkBuilder();

            IResourceDefinitionAccessor accessor = new Mock <IResourceDefinitionAccessor>().Object;

            return(new IncludedResourceObjectBuilder(fields, links, ResourceGraph, Enumerable.Empty <IQueryConstraintProvider>(), accessor,
                                                     GetSerializerSettingsProvider()));
        }
 public RequestPasswordResetCodeCommandHandler(IValidator <RequestPasswordResetCodeCommand> validator, IUserRepository userRepository, ICommunicationService communicationService, ICodeGenerator codeGenerator, ILinkBuilder linkBuilder, ILogger logger, IAuditService auditService, IHashingService hashingService)
 {
     _validator            = validator;
     _userRepository       = userRepository;
     _communicationService = communicationService;
     _codeGenerator        = codeGenerator;
     _linkBuilder          = linkBuilder;
     _logger         = logger;
     _auditService   = auditService;
     _hashingService = hashingService;
 }
Esempio n. 13
0
 public AtomicOperationsResponseSerializer(IResourceObjectBuilder resourceObjectBuilder,
                                           IMetaBuilder metaBuilder, ILinkBuilder linkBuilder, IFieldsToSerialize fieldsToSerialize,
                                           IJsonApiRequest request, IJsonApiOptions options)
     : base(resourceObjectBuilder)
 {
     _metaBuilder       = metaBuilder ?? throw new ArgumentNullException(nameof(metaBuilder));
     _linkBuilder       = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _fieldsToSerialize = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _request           = request ?? throw new ArgumentNullException(nameof(request));
     _options           = options ?? throw new ArgumentNullException(nameof(options));
 }
Esempio n. 14
0
 public ResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders,
                                      IResourceContextProvider resourceContextProvider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(resourceContextProvider, settingsProvider.Get())
 {
     _linkBuilder         = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _includedBuilder     = includedBuilder ?? throw new ArgumentNullException(nameof(includedBuilder));
     _constraintProviders = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
 }
 public ResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders,
                                      IResourceContextProvider provider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(provider, settingsProvider.Get())
 {
     _linkBuilder         = linkBuilder;
     _includedBuilder     = includedBuilder;
     _constraintProviders = constraintProviders;
 }
Esempio n. 16
0
        private IIncludedResourceObjectBuilder GetIncludedBuilder(bool hasIncludeQueryString)
        {
            IFieldsToSerialize                     fieldsToSerialize                     = GetSerializableFields();
            ILinkBuilder                           linkBuilder                           = GetLinkBuilder();
            IResourceDefinitionAccessor            resourceDefinitionAccessor            = GetResourceDefinitionAccessor();
            IRequestQueryStringAccessor            queryStringAccessor                   = new FakeRequestQueryStringAccessor(hasIncludeQueryString ? "include=" : null);
            IResourceObjectBuilderSettingsProvider resourceObjectBuilderSettingsProvider = GetSerializerSettingsProvider();

            return(new IncludedResourceObjectBuilder(fieldsToSerialize, linkBuilder, ResourceGraph, Enumerable.Empty <IQueryConstraintProvider>(),
                                                     resourceDefinitionAccessor, queryStringAccessor, resourceObjectBuilderSettingsProvider));
        }
Esempio n. 17
0
 public ResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IIncludeService includeService,
                                      IResourceContextProvider provider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(provider, settingsProvider.Get())
 {
     _linkBuilder     = linkBuilder;
     _includedBuilder = includedBuilder;
     _includeService  = includeService;
 }
Esempio n. 18
0
        public MessageLinkBuilder
        (
            ILinkBuilder linkBuilder
        )
        {
            _linkBuilder = linkBuilder
                           ?? throw new ArgumentNullException(nameof(linkBuilder));

            _action     = nameof(MessagesController.Get);
            _controller = nameof(MessagesController)
                          .Replace("Controller", string.Empty);
        }
        private static string GetParameterString(ILinkBuilder linkBuilder)
        {
            var parameters      = linkBuilder.Action.GetParameters();
            var parameterString = parameters.SingleOrDefault(p => p.Name == "id");

            if (parameterString == null)
            {
                return(string.Empty);
            }

            return($"/{{{linkBuilder.Arguments["id"].Origin ?? linkBuilder.Arguments["id"].Name}}}");
        }
Esempio n. 20
0
 public ServiceLinkBuilder() : base(new Dictionary <string, object>
 {
     { nameof(DescriptionFactory), new DefaultDescriptionFactory(false) },
     { nameof(PayloadManager), new DefaultLinkPayloadManager() }
 })
 {
     _linkBuilder =
         LinkBuilder.Configure
         .AutoStart(AutoStart())
         .Timeout(Timeout())
         .RecoveryInterval(RecoveryInterval())
         .UseBackgroundThreadsForConnection(UseBackgroundThreadsForConnection());
 }
Esempio n. 21
0
 public ResponseSerializer(IMetaBuilder <TResource> metaBuilder,
                           ILinkBuilder linkBuilder,
                           IIncludedResourceObjectBuilder includedBuilder,
                           IFieldsToSerialize fieldsToSerialize,
                           IResourceObjectBuilder resourceObjectBuilder) :
     base(resourceObjectBuilder)
 {
     _fieldsToSerialize   = fieldsToSerialize;
     _linkBuilder         = linkBuilder;
     _metaBuilder         = metaBuilder;
     _includedBuilder     = includedBuilder;
     _primaryResourceType = typeof(TResource);
 }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider resourceContextProvider,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders,
                                      IResourceDefinitionAccessor resourceDefinitionAccessor,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(resourceContextProvider, settingsProvider.Get())
 {
     _included                   = new HashSet <ResourceObject>(ResourceIdentifierObjectComparer.Instance);
     _fieldsToSerialize          = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _linkBuilder                = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
     _sparseFieldSetCache        = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
 }
Esempio n. 23
0
 public ResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders,
                                      IResourceContextProvider resourceContextProvider,
                                      IResourceDefinitionAccessor resourceDefinitionAccessor,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(resourceContextProvider, settingsProvider.Get())
 {
     _linkBuilder                = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _includedBuilder            = includedBuilder ?? throw new ArgumentNullException(nameof(includedBuilder));
     _constraintProviders        = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
     _sparseFieldSetCache        = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
 }
Esempio n. 24
0
        public WebsiteMenuViewComponent(
            IMenuService menuService,
            WebsiteOptionsProvider websiteOptionsProvider,
            ILinkBuilder linkBuilder)
        {
            menuService.CheckArgumentIsNull(nameof(menuService));
            _menuService = menuService;

            websiteOptionsProvider.CheckArgumentIsNull(nameof(websiteOptionsProvider));
            _websiteOptionsProvider = websiteOptionsProvider;

            linkBuilder.CheckArgumentIsNull(nameof(linkBuilder));
            _linkBuilder = linkBuilder;
        }
 public ResponseResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IIncludeService includeService,
                                      IResourceContextProvider provider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider,
                                      ILoggerFactory loggerFactory)
     : base(provider, settingsProvider.Get())
 {
     _logger            = loggerFactory.CreateLogger <ResponseResourceObjectBuilder>();
     _linkBuilder       = linkBuilder;
     _includedBuilder   = includedBuilder;
     _includeService    = includeService;
     _fieldsToSerialize = fieldsToSerialize;
 }
 public ResponseSerializer(IMetaBuilder metaBuilder,
                           ILinkBuilder linkBuilder,
                           IIncludedResourceObjectBuilder includedBuilder,
                           IFieldsToSerialize fieldsToSerialize,
                           IResourceObjectBuilder resourceObjectBuilder,
                           IJsonApiOptions options)
     : base(resourceObjectBuilder)
 {
     _fieldsToSerialize   = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _options             = options ?? throw new ArgumentNullException(nameof(options));
     _linkBuilder         = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _metaBuilder         = metaBuilder ?? throw new ArgumentNullException(nameof(metaBuilder));
     _includedBuilder     = includedBuilder ?? throw new ArgumentNullException(nameof(includedBuilder));
     _primaryResourceType = typeof(TResource);
 }
Esempio n. 27
0
        private ILinkBuilder BuildLink(ContentItem item, ContentItem selectedItem, string target)
        {
            StringBuilder className = new StringBuilder();

            if (!item.Published.HasValue || item.Published > N2.Utility.CurrentTime())
            {
                className.Append("unpublished ");
            }
            else if (item.Published > N2.Utility.CurrentTime().AddDays(-2))
            {
                className.Append("new ");
            }

            if (item.Expires.HasValue && item.Expires <= N2.Utility.CurrentTime())
            {
                className.Append("expired ");
            }

            if (item == selectedItem)
            {
                className.Append("selected ");
            }

            if (item.AuthorizedRoles != null && item.AuthorizedRoles.Count > 0)
            {
                className.Append("locked ");
            }

            string iconUrl   = item.IconUrl;
            int    iconIndex = icons.IndexOf(iconUrl);

            if (iconIndex < 0)
            {
                iconIndex = icons.Count;
                icons.Add(iconUrl);
            }
            className.Append("i" + iconIndex + " ");

            ILinkBuilder builder = Link.To(item).Target(target).Href(item.Url);

            if (className.Length > 0)
            {
                --className.Length;                 // remove trailing whitespace
                builder.Class(className.ToString());
            }

            return(builder);
        }
        public AtomicOperationsResponseSerializer(IResourceObjectBuilder resourceObjectBuilder, IMetaBuilder metaBuilder, ILinkBuilder linkBuilder,
                                                  IFieldsToSerialize fieldsToSerialize, IJsonApiRequest request, IJsonApiOptions options)
            : base(resourceObjectBuilder)
        {
            ArgumentGuard.NotNull(metaBuilder, nameof(metaBuilder));
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(fieldsToSerialize, nameof(fieldsToSerialize));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(options, nameof(options));

            _metaBuilder       = metaBuilder;
            _linkBuilder       = linkBuilder;
            _fieldsToSerialize = fieldsToSerialize;
            _request           = request;
            _options           = options;
        }
        protected ResponseSerializer <T> GetResponseSerializer <T>(IEnumerable <IEnumerable <RelationshipAttribute> > inclusionChains = null,
                                                                   Dictionary <string, object> metaDict = null, TopLevelLinks topLinks = null, ResourceLinks resourceLinks = null,
                                                                   RelationshipLinks relationshipLinks  = null)
            where T : class, IIdentifiable
        {
            IMetaBuilder meta = GetMetaBuilder(metaDict);
            ILinkBuilder link = GetLinkBuilder(topLinks, resourceLinks, relationshipLinks);
            IEnumerable <IQueryConstraintProvider> includeConstraints = GetIncludeConstraints(inclusionChains);
            IIncludedResourceObjectBuilder         includedBuilder    = GetIncludedBuilder();
            IFieldsToSerialize fieldsToSerialize = GetSerializableFields();

            var resourceObjectBuilder = new ResponseResourceObjectBuilder(link, includedBuilder, includeConstraints, ResourceGraph,
                                                                          GetResourceDefinitionAccessor(), GetSerializerSettingsProvider());

            return(new ResponseSerializer <T>(meta, link, includedBuilder, fieldsToSerialize, resourceObjectBuilder, new JsonApiOptions()));
        }
        public ResponseSerializer(IMetaBuilder metaBuilder, ILinkBuilder linkBuilder, IIncludedResourceObjectBuilder includedBuilder,
                                  IFieldsToSerialize fieldsToSerialize, IResourceObjectBuilder resourceObjectBuilder, IJsonApiOptions options)
            : base(resourceObjectBuilder)
        {
            ArgumentGuard.NotNull(metaBuilder, nameof(metaBuilder));
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(includedBuilder, nameof(includedBuilder));
            ArgumentGuard.NotNull(fieldsToSerialize, nameof(fieldsToSerialize));
            ArgumentGuard.NotNull(options, nameof(options));

            _metaBuilder         = metaBuilder;
            _linkBuilder         = linkBuilder;
            _includedBuilder     = includedBuilder;
            _fieldsToSerialize   = fieldsToSerialize;
            _options             = options;
            _primaryResourceType = typeof(TResource);
        }
 public JsonApiTransformerBuilder()
 {
     this.linkBuilder = new FakeLinkBuilder();
 }
Esempio n. 32
0
 public TransformationHelper(IConfiguration configuration, ILinkBuilder linkBuilder)
 {
     this.configuration = configuration;
     this.linkBuilder = linkBuilder;
 }