Example #1
0
        /// <summary>
        /// Downloads and updates a DLL.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="url">The URL of the new DLL.</param>
        /// <param name="filename">The file name of the DLL.</param>
        private bool DownloadAndUpdateDll(IProviderV40 provider, string url, string filename)
        {
            try {
                // They must always be null except in testing where they are mocked
                HttpWebRequest  request  = (HttpWebRequest)HttpWebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Log.LogEntry("Update failed for provider " + provider.GetType().FullName + ": Status Code=" + response.StatusCode.ToString(), EntryType.Error, Log.SystemUsername, null);
                    response.Close();
                    return(false);
                }

                BinaryReader reader  = new BinaryReader(response.GetResponseStream());
                byte[]       content = reader.ReadBytes((int)response.ContentLength);
                reader.Close();

                bool done = globalSettingsProvider.StorePluginAssembly(filename, content);
                if (done)
                {
                    Log.LogEntry("Provider " + provider.GetType().FullName + " updated", EntryType.General, Log.SystemUsername, null);
                }
                else
                {
                    Log.LogEntry("Update failed for provider " + provider.GetType().FullName + ": could not store assembly", EntryType.Error, Log.SystemUsername, null);
                }

                return(done);
            }
            catch (Exception ex) {
                Log.LogEntry("Update failed for provider " + provider.GetType().FullName + ": " + ex.ToString(), EntryType.Error, Log.SystemUsername, null);
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Finds a provider.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="typeName">The provider type name.</param>
        /// <param name="enabled">A value indicating whether the provider is enabled.</param>
        /// <returns>The provider, or <c>null</c>.</returns>
        public static IProviderV40 FindProvider(string wiki, string typeName, out bool enabled)
        {
            enabled = false;
            IProviderV40 prov = null;

            prov = CollectorsBox.FormatterProviderCollector.GetProvider(typeName, wiki);
            if (prov != null)
            {
                enabled = Settings.GetProvider(wiki).GetPluginStatus(typeName);
                return(prov);
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Tries to change a provider's configuration.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="configuration">The new configuration.</param>
        /// <param name="wiki">The wiki.</param>
        /// <param name="error">The error message, if any.</param>
        /// <returns><c>true</c> if the configuration is saved, <c>false</c> if the provider rejected it.</returns>
        public static bool TryChangePluginConfiguration(IProviderV40 plugin, string configuration, string wiki, out string error)
        {
            error = null;

            SavePluginConfiguration(wiki, plugin.GetType().FullName, configuration);
            try {
                SetUp <IFormatterProviderV40>(plugin.GetType(), configuration);
                SavePluginStatus(wiki, plugin.GetType().FullName, true);
            }
            catch (InvalidConfigurationException icex) {
                error = icex.Message;
                SavePluginStatus(wiki, plugin.GetType().FullName, false);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Detectes whether a provider is included in the list.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <returns><c>true</c> if the provider is included, <c>false</c> otherwise.</returns>
        private bool IsProviderIncludedInList(IProviderV40 provider)
        {
            IStorageProviderV40      storageProvider = provider as IStorageProviderV40;
            IUsersStorageProviderV40 usersProvider   = provider as IUsersStorageProviderV40;

            switch (providerType)
            {
            case ProviderType.Users:
                return(IsUsersProviderIncludedInList(usersProvider));

            case ProviderType.Pages:
                return(storageProvider == null || (!storageProvider.ReadOnly || storageProvider.ReadOnly && !excludeReadOnly));

            case ProviderType.Files:
                return(storageProvider == null || (!storageProvider.ReadOnly || storageProvider.ReadOnly && !excludeReadOnly));

            case ProviderType.Themes:
                return(storageProvider == null || (!storageProvider.ReadOnly || storageProvider.ReadOnly && !excludeReadOnly));

            default:
                throw new NotSupportedException();
            }
        }
Example #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool         enabled;
            IProviderV40 prov = GetCurrentProvider(out enabled);

            Log.LogEntry("Configuration change requested for Provider " + prov.Information.Name, EntryType.General, SessionFacade.CurrentUsername, currentWiki);

            string error;

            if (ProviderLoader.TryChangePluginConfiguration(prov, txtConfigurationString.Text, currentWiki, out error))
            {
                lblResult.CssClass = "resultok";
                lblResult.Text     = Properties.Messages.ProviderConfigurationSaved;

                ResetEditor();
                rptProviders.DataBind();
            }
            else
            {
                lblResult.CssClass = "resulterror";
                lblResult.Text     = Properties.Messages.ProviderRejectedConfiguration +
                                     (string.IsNullOrEmpty(error) ? "" : (": " + error));
            }
        }
Example #6
0
        protected void rptProviders_ItemCommand(object sender, CommandEventArgs e)
        {
            txtCurrentProvider.Value = e.CommandArgument as string;

            if (e.CommandName == "Select")
            {
                bool         enabled;
                IProviderV40 provider = GetCurrentProvider(out enabled);

                pnlProviderDetails.Visible = true;
                lblProviderName.Text       = provider.Information.Name + " (" + provider.Information.Version + ")";
                string dll = provider.GetType().Assembly.FullName;
                lblProviderDll.Text         = dll.Substring(0, dll.IndexOf(",")) + ".dll";
                txtConfigurationString.Text = ProviderLoader.LoadPluginConfiguration(currentWiki, provider.GetType().FullName);
                if (provider.ConfigHelpHtml != null)
                {
                    lblProviderConfigHelp.Text = provider.ConfigHelpHtml;
                }
                else
                {
                    lblProviderConfigHelp.Text = Properties.Messages.NoConfigurationRequired;
                }

                lblResult.CssClass = "";
                lblResult.Text     = "";
                rptProviders.DataBind();
            }
            else if (e.CommandName == "Disable")
            {
                bool         enabled;
                IProviderV40 prov = GetCurrentProvider(out enabled);
                Log.LogEntry("Deactivation requested for Provider " + prov.Information.Name, EntryType.General, SessionFacade.CurrentUsername, currentWiki);

                ProviderLoader.SavePluginStatus(currentWiki, txtCurrentProvider.Value, false);

                lblResult.CssClass = "resultok";
                lblResult.Text     = Properties.Messages.ProviderDisabled;

                ResetEditor();
                rptProviders.DataBind();
            }
            else if (e.CommandName == "Enable")
            {
                bool         enabled;
                IProviderV40 prov = GetCurrentProvider(out enabled);
                Log.LogEntry("Activation requested for provider provider " + prov.Information.Name, EntryType.General, SessionFacade.CurrentUsername, currentWiki);

                try {
                    ProviderLoader.SetUp <IFormatterProviderV40>(prov.GetType(), Settings.GetProvider(currentWiki).GetPluginConfiguration(prov.GetType().FullName));
                    ProviderLoader.SavePluginStatus(currentWiki, txtCurrentProvider.Value, true);
                    lblResult.CssClass = "resultok";
                    lblResult.Text     = Properties.Messages.ProviderEnabled;
                }
                catch (InvalidConfigurationException) {
                    ProviderLoader.SavePluginStatus(currentWiki, txtCurrentProvider.Value, false);
                    lblResult.CssClass = "resulterror";
                    lblResult.Text     = Properties.Messages.ProviderRejectedConfiguration;
                }

                ResetEditor();
                rptProviders.DataBind();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:StorageProviderRow" /> class.
 /// </summary>
 /// <param name="provider">The original provider.</param>
 public StorageProviderRow(IProviderV40 provider, Type providerInterface)
 {
     _provider          = provider.Information.Name;
     _providerType      = provider.GetType().FullName;
     _providerInterface = providerInterface.FullName;
 }