/// <summary> /// Ctor. /// </summary> /// <param name="useBundledLibrary"> /// If <code>true</code>, a bundled copy of fastText binary is extracted to process' current directory. /// You can set this to <code>false</code>, but then you must ensure that a compatible binary for your /// platform is discoverable by system library loader. /// /// You can compile your own binary from this specific fork: https://github.com/olegtarasov/fastText. /// </param> /// <param name="loggerFactory">Optional logger factory.</param> public FastTextWrapper(bool useBundledLibrary = true, ILoggerFactory loggerFactory = null) { _logger = loggerFactory?.CreateLogger <FastTextWrapper>(); if (useBundledLibrary) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var manager = new LibraryManager( loggerFactory, new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("fasttext.dll", accessor.Binary("Resources.fasttext.dll"))), new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libfasttext.dylib", accessor.Binary("Resources.libfasttext.dylib"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libfasttext.so", accessor.Binary("Resources.libfasttext.so")))); manager.LoadNativeLibrary(); } _mapper = new MapperConfiguration(config => { config.ShouldMapProperty = prop => prop.GetMethod.IsPublic || prop.GetMethod.IsAssembly; config.CreateMap <SupervisedArgs, FastTextArgsStruct>(); config.CreateMap <QuantizedSupervisedArgs, FastTextArgsStruct>(); config.CreateMap <UnsupervisedArgs, FastTextArgsStruct>(); config.CreateMap <AutotuneArgs, AutotuneArgsStruct>(); }) .CreateMapper(); _fastText = CreateFastText(); }
/// <summary> /// Ctor. /// </summary> public FastTextWrapper() { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var manager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("fasttext.dll", accessor.Binary("Resources.fasttext.dll"))), new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libfasttext.dylib", accessor.Binary("Resources.libfasttext.dylib"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libfasttext.so", accessor.Binary("Resources.libfasttext.so")))); manager.LoadNativeLibrary(); _fastText = CreateFastText(); }
/// <summary> /// Initializes a new instance of the <see cref="TaosConnection" /> class. /// </summary> public TaosConnection() { if (_dll_isloaded == false) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("taos.dll", accessor.Binary("libs.taos_x64.dll"))), new LibraryItem(Platform.Windows, Bitness.x32, new LibraryFile("taos.dll", accessor.Binary("libs.taos_x32.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libtaos.so", accessor.Binary("libs.libtaos_x64.so")))); libManager.LoadNativeLibrary(false); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { configDir = "/etc/taos"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { configDir = "C:/TDengine/cfg"; } var cfg = new System.IO.FileInfo(System.IO.Path.Combine(configDir, "taos.cfg")); if (!cfg.Directory.Exists) { cfg.Directory.Create(); } if (!cfg.Exists) { System.IO.File.WriteAllBytes(cfg.FullName, accessor.Binary("cfg.taos.cfg")); } if ((RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.OSArchitecture == Architecture.X64) || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X64) || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X86)) { TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, this.configDir); TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); TDengine.Init(); _dll_isloaded = true; } else { throw new PlatformNotSupportedException("Only Support Linux X64 And Windows X64/X86"); } } }
internal static void Init() { if (isLoaded) { return; } var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("dpfj.dll", accessor.Binary("dpfj.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libdpfj.so", accessor.Binary("libdpfj.so")))); libManager.LoadNativeLibrary(); isLoaded = true; }
private static void Main(string[] args) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libTestLib.dylib", accessor.Binary("libTestLib.dylib"))), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("TestLib.dll", accessor.Binary("TestLib.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libTestLib.so", accessor.Binary("libTestLib.so")))); libManager.LoadNativeLibrary(); hello(); Console.WriteLine("Hello from C#!"); }
public int CanLoadLibraryFromTempDirAndCallFunction() { string tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( tempDir, _factory, new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libTestLib.dylib", accessor.Binary("libTestLib.dylib"))), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("TestLib.dll", accessor.Binary("TestLib.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libTestLib.so", accessor.Binary("libTestLib.so")))) { LoadLibraryExplicit = true }; var item = libManager.FindItem(); libManager.LoadNativeLibrary(); int result; try { result = hello(); } catch (DllNotFoundException) { if (item.Platform == Platform.MacOs) { _logger.LogWarning("Hit an expected exception on MacOs. Skipping test."); return(0); } throw; } _logger.LogInformation($"Function result is {result}"); return(result == 42 ? 0 : 1); }
static JsonValidator() { var objectPoolProvider = new DefaultObjectPoolProvider(); StringBuilderPool = objectPoolProvider.CreateStringBuilderPool(); var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("nlohmann_json_schema_validator.dll", accessor.Binary("nlohmann_json_schema_validator.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libnlohmann_json_schema_validator.so", accessor.Binary("libnlohmann_json_schema_validator.so")))); libManager.LoadNativeLibrary(); }
public int CanLoadLibraryFromCurrentDirAndCallFunction() { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( _factory, new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libTestLib.dylib", accessor.Binary("libTestLib.dylib"))), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("TestLib.dll", accessor.Binary("TestLib.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libTestLib.so", accessor.Binary("libTestLib.so")))); libManager.LoadNativeLibrary(); int result = hello(); _logger.LogInformation($"Function result is {result}"); return(result == 42 ? 0 : 1); }
private static void Main(string[] args) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libTestLib.dylib", accessor.Binary("libTestLib.dylib"))), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("TestLib.dll", accessor.Binary("TestLib.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libTestLib.so", accessor.Binary("libTestLib.so")))); libManager.LoadNativeLibrary(); hello(); string_func("Oleg"); foo_func(new Foo { some_string = "dude", number = 5, another_string = "foo", number2 = 4, number3 = 3 }); Console.WriteLine("Hello from C#!"); }
/// <summary> /// Ctor. /// </summary> /// <param name="useBundledLibrary"> /// If <code>true</code>, a bundled copy of fastText binary is extracted to process' current directory. /// You can set this to <code>false</code>, but then you must ensure that a compatible binary for your /// platform is discoverable by system library loader. /// /// You can compile your own binary from this specific fork: https://github.com/olegtarasov/fastText. /// </param> /// <param name="loggerFactory">Optional logger factory.</param> public FastTextWrapper(bool useBundledLibrary = true, ILoggerFactory loggerFactory = null) { _logger = loggerFactory?.CreateLogger <FastTextWrapper>(); if (useBundledLibrary) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var manager = new LibraryManager( loggerFactory, new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("fasttext.dll", accessor.Binary("Resources.fasttext.dll"))), new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libfasttext.dylib", accessor.Binary("Resources.libfasttext.dylib"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libfasttext.so", accessor.Binary("Resources.libfasttext.so")))); manager.LoadNativeLibrary(); } _mapper = new MapperConfiguration(config => config.CreateMap <FastTextArgs, FastTextArgsStruct>()) .CreateMapper(); _fastText = CreateFastText(); }
static void Main(string[] args) { Console.WriteLine("Hello World Client starting..."); CheckEnvVar("ZMQ_SERVER_HOST", "137.117.199.77:9702"); CheckEnvVar("ZMQ_SOCKS_PROXY", "pxvip02.intranet.commerzbank.com:1080"); var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); LibraryManager libManager; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libzmq.so", accessor.Binary("libzmq.so"))) ); Console.WriteLine("Running on Linux"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.MacOs, Bitness.x64, new LibraryFile("libzmq.dylib", accessor.Binary("libzmq.dylib"))) ); Console.WriteLine("Running on MacOS"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console.WriteLine("Windows is not supported"); return; } else { Console.WriteLine("Unsupported platform"); return; } libManager.LoadNativeLibrary(); var context = zmq_ctx_new(); var socket = zmq_socket(context, 3); // 3 = ZMQ_REQ var server_host = Environment.GetEnvironmentVariable("ZMQ_SERVER_HOST"); Console.WriteLine("ZMQ_SERVER_HOST and Port: {0}", server_host); var socks_proxy = Environment.GetEnvironmentVariable("ZMQ_SOCKS_PROXY"); if (socks_proxy != null) { Console.WriteLine("ZMQ_SOCKS_PROXY: {0}", socks_proxy); zmq_setsockopt(socket, ZMQ_SOCKS_PROXY, socks_proxy, socks_proxy.Length); } zmq_connect(socket, String.Format("tcp://{0}", server_host)); int request_nbr; for (request_nbr = 0; request_nbr < 10; request_nbr++) { byte[] response = new byte[32]; String message = String.Format("Hello {0}", request_nbr); Console.WriteLine("Sending {0}", message); zmq_send(socket, message, 7, 0); zmq_recv(socket, response, 30, 0); // Hello, world! string charsStr = System.Text.Encoding.Default.GetString(response); Console.WriteLine("Received: {0}", charsStr); } zmq_close(socket); zmq_ctx_destroy(context); }