コード例 #1
0
ファイル: ThemeRepository.cs プロジェクト: RichardHaggard/BDC
 public static Theme FindTheme(string themeName, bool fallbackToControlDefault)
 {
     lock (ThemeRepository.lockObject)
     {
         if (string.IsNullOrEmpty(themeName) || themeName == "ControlDefault")
         {
             return(ThemeRepository.ControlDefault);
         }
         if (ThemeRepository.themes.Contains((object)themeName))
         {
             return((Theme)ThemeRepository.themes[(object)themeName]);
         }
         if (ThemeRepository.registeredThemes.Contains((object)themeName))
         {
             RadThemeComponentBase registeredTheme = (RadThemeComponentBase)ThemeRepository.registeredThemes[(object)themeName];
             ThemeRepository.registeredThemes.Remove((object)themeName);
             registeredTheme.Load();
             if (registeredTheme.Site == null && !registeredTheme.IsDesignMode)
             {
                 registeredTheme.Dispose();
             }
             return(ThemeRepository.FindTheme(themeName, fallbackToControlDefault));
         }
         if (fallbackToControlDefault)
         {
             return(ThemeRepository.ControlDefault);
         }
     }
     return((Theme)null);
 }
コード例 #2
0
        private void RemoveStyles(Theme theme)
        {
            Theme theme1 = ThemeRepository.FindTheme(theme.Name);

            foreach (StyleGroup styleGroup1 in theme.StyleGroups)
            {
                for (int index = theme1.StyleGroups.Count - 1; index >= 0; --index)
                {
                    StyleGroup styleGroup2 = theme1.StyleGroups[index];
                    if (styleGroup2.IsCompatible(styleGroup1))
                    {
                        theme1.StyleGroups.Remove(styleGroup2);
                        break;
                    }
                }
            }
            foreach (StyleRepository repository1 in theme.Repositories)
            {
                for (int index = theme1.Repositories.Count - 1; index >= 0; --index)
                {
                    StyleRepository repository2 = theme1.Repositories[index];
                    if (repository2.Key == repository1.Key)
                    {
                        theme1.Repositories.Remove(repository2);
                        break;
                    }
                }
            }
            ThemeResolutionService.RaiseThemeChanged(theme.Name, "");
        }
コード例 #3
0
        public static void RegisterThemeFromStorage(ThemeStorageType storageType, string themeLocation)
        {
            XMLThemeReader xmlThemeReader = new XMLThemeReader();

            if (storageType == ThemeStorageType.File)
            {
                Theme theme = xmlThemeReader.Read(themeLocation);
                if (theme == null)
                {
                    return;
                }
                ThemeRepository.Add(theme);
            }
            else
            {
                using (Stream manifestResourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(themeLocation))
                {
                    Theme theme = xmlThemeReader.Read(manifestResourceStream);
                    if (theme == null || string.IsNullOrEmpty(theme.Name))
                    {
                        return;
                    }
                    ThemeRepository.Add(theme);
                }
            }
        }
コード例 #4
0
        public static bool LoadPackageFile(string filePath, bool throwOnError)
        {
            if (!File.Exists(filePath))
            {
                if (throwOnError)
                {
                    throw new FileNotFoundException("File '" + filePath + "' does not exist.");
                }
                return(false);
            }
            if (new FileInfo(filePath).Extension != ".tssp")
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Provided file is not a valid RadThemePackage");
                }
                return(false);
            }
            Theme theme = new TSSPThemeReader().Read(filePath);

            if (theme == null)
            {
                return(false);
            }
            ThemeRepository.Add(theme);
            return(true);
        }
コード例 #5
0
        public virtual void ReloadThemeFromStorage()
        {
            Theme theme = (Theme)null;
            bool  flag  = this.OwnerThemeManager == null || !this.OwnerThemeManager.IsDesignMode && this.ownerThemeManager.LoadedThemes.Count == 0;

            if ((object)this.callingAssembly == null)
            {
                this.callingAssembly = Assembly.GetCallingAssembly();
            }
            if (flag && ThemeSource.locationsAlreadyLoaded[(object)(this.callingAssembly.FullName + this.ThemeLocation)] == ThemeSource.locationLoadedMarker)
            {
                return;
            }
            if (this.StorageType == ThemeStorageType.File)
            {
                theme = Theme.ReadXML(this.ThemeLocation);
                ThemeRepository.Add(theme);
            }
            else if ((object)this.callingAssembly != null)
            {
                if (this.ownerThemeManager != null && this.ownerThemeManager.Site != null && this.ownerThemeManager.Site.DesignMode)
                {
                    theme = this.LoadThemeInDesingMode(this);
                    this.loadSucceeded = true;
                }
                else
                {
                    Stream stream = this.callingAssembly.GetManifestResourceStream(this.ThemeLocation) ?? Assembly.GetExecutingAssembly().GetManifestResourceStream(this.ThemeLocation);
                    if (stream == null)
                    {
                        Assembly entryAssembly = Assembly.GetEntryAssembly();
                        if ((object)entryAssembly != null)
                        {
                            stream = entryAssembly.GetManifestResourceStream(this.ThemeLocation);
                        }
                    }
                    if (stream != null)
                    {
                        using (stream)
                        {
                            theme = new XMLThemeReader().Read(stream);
                            ThemeRepository.Add(theme);
                        }
                    }
                }
            }
            if (theme != null)
            {
                this.theme = theme;
                if (!string.IsNullOrEmpty(theme.Name))
                {
                    this.loadSucceeded = true;
                }
            }
            if (!flag || !this.loadSucceeded)
            {
                return;
            }
            ThemeSource.locationsAlreadyLoaded[(object)(this.callingAssembly.FullName + this.ThemeLocation)] = ThemeSource.locationLoadedMarker;
        }
