1 /** 2 Copyright 2018 Mark Fisher 3 4 Permission is hereby granted, free of charge, to any person obtaining a copy of 5 this software and associated documentation files (the "Software"), to deal in 6 the Software without restriction, including without limitation the rights to 7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 of the Software, and to permit persons to whom the Software is furnished to do 9 so, subject to the following conditions: 10 11 The above copyright notice and this permission notice shall be included in all 12 copies or substantial portions of the Software. 13 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 SOFTWARE. 21 **/ 22 module dxx.example.basic.app; 23 24 private import aermicioi.aedi; 25 26 private import std.stdio; 27 private import std.experimental.logger; 28 private import std.conv; 29 private import std..string; 30 private import std.file; 31 32 private import dxx.app; 33 private import dxx.util; 34 35 enum CFG = DXXConfig ~ IniConfig!"basic.ini"; 36 37 mixin __Text!(CFG.basic.lang); 38 39 class Example { 40 }; 41 42 alias BasicParam = Tuple!( 43 string,"name", 44 uint,"age", 45 PluginDef,"plugins" 46 ); 47 48 /* 49 @component 50 class BasicComponents : RuntimeComponents!BasicParam { 51 override void registerAppDependencies(InjectionContainer injector) { 52 debug { 53 sharedLog.info("BasicComponents registerAppDependencies()"); 54 } 55 } 56 shared static this() { 57 new BasicComponents; 58 } 59 mixin registerComponent!BasicComponents; 60 }; 61 */ 62 63 mixin registerComponent!(PlatformRuntime!BasicParam); 64 65 66 int main(string[] args) { 67 //scope(exit)terminateInjector; 68 69 //auto m = new BasicComponents; 70 debug { 71 sharedLog.info("basic main"); 72 } 73 MsgLog.info(MsgText!(CFG.basicMessages.MSG_APP_BANNER)); 74 // MsgLog.info("name = " ~ getInjectorProperty!string("name")); 75 // MsgLog.info("age = " ~ (getInjectorProperty!uint("age")).to!string); 76 string n = getInjectorProperty!string("name"); 77 MsgLog.info("name = " ~ n); 78 //sharedLog.info("name = " ~ getInjectorProperty!string("name")); 79 auto age = (getInjectorProperty!uint("age")); 80 MsgLog.info("age = " ~ age.to!string); 81 82 auto l = resolveInjector!PluginLoader(); 83 assert(l); 84 /*version(Posix) { 85 l.load("examples/plugin/bin/libdxx_plugin.so"); 86 } else version(Windows) { 87 l.load("examples/plugin/bin/dxx_plugin.dll"); 88 } else { 89 // ... 90 }*/ 91 auto paths = getInjectorProperty!string(CFG.keys.pluginDirs); 92 MsgLog.info(CFG.keys.pluginDirs ~ " = " ~ paths); 93 /*auto plugin = "dxx_plugin"; 94 95 foreach(p;paths.split(',')) { 96 MsgLog.info("Path: " ~ p); 97 if(PluginLoader.pluginFileName(plugin,p).exists) { 98 MsgLog.info("Load: dxx_plugin"); 99 l.load(plugin,p); 100 break; 101 } 102 }*/ 103 104 //auto plugins = getInjectorProperty!(PluginDef[])("plugins"); 105 auto plugin = getInjectorProperty!(PluginDef)("plugins"); 106 //auto plugin=Tuple!(string,"name")("dxx_plugin"); 107 108 //foreach(plugin;plugins) { 109 foreach(path;paths.split(',')) { 110 if(PluginLoader.pluginFileName(plugin.name,path).exists) { 111 MsgLog.info("Load: "~plugin.name); 112 l.load(plugin.name,path); 113 } 114 } 115 //} 116 117 l.update; 118 scope(exit)destroy(l); 119 MsgLog.info("Done."); 120 return 0; 121 }