Пример #1
0
 public static void debug(cape.LoggingContext context, string message)
 {
     if (context != null)
     {
         context.logDebug(message);
     }
 }
Пример #2
0
 public static void info(cape.LoggingContext context, string message)
 {
     if (context != null)
     {
         context.logInfo(message);
     }
 }
Пример #3
0
        public bool loadFile(cape.LoggingContext ctx, cape.File file)
        {
            if (!(file != null))
            {
                ctx.logError("DynamicModule" + ": Null file");
                return(false);
            }
            if (!file.isFile())
            {
                ctx.logError("DynamicModule" + ": Not a file: `" + file.getPath() + "'");
                return(false);
            }
            ctx.logDebug("Loading dynamic module: `" + file.getPath() + "'");
            string error = null;

            ctx.logError("Loading assemblies on UWP: Not supported");
            if (assembly == null)
            {
                if (error != null)
                {
                    ctx.logDebug(error);
                }
                ctx.logError("Failed to load assembly: `" + file.getPath() + "'");
                return(false);
            }
            ctx.logDebug("Assembly successfully loaded: `" + file.getPath() + "'");
            return(true);
        }
Пример #4
0
 public static void error(cape.LoggingContext context, string message)
 {
     if (context != null)
     {
         context.logError(message);
     }
 }
Пример #5
0
 public static void warning(cape.LoggingContext context, string message)
 {
     if (context != null)
     {
         context.logWarning(message);
     }
 }
Пример #6
0
        private bool executeSelect(cape.LoggingContext ctx, System.Collections.Generic.List <object> reads, System.Collections.Generic.List <object> writes)
        {
            var fdsetr = new System.Collections.Generic.List <System.Net.Sockets.Socket>();
            var fdsetw = new System.Collections.Generic.List <System.Net.Sockets.Socket>();

            if (readlist != null)
            {
                var n = 0;
                var m = readlist.Count;
                for (n = 0; n < m; n++)
                {
                    var myo1 = readlist[n] as capex.net.IOManagerDotNetSelect.MyEntry;
                    if (myo1 != null)
                    {
                        fdsetr.Add(myo1.getNetSocket());
                    }
                }
            }
            if (writelist != null)
            {
                var n2 = 0;
                var m2 = writelist.Count;
                for (n2 = 0; n2 < m2; n2++)
                {
                    var myo2 = writelist[n2] as capex.net.IOManagerDotNetSelect.MyEntry;
                    if (myo2 != null)
                    {
                        fdsetw.Add(myo2.getNetSocket());
                    }
                }
            }
            try {
                System.Net.Sockets.Socket.Select(fdsetr, fdsetw, null, -1);
            }
            catch (System.Exception e) {
                cape.Log.error(ctx, "Call to Select failed: " + e.ToString());
                return(false);
            }
            foreach (System.Net.Sockets.Socket socket in fdsetr)
            {
                var e = getEntryForSocket(socket, readlist);
                if (e != null)
                {
                    cape.Vector.append(reads, e);
                }
            }
            foreach (System.Net.Sockets.Socket socket in fdsetw)
            {
                var e = getEntryForSocket(socket, writelist);
                if (e != null)
                {
                    cape.Vector.append(writes, e);
                }
            }
            return(true);
        }
Пример #7
0
        public static capex.util.DynamicModule forFile(cape.LoggingContext ctx, cape.File file)
        {
            var v = new capex.util.DynamicModule();

            if (v.loadFile(ctx, file) == false)
            {
                v = null;
            }
            return(v);
        }
Пример #8
0
 public static bool isModuleFile(cape.LoggingContext ctx, cape.File file)
 {
     if (!(file != null))
     {
         return(false);
     }
     if (file.hasExtension("dll"))
     {
         return(true);
     }
     return(false);
 }
Пример #9
0
        public object createObject(cape.LoggingContext ctx, string className)
        {
            if (!(assembly != null))
            {
                ctx.logError("createObject: No assembly has been loaded.");
                return(null);
            }
            System.Type type = null;
            type = assembly.GetType(className);
            if (!(type != null))
            {
                ctx.logError("Failed to find class `" + className + "' in dynamic module: `" + getModuleDescription() + "'");
                return(null);
            }
            string error = null;

            System.Reflection.ConstructorInfo constructor = null;
            ctx.logError("GetConstructor on UWP: Not supported");
            if (constructor == null)
            {
                if (error != null)
                {
                    ctx.logDebug(error);
                }
                ctx.logError("Failed to find a default constructor in class `" + className + "' in module: `" + getModuleDescription() + "'");
                return(null);
            }
            object v = null;

            try {
                v = constructor.Invoke(null);
            }
            catch (System.Exception e) {
                error = e.ToString();
            }
            if (error != null)
            {
                ctx.logDebug(error);
                ctx.logError("Failed to call default constructor of class `" + className + "' in module: `" + getModuleDescription() + "'");
                return(null);
            }
            if (v == null)
            {
                ctx.logError("Constructor called without error for class `" + className + "' in module `" + getModuleDescription() + "', but no object was created!");
                return(null);
            }
            return(v);
        }
