Exemplo n.º 1
0
        char GetCharFromWrapper(IntPtr sw, int index)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getChar");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: getChar");
            }
            getChar getChar =
                (getChar)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getChar));

            return(getChar(sw, index));
        }
Exemplo n.º 2
0
        int DisposeDLLObject(IntPtr v)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "dispose");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: dispose");
            }
            dispose dispose =
                (dispose)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(dispose));

            return(dispose(v));
        }
Exemplo n.º 3
0
        int GetWrapperLen(IntPtr sw)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "len");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: len");
            }
            len len =
                (len)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(len));

            return(len(sw));
        }
Exemplo n.º 4
0
        public int AnomalyCount()
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getAnomalyCount");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: getAnomalyCount");
            }
            getAnomalyCount getAnomalyCount =
                (getAnomalyCount)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getAnomalyCount));

            return(getAnomalyCount(AnomalyReportVector));
        }
Exemplo n.º 5
0
        public int GetTimeStep(int index)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getTimeStep");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: getTimeStep");
            }
            getTimeStep getTimeStep =
                (getTimeStep)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getTimeStep));

            return(getTimeStep(AnomalyReportVector, index));
        }
Exemplo n.º 6
0
        void AddCharToWrapper(IntPtr sw, char c)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "addCharToString");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: addCharToString");
            }

            addCharToString addCharToString =
                (addCharToString)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(addCharToString));

            addCharToString(sw, c);
        }
Exemplo n.º 7
0
        public void Detect(string names, string filename)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "detect");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: detect");
            }
            detect detect =
                (detect)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(detect));

            IntPtr sw_filename = sw_string(filename);
            IntPtr sw_names    = sw_string(names);

            AnomalyReportVector = detect(this.detector, sw_names, names.Length, sw_filename);
            DisposeDLLObject(sw_filename);
            DisposeDLLObject(sw_names);
        }
Exemplo n.º 8
0
        public void LearnNormal(string names, string filename)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "learn");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: learn");
            }
            learn learn =
                (learn)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(learn));

            IntPtr sw_filename = sw_string(filename);
            IntPtr sw_names    = sw_string(names);

            learn(detector, sw_names, names.Length, sw_filename);
            DisposeDLLObject(sw_filename);
            DisposeDLLObject(sw_names);
        }
Exemplo n.º 9
0
        public AnomalyDetector()
        {
            pDll = DllLoader.LoadLibrary(dll_path);
            if (pDll == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading dll");
            }

            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "createSimpleAnomalyDetectorInstance");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function");
            }
            createSimpleAnomalyDetectorInstance createSimpleAnomalyDetectorInstance =
                (createSimpleAnomalyDetectorInstance)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(createSimpleAnomalyDetectorInstance));

            this.detector = createSimpleAnomalyDetectorInstance();
        }
Exemplo n.º 10
0
        public IntPtr sw_string(string s)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "createString");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: createString");
            }

            createString createString =
                (createString)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(createString));

            IntPtr STR = createString(s.Length);

            for (int i = 0; i < s.Length; i++)
            {
                AddCharToWrapper(STR, s[i]);
            }
            return(STR);
        }
Exemplo n.º 11
0
        public string GetFunction(int index)
        {
            IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getFunc");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                Trace.WriteLine("Error loading function: getFunc");
            }
            getFunc getFunc =
                (getFunc)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getFunc));

            IntPtr sw = getFunc(AnomalyReportVector, index);
            string s  = "";

            for (int i = 0; i < GetWrapperLen(sw); i++)
            {
                s += GetCharFromWrapper(sw, i);
            }
            DisposeDLLObject(sw);
            return(s);
        }
Exemplo n.º 12
0
 public void UnloadDlls()
 {
     DllLoader.FreeLibrary(pDll);
 }