Ejemplo n.º 1
0
		private void LoadConfiguration (Config config)
		{
			if (config == null)
				config = Conf.Get (Conf.Names.NetworkingConfig);

			if (String.IsNullOrEmpty (name))
				// Whats a good default value ?
				name = config.GetOption (Conf.Names.ServiceName, String.Empty);

			// Check to see if our enabled status hasn't changed
                        if (enabled != config.GetOption (Conf.Names.ServiceEnabled, enabled)) {
                                enabled = config.GetOption (Conf.Names.ServiceEnabled, enabled);
                                
                                if (enabled) {
					try {
						Publish ();
					} catch (ClientException) {
						Log.Error ("Could not start avahi");
						return;
					}
				} else
					Unpublish ();
                                
                                Logger.Log.Info ("Zeroconf: Index sharing is {0}", enabled ? "enabled" : "disabled");
                        }

                        // Handle index name changes
                        if (String.Compare (name, config.GetOption (Conf.Names.ServiceName, name)) != 0)
				Update ();
                }
Ejemplo n.º 2
0
        private static void NotifySubscribers(Config config, string name)
        {
            ArrayList callbacks = (ArrayList) subscriptions [name];

            if (callbacks == null)
                return;

            foreach (ConfigUpdateHandler callback in callbacks)
                callback (config);
        }
Ejemplo n.º 3
0
        /* External clients can use the following two xml based methods to read/write xml */
        // Use this method to write the config in its xml format.
        public static void WriteSectionXml(Config config, TextWriter writer)
        {
            if (config == null)
                return;

            // serialize will not serialize global options,
            // so temporarily make every option global
            Dictionary<Option, bool> global_options = new Dictionary<Option, bool> ();
            foreach (Option option in config.Options.Values) {
                global_options [option] = option.Global;
                option.Global = false;
            }

            conf_ser.Serialize (writer, config);

            foreach (Option option in config.Options.Values)
                option.Global = global_options [option];
        }
Ejemplo n.º 4
0
        public static void SaveTo(Config config, string path)
        {
            if (config == null)
                return;

            bool to_save = false;
            foreach (Option option in config.Options.Values)
                if (! option.Global)
                    to_save = true;

            if (! to_save)
                return;

            using (StreamWriter writer = new StreamWriter (path)) {
                conf_ser.Serialize (writer, config);
                Console.WriteLine ("Done writing to " + path);
            }
        }
Ejemplo n.º 5
0
        public static void Save(Config config)
        {
            if (config == null)
                return;

            bool to_save = false;
            foreach (Option option in config.Options.Values)
                if (! option.Global)
                    to_save = true;

            if (! to_save)
                return;

            bool watching_for_updates_current = watching_for_updates;
            watching_for_updates = false;

            string filename = Path.Combine (configs_dir, (config.Name + ".xml"));

            using (StreamWriter writer = new StreamWriter (filename)) {
                conf_ser.Serialize (writer, config);
                Log.Debug ("Done writing to " + filename);
            }

            watching_for_updates = watching_for_updates_current;
        }
Ejemplo n.º 6
0
        // Use this method to send in the xml for a config, and the original config
        // and the changes from the original to the xml will be added to the original config
        // Returns false if the read xml does not correspond to the same config as that
        // was passed, in which case please note that the passed config COULD BE IN A
        // modified state and should be discarded!
        public static bool ReadSectionXml(Config config, TextReader reader)
        {
            if (config == null)
                throw new ArgumentException ("config", "config cannot be null");

            Config new_config = (Config) conf_ser.Deserialize (reader);

            foreach (Option new_option in new_config.Options.Values) {
                Option option = config [new_option.Name] as Option;
                if (option == null || (option.Type != new_option.Type))
                    return false;

                switch (option.Type) {
                case OptionType.Bool:
                    BoolOption option_bool = (BoolOption) option;
                    BoolOption new_option_bool = (BoolOption) new_option;
                    option_bool.Value = new_option_bool.Value;
                    break;

                case OptionType.String:
                    StringOption option_str = (StringOption) option;
                    StringOption new_option_str = (StringOption) new_option;
                    option_str.Value = new_option_str.Value;
                    break;

                case OptionType.List:
                    ListOption option_list = (ListOption) option;
                    ListOption new_option_list = (ListOption) new_option;
                    if (option_list.NumParams != new_option_list.NumParams)
                        return false;

                    option_list.Values = new_option_list.Values;
                    break;
                }
            }

            return true;
        }
