public ServerHandler(string url, string SessionID, IRegistryCore registry) :
            base("POST", url)
        {
            m_SessionID   = SessionID;
            m_registry    = registry;
            m_capsService = m_registry.RequestModuleInterface <ICapsService>();
            m_urlModule   = m_registry.RequestModuleInterface <IGridRegistrationService>();
            if (m_methods == null)
            {
                m_methods = new Dictionary <string, List <MethodImplementation> >();
                List <string> alreadyRunPlugins = new List <string>();
                foreach (ConnectorBase plugin in ConnectorRegistry.Connectors)
                {
                    if (alreadyRunPlugins.Contains(plugin.PluginName))
                    {
                        continue;
                    }
                    alreadyRunPlugins.Add(plugin.PluginName);
                    foreach (MethodInfo method in plugin.GetType().GetMethods())
                    {
                        CanBeReflected reflection = (CanBeReflected)Attribute.GetCustomAttribute(method, typeof(CanBeReflected));
                        if (reflection != null)
                        {
                            string methodName = reflection.RenamedMethod == "" ? method.Name : reflection.RenamedMethod;
                            List <MethodImplementation> methods = new List <MethodImplementation>();
                            MethodImplementation        imp     = new MethodImplementation()
                            {
                                Method = method, Reference = plugin, Attribute = reflection
                            };
                            if (!m_methods.TryGetValue(methodName, out methods))
                            {
                                m_methods.Add(methodName, (methods = new List <MethodImplementation>()));
                            }

                            methods.Add(imp);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public object DoRemoteCall(bool forced, string url, UUID userID, params object[] o)
        {
            if (!m_doRemoteCalls && !forced)
            {
                return(null);
            }
            StackTrace stackTrace = new StackTrace();
            int        upStack    = 1;

            if (userID == UUID.Zero)
            {
                upStack = 2;
            }
            MethodInfo     method     = (MethodInfo)stackTrace.GetFrame(upStack).GetMethod();
            CanBeReflected reflection = (CanBeReflected)Attribute.GetCustomAttribute(method, typeof(CanBeReflected));
            string         methodName = reflection != null && reflection.RenamedMethod != "" ? reflection.RenamedMethod : method.Name;
            OSDMap         map        = new OSDMap();

            map["Method"] = methodName;
            int i          = 0;
            var parameters = method.GetParameters();

            if (o.Length != parameters.Length)
            {
                MainConsole.Instance.ErrorFormat("FAILED TO GET VALID NUMBER OF PARAMETERS TO SEND REMOTELY FOR {0}, EXPECTED {1}, GOT {2}", methodName, parameters.Length, o.Length);
                return(null);
            }
            foreach (ParameterInfo info in parameters)
            {
                OSD osd = o[i] == null ? null : Util.MakeOSD(o[i], o[i].GetType());
                if (osd != null)
                {
                    map.Add(info.Name, osd);
                }
                i++;
            }
            List <string> m_ServerURIs =
                m_configService.FindValueOf(userID.ToString(), url, false);
            OSDMap response = null;
            int    loops2Do = (m_ServerURIs.Count < m_OSDRequestTryCount) ? m_ServerURIs.Count : m_OSDRequestTryCount;

            for (int index = 0; index < loops2Do; index++)
            {
                string uri = m_ServerURIs[index];
                if (GetOSDMap(uri, map, out response))
                {
                    break;
                }
            }
            if (response == null || !response)
            {
                return(null);
            }
            object inst = null;

            try
            {
                if (method.ReturnType == typeof(string))
                {
                    inst = string.Empty;
                }
                else if (method.ReturnType == typeof(void))
                {
                    return(null);
                }
                else
                {
                    inst = Activator.CreateInstance(method.ReturnType);
                }
            }
            catch
            {
                if (method.ReturnType == typeof(string))
                {
                    inst = string.Empty;
                }
            }
            if (response["Value"] == "null")
            {
                return(null);
            }
            var instance = inst as IDataTransferable;

            if (instance != null)
            {
                instance.FromOSD((OSDMap)response["Value"]);
                return(instance);
            }
            return(Util.OSDToObject(response["Value"], method.ReturnType));
        }
 private void GetReflection(int upStack, StackTrace stackTrace, out MethodInfo method, out CanBeReflected reflection)
 {
     method     = (MethodInfo)stackTrace.GetFrame(upStack).GetMethod();
     reflection = (CanBeReflected)Attribute.GetCustomAttribute(method, typeof(CanBeReflected));
     if (reflection != null && reflection.NotReflectableLookUpAnotherTrace)
     {
         GetReflection(upStack + 1, stackTrace, out method, out reflection);
     }
 }
Esempio n. 4
0
 private void GetReflection(int upStack, StackTrace stackTrace, out MethodInfo method, out CanBeReflected reflection)
 {
     method = (MethodInfo)stackTrace.GetFrame(upStack).GetMethod();
     reflection = (CanBeReflected)Attribute.GetCustomAttribute(method, typeof(CanBeReflected));
     if (reflection != null && reflection.NotReflectableLookUpAnotherTrace)
         GetReflection(upStack + 1, stackTrace, out method, out reflection);
 }