コード例 #1
0
    public static EdgeOut Relay(EdgeIn jIn)
    {
        var jOut = new EdgeOut();

        if (jIn.parms.Length > 0)
        {
            jOut.parms = new dynamic[jIn.parms.Length];
        }

        dynamic o = null;
        Type    T = null;

        //create or return csid
        CreateGetObj(jIn, jOut, ref T, ref o);

        switch (jIn.act)
        {
        case 2:         //read fields or properties
        case 3:         //update
            DoMethod(o, T, jIn, jOut);
            break;

        case 4:         //delete
            release(jIn.csid);
            break;

        default:
            break;
        }

        return(jOut);
    }
コード例 #2
0
    public async Task <object> Invoke(dynamic input)
    {
        EdgeIn jIn = new EdgeIn();

        jIn.csid     = (int)input.csid;
        jIn.name     = (string)input.name;
        jIn.assembly = (string)input.assembly;
        jIn.file     = (string)input.file;
        jIn.act      = (int)input.act;
        jIn.index    = input.index;
        jIn.ret.type = (int)input.ret.type;

        int pl = input.parms.Length;

        if (pl > 0)
        {
            jIn.parms = new parm[pl];
            for (int i = 0; i < pl; i++)
            {
                jIn.parms[i] = new parm(
                    (int)input.parms[i].type,
                    input.parms[i].value);
            }
        }

        return(Runner.Relay(jIn));
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: FairSite2C/edge-sheath
            async public void TestSheath()
            {
                //    var x = new System.Data.SqlClient.SqlConnection("Data Source=localhost,1433;Network Library=DBMSSOCN;Initial Catalog=sweet16;User ID=guest;Password=guest;");
                //   x.Open();



                var st = new Startup();

                EdgeIn cInput = new EdgeIn();

                cInput.csid     = -404;
                cInput.name     = "queue";
                cInput.assembly = "string|";
                cInput.file     = "string|";
                cInput.act      = 1;
                cInput.ret.type = 2;


                string sqlc = "Data Source=localhost,1433;Network Library=DBMSSOCN;Initial Catalog=sweet16;User ID=guest;Password=guest;";

                cInput.parms    = new parm[1];
                cInput.parms[0] = new parm(1, sqlc);


                EdgeOut eo = (EdgeOut)await st.Invoke(cInput);

                //EdgeIn cInput = new EdgeIn();

                //cInput.csid = 0;
                //cInput.name = "System.Data.SqlClient.SqlConnection";
                //cInput.assembly = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
                //cInput.file = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll";
                //cInput.act = 1;
                //cInput.ret.type = -1;


                //string sqlc = "Data Source=localhost,1433;Network Library=DBMSSOCN;Initial Catalog=sweet16;User ID=guest;Password=guest;";
                //cInput.parms = new parm[1];
                //cInput.parms[0] = new parm(1, sqlc);


                //EdgeOut eo = (EdgeOut) await st.Invoke(cInput);

                cInput.csid  = eo.retval;
                cInput.name  = "Open";
                cInput.act   = 3;
                cInput.parms = new parm[0];

                var ex = await st.Invoke(cInput);
            }
コード例 #4
0
    public static void DoMethod(dynamic o, Type T, EdgeIn jIn, EdgeOut jOut)
    {
        int ix = 0;

        switch (jIn.name)
        {
        case "edKeyAt":

            foreach (dynamic el in o.Keys)
            {
                if (ix == jIn.index)
                {
                    ConvertOutParm(el, jIn.csid, jIn.ret.type, ref jOut.retval);
                    return;
                }
                ix++;
            }

            break;

        case "edValueAt":

            PropertyInfo piI = T.GetProperty("Item", BindingFlags.Instance | BindingFlags.Public);

            foreach (dynamic el in o.Keys)
            {
                if (ix == jIn.index)
                {
                    dynamic[] newArray = new dynamic[1];
                    newArray[0] = el;
                    jIn.index   = newArray;

                    if (jIn.parms.Length == 1)
                    {
                        dynamic pvalI = ConvertInParm(piI.PropertyType, jIn.parms[0]);
                        Console.WriteLine("Aafter ValueAt Set");
                        piI.SetValue(o, pvalI, jIn.index);
                        Console.WriteLine("Bafter ValueAt Set");
                    }
                    else
                    {
                        Console.WriteLine("C after ValueAt Set");

                        dynamic val = piI.GetValue(o, jIn.index);
                        Console.WriteLine("Dafter ValueAt Set");
                        ConvertOutParm(val, jIn.csid, jIn.ret.type, ref jOut.retval);
                        Console.WriteLine("Eafter ValueAt Set");
                    }

                    return;
                }
                ix++;
            }

            break;

        default:
            break;
        }

        var plist = T.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(x => x.Name == jIn.name).ToList();

        PropertyInfo pi   = null;
        dynamic      pval = null;

        if (plist.Count > 0)
        {
            if (jIn.act == 2)
            {
                pi = plist[0];
            }
            else
            {
                foreach (PropertyInfo minfo in plist)
                {
                    pval = ConvertInParm(minfo.PropertyType, jIn.parms[0]);

                    if (pval == null)
                    {
                        continue;
                    }

                    pi = minfo;
                    break;
                }

                if (pi == null)
                {
                    Console.WriteLine("SIGH");
                }
            }
        }

        if (pi != null)
        {
            if (jIn.index != null)
            {
                dynamic[] newArray = new dynamic[1];
                newArray[0] = jIn.index;
                jIn.index   = newArray;
            }

            if (jIn.act == 2)
            {
                dynamic result = pi.GetValue(o, jIn.index);
                //               Console.WriteLine("prop return " + result.ToString());
                ConvertOutParm(result, jIn.csid, jIn.ret.type, ref jOut.retval);
                //               Console.WriteLine("prop return after " + jOut.retval);
            }
            else
            {
                pi.SetValue(o, pval, jIn.index);
                //               dynamic result = pi.GetValue(o, jIn.index);
                //               Console.WriteLine("prop return " + result.ToString());
            }

            return;
        }

        FieldInfo fi = T.GetField(jIn.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

        if (fi != null)
        {
            if (jIn.act == 2)
            {
                dynamic result = fi.GetValue(o);
                ConvertOutParm(result, jIn.csid, jIn.ret.type, ref jOut.retval);
            }
            else
            {
                object parm = ConvertInParm(fi.FieldType, jIn.ret);

                fi.SetValue(o, parm);
            }

            return;
        }

        foreach (MethodInfo mi in T.GetMethods())
        {
            if (mi.Name == jIn.name)
            {
                ParameterInfo[] pis  = mi.GetParameters();
                int             pLen = pis.Length;
                if (pLen == jIn.parms.Length)
                {
                    object[] parms = null;

                    bool isMatch = true;

                    if (pLen > 0)
                    {
                        parms = new object[pLen];

                        for (int i = 0; i < pLen; i++)
                        {
                            dynamic newParm = ConvertInParm(pis[i].ParameterType, jIn.parms[i]);
                            if (newParm == null)
                            {
                                isMatch = false;
                                break;
                            }

                            parms[i] = newParm;
                        }
                    }

                    if (isMatch)
                    {
                        dynamic retval = mi.Invoke(o, parms);

                        if (pLen > 0)
                        {
                            jOut.parms = new dynamic[pLen];

                            for (int i = 0; i < pLen; i++)
                            {
                                if (pis[i].IsOut || pis[i].ParameterType.IsByRef)
                                {
                                    ConvertOutParm(parms[i], jIn.csid, jIn.parms[i].type, ref jOut.parms[i]);
                                }
                            }
                        }

                        ConvertOutParm(retval, jIn.csid, jIn.ret.type, ref jOut.retval);
                        return;
                    }
                }
            }
        }
    }
コード例 #5
0
    public static void CreateGetObj(EdgeIn jIn, EdgeOut jOut, ref Type T, ref dynamic o)
    {
        int ii = 0;

        o = null;
        try
        {
            if (jIn.csid == -404)
            {
                Type[] parms = new Type[1];
                Type   g     = null;

                int typeIdKey   = 0;
                int typeIdValue = 0;

                switch (jIn.name)
                {
                case ("array"):
                    Type t = GetTypeFromTypeName(jIn.name, jIn.assembly);
                    o = Array.CreateInstance(t, jIn.index);
                    break;

                case ("dictionary"):
                    parms    = new Type[2];
                    parms[0] = GetGenericType(jIn.assembly, ref typeIdKey);
                    parms[1] = GetGenericType(jIn.file, ref typeIdValue);
                    g        = typeof(Dictionary <,>);
                    break;

                case ("sorteddictionary"):
                    parms    = new Type[2];
                    parms[0] = GetGenericType(jIn.assembly, ref typeIdKey);
                    parms[1] = GetGenericType(jIn.file, ref typeIdValue);
                    g        = typeof(SortedDictionary <,>);
                    break;

                case ("list"):
                    parms[0] = GetGenericType(jIn.assembly, ref typeIdValue);
                    g        = typeof(List <>);
                    break;

                case ("linkedlist"):
                    parms[0] = GetGenericType(jIn.assembly, ref typeIdValue);
                    g        = typeof(LinkedList <>);
                    break;

                case ("stack"):
                    parms[0] = GetGenericType(jIn.assembly, ref typeIdValue);
                    g        = typeof(Stack <>);
                    break;

                case ("queue"):
                    parms[0] = GetGenericType(jIn.assembly, ref typeIdValue);
                    g        = typeof(Queue <>);
                    break;
                }

                if (jIn.name != "array")
                {
                    s Type constructed = g.MakeGenericType(parms);
                    o = Activator.CreateInstance(constructed);
                }

                NextCsID++;
                Cache.Add(NextCsID, new classy(o));
                jOut.retval   = NextCsID;
                jOut.parms    = new parm[1];
                jOut.parms[0] = new parm(typeIdKey, typeIdValue);

                return;
            }

            if (jIn.csid != 0)
            {
                o = Cache[jIn.csid].o;
                T = o.GetType();
                return;
            }

            var isLoaded = false;
            foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (ass.FullName == jIn.assembly)
                {
                    isLoaded = true;
                }
            }

            if (!isLoaded)
            {
                try
                {
                    Assembly.Load(jIn.assembly);
                    isLoaded = true;
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (!isLoaded)
                    {
                        string assfile = jIn.file.Replace("/", @"\");
                        Assembly.LoadFrom(assfile);
                        isLoaded = true;
                    }
                }
            }

            if (!isLoaded)
            {
                //  throw ("F*****g bummer");
            }
            ii++;

            T = GetTypeFromTypeName(jIn.name, jIn.assembly);

            if (T.GetConstructor(Type.EmptyTypes) == null && T.IsAbstract && T.IsSealed)
            {
                jIn.IsStatic = true;
            }

            if (!jIn.IsStatic)
            {
                ii++;

                int pLen = jIn.parms.Length;

                if (pLen == 0)
                {
                    o = Activator.CreateInstance(T);
                }
                else
                {
                    foreach (ConstructorInfo ci in T.GetConstructors())
                    {
                        ParameterInfo[] pis   = ci.GetParameters();
                        dynamic[]       parms = new dynamic[pLen];
                        if (pLen == pis.Length)
                        {
                            for (int i = 0; i < pLen; i++)
                            {
                                parms[i] = ConvertInParm(pis[i].ParameterType, jIn.parms[i]);
                            }
                            o = Activator.CreateInstance(T, parms);
                        }
                    }
                }


                if (o != null)
                {
                    NextCsID++;
                    Cache.Add(NextCsID, new classy(o));
                    jOut.retval = NextCsID;
                }
            }

            ii++;
        }
        catch (Exception ex)
        {
            jOut.errmsg = ii + " " + ex.Message;
        }
    }