Esempio n. 1
0
        public SubNavigationModel <T> GetSubNavigation(string url)
        {
            var categories = _catalogService.GetAllCategories();
            var parent     = categories.First(x => IncludeInNavigation(x) && _urlProvider.GetUrl(x, UrlProviderMode.Relative) == url);
            var children   = _catalogService.GetSubCategories(parent.Name).Where(IncludeInNavigation);

            return(new SubNavigationModel <T>
            {
                SectionParent = ToNavigationElement(parent),
                NavigationElements = children.Select(x => (T)ToNavigationElement(x)).ToList()
            });
        }
Esempio n. 2
0
    /// <summary>
    /// Extracts YAML metadata from the given file if it is a Razor file
    /// </summary>
    /// <param name="file">File to process</param>
    /// <returns>OutputFile if InputFile was Razor</returns>
    public async Task <OutputFile?> ProcessAsync(InputFile file)
    {
        // if this isn't CSHTML, or this is a Layout, or a partial, ignore
        if (!IsCshtmlFile(file) || (_context.Layout != null && _context.Layout.Equals(file)) || file.Name.StartsWith("_"))
        {
            return(null);
        }

        _log.Info <RazorProcessor>($"Processing Input : {file.RelativePath}");

        var fileContent = await _fileSystem.ReadAllTextAsync(file.FullPath);

        if (!fileContent.IsSet())
        {
            return(null);
        }

        var metadata = ExtractYamlMetadata(fileContent);

        var output = new OutputFile(file, _context.OutputDirectory)
        {
            Extension = ".html",
            Metadata  = metadata,
            Url       = _urlProvider.GetUrl(file)
        };

        return(output);
    }
Esempio n. 3
0
    /// <summary>
    /// Main markdown processing. Determines if the given file is a markdown file, and if so,
    /// pulls out metadata and converts content into HTML
    /// </summary>
    /// <param name="file">File to process</param>
    /// <returns>OutputFile if InputFile was markdown</returns>
    public async Task <OutputFile?> ProcessAsync(InputFile file)
    {
        if (!file.Extension.ToLower().Equals(".md"))
        {
            return(null);
        }

        _log.Info <MarkdownProcessor>($"Processing Input: {file.RelativePath}");

        var markdown = await _fileSystem.ReadAllTextAsync(file.FullPath);

        if (!markdown.IsSet())
        {
            return(null);
        }

        // extract our metadata
        var result = ExtractYamlMetadata(markdown);

        // convert markdown to HTML
        var html = Markdig.Markdown.ToHtml(result.markdown, _pipeline);

        var output = new OutputFile(file, _context.OutputDirectory)
        {
            Content   = html,
            Extension = ".html",
            Metadata  = result.metadata,
            Url       = _urlProvider.GetUrl(file)
        };

        return(output);
    }