Пример #10
0
        public bool executeStaticMethod(cape.LoggingContext ctx, string entityName, string methodName, object[] @params)
        {
            if (!(assembly != null))
            {
                ctx.logError("executeStaticMethod: No assembly has been loaded.");
                return(false);
            }
            System.Type mainType = null;
            mainType = assembly.GetType(entityName);
            if (!(mainType != null))
            {
                ctx.logError("Failed to find class `" + entityName + "' in dynamic module: `" + getModuleDescription() + "'");
                return(false);
            }
            string error = null;

            System.Reflection.MethodInfo methodRef = null;
            ctx.logError("GetMethod on UWP: Not supported");
            if (methodRef == null)
            {
                if (error != null)
                {
                    ctx.logDebug(error);
                }
                ctx.logError("Failed to find method `" + methodName + "' in entity `" + entityName + "' in module: `" + getModuleDescription() + "'");
                return(false);
            }
            try {
                methodRef.Invoke(null, @params);
            }
            catch (System.Exception e) {
                error = e.ToString();
            }
            if (error != null)
            {
                ctx.logDebug(error);
                ctx.logError("Failed to call method `" + methodName + "' in entity `" + entityName + "' in module: `" + getModuleDescription() + "'");
                return(false);
            }
            return(true);
        }
Пример #11
0
        public static capex.util.DynamicModule forObject(cape.LoggingContext ctx, object oo)
        {
            if (!(oo != null))
            {
                return(null);
            }
            System.Reflection.Assembly asm = null;
            var type = oo.GetType();

            if (type != null)
            {
                asm = System.Reflection.IntrospectionExtensions.GetTypeInfo(type).Assembly;
            }
            if (!(asm != null))
            {
                return(null);
            }
            var v = new capex.util.DynamicModule();

            v.setAssembly(asm);
            return(v);
        }
Пример #12
0
 public virtual bool execute(cape.LoggingContext ctx)
 {
     return(false);
 }
Пример #13
0
 public static capex.net.SSLSocket forServer(capex.net.ConnectedSocket cSocket, cape.File certFile = null, cape.File keyFile = null, cape.LoggingContext ctx = null, bool acceptInvalidCertificate = false, string passphrase = null)
 {
     return(capex.net.SSLSocket.createInstance(cSocket, null, ctx, certFile, keyFile, true, acceptInvalidCertificate, passphrase));
 }
Пример #14
0
 public static capex.net.SSLSocket forClient(capex.net.ConnectedSocket cSocket, string hostAddress, cape.LoggingContext ctx = null, bool acceptInvalidCertificate = false, string passphrase = null)
 {
     return(capex.net.SSLSocket.createInstance(cSocket, hostAddress, ctx, null, null, false, acceptInvalidCertificate, passphrase));
 }
Пример #15
0
 public capex.data.SQLDatabase setLogger(cape.LoggingContext v)
 {
     logger = v;
     return(this);
 }
Пример #16
0
        public static capex.text.TextTemplate forJSONString(string text, System.Collections.Generic.List <cape.File> includeDirs = null, cape.LoggingContext logContext = null)
        {
            var v = new capex.text.TextTemplate();

            v.setLogContext(logContext);
            v.setText(text);
            v.setType(capex.text.TextTemplate.TYPE_JSON);
            v.setMarkerBegin("{{");
            v.setMarkerEnd("}}");
            if (v.prepare(includeDirs) == false)
            {
                v = null;
            }
            return(v);
        }
Пример #17
0
        public static capex.text.TextTemplate forString(string text, string markerBegin, string markerEnd, int type = 0, System.Collections.Generic.List <cape.File> includeDirs = null, cape.LoggingContext logContext = null)
        {
            var v = new capex.text.TextTemplate();

            v.setLogContext(logContext);
            v.setText(text);
            v.setType(type);
            v.setMarkerBegin(markerBegin);
            v.setMarkerEnd(markerEnd);
            if (v.prepare(includeDirs) == false)
            {
                v = null;
            }
            return(v);
        }
Пример #18
0
        public static capex.text.TextTemplate forFile(cape.File file, string markerBegin, string markerEnd, int type = 0, System.Collections.Generic.List <cape.File> includeDirs = null, cape.LoggingContext logContext = null)
        {
            if (file == null)
            {
                return(null);
            }
            var text = file.getContentsString("UTF-8");

            if (object.Equals(text, null))
            {
                return(null);
            }
            var ids = includeDirs;

            if (ids == null)
            {
                ids = new System.Collections.Generic.List <cape.File>();
                ids.Add(file.getParent());
            }
            return(capex.text.TextTemplate.forString(text, markerBegin, markerEnd, type, ids, logContext));
        }
