private void InstallJavaScriptFiles(string assemblyName, IEnumerable <string> resourceNames)
        {
            var jsFiles = GetJavaScriptFiles(assemblyName, resourceNames);

            foreach (var theme in Themes.List(ThemeTypes.Site))
            {
                var supportedTheme = SupportedThemes.Get(theme.Id);
                if (supportedTheme == null)
                {
                    continue;
                }

                var themeName = supportedTheme.Name;
                foreach (var jsFile in jsFiles.ToList())
                {
                    using (var stream = EmbeddedResources.GetStream(jsFile.Path))
                    {
                        if (theme.IsConfigurationBased)
                        {
                            ThemeFiles.AddUpdateFactoryDefault(theme, ThemeProperties.JavascriptFiles, jsFile.Name, stream, (int)stream.Length);
                            stream.Seek(0, SeekOrigin.Begin);
                        }
                        ThemeFiles.AddUpdate(theme, ThemeTypes.Site, ThemeProperties.JavascriptFiles, jsFile.Name, stream, (int)stream.Length);
                    }
                }
            }
        }
        private void RemovePages(string assemblyName, IEnumerable <string> resourceNames)
        {
            var xml          = new XmlDocument();
            var contentPages = Pages(assemblyName, resourceNames);

            foreach (var theme in Themes.List(ThemeTypes.Group))
            {
                var supportedTheme = SupportedThemes.Get(theme.Id);
                if (supportedTheme == null)
                {
                    continue;
                }

                var themeName = supportedTheme.Name;
                foreach (var contentPage in contentPages.Where(p => p.Theme == themeName).ToList())
                {
                    xml.LoadXml(EmbeddedResources.GetString(contentPage.Path));
                    foreach (XmlNode xmlPage in xml.SelectNodes("//contentFragmentPage"))
                    {
                        var pageName = xmlPage.Attributes["pageName"].Value;
                        if (theme.IsConfigurationBased)
                        {
                            ThemePages.DeleteFactoryDefault(theme, pageName, false);
                        }
                        ThemePages.DeleteDefault(theme, pageName, false);
                        ThemePages.Delete(theme, pageName, false);
                    }
                }
            }
        }
        private void InstallPages(string assemblyName, IEnumerable <string> resourceNames)
        {
            var xml          = new XmlDocument();
            var contentPages = Pages(assemblyName, resourceNames);

            foreach (var theme in Themes.List(ThemeTypes.Group))
            {
                var supportedTheme = SupportedThemes.Get(theme.Id);
                if (supportedTheme == null)
                {
                    continue;
                }

                var themeName = supportedTheme.Name;
                foreach (var contentPage in contentPages.Where(p => p.Theme == themeName).ToList())
                {
                    xml.LoadXml(EmbeddedResources.GetString(contentPage.Path));
                    foreach (XmlNode xmlPage in xml.SelectNodes("//contentFragmentPage"))
                    {
                        var pageName = xmlPage.Attributes["pageName"].Value;
#if DEBUG
                        Telligent.Evolution.Extensibility.Api.Version1.PublicApi.Eventlogs.Write(string.Format("Adding Page \"{0}\"", pageName), new Telligent.Evolution.Extensibility.Api.Version1.EventLogEntryWriteOptions {
                            Category = "SharePoint", EventId = 1000, EventType = "Information"
                        });
#endif
                        if (theme.IsConfigurationBased)
                        {
                            ThemePages.AddUpdateFactoryDefault(theme, xmlPage);
                        }
                        if (!ThemePages.DefaultExists(theme, pageName, false))
                        {
                            ThemePages.AddUpdateDefault(theme, xmlPage);
                        }
                        ThemePages.AddUpdate(theme, ThemeTypes.Site, xmlPage);
                    }
                }
            }
        }
        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));
                    }
                }
            }
        }