Ejemplo n.º 7
0
 public static Config LoadNew(string name)
 {
     Config config = new Config ();
     config.Name = name;
     return config;
 }
Ejemplo n.º 8
0
		private void OnConfigurationChanged (Config config)
                {
			if (config == null || config.Name != Conf.Names.NetworkingConfig)
				return;

			LoadConfiguration (config);
		}
Ejemplo n.º 9
0
		private void OnConfigurationChanged (Config config)
		{
			if (config == null || config.Name != Conf.Names.FilesQueryableConfig)
				return;

			bool clear_fs_state = false;

			List<string[]> values = config.GetListOptionValues (Conf.Names.ExcludeSubdirectory);
			if (values != null) {
				ArrayList subdirs = new ArrayList (values.Count);
				foreach (string[] value in values) {
					string dir = GetExcludeDirectory (value [0]);
					if (! String.IsNullOrEmpty (dir))
						subdirs.Add (dir);
				}

				IList excludes_wanted = subdirs;
				IList excludes_to_add, excludes_to_remove;

				ArrayFu.IntersectListChanges (excludes_wanted, 
							      exclude_paths, 
						      	      out excludes_to_add, 
						      	      out excludes_to_remove);

				// Process any excludes we think we should remove
				foreach (string path in excludes_to_remove)
					RemoveExcludeDir (path);

				// Process any excludes we found to be new
				foreach (string path in excludes_to_add)
					AddExcludeDir (path);
			}

			values = config.GetListOptionValues (Conf.Names.ExcludePattern);
			if (values != null) {
				ArrayList patterns = new ArrayList (values.Count);
				foreach (string[] value in values)
					patterns.Add (value [0]);

				IList excludes_wanted = patterns;
				IList excludes_to_add, excludes_to_remove;

				ArrayFu.IntersectListChanges (excludes_wanted, 
							      exclude_patterns,
						      	      out excludes_to_add, 
						      	      out excludes_to_remove);

				// Process any excludes we think we should remove
				foreach (string pattern in excludes_to_remove) {
					clear_fs_state = true;
					RemoveExcludePattern (pattern);
				}

				// Process any excludes we found to be new
				foreach (string pattern in excludes_to_add)
					AddExcludePattern (pattern);

				exclude_regex = StringFu.GetPatternRegex (exclude_patterns);
			}

			// If an exclude pattern is removed, we need to recrawl everything
			// so that we can index those files which were previously ignored.
			if (clear_fs_state)
				queryable.RecrawlEverything ();
		}
Ejemplo n.º 10
0
		private void ConfigUpdateHandler (Config config)
		{
			if (config == null || config.Name != Conf.Names.NetworkingConfig)
				return;

			bool to_webinterface = config.GetOption ("WebInterface", false);
			Log.Debug ("WebInterface option changed to {0}", to_webinterface);
			if (to_webinterface)
				StartWebserver ();
			else
				StopWebserver ();
		}
Ejemplo n.º 11
0
		private void OnConfigurationChanged (Config config)
		{
			if (config == null || config.Name != Conf.Names.FilesQueryableConfig)
				return;

			List<string[]> values = config.GetListOptionValues (Conf.Names.Roots);
			if (values == null)
				values = new List<string[]> (0);

			ArrayList roots_wanted = new ArrayList (values.Count);
			foreach (string[] root in values)
				roots_wanted.Add (root [0]);
			
			if (config.GetOption (Conf.Names.IndexHomeDir, true))
				roots_wanted.Add (PathFinder.HomeDir);

			IList roots_to_add, roots_to_remove;
			ArrayFu.IntersectListChanges (roots_wanted, Roots, out roots_to_add, out roots_to_remove);

			foreach (string root in roots_to_remove)
				RemoveRoot (root);

			foreach (string root in roots_to_add)
				AddRoot (root);
		}