コード例 #6
0
        public static List <Theme> GetAvailableThemes(IComponentTreeHandler control)
        {
            List <Theme> themeList = new List <Theme>();

            if (control == null)
            {
                return(themeList);
            }
            ThemeRepository.LoadRegisteredThemes();
            foreach (Theme loadedTheme in (IEnumerable)ThemeRepository.LoadedThemes)
            {
                if (!(loadedTheme.Name == "*"))
                {
                    foreach (StyleGroup styleGroup in loadedTheme.StyleGroups)
                    {
                        if (styleGroup.IsCompatible(control as Control))
                        {
                            themeList.Add(loadedTheme);
                            break;
                        }
                    }
                }
            }
            return(themeList);
        }
コード例 #7
0
 protected override void Dispose(bool disposing)
 {
     if (this.Site == null && this.IsDesignMode)
     {
         ThemeRepository.Remove(this.ThemeName);
     }
     base.Dispose(disposing);
 }
コード例 #8
0
        private Theme LoadThemeInDesingMode(ThemeSource themeSource)
        {
            ProjectManagement managementInstance    = ProjectManagement.GetProjectManagementInstance((IServiceProvider)themeSource.OwnerThemeManager.Site);
            string            activeProjectFullPath = managementInstance.Services.GetActiveProjectFullPath();

            if (!themeSource.SettingsAreValid)
            {
                return(this.theme);
            }
            string configurationPropertyValue = (string)managementInstance.Services.GetProjectConfigurationPropertyValue("OutputPath");

            if (string.IsNullOrEmpty(activeProjectFullPath) || string.IsNullOrEmpty(configurationPropertyValue))
            {
                return((Theme)null);
            }
            string path1 = Path.Combine(activeProjectFullPath, configurationPropertyValue);
            string str   = (string)null;

            if (themeSource.StorageType == ThemeStorageType.File)
            {
                if (Path.IsPathRooted(themeSource.ThemeLocation))
                {
                    return((Theme)null);
                }
                string themeLocation = themeSource.ThemeLocation;
                if (path1 != null && !string.IsNullOrEmpty(themeLocation))
                {
                    string path2 = themeLocation.Replace("~\\", "").Replace("~", "");
                    str = Path.Combine(path1, path2);
                    if (!File.Exists(str))
                    {
                        themeSource.loadError = "Path not found: " + str;
                        return(this.theme);
                    }
                }
            }
            else if (themeSource.StorageType == ThemeStorageType.Resource)
            {
                string   themeLocation = themeSource.ThemeLocation;
                string[] fileNameParts = themeLocation.Split('.');
                str = ThemeSource.SearchFile(activeProjectFullPath, fileNameParts);
                if (str == null)
                {
                    themeSource.loadError = string.Format("Unable locate Resource file '{0}' in the project folder '{1}'", (object)string.Join(Path.DirectorySeparatorChar.ToString(), themeLocation.Split('.')), (object)activeProjectFullPath);
                    return(this.theme);
                }
            }
            if (str == null)
            {
                themeSource.loadError = "Unable to determine active project path.";
                return(this.theme);
            }
            Theme theme = Theme.ReadXML(str);

            ThemeRepository.Add(theme);
            return(theme);
        }
コード例 #9
0
        public static bool LoadPackageFile(string filePath)
        {
            Theme theme = new TSSPThemeReader().Read(filePath);

            if (theme == null)
            {
                return(false);
            }
            ThemeRepository.Add(theme);
            return(true);
        }
コード例 #10
0
        public static Theme EnsureThemeRegistered(string themeName)
        {
            Theme theme = ThemeRepository.FindTheme(themeName);

            if (theme == null)
            {
                theme = new Theme(themeName);
                ThemeRepository.Add(theme);
            }
            return(theme);
        }
