Ejemplo n.º 1
0
        /// <summary>
        /// Loads a theme package stored in the provided file.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="throwOnError">True to throw an exception if it occurs, false otherwise.</param>
        /// <returns></returns>
        public static bool LoadPackageFile(string filePath, bool throwOnError)
        {
            if (!File.Exists(filePath))
            {
                if (throwOnError)
                {
                    throw new FileNotFoundException("File '" + filePath + "' does not exist.");
                }

                return(false);
            }

            FileInfo fi = new FileInfo(filePath);

            if (fi.Extension != "." + RadThemePackage.FileExtension)
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Provided file is not a valid RadThemePackage");
                }

                return(false);
            }

            RadThemePackage package = RadThemePackage.Decompress(filePath, typeof(RadThemePackage)) as RadThemePackage;

            if (package == null)
            {
                return(false);
            }

            return(LoadPackage(package, throwOnError));
        }
Ejemplo n.º 2
0
        public static bool LoadPackageResource(ResourceParams resourceParams, bool throwOnError)
        {
            if (loadedResourcePackages.ContainsKey(resourceParams.ResourcePath))
            {
                return(true);
            }

            Assembly assembly = null;

            assembly = resourceParams.UserAssembly;
            string resourcePath = resourceParams.ResourcePath;

            if (assembly == null)
            {
                assembly = resourceParams.CallingAssembly;

                if (assembly == null)
                {
                    assembly = Assembly.GetCallingAssembly();
                }
            }

            Stream stream = assembly.GetManifestResourceStream(resourcePath);

            if (stream == null)
            {
                assembly = resourceParams.ExecutingAssembly;

                if (assembly == null)
                {
                    assembly = Assembly.GetExecutingAssembly();
                }

                stream = assembly.GetManifestResourceStream(resourcePath);
            }

            if (stream == null)
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Specified resource does not exist in the provided assembly.");
                }

                return(false);
            }

            RadThemePackage package = RadThemePackage.Decompress(stream, typeof(RadThemePackage)) as RadThemePackage;

            if (package == null)
            {
                return(false);
            }

            //remember this location and do not load it again
            loadedResourcePackages[resourceParams.ResourcePath] = null;

            return(LoadPackage(package, throwOnError));
        }
Ejemplo n.º 3
0
        private static bool LoadPackage(RadThemePackage package, bool throwOnError)
        {
            try
            {
                foreach (XmlTheme xmlTheme in package.DecompressThemes())
                {
                    Theme.Deserialize(xmlTheme);
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (throwOnError)
                {
                    throw;
                }

                Debug.Fail("Failed to decompress themes from package. Exception was:\r\n" + ex);
                return(false);
            }
        }