Пример #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(IProviderV60 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);
            }
        }
Пример #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 IProviderV60 FindProvider(string wiki, string typeName, out bool enabled)
        {
            enabled = false;
            IProviderV60 prov = null;

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

            return(null);
        }
Пример #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(IProviderV60 plugin, string configuration, string wiki, out string error)
        {
            error = null;

            SavePluginConfiguration(wiki, plugin.GetType().FullName, configuration);
            try {
                SetUp <IFormatterProviderV50>(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);
        }
Пример #4
0
 /// <summary>
 /// Check need set master-password
 /// </summary>
 /// <param name="applicationSettings"></param>
 /// <returns></returns>
 public bool NeedMasterPassword(ApplicationSettings applicationSettings)
 {
     if (applicationSettings.Installed)
     {
         try
         {
             IProviderV60 globalSettingsStorageProvider = ProviderLoader.LoadGlobalSettingsStorageProvider(applicationSettings.GlobalSettingsStorageProvider);
             var          host = new Host();
             globalSettingsStorageProvider.SetUp(host, applicationSettings.GlobalSettingsStorageProviderConfig);
             var password = GlobalSettings.GetMasterPassword((IGlobalSettingsStorageProviderV60)globalSettingsStorageProvider);
             return(String.IsNullOrEmpty(password));
         }
         catch (Exception ex)
         {
             var message = ExceptionHelper.BuildLogError(ex, "");
             Log.LogEntry(message, EntryType.Error, Log.SystemUsername, null);
         }
     }
     return(true);
 }