コード例 #11
0
ファイル: ThemeRepository.cs プロジェクト: RichardHaggard/BDC
 public static void Add(Theme theme, bool replaceExistingStyle)
 {
     lock (ThemeRepository.lockObject)
     {
         string name    = theme.Name;
         char[] chArray = new char[1] {
             ','
         };
         foreach (string str in name.Split(chArray))
         {
             string themeName = str.Trim();
             if (themeName == "*" || themeName == "ControlDefault")
             {
                 if (theme != ThemeRepository.ControlDefault)
                 {
                     if (ThemeRepository.ControlDefault != null)
                     {
                         ThemeRepository.ControlDefault.Combine(theme, true, replaceExistingStyle);
                     }
                     else
                     {
                         ThemeRepository.controlDefault = theme;
                         theme.MergeRepositories();
                     }
                 }
             }
             else
             {
                 Theme theme1 = ThemeRepository.FindTheme(themeName, false);
                 if (theme1 != null)
                 {
                     if (theme != theme1)
                     {
                         theme1.Combine(theme, true, replaceExistingStyle);
                     }
                 }
                 else
                 {
                     theme.MergeRepositories();
                     ThemeRepository.themes.Add((object)themeName, (object)theme);
                 }
             }
         }
     }
     ThemeResolutionService.RaiseThemeChanged(theme.Name, (string)null);
 }
コード例 #12
0
        public static bool LoadPackageResource(
            ThemeResolutionService.ResourceParams resourceParams,
            bool throwOnError)
        {
            Assembly assembly     = resourceParams.UserAssembly;
            string   resourcePath = resourceParams.ResourcePath;

            if ((object)assembly == null)
            {
                assembly = resourceParams.CallingAssembly;
                if ((object)assembly == null)
                {
                    assembly = Assembly.GetCallingAssembly();
                }
            }
            Stream manifestResourceStream = assembly.GetManifestResourceStream(resourcePath);

            if (manifestResourceStream == null)
            {
                Assembly executingAssembly = resourceParams.ExecutingAssembly;
                if ((object)executingAssembly == null)
                {
                    executingAssembly = Assembly.GetExecutingAssembly();
                }
                manifestResourceStream = executingAssembly.GetManifestResourceStream(resourcePath);
            }
            if (manifestResourceStream == null)
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Specified resource does not exist in the provided assembly.");
                }
                return(false);
            }
            using (manifestResourceStream)
            {
                Theme theme = new TSSPThemeReader().Read(manifestResourceStream);
                if (theme != null)
                {
                    ThemeRepository.Add(theme);
                    return(true);
                }
            }
            return(false);
        }
コード例 #13
0
        private void EnsureTheme()
        {
            if (this.theme != null)
            {
                return;
            }
            string themeName = this.ThemeName;

            if (this.EnableApplicationThemeName && !string.IsNullOrEmpty(ThemeResolutionService.ApplicationThemeName))
            {
                themeName = ThemeResolutionService.ApplicationThemeName;
            }
            this.theme = ThemeRepository.FindTheme(themeName);
            if (this.theme == null)
            {
                return;
            }
            ++this.styleVersion;
        }
コード例 #14
0
ファイル: RadThemeManager.cs プロジェクト: RichardHaggard/BDC
        protected override void Dispose(bool disposing)
        {
            if (this.Site != null)
            {
                return;
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            foreach (ThemeSource loadedTheme in this.loadedThemes)
            {
                if (loadedTheme.theme != null && !string.IsNullOrEmpty(loadedTheme.theme.Name) && !dictionary.ContainsKey(loadedTheme.theme.Name))
                {
                    dictionary.Add(loadedTheme.theme.Name, loadedTheme.theme.Name);
                }
            }
            foreach (string themeName in dictionary.Values)
            {
                ThemeRepository.Remove(themeName);
            }
            base.Dispose(disposing);
        }
コード例 #15
0
 protected virtual bool LoadResource(Assembly resourceAssembly, string resourcePath)
 {
     try
     {
         using (Stream manifestResourceStream = resourceAssembly.GetManifestResourceStream(resourcePath))
         {
             if (manifestResourceStream != null)
             {
                 Theme theme = new TSSPThemeReader().Read(manifestResourceStream);
                 if (theme != null)
                 {
                     ThemeRepository.Add(theme);
                     return(true);
                 }
             }
         }
     }
     catch
     {
         int num = (int)MessageBox.Show(string.Format("Failed to load {0} theme.", (object)resourcePath));
     }
     return(false);
 }
コード例 #16
0
ファイル: ThemeRepository.cs プロジェクト: RichardHaggard/BDC
 public static Theme FindTheme(string themeName)
 {
     return(ThemeRepository.FindTheme(themeName, true));
 }
コード例 #17
0
ファイル: ThemeRepository.cs プロジェクト: RichardHaggard/BDC
 public static void Add(Theme theme)
 {
     ThemeRepository.Add(theme, true);
 }
コード例 #18
0
 public static void RemoveThemeRegistration(string themeName)
 {
     ThemeRepository.Remove(themeName);
 }