Example #1
0
        static void CreateAndSaveIndexHtml(
            string outputPathAbsolute,
            string startupCode,
            string codeForReferencingAdditionalLibraries,
            string outputRootPath,
            string outputAppFilesPath,
            string outputLibrariesPath,
            string outputResourcesPath,
            string assemblyNameWithoutExtension
            )
        {
            // Read the "index.html" template:
            string indexHtmlFileTemplate = WrapperHelpers.ReadTextFileFromEmbeddedResource("index.html");

            // Replace the placeholders:
            string indexHtmlFile = indexHtmlFileTemplate.Replace("[BOOT_JAVASCRIPT_CODE_GOES_HERE]", startupCode);

            indexHtmlFile = indexHtmlFile.Replace("[ADDITIONAL_LIBRARIES_GO_HERE]", codeForReferencingAdditionalLibraries);
            indexHtmlFile = indexHtmlFile.Replace("[LIBRARIES_PATH_GOES_HERE]", PathsHelper.EnsureNoBackslashAndEnsureItEndsWithAForwardSlash(outputLibrariesPath));
            indexHtmlFile = indexHtmlFile.Replace("[APPFILES_PATH_GOES_HERE]", PathsHelper.EnsureNoBackslashAndEnsureItEndsWithAForwardSlash(outputAppFilesPath));

            // Prevent browser caching of the JSIL and CSHTML5 libraries:
            indexHtmlFile = WrapperHelpers.AppendDateToLibraryFileName("JSIL.js", indexHtmlFile);
            indexHtmlFile = WrapperHelpers.AppendDateToLibraryFileName("cshtml5.js", indexHtmlFile);
            indexHtmlFile = WrapperHelpers.AppendDateToLibraryFileName("cshtml5.css", indexHtmlFile);

            // Read the "App.Config" file for future use by the ClientBase.
            string relativePathToAppConfigFolder = PathsHelper.CombinePathsWhileEnsuringEndingBackslashAndMore(outputResourcesPath, assemblyNameWithoutExtension);
            string relativePathToAppConfig       = Path.Combine(relativePathToAppConfigFolder, "app.config.g.js");

            if (File.Exists(Path.Combine(outputPathAbsolute, relativePathToAppConfig)))
            {
                string scriptToReadAppConfig = "<script type=\"application/javascript\" src=\"" + relativePathToAppConfig + "\"></script>";
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_APPCONFIG_GOES_HERE]", scriptToReadAppConfig);
            }
            else
            {
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_APPCONFIG_GOES_HERE]", string.Empty);
            }

            // Read the "ServiceReferences.ClientConfig" file for future use by the ClientBase.
            string relativePathToServiceReferencesClientConfig = Path.Combine(relativePathToAppConfigFolder, "servicereferences.clientconfig.g.js");

            if (File.Exists(Path.Combine(outputPathAbsolute, relativePathToServiceReferencesClientConfig)))
            {
                string scriptToReadServiceReferencesClientConfig = "<script src=\"" + relativePathToServiceReferencesClientConfig.Replace('\\', '/') + "\"></script>";
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_SERVICEREFERENCESCLIENTCONFIG_GOES_HERE]", scriptToReadServiceReferencesClientConfig);
            }
            else
            {
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_SERVICEREFERENCESCLIENTCONFIG_GOES_HERE]", string.Empty);
            }

            // Save the "index.html" to the final folder:
            File.WriteAllText(Path.Combine(outputPathAbsolute, "index.html"), indexHtmlFile);
        }
