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); }
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); }