Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the Storage Provider.
        /// </summary>
        /// <param name="host">The Host of the Component.</param>
        /// <param name="config">The Configuration data, if any.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="host"/> or <paramref name="config"/> are <c>null</c>.</exception>
        /// <exception cref="InvalidConfigurationException">If <paramref name="config"/> is not valid or is incorrect.</exception>
        public void Init(IHostV30 host, string config)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (AlreadyRun)
            {
                return;
            }

            // 1. Delete PluginPack.dll
            // 2. Download all other DLLs

            string root = "http://www.screwturn.eu/Version/PluginPack/";

            string[] dllNames = new string[] {
                "DownloadCounterPlugin.dll",
                "FootnotesPlugin.dll",
                "MultilanguageContentPlugin.dll",
                "RssFeedDisplayPlugin.dll",
                "UnfuddleTicketsPlugin.dll"
            };

            string[] providerNames = new string[] {
                "ScrewTurn.Wiki.Plugins.PluginPack.DownloadCounter",
                "ScrewTurn.Wiki.Plugins.PluginPack.Footnotes",
                "ScrewTurn.Wiki.Plugins.PluginPack.MultilanguageContentPlugin",
                "ScrewTurn.Wiki.Plugins.PluginPack.RssFeedDisplay",
                "ScrewTurn.Wiki.Plugins.PluginPack.UnfuddleTickets",
            };

            Dictionary <string, byte[]> assemblies = new Dictionary <string, byte[]>(dllNames.Length);

            try {
                foreach (string dll in dllNames)
                {
                    host.LogEntry("Downloading " + dll, LogEntryType.General, null, this);

                    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(root + dll);
                    req.AllowAutoRedirect = true;
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        BinaryReader reader  = new BinaryReader(resp.GetResponseStream());
                        byte[]       content = reader.ReadBytes((int)resp.ContentLength);
                        reader.Close();

                        assemblies.Add(dll, content);
                    }
                    else
                    {
                        throw new InvalidOperationException("Response status code for " + dll + ":" + resp.StatusCode.ToString());
                    }
                }

                foreach (string dll in dllNames)
                {
                    host.GetSettingsStorageProvider().StorePluginAssembly(dll, assemblies[dll]);
                }

                foreach (string dll in dllNames)
                {
                    LoadProvider(dll);
                }

                host.GetSettingsStorageProvider().DeletePluginAssembly("PluginPack.dll");

                AlreadyRun = true;
            }
            catch (Exception ex) {
                host.LogEntry("Error occurred during automatic DLL updating with Updater Plugin\n" + ex.ToString(), LogEntryType.Error, null, this);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the Storage Provider.
        /// </summary>
        /// <param name="host">The Host of the Component.</param>
        /// <param name="config">The Configuration data, if any.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="host"/> or <paramref name="config"/> are <c>null</c>.</exception>
        /// <exception cref="InvalidConfigurationException">If <paramref name="config"/> is not valid or is incorrect.</exception>
        public void Init(IHostV30 host, string config)
        {
            if(host == null) throw new ArgumentNullException("host");
            if(config == null) throw new ArgumentNullException("config");

            if(AlreadyRun) return;

            // 1. Delete PluginPack.dll
            // 2. Download all other DLLs

            string root = "http://www.screwturn.eu/Version/PluginPack/";

            string[] dllNames = new string[] {
                "DownloadCounterPlugin.dll",
                "FootnotesPlugin.dll",
                "MultilanguageContentPlugin.dll",
                "RssFeedDisplayPlugin.dll",
                "UnfuddleTicketsPlugin.dll"
            };

            string[] providerNames = new string[] {
                "ScrewTurn.Wiki.Plugins.PluginPack.DownloadCounter",
                "ScrewTurn.Wiki.Plugins.PluginPack.Footnotes",
                "ScrewTurn.Wiki.Plugins.PluginPack.MultilanguageContentPlugin",
                "ScrewTurn.Wiki.Plugins.PluginPack.RssFeedDisplay",
                "ScrewTurn.Wiki.Plugins.PluginPack.UnfuddleTickets",
            };

            Dictionary<string, byte[]> assemblies = new Dictionary<string, byte[]>(dllNames.Length);

            try {
                foreach(string dll in dllNames) {
                    host.LogEntry("Downloading " + dll, LogEntryType.General, null, this);

                    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(root + dll);
                    req.AllowAutoRedirect = true;
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                    if(resp.StatusCode == HttpStatusCode.OK) {
                        BinaryReader reader = new BinaryReader(resp.GetResponseStream());
                        byte[] content = reader.ReadBytes((int)resp.ContentLength);
                        reader.Close();

                        assemblies.Add(dll, content);
                    }
                    else {
                        throw new InvalidOperationException("Response status code for " + dll + ":" + resp.StatusCode.ToString());
                    }
                }

                foreach(string dll in dllNames) {
                    host.GetSettingsStorageProvider().StorePluginAssembly(dll, assemblies[dll]);
                }

                foreach(string dll in dllNames) {
                    LoadProvider(dll);
                }

                host.GetSettingsStorageProvider().DeletePluginAssembly("PluginPack.dll");

                AlreadyRun = true;
            }
            catch(Exception ex) {
                host.LogEntry("Error occurred during automatic DLL updating with Updater Plugin\n" + ex.ToString(), LogEntryType.Error, null, this);
            }
        }