Esempio n. 1
0
 public void GetResourcesThatDoNotExist()
 {
     Assert.IsNull(EmbeddedResourceHelper.GetResource(null));
     Assert.IsNull(EmbeddedResourceHelper.GetResource(string.Empty));
     // file extension is for client dependency framework, so used not needed for html files
     Assert.IsNull(EmbeddedResourceHelper.GetResource(EmbeddedResource.RESOURCE_PREFIX + CSS_RESOURCE + EmbeddedResource.FILE_EXTENSION));
     Assert.IsNull(EmbeddedResourceHelper.GetResource(EmbeddedResource.RESOURCE_PREFIX + JS_RESOURCE + EmbeddedResource.FILE_EXTENSION));
 }
Esempio n. 2
0
        /// <summary>
        /// Gets an embedded resource from the main assembly
        /// </summary>
        /// <param name="fileName">Name of resource</param>
        /// <returns>File stream of resource</returns>
        public ActionResult GetResource(string fileName)
        {
            Mandate.ParameterNotNullOrEmpty(fileName, nameof(fileName));

            var assembly       = typeof(ResourceController).Assembly;
            var resourceStream = EmbeddedResourceHelper.GetResource(assembly, fileName, out string resourceName);

            if (resourceStream != null)
            {
                return(new FileStreamResult(resourceStream, GetMimeType(resourceName)));
            }

            return(HttpNotFound());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets an embedded resource from the main assembly
        /// </summary>
        /// <param name="fileName">Name of resource</param>
        /// <returns>File stream of resource</returns>
        public ActionResult GetResource(string fileName)
        {
            Mandate.ParameterNotNullOrEmpty(fileName, "fileName");

            // Get this assembly.
            Assembly assembly = typeof(ResourceController).Assembly;
            string   resourceName;
            Stream   resourceStream = EmbeddedResourceHelper.GetResource(assembly, fileName, out resourceName);

            if (resourceStream != null)
            {
                return(new FileStreamResult(resourceStream, this.GetMimeType(resourceName)));
            }

            return(this.HttpNotFound());
        }
Esempio n. 4
0
        /// <summary>
        /// Gets an embedded resource for a given criteria, that may be from the main assembly or another one
        /// </summary>
        /// <param name="criteriaAlias">Alias of criteria</param>
        /// <param name="fileName">Name of resource</param>
        /// <returns>File stream of resource</returns>
        public ActionResult GetResourceForCriteria(string criteriaAlias, string fileName)
        {
            Mandate.ParameterNotNullOrEmpty(criteriaAlias, "criteriaAlias");
            Mandate.ParameterNotNullOrEmpty(fileName, "fileName");

            var criteria = PersonalisationGroupMatcher.GetAvailableCriteria()
                           .SingleOrDefault(x => x.Alias.InvariantEquals(criteriaAlias));

            if (criteria != null)
            {
                string resourceName;
                var    resourceStream = EmbeddedResourceHelper.GetResource(criteria.GetType().Assembly, criteriaAlias + "." + fileName, out resourceName);

                if (resourceStream != null)
                {
                    return(new FileStreamResult(resourceStream, GetMimeType(resourceName)));
                }
            }

            return(HttpNotFound());
        }
Esempio n. 5
0
 public void GetResourcesThatExist()
 {
     Assert.IsNotNull(EmbeddedResourceHelper.GetResource(EmbeddedResource.RESOURCE_PREFIX + HTML_RESOURCE));
     Assert.IsNotNull(EmbeddedResourceHelper.GetResource(EmbeddedResource.RESOURCE_PREFIX + CSS_RESOURCE));
     Assert.IsNotNull(EmbeddedResourceHelper.GetResource(EmbeddedResource.RESOURCE_PREFIX + JS_RESOURCE));
 }
        /// <summary>
        /// Performs installation of the Zoombraco package.
        /// Note: At this point in time it is not possible to register the package as installed to the CMS. This means that we are
        /// unable to automatically uninstall the package.
        /// </summary>
        /// <param name="umbracoApplication">
        /// The current <see cref="UmbracoApplicationBase"/>
        /// </param>
        /// <param name="applicationContext">
        /// The Umbraco <see cref="ApplicationContext"/> for the current application.
        /// </param>
        /// <returns>The <see cref="bool"/></returns>
        public static bool Install(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (!applicationContext.IsConfigured)
            {
                LogHelper.Info <ZoombracoBootstrapper>("Umbraco is not configured. Aborting Zoombraco setup.");
                return(false);
            }

            // Check our versioning.
            Assembly   assembly         = VersionParser.Assembly;
            SemVersion currentVersion   = VersionParser.ZoombracoProductVersion();
            SemVersion installedVersion = ZoombracoConfiguration.Instance.ProductVersion;

            if (installedVersion >= currentVersion)
            {
                LogHelper.Info <ZoombracoBootstrapper>($"Zoombraco {installedVersion} is installed and up-to-date. Aborting Zoombraco setup.");
                return(true);
            }

            try
            {
                // Install our package.
                string resourceName;
                using (Stream package = EmbeddedResourceHelper.GetResource(assembly, "package.xml", out resourceName))
                {
                    PackageHelper packageHelper = new PackageHelper(package, applicationContext);
                    packageHelper.Unpack();

                    using (Stream meta = EmbeddedResourceHelper.GetResource(assembly, "_Meta.cshtml", out resourceName))
                        using (Stream sitemap = EmbeddedResourceHelper.GetResource(assembly, "XmlSitemap.cshtml", out resourceName))
                            using (Stream error = EmbeddedResourceHelper.GetResource(assembly, "Error.cshtml", out resourceName))
                            {
                                packageHelper.UnpackFile(meta, "_Meta.cshtml");
                                packageHelper.UnpackFile(sitemap, "XmlSitemap.cshtml");
                                packageHelper.UnpackFile(error, "Error.cshtml");
                            }
                }

                // Edit the Examine config file.
                string settings = Path.Combine(IOHelper.GetRootDirectorySafe(), "Config", "ExamineSettings.config");
                if (!File.Exists(settings))
                {
                    LogHelper.Error <ZoombracoBootstrapper>($"Unable to install the Zoombraco. No ExamineSetting.config exists at the path {settings}", new FileNotFoundException());
                    return(false);
                }

                using (FileStream stream = File.Open(settings, FileMode.Open, FileAccess.ReadWrite))
                {
                    ExamineHelper examineHelper = new ExamineHelper(stream);
                    examineHelper.UpdateExamineAnalyzer();
                }

                // Set default values.
                if (installedVersion == new SemVersion(0))
                {
                    ZoombracoConfiguration.SaveSetting(ZoombracoConstants.Configuration.OutputCacheDuration, "0");
                    ZoombracoConfiguration.SaveSetting(ZoombracoConstants.Configuration.ImageCdnRequestTimeout, "2000");
                    ZoombracoConfiguration.SaveSetting(ZoombracoConstants.Configuration.ModelsBuilderEnabled, "false");
                }

                // Update our version number
                ZoombracoConfiguration.SaveSetting(ZoombracoConstants.Configuration.Version, currentVersion.ToSemanticString());

                return(true);
            }
            catch (Exception e)
            {
                LogHelper.Error <ZoombracoBootstrapper>("Unable to install the Zoombraco.", e);
                return(false);
            }
        }