Exemplo n.º 1
0
        protected async Task <string> SaveFileDataFromWebClient(string absoluteUrl, string filePath)
        {
            SslTruster.TrustSslIfAppSettingConfigured();

            try
            {
                if (absoluteUrl == null || absoluteUrl == "#")
                {
                    return(null);
                }

                using (var client = new System.Net.WebClient())
                {
                    client.Encoding = DefaultEncoder;

                    await client.DownloadFileTaskAsync(new Uri(absoluteUrl), filePath);
                }

                return(filePath);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error while publishing to file " + ex.Message);
                //throw;
            }

            return(null);
        }
Exemplo n.º 2
0
        public override async Task <string> GeneratePage(int id, int staticSiteId, IFileNameGenerator fileNamer, IEnumerable <ITransformer> transformers = null)
        {
            SslTruster.TrustSslIfAppSettingConfigured();

            var node = GetNode(id);

            if (node == null)
            {
                return(null);
            }

            var    url         = node.Url(mode: UrlMode.Relative);
            string absoluteUrl = node.Url(mode: UrlMode.Absolute);

            var fileData = await GetFileDataFromWebClient(absoluteUrl);

            if (fileData == null)
            {
                return(null);
            }

            var transformedData = RunTransformers(fileData, transformers);

            var filePath = fileNamer.GetFilePartialPath(url);

            var generatedFileLocation = await Store(staticSiteId, filePath, transformedData);

            return(generatedFileLocation);
        }