public virtual void Install(Version lastInstalledVersion) { var assembly = GetType().Assembly; foreach (var fragment in ScriptedContentFragments) { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateDefinitionFile(this, string.Format("{0}.xml", fragment.GetType().Name), assembly.GetManifestResourceStream(fragment.DefinitionFile)); foreach (var supplementaryFile in fragment.SupplementaryFiles) { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateSupplementaryFile(this, fragment.FragmentId, supplementaryFile.Filename, assembly.GetManifestResourceStream(supplementaryFile.ResourceName)); } } }
public void Initialize() { Func <string, Guid> getGuidFromResourceString = delegate(string inGuid) { Guid outGuid; if (Guid.TryParse(inGuid.StartsWith("_") ? inGuid.Substring(1) : inGuid, out outGuid)) { return(outGuid); } return(Guid.Empty); }; var assembly = GetType().Assembly; var assemblyNameLength = assembly.GetName().Name.Length + 1; foreach (string resourceName in assembly.GetManifestResourceNames()) { string[] path = resourceName.Substring(assemblyNameLength).Split('.'); if (path.Length > 3 && string.Compare(path[0], "filestorage", true) == 0 && string.Compare(path[1], "defaultwidgets", true) == 0 && getGuidFromResourceString(path[2]) == ScriptedContentFragmentFactoryDefaultIdentifier) { Guid instanceId = getGuidFromResourceString(path[3]); if (path.Length > 4 && instanceId != Guid.Empty && (string.Compare(path[4], "xml", true) != 0 || path.Length > 5)) { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateSupplementaryFile( this, instanceId, string.Join(".", path.ToList().GetRange(4, path.Length - 4)), assembly.GetManifestResourceStream(resourceName) ); } else if (string.Compare(path[path.Length - 1], "xml", true) == 0) { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateDefinitionFile( this, string.Join(".", path.ToList().GetRange(3, path.Length - 3)), assembly.GetManifestResourceStream(resourceName) ); } } } }
public virtual void Install(Version lastInstalledVersion) { if (lastInstalledVersion < Version) { Uninstall(); string basePath = BaseResourcePath + "Widgets."; EmbeddedResources.EnumerateReosurces(basePath, ".xml", resourceName => { try { string widgetName = resourceName.Substring(basePath.Length); using (var stream = EmbeddedResources.GetStream(resourceName)) { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateDefinitionFile(this, widgetName, stream); } // Get widget identifier XDocument xdoc = XDocument.Parse(EmbeddedResources.GetString(resourceName)); XElement root = xdoc.Root; if (root == null) { return; } XElement element = root.Element("scriptedContentFragment"); if (element == null) { return; } XAttribute attribute = element.Attribute("instanceIdentifier"); if (attribute == null) { return; } Guid instanceId = new Guid(attribute.Value); string widgetBasePath = string.Concat(basePath, char.IsNumber(attribute.Value[0]) ? "_" : "", instanceId.ToString("N"), "."); IEnumerable <string> supplementaryResources = GetType().Assembly.GetManifestResourceNames().Where(r => r.StartsWith(widgetBasePath)).ToArray(); if (!supplementaryResources.Any()) { return; } foreach (string supplementPath in supplementaryResources) { string supplementName = supplementPath.Substring(widgetBasePath.Length); using (var stream = EmbeddedResources.GetStream(supplementPath)) { FactoryDefaultScriptedContentFragmentProviderFiles .AddUpdateSupplementaryFile(this, instanceId, supplementName, stream); } } } catch (Exception exception) { new CSException(CSExceptionType.UnknownError, string.Format("Couldn't load widget from '{0}' embedded resource.", resourceName), exception).Log(); } }); } }
private void InstallWidgets(string assemblyName, IEnumerable <string> resourceNames) { foreach (string resourceName in resourceNames) { string[] path = resourceName.Split('.'); // path: Resources.Widgets.[name] const int resourcesIndex = 0; const int widgetsIndex = 1; const int widgetNameIndex = 2; // path: Resources.Widgets.[name].[file].xml const int xmlFileIndex = 3; int xmlExtensionIndex = path.Length - 1; // path: Resources.Widgets.[name].[guid].[theme].[file] const int widgetFolderIdIndex = 3; const int themeIndex = 4; const int fileIndex = 5; bool isAWidgetDefinitionFile = path.Length > 4 && string.Equals(path[resourcesIndex], "Resources", StringComparison.OrdinalIgnoreCase) && string.Equals(path[widgetsIndex], "Widgets", StringComparison.OrdinalIgnoreCase); if (!isAWidgetDefinitionFile) { continue; } var resourceFullName = string.Concat(assemblyName, ".", resourceName); bool isAWidgetXmlFile = path.Length == 5 && string.Equals(path[xmlExtensionIndex], "xml", StringComparison.OrdinalIgnoreCase); if (isAWidgetXmlFile) { var fileName = string.Join(".", path.ToList().GetRange(xmlFileIndex, path.Length - xmlFileIndex)); FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateDefinitionFile( this, fileName, EmbeddedResources.GetStream(resourceFullName)); continue; } var widgetFolderId = GetGuidFromResourceString(path[widgetFolderIdIndex]); bool isAWidgetResourceFile = path.Length > 5 && widgetFolderId != Guid.Empty; if (isAWidgetResourceFile) { var fileName = string.Join(".", path.ToList().GetRange(fileIndex, path.Length - fileIndex)); var theme = SupportedThemes.Get(path[themeIndex]); if (theme != null) { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateSupplementaryFile( this, widgetFolderId, theme.Id.ToString("N"), fileName, EmbeddedResources.GetStream(resourceFullName)); } else { FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateSupplementaryFile( this, widgetFolderId, fileName, EmbeddedResources.GetStream(resourceFullName)); } } } }
private void InstallWidgets() { var assembly = GetType().Assembly; var assemblyNameLength = assembly.GetName().Name.Length + 1; foreach (string resourceName in assembly.GetManifestResourceNames()) { string[] path = resourceName.Substring(assemblyNameLength).Split('.'); // path: Resources.Widgets.[widget files] const int resourcesIndex = 0; const int widgetsIndex = 1; bool isAWidgetDefinitionFile = path.Length > 2 && string.Equals(path[resourcesIndex], "Resources", StringComparison.OrdinalIgnoreCase) && string.Equals(path[widgetsIndex], "Widgets", StringComparison.OrdinalIgnoreCase); if (isAWidgetDefinitionFile) { // path: Resources.Widgets.WidgetFolderId.[widget files] const int widgetFolderIdIndex = 2; Guid widgetFolderId = GetGuidFromResourceString(path[widgetFolderIdIndex]); bool isAWidgetXmlFile = (string.Equals(path[path.Length - 1], "xml", StringComparison.OrdinalIgnoreCase)); bool isAWidgetFolder = path.Length > 3 && widgetFolderId != Guid.Empty && !isAWidgetXmlFile; if (isAWidgetFolder) { // path: Resources.Widgets.WidgetFolderId.ThemeId.[widget files] const int themeIdIndex = 3; Guid themeId = GetGuidFromResourceString(path[themeIdIndex]); bool hasSubfolders = (themeId != Guid.Empty); if (hasSubfolders) { string fileName = string.Join(".", path.ToList().GetRange(themeIdIndex + 1, path.Length - themeIdIndex - 1)); FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateSupplementaryFile( this, widgetFolderId, themeId.ToString("N"), fileName, assembly.GetManifestResourceStream(resourceName) ); } else { // path: Resources.Widgets.WidgetFolderId.FileName const int fileNameIndex = 3; string fileName = string.Join(".", path.ToList().GetRange(fileNameIndex, path.Length - fileNameIndex)); FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateSupplementaryFile( this, widgetFolderId, fileName, assembly.GetManifestResourceStream(resourceName)); } } else if (isAWidgetXmlFile) { // path: Resources.Widgets.WidgetName.xml const int widgetNameIndex = 2; FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateDefinitionFile( this, string.Join(".", path.ToList().GetRange(widgetNameIndex, path.Length - widgetNameIndex)), assembly.GetManifestResourceStream(resourceName)); } } } }