Exemplo n.º 1
0
 public object ConvertTo(Type t)
 {
     if (t == typeof(Func <object, Task <object> >) || t == typeof(Func <object[], Task <object> >))
     {
         if (dictionary.ContainsKey("rpa_function") && (bool)dictionary["rpa_function"])
         {
             if (t == typeof(Func <object, Task <object> >))
             {
                 return(new Func <object, Task <object> >((object arg) =>
                 {
                     return RemoteSender.Invoke(server, socket, (string)dictionary["rpa_id"], new object[] { arg });
                 }));
             }
             else if (t == typeof(Func <object[], Task <object> >))
             {
                 return(new Func <object[], Task <object> >((object[] args) =>
                 {
                     return RemoteSender.Invoke(server, socket, (string)dictionary["rpa_id"], args);
                 }));
             }
         }
         else
         {
             var ex = new RemoteException("Cannot cast this object as a Function");
             ex.Code = "INVALID_CAST_EXCEPTION";
             throw ex;
         }
     }
     else if (t == typeof(Dictionary <string, object>))
     {
         return(dictionary);
     }
     return(this);
 }
Exemplo n.º 2
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     if (server == null)
     {
         result = null;
         return(false);
     }
     result = RemoteSender.Invoke(server, socket, (string)dictionary["rpa_id"], args);
     return(true);
 }
Exemplo n.º 3
0
        public bool _TryGetMember(string name, out object result)
        {
            // If the property name is found in a dictionary,
            // set the result parameter to the property value and return true.
            // Otherwise, return false.
            if (!dictionary.TryGetValue(name, out result))
            {
                if (server == null)
                {
                    return(false);
                }


                if (name == "UnRef" || name == "rpa_unref")
                {
                    result = new Func <Task>(this.UnRef);
                    dictionary.Add(name, result);
                }
                else if (name == "Preserve" || name == "rpa_preserve")
                {
                    result = new Action(this.Preserve);
                    dictionary.Add(name, result);
                }
                else if (name == "Invoke")
                {
                    result = new Func <object[], Task <object> >(this.Invoke);
                    dictionary.Add(name, result);
                }

                else
                {
                    result = new Func <object[], Task <object> >((object[] args) =>
                    {
                        return(RemoteSender.InvokeMethod(server, socket, (string)dictionary["rpa_id"], name, args));
                    });
                    dictionary.Add(name, result);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
 public Task <object> Invoke(object[] args)
 {
     return(RemoteSender.Invoke(server, socket, (string)dictionary["rpa_id"], args));
 }