MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
CustomQueryCollection.cs
1using MyCaffe.basecode;
2using System;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Reflection;
7using System.Text;
8using System.Threading.Tasks;
9
11{
17 {
19
24 {
25 }
26
30 public void Load()
31 {
32 addCustomQueries();
33 }
34
39 public void Add(IXCustomQuery iqry)
40 {
41 m_rgCustomQueries.Add(iqry);
42 }
43
49 public IXCustomQuery Find(string strName)
50 {
51 if (strName == "OutputConverter" || strName == "Info")
52 return m_rgCustomQueries[0];
53
54 foreach (IXCustomQuery iqry in m_rgCustomQueries)
55 {
56 if (strName == iqry.Name)
57 return iqry;
58 }
59
60 return null;
61 }
62
63 private void addCustomQueries()
64 {
65 string codeBase = Assembly.GetExecutingAssembly().CodeBase;
66 UriBuilder uri = new UriBuilder(codeBase);
67 string path = Uri.UnescapeDataString(uri.Path);
68 string strPath = Path.GetDirectoryName(path);
69
70 strPath += "\\CustomQuery";
71
72 if (Directory.Exists(strPath))
73 {
74 string[] rgstrFiles = Directory.GetFiles(strPath);
75
76 foreach (string strFile in rgstrFiles)
77 {
78 FileInfo fi = new FileInfo(strFile);
79
80 if (fi.Extension.ToLower() == ".dll")
81 {
82 IXCustomQuery iqry = loadCustomQuery(strFile);
83 if (iqry != null)
84 m_rgCustomQueries.Add(iqry);
85 }
86 }
87 }
88 }
89
90 private IXCustomQuery loadCustomQuery(string strFile)
91 {
92 try
93 {
94 Assembly a = Assembly.LoadFile(strFile);
95 AssemblyName aName = a.GetName();
96
97 foreach (Type t in a.GetTypes())
98 {
99 Type[] rgT = t.GetInterfaces();
100
101 foreach (Type iface in rgT)
102 {
103 string strIface = iface.ToString();
104 if (strIface.Contains("IXCustomQuery"))
105 {
106 object obj = Activator.CreateInstance(t);
107 return obj as IXCustomQuery;
108 }
109 }
110 }
111
112 return null;
113 }
114 catch (Exception)
115 {
116 return null;
117 }
118 }
119 }
120}
The GenericList provides a base used to implement a generic list by only implementing the minimum amo...
Definition: GenericList.cs:15
virtual void Add(T item)
Add a new item to the list.
Definition: GenericList.cs:40
The CustomQueryCollection manages the external Custom Queries placed in the
void Load()
Loads all custom query DLL's (if found).
IXCustomQuery Find(string strName)
Locates a custom query by name and returns it.
void Add(IXCustomQuery iqry)
Directly adds a custom query to the list.
The custom query interface defines the functions implemented by each Custom Query object used to spec...
Definition: Interfaces.cs:168
string Name
Returns the name of the Custom Query.
Definition: Interfaces.cs:176
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.db.stream namespace contains all data streaming related classes.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12