Esempio n. 4
0
        public T GetContent(string subject, ActionType actionType, string additionalParameters, long subjectId = 0, string attribute = "")
        {
            logger.LogInformation("Getting content from music.story using {subject} and {actionType}", subject, actionType);
            if (string.IsNullOrEmpty(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }
            if (actionType == ActionType.None)
            {
                throw new ArgumentException(nameof(actionType));
            }
            if (actionType == ActionType.GetById && subjectId == 0)
            {
                throw new ArgumentException(nameof(subjectId));
            }

            var url     = urlProvider.GetUrl(subject, actionType, additionalParameters, subjectId, attribute);
            var rawData = musicStoryProvider.Get(url);

            if (string.IsNullOrEmpty(rawData))
            {
                logger.LogWarning("No content or empty content returned from music story.");
                return(null);
            }
            logger.LogInformation("Content retrieved Ok from musicStory.");
            var xmlSerialzer = new XmlSerializer(typeof(T));
            var encoding     = new UTF8Encoding();

            using (var s = new MemoryStream(encoding.GetBytes(rawData)))
                return(xmlSerialzer.Deserialize(s) as T);
        }
Esempio n. 5
0
        public LovePage GetPage(int currentLovedPage)
        {
            var url     = _urlProvider.GetUrl(currentLovedPage);
            var rawData = _lastFmProvider.GetLastFmContent(url);

            if (string.IsNullOrEmpty(rawData))
            {
                return(new LovePage());
            }

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <RootObject>(rawData).LovePage);
        }
        public bool Sync()
        {
            if (string.IsNullOrWhiteSpace(_panelUrl) || string.IsNullOrWhiteSpace(_secret))
            {
                throw new ArgumentNullException();
            }

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var syncUrl   = _urlProvider.GetUrl(Verb.Sync);
            var challenge = _requestFactory.Create(_urlProvider.GetUrl(Verb.Challenge), 360000, null).Execute();
            var signature = _signatureService.CreateSignature(challenge, syncUrl, null);

            return(_requestFactory
                   .Create(syncUrl, 10800000,
                           new Dictionary <string, string>
            {
                { "X-MC-MAC", signature.SignatureHash }, { "X-MC-Nonce", challenge }
            })
                   .Execute(_streamProcessor) &&
                   !_log.HasLoggedErrors);
        }
Esempio n. 7
0
    /// <summary>
    /// Main process action to define the destination file paths
    /// </summary>
    /// <param name="file">Intput file</param>
    /// <returns>OutputFile if static file</returns>
    public Task <OutputFile?> ProcessAsync(InputFile file)
    {
        // If our file is something to ignore, ignore it
        if (_ignoreExtensions.Contains(file.Extension.ToLower()))
        {
            return(Task.FromResult <OutputFile?>(null));
        }

        _log.Info <StaticProcessor>($"Processing Input: {file.RelativePath}");

        // create OutputFile with the Direct Copy flag set to true
        var output = new OutputFile(file, _context.OutputDirectory)
        {
            DirectCopy = true,
            Url        = _urlProvider.GetUrl(file)
        };

        return(Task.FromResult <OutputFile?>(output));
    }
        public async Task SendEventAsync(PublicationMethod publicationMethod,
                                         string hubName,
                                         string hubMethodName,
                                         string[] receiverIds,
                                         object e
                                         )
        {
            foreach (var receiverId in receiverIds ?? _nullReceiver)
            {
                var url = _urlProvider.GetUrl(
                    _connectionString.Endpoint,
                    publicationMethod,
                    hubName,
                    receiverId
                    );

                var request = _httpRequestFactory.CreateHttpRequest(
                    _connectionString,
                    hubMethodName,
                    e,
                    url
                    );

                using (var response = await _signalRHttpClient.SendAsync(request).ConfigureAwait(false))
                {
                    try
                    {
                        response.EnsureSuccessStatusCode();
                    }
                    catch (HttpRequestException ex)
                    {
                        throw new AzureSignalRPublishingFailedException(ex);
                    }

                    if (response.StatusCode != HttpStatusCode.Accepted)
                    {
                        throw new AzureSignalRPublishingFailedException(response.StatusCode);
                    }
                }
            }
        }
Esempio n. 9
0
        public T GetContent(string methodName, string userName, int currentPage = 1, string additionalParameters = "")
        {
            logger.LogInformation("Getting content from last.fm using {methodName}", methodName);
            if (string.IsNullOrEmpty(methodName))
            {
                throw new ArgumentNullException(nameof(methodName));
            }
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException(nameof(userName));
            }
            var url     = _urlProvider.GetUrl(methodName, userName, currentPage, additionalParameters);
            var rawData = _lastFmProvider.Get(url);

            if (string.IsNullOrEmpty(rawData))
            {
                logger.LogWarning("No content or empty content returned from las.fm.");
                return(new T());
            }
            logger.LogInformation("Content retrieved Ok from last.fm.");
            return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(rawData));
        }