Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #12
0
 public void UnloadDlls()
 {
     DllLoader.FreeLibrary(pDll);
 }