예제 #1
0
        public static async Task <string> GetGeneratedContent(this ITagHelper tagHelper, HtmlEncoder htmlEncoder, string tagName, TagMode tagMode,
                                                              TagHelperAttributeList attributes = null)
        {
            if (attributes == null)
            {
                attributes = new TagHelperAttributeList();
            }

            TagHelperOutput output = new TagHelperOutput(tagName, attributes, (arg1, arg2) =>
            {
                return(Task.Run <TagHelperContent>(() => new DefaultTagHelperContent()));
            })
            {
                TagMode = tagMode
            };
            TagHelperContext context = new TagHelperContext(attributes, new Dictionary <object, object>(), Guid.NewGuid().ToString());

            tagHelper.Init(context);
            await tagHelper.ProcessAsync(context, output);

            using (var writer = new StringWriter())
            {
                output.WriteTo(writer, htmlEncoder);
                return(writer.ToString());
            }
        }
        public static async Task RunTagHelperAsync(this ITagHelper tagHelper, Options options)
        {
            if (options.Context == null)
            {
                options.Context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), Guid.NewGuid().ToString("N"));
            }

            if (options.Attributes == null)
            {
                options.Attributes = new List <TagHelperAttribute>();
            }

            if (options.TagName == null)
            {
                options.TagName = tagHelper.GetTagName();
            }

            var output = new TagHelperOutput(options.TagName, new TagHelperAttributeList(options.Attributes), (b, e) => Task.Factory.StartNew(() => options.Content))
            {
                TagMode = options.TagMode
            };

            if (options.InitTagHelper)
            {
                tagHelper.Init(options.Context);
            }

            await tagHelper.ProcessAsync(options.Context, output);
        }
예제 #3
0
        /// <summary>
        /// Tracks the given <paramref name="tagHelper"/>.
        /// </summary>
        /// <param name="tagHelper">The tag helper to track.</param>
        public void Add(ITagHelper tagHelper)
        {
            if (tagHelper == null)
            {
                throw new ArgumentNullException(nameof(tagHelper));
            }

            _tagHelpers.Add(tagHelper);
        }
예제 #4
0
        /// <inheritdoc />
        public void Activate([NotNull] ITagHelper tagHelper, [NotNull] ViewContext context)
        {
            var propertiesToActivate = _injectActions.GetOrAdd(tagHelper.GetType(),
                                                               _getPropertiesToActivate);

            for (var i = 0; i < propertiesToActivate.Length; i++)
            {
                var activateInfo = propertiesToActivate[i];
                activateInfo.Activate(tagHelper, context);
            }
        }
        public void Initialize()
        {
            _directory = Substitute.For<IDirectory>();
			_file = Substitute.For<IFile>();
            _path = Substitute.For<IPath>();
            _path.SetPathDefaultBehavior();
			_tagHelper = Substitute.For<ITagHelper>();
			_streamFactory = Substitute.For<IStreamFactory>();
			_fileStream = Substitute.For<IFileStream>();
			_streamFactory.CreateFileStream(Arg.Any<string>(), Arg.Any<FileMode>(), Arg.Any<FileAccess>(), Arg.Any<FileShare>()).Returns(_fileStream);
			_geolocHelper = Substitute.For<IGeolocationHelper>();

			_target = new FileSystemHelperTester(_directory, _file, _path, _tagHelper, _streamFactory, _geolocHelper);
        }
