private void LoadParamsOnAddedScene(SceneInterface scene) { ServerParamServiceInterface serverParams = GetServerParamStorage(); var cachedResults = new Dictionary <string, List <KeyValuePair <UUID, string> > >(); Type instanceType = scene.GetType(); foreach (ServerParamAttribute attr in Attribute.GetCustomAttributes(instanceType, typeof(ServerParamAttribute)) as ServerParamAttribute[]) { string parameterName = attr.ParameterName; List <KeyValuePair <UUID, string> > result; if (!cachedResults.TryGetValue(parameterName, out result)) { result = serverParams[parameterName]; cachedResults.Add(parameterName, result); } bool foundSpecific = false; MethodInfo[] mis = instanceType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (MethodInfo mi in mis) { ServerParamAttribute[] mi_attrs = Attribute.GetCustomAttributes(mi, typeof(ServerParamAttribute)) as ServerParamAttribute[]; foreach (ServerParamAttribute mi_attr in mi_attrs) { if (mi_attr.ParameterName == parameterName) { Action <UUID, string> del; try { del = Delegate.CreateDelegate(typeof(Action <UUID, string>), scene, mi) as Action <UUID, string>; } catch (Exception e) { /* could not create so skip it */ m_Log.WarnFormat("Failed to initialize scene {0} for parameter {1}: {2}: {3}\n{4}", scene.Name, parameterName, e.GetType().FullName, e.Message, e.StackTrace); continue; } foundSpecific = true; foreach (KeyValuePair <UUID, string> kvp in result) { #if DEBUG m_Log.DebugFormat("sending update to scene {0} with parameter {1}/{2}", scene.Name, kvp.Key.ToString(), parameterName); #endif try { del(kvp.Key, kvp.Value); } catch (Exception e) { m_Log.WarnFormat("Failed to configure scene {0} with parameter {1}/{2}: {3}: {4}\n{5}", scene.Name, kvp.Key.ToString(), parameterName, e.GetType().FullName, e.Message, e.StackTrace); } } } } } if (foundSpecific) { continue; } if (instanceType.GetInterfaces().Contains(typeof(IServerParamAnyListener))) { IServerParamAnyListener listener = (IServerParamAnyListener)scene; foreach (KeyValuePair <UUID, string> kvp in result) { #if DEBUG m_Log.DebugFormat("sending update to {0} with parameter {1}/{2}", scene.Name, kvp.Key.ToString(), parameterName); #endif try { listener.TriggerParameterUpdated(kvp.Key, parameterName, kvp.Value); } catch (Exception e) { m_Log.WarnFormat("Failed to configure scene {0} with parameter {1}/{2}: {3}: {4}\n{5}", scene.Name, kvp.Key.ToString(), parameterName, e.GetType().FullName, e.Message, e.StackTrace); } } } } }
private void LoadServerParamsForPlugin(string name, IPlugin instance, Dictionary <string, List <KeyValuePair <UUID, string> > > cachedResults) { ServerParamServiceInterface serverParams = GetServerParamStorage(); Type instanceType = instance.GetType(); var startswithattrs = Attribute.GetCustomAttributes(instanceType, typeof(ServerParamStartsWithAttribute)) as ServerParamStartsWithAttribute[]; if (instanceType.GetInterfaces().Contains(typeof(IServerParamAnyListener)) && startswithattrs.Length != 0) { var listener = (IServerParamAnyListener)instance; #if DEBUG m_Log.DebugFormat("Processing {0} for start with server params", name); #endif foreach (ServerParamStartsWithAttribute attr in startswithattrs) { foreach (KeyValuePair <UUID, string> kvp in serverParams.KnownParameters) { if (kvp.Value.StartsWith(attr.ParameterNameStartsWith)) { #if DEBUG m_Log.DebugFormat("sending config value to {0} with parameter {1}/{2}", name, kvp.Key.ToString(), kvp.Value); #endif try { listener.TriggerParameterUpdated(kvp.Key, kvp.Value, serverParams.GetString(kvp.Key, kvp.Value)); } catch (Exception e) { m_Log.WarnFormat("Failed to configure {0} with parameter {1}/{2}: {3}: {4}\n{5}", name, kvp.Key.ToString(), kvp.Value, e.GetType().FullName, e.Message, e.StackTrace); } } } #if DEBUG m_Log.DebugFormat("adding update listener for {0} with start with parameter {1}", name, attr.ParameterNameStartsWith); #endif serverParams.StartsWithServerParamListeners[attr.ParameterNameStartsWith].Add((IServerParamAnyListener)instance); } } if (instanceType.GetInterfaces().Contains(typeof(IServerParamListener))) { #if DEBUG m_Log.DebugFormat("Processing {0} for specific server param", name); #endif ServerParamAttribute[] attrs = Attribute.GetCustomAttributes(instanceType, typeof(ServerParamAttribute)) as ServerParamAttribute[]; foreach (ServerParamAttribute attr in attrs) { string parameterName = attr.ParameterName; List <KeyValuePair <UUID, string> > result; if (!cachedResults.TryGetValue(parameterName, out result)) { result = serverParams[parameterName]; cachedResults.Add(parameterName, result); } bool foundSpecific = false; MethodInfo[] mis = instanceType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (MethodInfo mi in mis) { ServerParamAttribute[] mi_attrs = Attribute.GetCustomAttributes(mi, typeof(ServerParamAttribute)) as ServerParamAttribute[]; foreach (ServerParamAttribute mi_attr in mi_attrs) { if (mi_attr.ParameterName == parameterName) { Action <UUID, string> del; try { del = Delegate.CreateDelegate(typeof(Action <UUID, string>), instance, mi) as Action <UUID, string>; } catch (Exception e) { m_Log.WarnFormat("Failed to initialize {0} for parameter {1}: {2}: {3}\n{4}", name, parameterName, e.GetType().FullName, e.Message, e.StackTrace); /* could not create so skip it */ continue; } foundSpecific = true; foreach (KeyValuePair <UUID, string> kvp in result) { #if DEBUG m_Log.DebugFormat("sending config value to {0} with parameter {1}/{2}", name, kvp.Key.ToString(), parameterName); #endif try { del(kvp.Key, kvp.Value); } catch (Exception e) { m_Log.WarnFormat("Failed to configure {0} with parameter {1}/{2}: {3}: {4}\n{5}", name, kvp.Key.ToString(), parameterName, e.GetType().FullName, e.Message, e.StackTrace); } } #if DEBUG m_Log.DebugFormat("adding update listener for {0} with parameter {1}", name, parameterName); #endif serverParams.SpecificParamListeners[parameterName].Add(del); } } } if (foundSpecific) { continue; } if (instanceType.GetInterfaces().Contains(typeof(IServerParamAnyListener))) { IServerParamAnyListener listener = (IServerParamAnyListener)instance; foreach (KeyValuePair <UUID, string> kvp in result) { #if DEBUG m_Log.DebugFormat("sending config value to {0} with parameter {1}/{2}", name, kvp.Key.ToString(), parameterName); #endif try { listener.TriggerParameterUpdated(kvp.Key, parameterName, kvp.Value); } catch (Exception e) { m_Log.WarnFormat("Failed to configure {0} with parameter {1}/{2}: {3}: {4}\n{5}", name, kvp.Key.ToString(), parameterName, e.GetType().FullName, e.Message, e.StackTrace); } } #if DEBUG m_Log.DebugFormat("adding update listener for {0} with parameter {1}", name, parameterName); #endif serverParams.GenericServerParamListeners[parameterName].Add(listener); } } } }