Example #2
0
        public static void CreateAndCopySupportFiles(
            string pathOfAssemblyThatContainsEntryPoint,
            List <string> librariesFolders,
            string outputRootPath,
            string outputAppFilesPath,
            string outputLibrariesPath,
            string outputResourcesPath,
            string assemblyNameWithoutExtension
            )
        {
            StringBuilder codeForReferencingAdditionalLibraries = new StringBuilder();

            // Determine the output path:
            string outputPathAbsolute = PathsHelper.GetOutputPathAbsolute(pathOfAssemblyThatContainsEntryPoint, outputRootPath);

            // Combine the output path and the relative "Libraries" folder path, while also ensuring that there is no forward slash, and that the path ends with a backslash:
            string absoluteOutputLibrariesPath = PathsHelper.CombinePathsWhileEnsuringEndingBackslashAndMore(outputPathAbsolute, outputLibrariesPath); // Note: when it was hard-coded, it was Path.Combine(outputPath, @"Libraries\");

            // Create the destination folders hierarchy if it does not already exist:
            if (!Directory.Exists(absoluteOutputLibrariesPath))
            {
                Directory.CreateDirectory(absoluteOutputLibrariesPath);
            }

            // Copy the content of the "Libraries" files:
            bool mainJsilFileFound = false;

            foreach (string librariesFolder in librariesFolders)
            {
                foreach (var file in Directory.GetFiles(librariesFolder))
                {
                    string fileName = Path.GetFileName(file);
                    string outputFileWithFullPath = Path.Combine(absoluteOutputLibrariesPath, fileName);
                    if (fileName.ToUpper() == "JSIL.JS")
                    {
                        // Replace some JS code that is inside the file "JSIL.js":
                        string stringToReplace = @"src=\"""" + uri + ""\""";
                        string replaceWith     = @"src=\"""" + uri + """ + String.Format("?{0:yyyyMdHHmm}", DateTime.Now) + @"\""";
                        CopyFileWhilePerformingStringReplace(file, outputFileWithFullPath, stringToReplace, replaceWith, throwIfNotFound: true);
                        mainJsilFileFound = true;
                    }
                    else
                    {
                        File.Copy(file, Path.Combine(absoluteOutputLibrariesPath, fileName), true);
                    }
                    if (!fileName.ToUpper().StartsWith("JSIL."))
                    {
                        codeForReferencingAdditionalLibraries.AppendLine(string.Format(@"<script src=""{0}{1}"" type=""text/javascript""></script>", PathsHelper.EnsureNoBackslashAndEnsureItEndsWithAForwardSlash(outputLibrariesPath), fileName + String.Format("?{0:yyyyMdHHmm}", DateTime.Now)));
                    }
                }
            }
            if (!mainJsilFileFound)
            {
                throw new Exception("The file \"jsil.js\" was not found.");
            }

            // Generate the startup code that instantiates the application class:
            string startupCode = GenerateStartupCode(pathOfAssemblyThatContainsEntryPoint);

            // Create and save the "index.html" file:
            CreateAndSaveIndexHtml(
                outputPathAbsolute,
                startupCode,
                codeForReferencingAdditionalLibraries.ToString(),
                outputRootPath,
                outputAppFilesPath,
                outputLibrariesPath,
                outputResourcesPath,
                assemblyNameWithoutExtension
                );
        }
Example #3
0
        static void CreateAndSaveIndexHtml(
            string outputFileNameWithPath,
            string outputPathAbsolute,
            string outputRootPath,
            string outputAppFilesPath,
            string outputLibrariesPath,
            string outputResourcesPath,
            string[] listOfResXGeneratedFiles,
            string assemblyNameWithoutExtension,
            string title,
            string scriptsForApplicationFiles
            )
        {
            // Read the "index.html" template:
            string indexHtmlFileTemplate = WrapperHelpers.ReadTextFileFromEmbeddedResource("index_BridgeVersion.html");

            // Replace the placeholders:
            string indexHtmlFile = indexHtmlFileTemplate.Replace("[LIBRARIES_PATH_GOES_HERE]", PathsHelper.EnsureNoBackslashAndEnsureItEndsWithAForwardSlash(outputLibrariesPath));

            indexHtmlFile = indexHtmlFile.Replace("[TITLE_GOES_HERE]", title);
            indexHtmlFile = indexHtmlFile.Replace("[SCRIPTS_FOR_APPLICATION_FILES_GO_HERE]", scriptsForApplicationFiles);

            // Read the "App.Config" file for future use by the ClientBase.
            string relativePathToAppConfigFolder = PathsHelper.CombinePathsWhileEnsuringEndingBackslashAndMore(outputResourcesPath, assemblyNameWithoutExtension);
            string relativePathToAppConfig       = Path.Combine(relativePathToAppConfigFolder, "app.config.g.js");

            if (File.Exists(Path.Combine(outputPathAbsolute, relativePathToAppConfig)))
            {
                string scriptToReadAppConfig = "        <script src=\"" + relativePathToAppConfig.Replace('\\', '/') + "\"></script>";
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_APPCONFIG_GOES_HERE]", scriptToReadAppConfig);
            }
            else
            {
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_APPCONFIG_GOES_HERE]", string.Empty);
            }

            // Read the "ServiceReferences.ClientConfig" file for future use by the ClientBase.
            string relativePathToServiceReferencesClientConfig = Path.Combine(relativePathToAppConfigFolder, "servicereferences.clientconfig.g.js");

            if (File.Exists(Path.Combine(outputPathAbsolute, relativePathToServiceReferencesClientConfig)))
            {
                string scriptToReadServiceReferencesClientConfig = "        <script src=\"" + relativePathToServiceReferencesClientConfig.Replace('\\', '/') + "\"></script>";
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_SERVICEREFERENCESCLIENTCONFIG_GOES_HERE]", scriptToReadServiceReferencesClientConfig);
            }
            else
            {
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_SERVICEREFERENCESCLIENTCONFIG_GOES_HERE]", string.Empty);
            }

            // Add the scripts for reading the ResX files:
            if (listOfResXGeneratedFiles != null && listOfResXGeneratedFiles.Length > 0)
            {
                string resultingStringForLoadingResXFiles = String.Empty;
                foreach (string str in listOfResXGeneratedFiles)
                {
                    int indexForRelativePath = str.IndexOf(outputResourcesPath);
                    if (indexForRelativePath == -1)
                    {
                        throw new Exception(string.Format("The file path '{0}' does not contain the substring '{1}'.", str, outputResourcesPath));
                    }
                    string relativePath = str.Substring(indexForRelativePath).Replace('\\', '/');
                    resultingStringForLoadingResXFiles += Environment.NewLine + "        <script src=\"" + relativePath + "\"></script>";
                }
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPTS_FOR_RESX_GO_HERE]", resultingStringForLoadingResXFiles);
            }
            else
            {
                indexHtmlFile = indexHtmlFile.Replace("[SCRIPTS_FOR_RESX_GO_HERE]", string.Empty);
            }

            // Add the version number to the files so that they are cached by the web browser only until a new version is available:
            indexHtmlFile = indexHtmlFile.Replace(".js\"", ".js?" + String.Format("?{0:yyyyMMddHHmm}", DateTime.UtcNow) + "\"");
            indexHtmlFile = indexHtmlFile.Replace(".css\"", ".css?" + String.Format("?{0:yyyyMMddHHmm}", DateTime.UtcNow) + "\"");

            // Save the "index.html" to the final folder:
            File.WriteAllText(outputFileNameWithPath, indexHtmlFile);
        }