Exemple #1
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);
        }
Exemple #2
0
        private bool LoadThemeInDesingMode(ThemeSource themeSource)
        {
            ProjectManagement pm = ProjectManagement.GetProjectManagementInstance(themeSource.OwnerThemeManager.Site);
            string            projectFullPath = pm.Services.GetActiveProjectFullPath();

            //return true - means no further processing required
            if (!themeSource.SettingsAreValid)
            {
                return(true);
            }

            string baseFolder = null;
            string fileName   = null;

            string outputPath = (string)pm.Services.GetProjectConfigurationPropertyValue("OutputPath");

            if (string.IsNullOrEmpty(projectFullPath) || string.IsNullOrEmpty(outputPath))
            {
                return(false);
            }

            baseFolder = Path.Combine(projectFullPath, outputPath);

            string validFilePath = null;

            if (themeSource.StorageType == ThemeStorageType.File)
            {
                if (Path.IsPathRooted(themeSource.ThemeLocation))
                {
                    return(false);
                }

                fileName = themeSource.ThemeLocation;

                if (baseFolder != null && !string.IsNullOrEmpty(fileName))
                {
                    fileName      = fileName.Replace("~\\", "");
                    fileName      = fileName.Replace("~", "");
                    validFilePath = Path.Combine(baseFolder, fileName);

                    if (!File.Exists(validFilePath))
                    {
                        themeSource.loadError = "Path not found: " + validFilePath;
                        return(true);
                    }
                }
            }
            else if (themeSource.StorageType == ThemeStorageType.Resource)
            {
                string   themeLocation = themeSource.ThemeLocation;
                string[] fileNameParts = themeLocation.Split('.');

                validFilePath = SearchFile(projectFullPath, fileNameParts);

                if (validFilePath == null)
                {
                    themeSource.loadError =
                        string.Format(
                            "Unable locate Resource file '{0}' in the project folder '{1}'",
                            string.Join(Path.DirectorySeparatorChar.ToString(), themeLocation.Split('.')),
                            projectFullPath
                            );

                    return(true);
                }
            }

            if (validFilePath == null)
            {
                themeSource.loadError = "Unable to determine active project path.";
                return(true);
            }

            using (XmlReader reader = XmlReader.Create(validFilePath))
            {
                this.DeserializePartiallyThemeFromReader(reader, validFilePath);
            }

            themeSource.loadSucceeded = true;

            return(true);
        }