using System; using System.Collections.Generic; using ScrewTurn.Wiki.PluginFramework; using System.Text; using ScrewTurn.Wiki.SearchEngine; namespace ScrewTurn.Wiki { /// /// Implements the IHost interface. /// public class Host : IHostV30 { private static Host instance; /// /// Gets or sets the singleton instance of the Host object. /// public static Host Instance { get { if(instance == null) throw new InvalidOperationException("Host.Instance is null"); return instance; } set { instance = value; } } private Dictionary customSpecialTags; /// /// Initializes a new instance of the PluginHost class. /// public Host() { customSpecialTags = new Dictionary(5); } /// /// Gets the Special Tags added by providers. /// public Dictionary CustomSpecialTags { get { lock(customSpecialTags) { return customSpecialTags; } } } /// /// Gets the values of the Wiki Settings. /// /// The Setting's Name. /// The Setting's value. public string GetSettingValue(SettingName name) { switch(name) { case SettingName.ContactEmail: return Settings.ContactEmail; case SettingName.DateTimeFormat: return Settings.DateTimeFormat; case SettingName.DefaultLanguage: return Settings.DefaultLanguage; case SettingName.RootNamespaceDefaultPage: return Settings.DefaultPage; case SettingName.DefaultTimeZone: return Settings.DefaultTimezone.ToString(); case SettingName.MainUrl: return Settings.MainUrl; case SettingName.SenderEmail: return Settings.SenderEmail; case SettingName.WikiTitle: return Settings.WikiTitle; case SettingName.ThemesDirectory: return Settings.ThemesDirectory; case SettingName.PublicDirectory: return Settings.PublicDirectory; case SettingName.UsersCanRegister: return Settings.UsersCanRegister.ToString(); case SettingName.UsernameRegex: return Settings.UsernameRegex; case SettingName.PasswordRegex: return Settings.PasswordRegex; case SettingName.EmailRegex: return Settings.EmailRegex; case SettingName.MainUrlRegex: return Settings.MainUrlRegex; case SettingName.EnableDoubleClickEditing: return Settings.EnableDoubleClickEditing.ToString(); case SettingName.ProcessSingleLineBreaks: return Settings.ProcessSingleLineBreaks.ToString(); case SettingName.AccountActivationMode: return Settings.AccountActivationMode.ToString(); case SettingName.AllowedFileTypes: StringBuilder sb = new StringBuilder(50); foreach(string s in Settings.AllowedFileTypes) sb.Append(s + ","); return sb.ToString().TrimEnd(','); case SettingName.DisableAutomaticVersionCheck: return Settings.DisableAutomaticVersionCheck.ToString(); case SettingName.DisableBreadcrumbsTrail: return Settings.DisableBreadcrumbsTrail.ToString(); case SettingName.DisableCache: return Settings.DisableCache.ToString(); case SettingName.DisableCaptchaControl: return Settings.DisableCaptchaControl.ToString(); case SettingName.DisableConcurrentEditing: return Settings.DisableConcurrentEditing.ToString(); case SettingName.EnableHttpCompression: return Settings.EnableHttpCompression.ToString(); case SettingName.EnableViewStateCompression: return Settings.EnableViewStateCompression.ToString(); case SettingName.LoggingLevel: return Settings.LoggingLevel.ToString(); case SettingName.MaxFileSize: return Settings.MaxFileSize.ToString(); case SettingName.PageExtension: return Settings.PageExtension; case SettingName.ScriptTagsAllowed: return Settings.ScriptTagsAllowed.ToString(); case SettingName.WikiVersion: return Settings.WikiVersion; case SettingName.MaxLogSize: return Settings.MaxLogSize.ToString(); case SettingName.MaxRecentChanges: return Settings.MaxRecentChanges.ToString(); case SettingName.CacheSize: return Settings.CacheSize.ToString(); case SettingName.CacheCutSize: return Settings.CacheCutSize.ToString(); case SettingName.EditingSessionTimeout: return Collisions.EditingSessionTimeout.ToString(); case SettingName.AdministratorsGroup: return Settings.AdministratorsGroup; case SettingName.UsersGroup: return Settings.UsersGroup; case SettingName.AnonymousGroup: return Settings.AnonymousGroup; case SettingName.ChangeModerationMode: return Settings.ChangeModerationMode.ToString(); case SettingName.DefaultPagesStorageProvider: return Settings.DefaultPagesProvider; case SettingName.DefaultUsersStorageProvider: return Settings.DefaultUsersProvider; case SettingName.DefaultFilesStorageProvider: return Settings.DefaultFilesProvider; case SettingName.DefaultCacheProvider: return Settings.DefaultCacheProvider; } return ""; } /// /// Gets the list of the Users. /// /// The users. public UserInfo[] GetUsers() { return Users.GetUsers().ToArray(); } /// /// Finds a user by username, properly handling Users Storage Providers. /// /// The username. /// The , or null if no users are found. /// If username is null. /// If username is empty. public UserInfo FindUser(string username) { if(username == null) throw new ArgumentNullException("username"); if(username.Length == 0) throw new ArgumentException("Username cannot be empty", "username"); return Users.FindUser(username); } /// /// Gets the authenticated user in the current session, if any. /// /// The authenticated user, or null if no user is authenticated. /// If the built-it admin user is authenticated, the returned user /// has admin as Username. public UserInfo GetCurrentUser() { return SessionFacade.GetCurrentUser(); } /// /// Gets the list of the user groups. /// /// The groups. public UserGroup[] GetUserGroups() { return Users.GetUserGroups().ToArray(); } /// /// Finds a user group by name. /// /// The name. /// The , or null if no groups are found. /// If name is null. /// If name is empty. public UserGroup FindUserGroup(string name) { if(name == null) throw new ArgumentNullException("name"); if(name.Length == 0) throw new ArgumentException("Name cannot be empty", "name"); return Users.FindUserGroup(name); } /// /// Checks whether an action is allowed for a global resource. /// /// The action (see class) /// The user. /// true if the action is allowed, false otherwise. /// If action or user are null. /// If action is empty. public bool CheckActionForGlobals(string action, UserInfo user) { if(action == null) throw new ArgumentNullException("action"); if(action.Length == 0) throw new ArgumentException("Action cannot be empty", "action"); if(user == null) throw new ArgumentNullException("user"); return AuthChecker.CheckActionForGlobals(action, user.Username, user.Groups); } /// /// Checks whether an action is allowed for a namespace. /// /// The namespace (null for the root). /// The action (see class) /// The user. /// true if the action is allowed, false otherwise. /// If action or user are null. /// If action is empty. public bool CheckActionForNamespace(NamespaceInfo nspace, string action, UserInfo user) { if(action == null) throw new ArgumentNullException("action"); if(action.Length == 0) throw new ArgumentException("Action cannot be empty", "action"); if(user == null) throw new ArgumentNullException("user"); return AuthChecker.CheckActionForNamespace(nspace, action, user.Username, user.Groups); } /// /// Checks whether an action is allowed for a page. /// /// The page. /// The action (see class) /// The user. /// true if the action is allowed, false otherwise. /// If page, action or user are null. /// If action is empty. public bool CheckActionForPage(PageInfo page, string action, UserInfo user) { if(page == null) throw new ArgumentNullException("page"); if(action == null) throw new ArgumentNullException("action"); if(action.Length == 0) throw new ArgumentException("Action cannot be empty", "action"); if(user == null) throw new ArgumentNullException("user"); return AuthChecker.CheckActionForPage(page, action, user.Username, user.Groups); } /// /// Checks whether an action is allowed for a directory. /// /// The directory. /// The action (see ). /// The user. /// true if the action is allowed, false otherwise. /// If directory, action or user are null. /// If action is empty. public bool CheckActionForDirectory(StDirectoryInfo directory, string action, UserInfo user) { if(directory == null) throw new ArgumentNullException("directory"); if(action == null) throw new ArgumentNullException("action"); if(action.Length == 0) throw new ArgumentException("Action cannot be empty", "action"); if(user == null) throw new ArgumentNullException("user"); return AuthChecker.CheckActionForDirectory(directory.Provider, directory.FullPath, action, user.Username, user.Groups); } /// /// Gets the theme in use for a namespace. /// /// The namespace (null for the root). /// The theme. public string GetTheme(NamespaceInfo nspace) { return Settings.GetTheme(nspace != null ? nspace.Name : null); } /// /// Gets the list of the namespaces. /// /// The namespaces. public NamespaceInfo[] GetNamespaces() { return Pages.GetNamespaces().ToArray(); } /// /// Finds a namespace by name. /// /// The name. /// The , or null if no namespaces are found. public NamespaceInfo FindNamespace(string name) { return Pages.FindNamespace(name); } /// /// Gets the list of the Wiki Pages in a namespace. /// /// The namespace (null for the root). /// The pages. public PageInfo[] GetPages(NamespaceInfo nspace) { return Pages.GetPages(nspace).ToArray(); } /// /// Gets the List of Categories in a namespace. /// /// The namespace (null for the root). /// The categories. public CategoryInfo[] GetCategories(NamespaceInfo nspace) { return Pages.GetCategories(nspace).ToArray(); } /// /// Gets the list of Snippets. /// /// The snippets. public Snippet[] GetSnippets() { return Snippets.GetSnippets().ToArray(); } /// /// Gets the list of Navigation Paths in a namespace. /// /// The namespace (null for the root). /// The navigation paths. public NavigationPath[] GetNavigationPaths(NamespaceInfo nspace) { return NavigationPaths.GetNavigationPaths(nspace).ToArray(); } /// /// Gets the Categories of a Page. /// /// The Page. /// The Categories. /// If page is null. public CategoryInfo[] GetCategoriesPerPage(PageInfo page) { if(page == null) throw new ArgumentNullException("page"); return Pages.GetCategoriesForPage(page); } /// /// Gets a Wiki Page. /// /// The full Name of the Page. /// The Wiki Page or null. /// If fullName is null. /// If fullName is empty. public PageInfo FindPage(string fullName) { if(fullName == null) throw new ArgumentNullException("fullName"); if(fullName.Length == 0) throw new ArgumentException("Full Name cannot be empty"); return Pages.FindPage(fullName); } /// /// Gets the Content of a Page. /// /// The Page. /// The Page Content. /// If page is null. public PageContent GetPageContent(PageInfo page) { if(page == null) throw new ArgumentNullException("page"); return Content.GetPageContent(page, true); } /// /// Gets the Backup/Revision numbers of a Page. /// /// The Page. /// The Backup/Revision numbers. /// If page is null. public int[] GetBackups(PageInfo page) { if(page == null) throw new ArgumentNullException("page"); return Pages.GetBackups(page).ToArray(); } /// /// Gets the Content of a Page Backup. /// /// The Page. /// The revision. /// The Backup Content. /// If page is null. /// If revision is less than zero. public PageContent GetBackupContent(PageInfo page, int revision) { if(page == null) throw new ArgumentNullException("page"); if(revision < 0) throw new ArgumentOutOfRangeException("revision", "Revision must be greater than or equal to zero"); return Pages.GetBackupContent(page, revision); } /// /// Gets the formatted content of a Wiki Page. /// /// The Page. /// The formatted content. /// If page is null. public string GetFormattedContent(PageInfo page) { if(page == null) throw new ArgumentNullException("page"); PageInfo pageInfo = Pages.FindPage(page.FullName); if(pageInfo == null) return null; PageContent content = Content.GetPageContent(pageInfo, true); return Formatter.Format(content.Content, false, FormattingContext.PageContent, page); } /// /// Formats a block of WikiMarkup, using the built-in formatter only. /// /// The block of WikiMarkup. /// The formatted content. /// If raw is null. public string Format(string raw) { if(raw == null) throw new ArgumentNullException("raw"); return Formatter.Format(raw, false, FormattingContext.Unknown, null); } /// /// Prepares content for indexing in the search engine, performing bare-bones formatting and removing all WikiMarkup and XML-like characters. /// /// The page being indexed, if any, null otherwise. /// The string to prepare. /// The sanitized string. /// If content is null. public string PrepareContentForIndexing(PageInfo page, string content) { if(content == null) throw new ArgumentNullException("content"); // TODO: Improve this method - HTML formatting should not be needed return Tools.RemoveHtmlMarkup(FormattingPipeline.FormatWithPhase1And2(content, true, page != null ? FormattingContext.PageContent : FormattingContext.Unknown, page)); } /// /// Prepares a title for indexing in the search engine, removing all WikiMarkup and XML-like characters. /// /// The page being indexed, if any, null otherwise. /// The title to prepare. /// The sanitized string. /// If title is null. public string PrepareTitleForIndexing(PageInfo page, string title) { if(title == null) throw new ArgumentNullException("title"); return FormattingPipeline.PrepareTitle(title, true, page != null ? FormattingContext.PageContent : FormattingContext.Unknown, page); } /// /// Performs a search. /// /// The search query. /// A value indicating whether to perform a full-text search. /// A value indicating whether to search the names of files and attachments. /// The search options. /// The search results. /// If query is null. /// If query is empty. public SearchResultCollection PerformSearch(string query, bool fullText, bool filesAndAttachments, SearchOptions options) { if(query == null) throw new ArgumentNullException("query"); if(query.Length == 0) throw new ArgumentException("Query cannot be empty", "query"); return SearchTools.Search(query, fullText, filesAndAttachments, options); } /// /// Lists directories in a directory. /// /// The directory (null for the root, first invocation). /// The directories. public StDirectoryInfo[] ListDirectories(StDirectoryInfo directory) { List result = new List(20); if(directory == null) { foreach(IFilesStorageProviderV30 prov in Collectors.FilesProviderCollector.AllProviders) { string[] dirs = prov.ListDirectories(null); foreach(string dir in dirs) { result.Add(new StDirectoryInfo(dir, prov)); } } } else { string[] dirs = directory.Provider.ListDirectories(null); foreach(string dir in dirs) { result.Add(new StDirectoryInfo(dir, directory.Provider)); } } return result.ToArray(); } /// /// Lists files in a directory. /// /// The directory (null for the root, first invocation). /// The files. public StFileInfo[] ListFiles(StDirectoryInfo directory) { List result = new List(20); if(directory == null) { foreach(IFilesStorageProviderV30 prov in Collectors.FilesProviderCollector.AllProviders) { string[] files = prov.ListFiles(null); foreach(string file in files) { FileDetails details = prov.GetFileDetails(file); result.Add(new StFileInfo(details.Size, details.LastModified, details.RetrievalCount, file, prov)); } } } else { string[] files = directory.Provider.ListFiles(directory.FullPath); foreach(string file in files) { FileDetails details = directory.Provider.GetFileDetails(file); result.Add(new StFileInfo(details.Size, details.LastModified, details.RetrievalCount, file, directory.Provider)); } } return result.ToArray(); } /// /// Lists page attachments. /// /// The page. /// The attachments. /// If page is null. public StFileInfo[] ListPageAttachments(PageInfo page) { if(page == null) throw new ArgumentNullException("page"); List result = new List(10); foreach(IFilesStorageProviderV30 prov in Collectors.FilesProviderCollector.AllProviders) { string[] attachments = prov.ListPageAttachments(page); foreach(string attn in attachments) { FileDetails details = prov.GetPageAttachmentDetails(page, attn); result.Add(new StFileInfo(details.Size, details.LastModified, details.RetrievalCount, attn, prov)); } } return result.ToArray(); } /// /// Sends an Email. /// /// The Recipient Email address. /// The Sender's Email address. /// The Subject. /// The Body. /// True if the message is HTML. /// True if the message has been sent successfully. /// If recipient, sender, subject or body are null. /// If recipient, sender, subject or body are empty. public bool SendEmail(string recipient, string sender, string subject, string body, bool html) { if(recipient == null) throw new ArgumentNullException("recipient"); if(recipient.Length == 0) throw new ArgumentException("Recipient cannot be empty"); if(sender == null) throw new ArgumentNullException("sender"); if(sender.Length == 0) throw new ArgumentException("Sender cannot be empty"); if(subject == null) throw new ArgumentNullException("subject"); if(subject.Length == 0) throw new ArgumentException("Subject cannot be empty", "subject"); if(body == null) throw new ArgumentNullException("body"); if(body.Length == 0) throw new ArgumentException("Body cannot be empty", "body"); try { EmailTools.AsyncSendEmail(recipient, sender, subject, body, html); return true; } catch { return false; } } /// /// Logs a new message. /// /// The Message. /// The Entry Type. /// The user, or null. If null, the system will log "PluginName+System". /// The Component that calls the method. The caller cannot be null. /// If message or caller are null. /// If message is empty. public void LogEntry(string message, LogEntryType entryType, string user, object caller) { if(message == null) throw new ArgumentNullException("message"); if(message.Length == 0) throw new ArgumentException("Message cannot be empty"); if(caller == null) throw new ArgumentNullException("caller"); EntryType t = EntryType.General; switch(entryType) { case LogEntryType.General: t = EntryType.General; break; case LogEntryType.Warning: t = EntryType.Warning; break; case LogEntryType.Error: t = EntryType.Error; break; } string name = "?"; if(user == null) { if(caller is IUsersStorageProviderV30) name = ((IUsersStorageProviderV30)caller).Information.Name; else if(caller is IPagesStorageProviderV30) name = ((IPagesStorageProviderV30)caller).Information.Name; else if(caller is IFormatterProviderV30) name = ((IFormatterProviderV30)caller).Information.Name; else if(caller is ISettingsStorageProviderV30) name = ((ISettingsStorageProviderV30)caller).Information.Name; else if(caller is IFilesStorageProviderV30) name = ((IFilesStorageProviderV30)caller).Information.Name; else if(caller is ICacheProviderV30) name = ((ICacheProviderV30)caller).Information.Name; name += "+" + Log.SystemUsername; } else name = user; Log.LogEntry(message, t, name); } /// /// Changes the language of the current user. /// /// The language code. public void ChangeCurrentUserLanguage(string language) { int timezone = Preferences.LoadTimezoneFromCookie() ?? Settings.DefaultTimezone; if(SessionFacade.LoginKey == null || SessionFacade.CurrentUsername == "admin") Preferences.SavePreferencesInCookie(language, timezone); else Preferences.SavePreferencesInUserData(language, timezone); } /// /// Aligns a Date and Time object to the User's Time Zone preferences. /// /// The Date/Time to align. /// The aligned Date/Time. /// The method takes care of daylight saving settings. public DateTime AlignDateTimeWithPreferences(DateTime dt) { return Preferences.AlignWithTimezone(dt); } /// /// Clears the cache. /// /// The part of the cache to clear. public void ClearCache(CacheData data) { switch(data) { case CacheData.Pages: Content.InvalidateAllPages(); break; case CacheData.MetaFiles: Content.ClearPseudoCache(); break; default: throw new ArgumentException("Invalid CacheData"); } } /// /// Adds an item in the Editing Toolbar. /// /// The item to add. /// The text of the item. /// The value of the item. /// If text or value are null. /// If text or value are empty, or if they contain single or double quotes, /// or if value does not contain a pipe when item is SpecialTagWrap. public void AddToolbarItem(ToolbarItem item, string text, string value) { if(text == null) throw new ArgumentNullException("text"); if(text.Length == 0) throw new ArgumentException("Text cannot be empty", "text"); if(text.Contains("\"") || text.Contains("'")) throw new ArgumentException("Text cannot contain single or double quotes", "text"); if(value == null) throw new ArgumentNullException("value"); if(value.Length == 0) throw new ArgumentException("Value cannot be empty", "value"); if(value.Contains("\"") || value.Contains("'")) throw new ArgumentException("Value cannot contain single or double quotes", "value"); if(item == ToolbarItem.SpecialTagWrap && !value.Contains("|")) throw new ArgumentException("Invalid value for a SpecialTagWrap (pipe not found)", "value"); lock(customSpecialTags) { if(customSpecialTags.ContainsKey(text)) { customSpecialTags[text].Value = value; customSpecialTags[text].Item = item; } else customSpecialTags.Add(text, new CustomToolbarItem(item, text, value)); } } /// /// Gets the default provider of the specified type. /// /// The type of the provider ( /// , /// , /// , /// ). /// The Full type name of the default provider of the specified type or null. public string GetDefaultProvider(Type providerType) { switch(providerType.FullName) { case ProviderLoader.UsersProviderInterfaceName: return Settings.DefaultUsersProvider; case ProviderLoader.PagesProviderInterfaceName: return Settings.DefaultPagesProvider; case ProviderLoader.FilesProviderInterfaceName: return Settings.DefaultFilesProvider; case ProviderLoader.CacheProviderInterfaceName: return Settings.DefaultCacheProvider; default: return null; } } /// /// Gets the pages storage providers, either enabled or disabled. /// /// true to get enabled providers, false to get disabled providers. /// The providers. public IPagesStorageProviderV30[] GetPagesStorageProviders(bool enabled) { if(enabled) return Collectors.PagesProviderCollector.AllProviders; else return Collectors.DisabledPagesProviderCollector.AllProviders; } /// /// Gets the users storage providers, either enabled or disabled. /// /// true to get enabled providers, false to get disabled providers. /// The providers. public IUsersStorageProviderV30[] GetUsersStorageProviders(bool enabled) { if(enabled) return Collectors.UsersProviderCollector.AllProviders; else return Collectors.DisabledUsersProviderCollector.AllProviders; } /// /// Gets the files storage providers, either enabled or disabled. /// /// true to get enabled providers, false to get disabled providers. /// The providers. public IFilesStorageProviderV30[] GetFilesStorageProviders(bool enabled) { if(enabled) return Collectors.FilesProviderCollector.AllProviders; else return Collectors.DisabledFilesProviderCollector.AllProviders; } /// /// Gets the cache providers, either enabled or disabled. /// /// true to get enabled providers, false to get disabled providers. /// The providers. public ICacheProviderV30[] GetCacheProviders(bool enabled) { if(enabled) return Collectors.CacheProviderCollector.AllProviders; else return Collectors.DisabledCacheProviderCollector.AllProviders; } /// /// Gets the formatter providers, either enabled or disabled. /// /// true to get enabled providers, false to get disabled providers. /// The providers. public IFormatterProviderV30[] GetFormatterProviders(bool enabled) { if(enabled) return Collectors.FormatterProviderCollector.AllProviders; else return Collectors.DisabledFormatterProviderCollector.AllProviders; } /// /// Gets the current settings storage provider. /// /// The settings storage provider. public ISettingsStorageProviderV30 GetSettingsStorageProvider() { return Settings.Provider; } /// /// Gets the configuration of a provider. /// /// The type name of the provider, such as 'Vendor.Namespace.Provider'. /// The configuration (can be empty or null). /// If providerTypeName is null. /// If providerTypeName is empty. public string GetProviderConfiguration(string providerTypeName) { if(providerTypeName == null) throw new ArgumentNullException("providerTypeName"); if(providerTypeName.Length == 0) throw new ArgumentException("Provider Type Name cannot be empty", "providerTypeName"); if(providerTypeName == Settings.Provider.GetType().FullName) { return StartupTools.GetSettingsStorageProviderConfiguration(); } else return ProviderLoader.LoadConfiguration(providerTypeName); } /// /// Sets the configuration of a provider. /// /// The provider of which to set the configuration. /// The configuration to set. /// true if the configuration is set, false otherwise. /// If provider is null. public bool SetProviderConfiguration(IProviderV30 provider, string configuration) { if(provider == null) throw new ArgumentNullException("provider"); if(configuration == null) configuration = ""; ProviderLoader.SaveConfiguration(provider.GetType().FullName, configuration); return true; } /// /// Upgrades the old Page Status to use the new ACL facilities. /// /// The page of which to upgrade the status. /// The old status ('L' = Locked, 'P' = Public). /// true if the operation succeeded, false otherwise. /// If page is null. /// If oldStatus is invalid. public bool UpgradePageStatusToAcl(PageInfo page, char oldStatus) { if(page == null) throw new ArgumentNullException("page"); switch(oldStatus) { case 'L': // Locked: only administrators can edit this page return AuthWriter.SetPermissionForPage(AuthStatus.Deny, page, Actions.ForPages.ModifyPage, Users.FindUserGroup(Settings.UsersGroup)); case 'P': // Public: anonymous users can edit this page return AuthWriter.SetPermissionForPage(AuthStatus.Grant, page, Actions.ForPages.ModifyPage, Users.FindUserGroup(Settings.AnonymousGroup)); default: throw new ArgumentOutOfRangeException("oldStatus", "Invalid old status code"); } } /// /// Upgrades the old security flags to use the new ACL facilities and user groups support. /// /// The administrators group. /// The users group. /// true if the operation succeeded, false otherwise. /// If administrators or users are null. public bool UpgradeSecurityFlagsToGroupsAcl(UserGroup administrators, UserGroup users) { if(administrators == null) throw new ArgumentNullException("administrators"); if(users == null) throw new ArgumentNullException("users"); bool done = true; done &= StartupTools.SetAdministratorsGroupDefaultPermissions(administrators); done &= StartupTools.SetUsersGroupDefaultPermissions(users); return done; } /// /// Event fired whenever an activity is performed on a User Account. /// public event EventHandler UserAccountActivity; /// /// Fires the UserAccountActivity event. /// /// The user the activity refers to. /// The activity. public void OnUserAccountActivity(UserInfo user, UserAccountActivity activity) { if(UserAccountActivity != null) { UserAccountActivity(this, new UserAccountActivityEventArgs(user, activity)); } } /// /// Event fired whenever an activity is performed on a user group. /// public event EventHandler UserGroupActivity; /// /// Fires the UserGroupActivity event. /// /// The group the activity refers to. /// The activity. public void OnUserGroupActivity(UserGroup group, UserGroupActivity activity) { if(UserGroupActivity != null) { UserGroupActivity(this, new UserGroupActivityEventArgs(group, activity)); } } /// /// Event fired whenever an activity is performed on a namespace. /// public event EventHandler NamespaceActivity; /// /// Fires the NamespaceActivity event. /// /// The namespace the activity refers to. /// The old name of the renamed namespace, or null. /// The activity. public void OnNamespaceActivity(NamespaceInfo nspace, string nspaceOldName, NamespaceActivity activity) { if(NamespaceActivity != null) { NamespaceActivity(this, new NamespaceActivityEventArgs(nspace, nspaceOldName, activity)); } } /// /// Even fired whenever an activity is performed on a Page. /// public event EventHandler PageActivity; /// /// Fires the PageActivity event. /// /// The page the activity refers to. /// The old name of the renamed page, or null. /// The author of the activity. /// The activity. public void OnPageActivity(PageInfo page, string pageOldName, string author, PageActivity activity) { if(PageActivity != null) { PageActivity(this, new PageActivityEventArgs(page, pageOldName, author, activity)); } } /// /// Event fired whenever an activity is performed on a file, directory or attachment. /// public event EventHandler FileActivity; /// /// Fires the FileActivity event. /// /// The provider that handles the file. /// The name of the file that changed. /// The old name of the renamed file, if any. /// The activity. public void OnFileActivity(string provider, string file, string oldFileName, FileActivity activity) { if(FileActivity != null) { IFilesStorageProviderV30 prov = Collectors.FilesProviderCollector.GetProvider(provider); FileActivity(this, new FileActivityEventArgs( new StFileInfo(prov.GetFileDetails(file), file, prov), oldFileName, null, null, null, activity)); } } /// /// Fires the FileActivity event. /// /// The provider that handles the attachment. /// The old name of the renamed attachment, if any. /// The page that owns the attachment. /// The old name of the renamed attachment, if any. /// The activity. public void OnAttachmentActivity(string provider, string attachment, string page, string oldAttachmentName, FileActivity activity) { if(FileActivity != null) { IFilesStorageProviderV30 prov = Collectors.FilesProviderCollector.GetProvider(provider); PageInfo pageInfo = Pages.FindPage(page); FileActivity(this, new FileActivityEventArgs( new StFileInfo(prov.GetPageAttachmentDetails(pageInfo, attachment), attachment, prov), oldAttachmentName, null, null, pageInfo, activity)); } } /// /// Fires the FileActivity event. /// /// The provider that handles the directory. /// The directory that changed. /// The old name of the renamed directory, if any. /// The activity. public void OnDirectoryActivity(string provider, string directory, string oldDirectoryName, FileActivity activity) { if(FileActivity != null) { IFilesStorageProviderV30 prov = Collectors.FilesProviderCollector.GetProvider(provider); FileActivity(this, new FileActivityEventArgs( null, null, new StDirectoryInfo(directory, prov), oldDirectoryName, null, activity)); } } } /// /// Represents a custom toolbar item. /// public class CustomToolbarItem { private ToolbarItem item; private string text, value; /// /// Initializes a new instance of the ToolbarItem class. /// /// The item. /// The text. /// The value. public CustomToolbarItem(ToolbarItem item, string text, string value) { this.item = item; this.text = text; this.value = value; } /// /// Gets or sets the item. /// public ToolbarItem Item { get { return item; } set { item = value; } } /// /// Gets the text. /// public string Text { get { return text; } } /// /// Gets or sets the value. /// public string Value { get { return value; } set { this.value = value; } } } }