Пример #1
0
 private void _ScanForAutoRegisteredModules()
 {
     Log.WriteLine("Scanning for auto-registered communication modules.");
     foreach (var m in AssemblyUtility.GetAllClassTypes <CommunicationModule, AutoRegisteredCommunicationModuleAttribute>())
     {
         m_RegisteredModuleTypes.Add(m);
     }
 }
Пример #2
0
        /// <returns>E_SUCCESS or E_FAILURE</returns>
        private static TrinityErrorCode _ScanForMemoryCloudExtension()
        {
            Log.WriteLine(LogLevel.Info, "Scanning for MemoryCloud extensions.");
            new_memorycloud_func = () => new FixedMemoryCloud();

            if (!AssemblyUtility.GetAllClassTypes <MemoryCloud>().Any(t => t != typeof(FixedMemoryCloud)))
            {
                Log.WriteLine(LogLevel.Info, "No MemoryCloud extension found.");
                return(TrinityErrorCode.E_FAILURE);
            }

            new_memorycloud_func = () =>
            {
                var mc_ext_rank = ExtensionConfig.Instance.ResolveTypePriorities();
                Func <Type, int> mc_rank_func = t =>
                {
                    if (mc_ext_rank.TryGetValue(t, out var r))
                    {
                        return(r);
                    }
                    else
                    {
                        return(0);
                    }
                };
                var memcloud_types = AssemblyUtility.GetAllClassTypes <MemoryCloud>().OrderByDescending(mc_rank_func);
                foreach (var mc_type in memcloud_types)
                {
                    if (mc_type == null)
                    {
                        continue;
                    }
                    try
                    {
                        var ctor = mc_type.GetConstructor(new Type[] { });
                        if (ctor == null)
                        {
                            Log.WriteLine(LogLevel.Warning, "MemoryCloud extension '{0}': no default constructor, skipping.", mc_type.Name);
                            continue;
                        }
                        var mc = ctor.Invoke(new object[] { }) as MemoryCloud;
                        Log.WriteLine(LogLevel.Info, "MemoryCloud extension '{0}' loaded.", mc_type.Name);
                        return(mc);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine(LogLevel.Error, "Exception thrown while loading MemoryCloud extension '{0}': {1}.", mc_type.Name, ex.ToString());
                        continue;
                    }
                }
                // should never reach here
                throw new InvalidOperationException();
            };
            return(TrinityErrorCode.E_SUCCESS);
        }
Пример #3
0
        private static Tuple <IGenericCellOperations, IStorageSchema, int> _LoadTSLStorageExtension(Assembly extension_assembly)
        {
            Type default_provider_type               = typeof(DefaultGenericCellOperations);
            Type schema_interface_type               = typeof(IStorageSchema);
            Type default_storage_schema_type         = typeof(DefaultStorageSchema);
            IGenericCellOperations _generic_cell_ops = null;
            IStorageSchema         _storage_schema   = null;
            int priority = 0;

            var provider_type = AssemblyUtility.GetAllClassTypes <IGenericCellOperations>(_ => _ != default_provider_type, extension_assembly).FirstOrDefault();

            if (provider_type == null)
            {
                goto _return;
            }

            var schema_type = AssemblyUtility.GetAllClassTypes <IStorageSchema>(_ => _ != default_storage_schema_type, extension_assembly).FirstOrDefault();

            if (schema_type == null)
            {
                goto _return;
            }

            var pdict = ExtensionConfig.Instance.ResolveTypePriorities();

            try
            {
                _generic_cell_ops = provider_type.GetConstructor(new Type[] { }).Invoke(new object[] { }) as IGenericCellOperations;
                _storage_schema   = schema_type.GetConstructor(new Type[] { }).Invoke(new object[] { }) as IStorageSchema;

                if (pdict.TryGetValue(provider_type, out var provider_priority))
                {
                    priority = provider_priority;
                }
                if (pdict.TryGetValue(schema_type, out var schema_priority))
                {
                    priority = schema_priority;
                }
            }
            catch
            {
                _generic_cell_ops = null;
                _storage_schema   = null;
            }

_return:

            return(Tuple.Create(_generic_cell_ops, _storage_schema, priority));
        }