예제 #6
0
 public AccessValidator(
     ICurrentUserProvider currentUserProvider,
     IProjectAccessChecker projectAccessChecker,
     ICrossPlantAccessChecker crossPlantAccessChecker,
     IContentRestrictionsChecker contentRestrictionsChecker,
     ITagHelper tagHelper,
     ILogger <AccessValidator> logger)
 {
     _currentUserProvider        = currentUserProvider;
     _projectAccessChecker       = projectAccessChecker;
     _crossPlantAccessChecker    = crossPlantAccessChecker;
     _contentRestrictionsChecker = contentRestrictionsChecker;
     _tagHelper = tagHelper;
     _logger    = logger;
 }
        protected virtual void Bind(ITagHelper tagHelper, Type tagType, IDictionary <string, TagAttribute> attributes)
        {
            foreach (var propertyDescr in TypeDescriptor.GetProperties(tagType).OfType <PropertyDescriptor>().Where(p => !p.IsReadOnly))
            {
                TagAttribute attr;
                if (attributes.TryGetValue(propertyDescr.Name, out attr))
                {
                    var convertor = propertyDescr.Converter;
                    propertyDescr.SetValue(tagHelper, convertor.ConvertFrom(attr.Value));

                    attributes.Remove(propertyDescr.Name);
                }
            }
            tagHelper.Attributes = attributes;
        }
        protected virtual void Bind(ITagHelper tagHelper, Type tagType, IDictionary<string, TagAttribute> attributes)
        {
            foreach (var propertyDescr in TypeDescriptor.GetProperties(tagType).OfType<PropertyDescriptor>().Where(p => !p.IsReadOnly))
            {
                TagAttribute attr;
                if (attributes.TryGetValue(propertyDescr.Name, out attr))
                {
                    var convertor = propertyDescr.Converter;
                    propertyDescr.SetValue(tagHelper, convertor.ConvertFrom(attr.Value));

                    attributes.Remove(propertyDescr.Name);
                }
            }
            tagHelper.Attributes = attributes;
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelfMediaDatabase.Core.Operations.Tags.TagsOperation"/> class.
        /// </summary>
        /// <param name="fileSystemHelper">Helper for file system access.</param>
        /// <param name="directory">Injection wrapper of <see cref="System.IO.Directory"/>.</param>
        /// <param name="file">Injection wrapper of <see cref="System.IO.File"/>.</param>
        /// <param name="path">Injection wrapper of <see cref="System.IO.Path"/>.</param>
        /// <param name="tagHelper">Helper to access to tags of media files.</param>
        public TagsOperation(IFileSystemHelper fileSystemHelper, IFile file, IPath path, ITagHelper tagHelper)
        {
            if (fileSystemHelper == null)
                throw new ArgumentNullException("fileSystemHelper");
            if (file == null)
                throw new ArgumentNullException("file");
            if (path == null)
                throw new ArgumentNullException("path");
            if (tagHelper == null)
                throw new ArgumentNullException("exifHelper");

            _fileSystemHelper = fileSystemHelper;
            _file = file;
            _tagHelper = tagHelper;
            _path = path;
        }
예제 #10
0
        private static void OrderTagHelpers(IList <ITagHelper> tagHelpers)
        {
            // Using bubble-sort here due to its simplicity. It'd be an extreme corner case to ever have more than 3 or
            // 4 tag helpers simultaneously.
            ITagHelper temp = null;

            for (var i = 0; i < tagHelpers.Count; i++)
            {
                for (var j = i + 1; j < tagHelpers.Count; j++)
                {
                    if (tagHelpers[j].Order < tagHelpers[i].Order)
                    {
                        temp          = tagHelpers[i];
                        tagHelpers[i] = tagHelpers[j];
                        tagHelpers[j] = temp;
                    }
                }
            }
        }
		public void Intialize()
		{
			_fileSystemHelper = Substitute.For<IFileSystemHelper>();
			_directory = Substitute.For<IDirectory>();
			_fileOutput = Substitute.For<IFileOutput>();
			_consoleOutput = Substitute.For<IConsoleOutput>();
			_utils = Substitute.For<IUtils>();
			_tagsOperation = Substitute.For<ITagsOperation>();
			_tagHelper = Substitute.For<ITagHelper>();
			_file = Substitute.For<IFile>();

			_target = new SearchOperation(
				_fileSystemHelper , 
				_directory, 
				_fileOutput, 
				_consoleOutput, 
				_file, 
				_utils, 
				_tagsOperation,
				_tagHelper);
		}
예제 #12
0
        private async Task <string> GetGeneratedContentFromTagHelper(string tagName, TagMode tagMode,
                                                                     ITagHelper tagHelper, TagHelperAttributeList attributes = null)
        {
            if (attributes == null)
            {
                attributes = new TagHelperAttributeList();
            }

            TagHelperOutput output = new TagHelperOutput(tagName, attributes, (arg1, arg2) =>
            {
                return(Task.Run <TagHelperContent>(() => new DefaultTagHelperContent()));
            })
            {
                TagMode = tagMode
            };
            TagHelperContext context = new TagHelperContext(attributes, new Dictionary <object, object>(), Guid.NewGuid().ToString());

            tagHelper.Init(context);
            await tagHelper.ProcessAsync(context, output);

            return(output.RenderTag(_htmlEncoder));
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="SelfMediaDatabase.Core.Operations.Search.SearchOperation"/> class.
		/// </summary>
		/// <param name="fileSystemHelper">File system helper.</param>
		/// <param name="directory">Directory.</param>
		/// <param name="fileOutput">File output.</param>
		/// <param name="consoleOutput">Console output.</param>
		/// <param name="file">Injectable wrapper of <see cref="System.IO.File"/>.</param>
		/// <param name="utils">Some utils methods provider.</param>
		/// <param name="tagsOperation">Tags operation library.</param>
		/// <param name="tagHelper">Helper to access to tags of media files.</param>
		public SearchOperation(
			IFileSystemHelper fileSystemHelper, 
			IDirectory directory, 
			IFileOutput fileOutput, 
			IConsoleOutput consoleOutput, 
			IFile file, 
			IUtils utils,
			ITagsOperation tagsOperation,
			ITagHelper tagHelper)
		{
			if (fileSystemHelper == null)
				throw new ArgumentNullException("fileSystemHelper");
			if (directory == null)
				throw new ArgumentNullException("directory");
			if (fileOutput == null)
				throw new ArgumentNullException("fileOutput");
			if (consoleOutput == null)
				throw new ArgumentNullException("consoleOutput");
			if (file == null)
				throw new ArgumentNullException("file");
			if (utils == null)
				throw new ArgumentNullException("utils");
			if (tagsOperation == null)
				throw new ArgumentNullException("tagsOperation");
			if (tagHelper == null)
				throw new ArgumentNullException("exifHelper");

			_fileSystemHelper = fileSystemHelper;
			_directory = directory;
			_fileOutput = fileOutput;
			_consoleOutput = consoleOutput;
			_file = file;
			_utils = utils;
			_tagsOperation = tagsOperation;
			_tagHelper = tagHelper;
		}
			public FileSystemHelperTester(IDirectory directory, IFile file, IPath path, ITagHelper tagHelper, IStreamFactory streamFactory, IGeolocationHelper geolocHelper)
				: base(directory, file, path, tagHelper, streamFactory, geolocHelper)
			{
			}
        public void Initialize()
        {
            _fileSystemHelper = Substitute.For<IFileSystemHelper>();
            _file = Substitute.For<IFile>();
            _path = Substitute.For<IPath>();
            _tagHelper = Substitute.For<ITagHelper>();

            _path.GetFullPath(Arg.Any<string>()).ReturnsForAnyArgs(args => args.Arg<string>());
            _path.Combine(Arg.Any<string[]>()).ReturnsForAnyArgs(args => System.IO.Path.Combine(args.Arg<string[]>()));
            _path.GetDirectoryName(Arg.Any<string>()).ReturnsForAnyArgs(args => System.IO.Path.GetDirectoryName(args.Arg<string>()));

            _target = new TagsOperation(_fileSystemHelper, _file, _path, _tagHelper);
        }
 public TagsOperationTester(IFileSystemHelper fileSystemHelper, IFile file, IPath path, ITagHelper exifHelper, ITagsOperation self)
     : base(fileSystemHelper, file, path, exifHelper)
 {
     if (self == null)
         self = this;
     _self = self;
 }
 public static async Task RunTagHelperAsync(this ITagHelper tagHelper, TagHelperContext context)
 {
     await RunTagHelperAsync(tagHelper, new Options { Context = context });
 }
예제 #18
0
 /// <summary>
 /// Tracks the given <paramref name="tagHelper"/>.
 /// </summary>
 /// <param name="tagHelper">The tag helper to track.</param>
 public void Add([NotNull] ITagHelper tagHelper)
 {
     _tagHelpers.Add(tagHelper);
 }
 public static async Task <TagHelperContent> ToTagHelperContentAsync(this ITagHelper tagHelper)
 {
     return(await ToTagHelperContentAsync(tagHelper, (TagHelperContent)null));
 }
 public static async Task RunTagHelperAsync(this ITagHelper tagHelper)
 {
     await RunTagHelperAsync(tagHelper, (TagHelperContent)null);
 }
예제 #21
0
 protected void Add(ITagHelper tag, Action executeChildContent = null)
 {
     Add(new[] { tag }, executeChildContent);
 }
 public static async Task <TagHelperContent> ToTagHelperContentAsync(this ITagHelper tagHelper, string tagName)
 {
     return(await ToTagHelperContentAsync(tagHelper, new Options { TagName = tagName }));
 }
 public static async Task <TagHelperContent> ToTagHelperContentAsync(this ITagHelper tagHelper, IEnumerable <TagHelperAttribute> attributes)
 {
     return(await ToTagHelperContentAsync(tagHelper, new Options { Attributes = attributes }));
 }
 public static async Task <TagHelperContent> ToTagHelperContentAsync(this ITagHelper tagHelper, TagHelperContext context)
 {
     return(await ToTagHelperContentAsync(tagHelper, new Options { Context = context }));
 }
        protected async Task <string> RenderTagHelperAsync(string tagName, TagMode tagMode, ITagHelper tagHelper, TagHelperAttributeList tagHelperAttributes = null)
        {
            if (tagHelperAttributes == null)
            {
                tagHelperAttributes = new TagHelperAttributeList();
            }

            TagHelperOutput output = new TagHelperOutput(tagName, tagHelperAttributes, (useCachedResult, encoder) =>
            {
                return(Task.Run <TagHelperContent>(() => new DefaultTagHelperContent()));
            })
            {
                TagMode = tagMode
            };

            TagHelperContext context = new TagHelperContext(tagHelperAttributes, new Dictionary <object, object>(), Guid.NewGuid().ToString());

            tagHelper.Init(context);
            await tagHelper.ProcessAsync(context, output);

            return(output.RenderTag());
        }
 public static async Task RunTagHelperAsync(this ITagHelper tagHelper, bool initTagHelper)
 {
     await RunTagHelperAsync(tagHelper, new Options { InitTagHelper = initTagHelper });
 }
예제 #27
0
        /// <summary>
        /// Tracks the given <paramref name="tagHelper"/>.
        /// </summary>
        /// <param name="tagHelper">The tag helper to track.</param>
        public void Add(ITagHelper tagHelper)
        {
            if (tagHelper == null)
            {
                throw new ArgumentNullException(nameof(tagHelper));
            }

            _tagHelpers.Add(tagHelper);
        }
 public static async Task RunTagHelperAsync(this ITagHelper tagHelper, string tagName)
 {
     await RunTagHelperAsync(tagHelper, new Options { TagName = tagName });
 }
 public static async Task <TagHelperContent> ToTagHelperContentAsync(this ITagHelper tagHelper, bool initTagHelper)
 {
     return(await ToTagHelperContentAsync(tagHelper, new Options { InitTagHelper = initTagHelper }));
 }
 public void Add(ITagHelper tagHelper)
 {
 }
 public static async Task RunTagHelperAsync(this ITagHelper tagHelper, IEnumerable <TagHelperAttribute> attributes)
 {
     await RunTagHelperAsync(tagHelper, new Options { Attributes = attributes });
 }
예제 #32
0
 public static (TagHelperContext, TagHelperOutput) GetContextAndOutput(this ITagHelper tagHelper, string tagName) => (tagHelper.GetContext(), tagHelper.GetOutput(tagName));
 public static string GetTagName(this ITagHelper tagHelper)
 {
     return(tagHelper.GetType().GetTypeInfo().GetCustomAttributes <HtmlTargetElementAttribute>().FirstOrDefault(a => a.Tag != "*")?.Tag
            ?? Regex.Replace(tagHelper.GetType().Name.Replace("TagHelper", ""), "([A-Z])", "-$1").Trim('-').ToLower());
 }