Esempio n. 1
0
        /// <summary>
        /// Fill the <paramref name="emptyCollection"/> with all the media templates in the current application. The return value is the same reference
        /// as the parameter.
        /// </summary>
        /// <param name="emptyCollection">An empty <see cref="IMediaTemplateCollection"/> object to populate with the list of media templates in the current
        /// application. This parameter is required because the library that implements this interface does not have
        /// the ability to directly instantiate any object that implements <see cref="IMediaTemplateCollection"/>.</param>
        /// <returns>
        /// Returns an <see cref="IMediaTemplateCollection"/> representing the media templates in the current application. The returned object is the
        /// same object in memory as the <paramref name="emptyCollection"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="emptyCollection" /> is null.</exception>
        public IMediaTemplateCollection GetMediaTemplates(IMediaTemplateCollection emptyCollection)
        {
            if (emptyCollection == null)
            {
                throw new ArgumentNullException("emptyCollection");
            }

            if (emptyCollection.Count > 0)
            {
                emptyCollection.Clear();
            }

            foreach (MediaTemplateDto btDto in Context.MediaTemplates.OrderBy(i => i.MimeType))
            {
                var bt = emptyCollection.CreateEmptyMediaTemplateInstance();
                bt.MediaTemplateId = btDto.MediaTemplateId;
                bt.MimeType        = btDto.MimeType.Trim();
                bt.BrowserId       = btDto.BrowserId.Trim();
                bt.HtmlTemplate    = btDto.HtmlTemplate.Trim();
                bt.ScriptTemplate  = btDto.ScriptTemplate.Trim();

                emptyCollection.Add(bt);
            }

            return(emptyCollection);
        }
Esempio n. 2
0
        /// <summary>
        /// Fill the <paramref name="emptyCollection"/> with all the media templates in the current application. The return value is the same reference
        /// as the parameter.
        /// </summary>
        /// <param name="emptyCollection">An empty <see cref="IMediaTemplateCollection"/> object to populate with the list of media templates in the current
        /// application. This parameter is required because the library that implements this interface does not have
        /// the ability to directly instantiate any object that implements <see cref="IMediaTemplateCollection"/>.</param>
        /// <returns>
        /// Returns an <see cref="IMediaTemplateCollection"/> representing the media templates in the current application. The returned object is the
        /// same object in memory as the <paramref name="emptyCollection"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="emptyCollection" /> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="emptyCollection" /> is not empty.</exception>
        public IMediaTemplateCollection GetMediaTemplates(IMediaTemplateCollection emptyCollection)
        {
            if (emptyCollection == null)
            {
                throw new ArgumentNullException(nameof(emptyCollection));
            }

            if (emptyCollection.Count > 0)
            {
                throw new ArgumentException($"The emptyCollection parameter must be empty. Instead, it had {emptyCollection.Count} elements.", nameof(emptyCollection));
            }

            foreach (MediaTemplateDto btDto in Context.MediaTemplates.OrderBy(i => i.MimeType))
            {
                var bt = emptyCollection.CreateEmptyMediaTemplateInstance();
                bt.MediaTemplateId = btDto.MediaTemplateId;
                bt.MimeType        = btDto.MimeType.Trim();
                bt.BrowserId       = btDto.BrowserId.Trim();
                bt.HtmlTemplate    = btDto.HtmlTemplate.Trim();
                bt.ScriptTemplate  = btDto.ScriptTemplate.Trim();

                emptyCollection.Add(bt);
            }

            return(emptyCollection);
        }
 private static bool HasDefaultTemplate(IMediaTemplateCollection items)
 {
     return(items.Any(t => t.BrowserId.Equals("default", StringComparison.Ordinal)));
 }