Ejemplo n.º 1
0
        internal async Task <Dictionary <string, bool> > GenerateWebHtml(List <AppSettingsPublishProfiles> profiles,
                                                                         AppSettingsPublishProfiles currentProfile, string itemName, string[] base64ImageArray,
                                                                         IEnumerable <FileIndexItem> fileIndexItemsList, string outputParentFullFilePathFolder)
        {
            if (string.IsNullOrEmpty(currentProfile.Template))
            {
                _console.WriteLine("CurrentProfile Template not configured");
                return(new Dictionary <string, bool>());
            }

            // Generates html by razorLight
            var viewModel = new WebHtmlViewModel
            {
                ItemName         = itemName,
                Profiles         = profiles,
                AppSettings      = _appSettings,
                CurrentProfile   = currentProfile,
                Base64ImageArray = base64ImageArray,
                // apply slug to items, but use it only in the copy
                FileIndexItems = fileIndexItemsList.Select(c => c.Clone()).ToList(),
            };

            // add to IClonable
            foreach (var item in viewModel.FileIndexItems)
            {
                item.FileName = _appSettings.GenerateSlug(item.FileCollectionName, true) +
                                Path.GetExtension(item.FileName);
            }

            // has a direct dependency on the filesystem
            var embeddedResult = await new ParseRazor(_hostFileSystemStorage)
                                 .EmbeddedViews(currentProfile.Template, viewModel);

            var stream = new PlainTextFileHelper().StringToStream(embeddedResult);
            await _hostFileSystemStorage.WriteStreamAsync(stream,
                                                          Path.Combine(outputParentFullFilePathFolder, currentProfile.Path));

            _console.Write(_appSettings.IsVerbose() ? embeddedResult + "\n" : "•");

            return(new Dictionary <string, bool>
            {
                {
                    currentProfile.Path.Replace(outputParentFullFilePathFolder, string.Empty),
                    currentProfile.Copy
                }
            });
        }
Ejemplo n.º 2
0
    public void WebHtmlViewModel1()
    {
        var model = new WebHtmlViewModel
        {
            AppSettings      = new AppSettings(),
            CurrentProfile   = new AppSettingsPublishProfiles(),
            Profiles         = new List <AppSettingsPublishProfiles>(),
            Base64ImageArray = Array.Empty <string>(),
            FileIndexItems   = new List <FileIndexItem>()
        };

        Assert.IsNotNull(model.AppSettings);
        Assert.IsNotNull(model.CurrentProfile);
        Assert.IsNotNull(model.Profiles);
        Assert.IsNotNull(model.Base64ImageArray);
        Assert.IsNotNull(model.FileIndexItems);
    }