Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2931_OR-Tools_LP_MIP/HeuristicLab.ExtLibs/HeuristicLab.OrTools/7.0.0/HeuristicLab.OrTools-7.0.0/Plugin.cs.frame @ 16748

Last change on this file since 16748 was 16748, checked in by ddorfmei, 5 years ago

#2931: Removed Google.Protobuf.dll from HeurisiticLb.OrTools (Assembly is already provided by HEAL.Attic)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Diagnostics;
24using System.IO;
25using System.Linq;
26using System.Runtime.InteropServices;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.OrTools {
30
31  [Plugin("HeuristicLab.OrTools", "Provides functionality of Google OR-Tools in HeuristicLab. Requires Windows 64-bit", "7.0.0.$WCREV$")]
32  [PluginFile("HeuristicLab.OrTools-7.0.0.dll", PluginFileType.Assembly)]
33  [PluginFile("Google.OrTools.dll", PluginFileType.Assembly)]
34  [PluginFile("Google.OrTools-license.txt", PluginFileType.License)]
35  [PluginFile("Google.OrTools.runtime.win-x64.dll", PluginFileType.NativeDll)]
36  [PluginFile("Google.OrTools_version.txt", PluginFileType.Data)]
37  public class HeuristicLabOrToolsPlugin : PluginBase {
38
39    public override void OnUnload() {
40      // HACK: free handle to native DLL used temporarily by the Hive Slave
41      // should be solved for all native DLLs used by the Hive Slave
42      var dllDir = new FileInfo(GetType().Assembly.Location).Directory;
43      if (dllDir == null || !dllDir.FullName.Contains(Path.DirectorySeparatorChar + "PluginTemp" + Path.DirectorySeparatorChar))
44        return;
45
46      var nativeDlls = GetType().GetCustomAttributes(typeof(PluginFileAttribute), true)
47        .Cast<PluginFileAttribute>()
48        .Where(pf => pf.FileType == PluginFileType.NativeDll)
49        .Select(pf => pf.FileName);
50
51      foreach (var nativeDll in dllDir.EnumerateFiles().Where(f => nativeDlls.Contains(f.Name))) {
52        if (Process.GetCurrentProcess().Modules.Cast<ProcessModule>().All(m => m.ModuleName != nativeDll.Name))
53          continue;
54
55        var handle = LoadLibrary(nativeDll.FullName);
56        if (handle == IntPtr.Zero)
57          continue;
58
59        FreeLibrary(handle); // close handle obtained above
60        FreeLibrary(handle); // close implicitly obtained handle
61      }
62    }
63
64    [DllImport("kernel32.dll", SetLastError = true)]
65    [return: MarshalAs(UnmanagedType.Bool)]
66    private static extern bool FreeLibrary(IntPtr hModule);
67
68    [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
69    private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
70  }
71}
Note: See TracBrowser for help on using the repository browser.