Пример #19
0
 public capex.text.TextTemplate setLogContext(cape.LoggingContext v)
 {
     logContext = v;
     return(this);
 }
Пример #20
0
 public void reportAsUnsupported(cape.LoggingContext ctx)
 {
     cape.Log.error(ctx, "Unsupported command line parameter: `" + arg + "'");
 }
Пример #21
0
 public static capex.net.SSLSocket createInstance(capex.net.ConnectedSocket cSocket, string serverAddress = null, cape.LoggingContext ctx = null, cape.File certFile = null, cape.File keyFile = null, bool isServer = false, bool acceptInvalidCertificate = false, string passphrase = null)
 {
     if (!(cSocket != null))
     {
         return(null);
     }
     capex.net.SSLSocket v = null;
     return(v);
 }
Пример #22
0
        public static capex.data.SQLiteDatabase forFile(cape.File file, bool allowCreate = true, cape.LoggingContext logger = null)
        {
            if (!(file != null))
            {
                return(null);
            }
            var v = capex.data.SQLiteDatabase.instance();

            if (!(v != null))
            {
                return(null);
            }
            if (logger != null)
            {
                v.setLogger(logger);
            }
            if (!file.isFile())
            {
                if (allowCreate == false)
                {
                    return(null);
                }
                var pp = file.getParent();
                if (pp.isDirectory() == false)
                {
                    if (pp.createDirectoryRecursive() == false)
                    {
                        cape.Log.error(v.getLogger() as cape.LoggingContext, "Failed to create directory: " + pp.getPath());
                    }
                }
                if (v.initialize(file, true) == false)
                {
                    v = null;
                }
            }
            else if (v.initialize(file, false) == false)
            {
                v = null;
            }
            return(v);
        }
Пример #23
0
        public override bool execute(cape.LoggingContext ctx)
        {
            exitflag = false;
            running  = true;
            var signalSocket = openSignalSocket();

            if (signalSocket != null)
            {
                var ee = add((object)signalSocket);
                if (ee != null)
                {
                    ee.setReadListener(() => {
                        onReadReady(signalSocket);
                    });
                }
            }
            var reads  = new System.Collections.Generic.List <object>();
            var writes = new System.Collections.Generic.List <object>();
            var now    = new cape.TimeValue();

            cape.Log.debug(ctx, "IOManagerDotNetSelect" + " started");
            while (exitflag == false)
            {
                if (executeSelect(ctx, reads, writes) == false)
                {
                    continue;
                }
                if (reads != null)
                {
                    var n = 0;
                    var m = reads.Count;
                    for (n = 0; n < m; n++)
                    {
                        var ele = reads[n] as capex.net.IOManagerDotNetSelect.MyEntry;
                        if (ele != null)
                        {
                            ele.onReadReady();
                        }
                    }
                }
                if (writes != null)
                {
                    var n2 = 0;
                    var m2 = writes.Count;
                    for (n2 = 0; n2 < m2; n2++)
                    {
                        var ele1 = writes[n2] as capex.net.IOManagerDotNetSelect.MyEntry;
                        if (ele1 != null)
                        {
                            ele1.onWriteReady();
                        }
                    }
                }
                cape.Vector.clear(reads);
                cape.Vector.clear(writes);
                if (cape.Vector.isEmpty(timers) == false)
                {
                    cape.SystemClock.update(now);
                    System.Collections.Generic.List <capex.net.IOManagerDotNetSelect.MyTimer> timersToRemove = null;
                    if (timers != null)
                    {
                        var n3 = 0;
                        var m3 = timers.Count;
                        for (n3 = 0; n3 < m3; n3++)
                        {
                            var timer = timers[n3];
                            if (timer != null)
                            {
                                if (timer.process(now) == false)
                                {
                                    if (timersToRemove == null)
                                    {
                                        timersToRemove = new System.Collections.Generic.List <capex.net.IOManagerDotNetSelect.MyTimer>();
                                    }
                                    timersToRemove.Add(timer);
                                }
                            }
                        }
                    }
                    if (timersToRemove != null)
                    {
                        var n4 = 0;
                        var m4 = timersToRemove.Count;
                        for (n4 = 0; n4 < m4; n4++)
                        {
                            var timer1 = timersToRemove[n4];
                            if (timer1 != null)
                            {
                                cape.Vector.removeValue(timers, timer1);
                            }
                        }
                    }
                }
            }
            if (signalSocket != null)
            {
                signalSocket.close();
                signalSocket = null;
            }
            cape.Vector.clear(readlist);
            cape.Vector.clear(writelist);
            signalPort = -1;
            running    = false;
            cape.Log.debug(ctx, "IOManagerDotNetSelect" + " ended");
            return(true);
        }