Example #1
0
        public void ScanEntryAssemblyDirectoryForAssemblies()
        {
            TypalGlobalContext_I typal = XContextual.GetGlobal <TypalGlobalContext_I>();

            if (typal == null)
            {
                return;
            }

            // Need to build a semantic model of what is currently present.
            ScanEntryAssemblyDirectoryForAssemblies(typal.Library.SemanticModel);
        }
Example #2
0
File: ApiApi.cs Project: E01D/Base
        public void LoadApis(System.Type interfaceType, Dictionary <long, object> dictionary)
        {
            TypalGlobalContext_I typal = XContextual.GetGlobal <TypalGlobalContext_I>();

            var y = XSemanticMetadata.Api.Elements.GetImplementingClasses(typal.Library.SemanticModel, interfaceType);

            foreach (var z in y)
            {
                var handle = XTypes.GetTypeHandle(z.TypeId);

                var type = System.Type.GetTypeFromHandle(handle);

                if (type.IsAbstract)
                {
                    continue;
                }

                if (type.ContainsGenericParameters)
                {
                    continue;
                }

                var implementedInterfaces = type.GetInterfaces();

                for (int i = 0; i < implementedInterfaces.Length; i++)
                {
                    //var implementedInterface = implementedInterfaces[i];

                    //if (!implementedInterface.IsGenericType) continue;

                    //var genericTypeDefinition = implementedInterface.GetGenericTypeDefinition();

                    //if (genericTypeDefinition != interfaceType) continue;

                    var instance = XNew.New(type);

                    //var arguments = implementedInterface.GenericTypeArguments;

                    //if (arguments.Length != 1) continue;

                    //XTypal.Api.Types.

                    if (!dictionary.ContainsKey(z.TypeId.Value))
                    {
                        dictionary.Add(z.TypeId.Value, instance);
                    }
                }
            }
        }
Example #3
0
        public DataLayerApi_I GetApiForModel <T>()
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            DataLayerApi_I api = null;

            var modelTypeId = XTypes.GetTypeId(typeof(T));

            if (context.DataApisByModelType.TryGetValue(modelTypeId.Value, out object apiObject))
            {
                api = (DataLayerApi_I)apiObject;
            }

            return(api);
        }
Example #4
0
        public object GetApi(TypeId_I typeId)
        {
            var contextHost = XContextual.GetGlobal <LogicalGlobalContextHost_I>();

            if (typeId.Value == 0)
            {
                return(null);
            }

            if (contextHost.Logical.LogicApis.TryGetValue(typeId.Value, out object logicObject))
            {
                return(logicObject);
            }

            return(null);
        }
Example #5
0
        public void LoadApis()
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            var dictionary = context.DataApis;

            XApis.Api.LoadApis(typeof(DataLayerApi_I), dictionary);

            foreach (var keyPair in dictionary)
            {
                var value = keyPair.Value;

                var type = value.GetType();

                var interfaces = type.GetInterfaces();

                var apiType = typeof(BasicLayerApi_I <>);

                for (int i = 0; i < interfaces.Length; i++)
                {
                    var interface1 = interfaces[i];

                    if (!interface1.IsGenericType)
                    {
                        continue;
                    }

                    if (interface1.GetGenericTypeDefinition() == apiType)
                    {
                        var args = interface1.GenericTypeArguments;

                        var modelType = args[0];

                        var modelTypeId = XTypes.GetTypeId(modelType);

                        context.DataApisByModelType.Add(modelTypeId.Value, keyPair.Value);
                    }
                }
            }

            //XApis.LoadAttributedApis(typeof(DataApiAttribute), dictionary);
        }
Example #6
0
 public SettingGlobalContext_I Get()
 {
     // Gets the current object registered as a SettingGlobalContext_I or creates a registration based upon the type SettingGlobalContext.
     return(XContextual.GetGlobal <SettingGlobalContext_I, SettingGlobalContext>());
 }
Example #7
0
        public object CreateConnection <T>()
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            return(new SqlConnection(context.DefaultConnectionString));
        }
Example #8
0
        public void SetDefaultConnection(string connectionString)
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            context.DefaultConnectionString = connectionString;
        }
Example #9
0
        public void DefaultConnectionProvider <T>() where T : DataConnectionApi_I, new()
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            context.DefaultDataConnectionProvider = new T();
        }