Пример #1
0
        /// <summary>
        /// Loads a tree of services in the existing context
        /// </summary>
        /// <returns>The tree.</returns>
        /// <param name="config">Config.</param>
        private Service GetServiceForSettings(Settings config)
        {
            string   type;
            Settings moduleConfiguration;
            Service  newService;
            bool     succesfulInit;

            if (config.Tag is Service)
            {
                newService = config.Tag as Service;
            }
            else
            {
                type = config.GetString("type", "StubService");
                moduleConfiguration = (Settings)config ["modconf"];

                newService = plugins.GetConstructed(type);

                succesfulInit = newService.SetSettings(moduleConfiguration);

                newService.ConfigLine           = config ["_configline"].ToString();
                newService.PossibleSiblingTypes = plugins;
                newService.FailHard             = config.GetBool("fail", false);

                foreach (KeyValuePair <string, object> nameAndBranch in config.Dictionary)
                {
                    Match branchName = branchNameMatcher.Match(nameAndBranch.Key);

                    if (branchName.Success)
                    {
                        ConnectBranch(
                            newService,
                            branchName.Groups [1].Value,
                            nameAndBranch.Value as Settings);
                    }
                }

                if (config.Has("branches"))
                {
                    Settings branches = config.GetSubsettings("branches");

                    foreach (KeyValuePair <string, object> nameAndBranch in branches.Dictionary)
                    {
                        ConnectBranch(newService, nameAndBranch.Key, nameAndBranch.Value as Settings);
                    }
                }

                if (!succesfulInit)
                {
                    Secretary.Report(5, type, " produced an error on initialization: ", newService.InitErrorMessage);
                }


                newService.OnReady();

                config.Tag = newService;
            }


            return(newService);
        }