コード例 #1
0
    public object GetDefaultConfig()
    {
        const string fileSystem = "FileSystem";

        ComponentizedDalItem dalItem = new ComponentizedDalItem
        {
            Key  = fileSystem,
            Type = "Synapse.Controller.Dal.FileSystem:FileSystemDal"
        };

        IControllerDal fsd = AssemblyLoader.Load <IControllerDal>(dalItem.Type, string.Empty);

        dalItem.Config = fsd.GetDefaultConfig();

        return(new ComponentizedDalConfig
        {
            SecurityProviderKey = fileSystem,
            ExecuteReaderKey = fileSystem,
            HistoryWriterKey = fileSystem,

            DalComponents = new List <ComponentizedDalItem> {
                dalItem
            }
        });
    }
コード例 #2
0
    public Dictionary <string, string> Configure(ISynapseDalConfig conifg)
    {
        ComponentizedDalConfig cdc = null;

        if (conifg != null)
        {
            string s = YamlHelpers.Serialize(conifg.Config);
            cdc = YamlHelpers.Deserialize <ComponentizedDalConfig>(s);
        }
        else
        {
            cdc = (ComponentizedDalConfig)GetDefaultConfig();
        }

        Dictionary <string, string> secProps = new Dictionary <string, string>();
        ComponentizedDalItem        cdi      = cdc.DalComponents.SingleOrDefault(r => r.Key.Equals(cdc.SecurityProviderKey, StringComparison.OrdinalIgnoreCase));

        if (cdi != null)
        {
            _planSecurityProvider = AssemblyLoader.Load <IPlanSecurityProvider>(cdi.Type, string.Empty);
            secProps = _planSecurityProvider.Configure(new ConfigWrapper {
                Config = cdi.Config, Type = cdi.Type
            });
        }
        else
        {
            throw new TypeLoadException($"Could not load {cdi.Key}/{cdi.Type} for {nameof( IPlanSecurityProvider )}");
        }

        Dictionary <string, string> execProps = new Dictionary <string, string>();

        cdi = cdc.DalComponents.SingleOrDefault(r => r.Key.Equals(cdc.ExecuteReaderKey, StringComparison.OrdinalIgnoreCase));
        if (cdi != null)
        {
            _planExecuteReader = AssemblyLoader.Load <IPlanExecuteReader>(cdi.Type, string.Empty);
            execProps          = _planExecuteReader.Configure(new ConfigWrapper {
                Config = cdi.Config, Type = cdi.Type
            });
        }
        else
        {
            throw new TypeLoadException($"Could not load {cdi.Key}/{cdi.Type} for {nameof( IPlanExecuteReader )}");
        }

        Dictionary <string, string> histProps = new Dictionary <string, string>();

        cdi = cdc.DalComponents.SingleOrDefault(r => r.Key.Equals(cdc.HistoryWriterKey, StringComparison.OrdinalIgnoreCase));
        if (cdi != null)
        {
            _planHistoryWriter = AssemblyLoader.Load <IPlanHistoryWriter>(cdi.Type, string.Empty);
            histProps          = _planHistoryWriter.Configure(new ConfigWrapper {
                Config = cdi.Config, Type = cdi.Type
            });
        }
        else
        {
            throw new TypeLoadException($"Could not load {cdi.Key}/{cdi.Type} for {nameof( IPlanHistoryWriter )}");
        }


        string name = nameof(ComponentizedDal);
        Dictionary <string, string> props = new Dictionary <string, string>
        {
            { $"{name} ExecuteReaderKey", cdc.ExecuteReaderKey },
            { $"{name} HistoryWriterKey", cdc.HistoryWriterKey },
            { $"{name} SecurityProviderKey", cdc.SecurityProviderKey }
        };

        props.AddRange(execProps);
        props.AddRange(histProps);
        props.AddRange(secProps);
        return(props);
    }