Example #1
0
        public static List <XFrmWorkAttribute> GetPluginCollection(
            Type typeInterface, Assembly myAssembly, bool isAbstractRequired)
        {
            if (PluginDictionary.ContainsKey(typeInterface))
            {
                return(PluginDictionary[typeInterface].ToList());
            }
            var tc = new List <XFrmWorkAttribute>();

            var types = myAssembly.GetTypes();

            foreach (var type in types)
            {
                if (type.GetInterface(typeInterface.ToString()) == null)
                {
                    continue;
                }
                if (!isAbstractRequired && type.IsAbstract)
                {
                    continue;
                }

                // Iterate through all the Attributes for each method.
                foreach (Attribute attr in
                         type.GetCustomAttributes(typeof(XFrmWorkAttribute), false))
                {
                    var attr2 = attr as XFrmWorkAttribute;
                    attr2.MyType = type;
                    tc.Add(attr2);
                }
            }
            PluginDictionary.Add(typeInterface, tc);
            return(tc);
        }
Example #2
0
        public TestAtgi()
        {
            PluginDictionary plugins = Singleton <PluginDictionary> .Instance;

            m_appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // Setup schema path
            string schemaPath = Path.Combine(m_appPath, "schemas");

            DomSchemaRegistry.SchemaResolver = new FileStreamResolver(schemaPath);

            // load atgi plugin
            string   atgiPath = m_appPath + @"\Plugins\Scea.Atgi.pll";
            Assembly assembly = Assembly.LoadFrom(atgiPath);

            plugins.Add(assembly);
            plugins.GetPlugins <PluginBase>();


            // 2- create colleciton
            DomRepository repository = new DomRepository();
            string        atgiFile   = m_appPath + @"\cube.atgi";

            m_domCollection            = repository.ReadCollection(new Uri(atgiFile));
            m_domCollection.IsReadOnly = true;
            // add dc to DomRepository
            repository.Add(m_domCollection);
        }
Example #3
0
        public static XFrmWorkAttribute GetAttribute(Type dataType, Type interfaceType)
        {
            List <XFrmWorkAttribute> plugins = null;

            if (PluginDictionary.TryGetValue(interfaceType, out plugins))
            {
                try
                {
                    var attr = plugins.First(d => d.MyType == dataType);
                    return(attr);
                }
                catch (Exception ex)
                {
                    XLogSys.Print.Error(ex);
                }
            }
            return(null);
        }
Example #4
0
        public static List <XFrmWorkAttribute> GetPluginCollection(Type typeInterface)
        {
            if (PluginDictionary.ContainsKey(typeInterface))
            {
                return(PluginDictionary[typeInterface].ToList());
            }
            var attrs = new List <XFrmWorkAttribute>();

            foreach (var item in PluginDictionary)
            {
                foreach (var attribute in item.Value)
                {
                    if (attribute.MyType.GetInterface(typeInterface.Name) != null &&
                        attrs.FirstOrDefault(d => d.Name == attribute.Name) == null)
                    {
                        attrs.Add(attribute);
                    }
                }
            }
            PluginDictionary.Add(typeInterface, attrs);


            return(attrs);
        }
Example #5
0
        public PluginManager(PRoConClient cpcClient) {
            AppDomainSandbox = null;
            Plugins = new PluginDictionary();
            //this.m_dicLoadedPlugins = new Dictionary<string, IPRoConPluginInterface>();
            //this.m_dicEnabledPlugins = new Dictionary<string, IPRoConPluginInterface>();

            //this.CacheFailCompiledPluginVariables = new Dictionary<string, Dictionary<string, string>>();

            ProconClient = cpcClient;
            //this.LoadedClassNames = new List<string>();
            MatchedInGameCommands = new Dictionary<string, MatchCommand>();
            CommandsNeedingConfirmation = new ConfirmationDictionary();

            // Handle plugin invocation timeouts.
            Invocations = new List<PluginInvocation>();
            IgnoredPluginClassNames = new List<String>();

            InvocationTimeoutThreadRunning = true;
            InvocationTimeoutThread = new Thread(new ThreadStart(InvocationTimeoutLoop));
            InvocationTimeoutThread.Start();

            AssignEventHandler();
        }
Example #6
0
 public static XFrmWorkAttribute GetPlugin(string pluginName)
 {
     return
         (PluginDictionary.Select(item => item.Value.FirstOrDefault(d => d.Name == pluginName))
          .FirstOrDefault(p => p != null));
 }
Example #7
0
 public static XFrmWorkAttribute GetPluginAttribute(Type pluginType)
 {
     return(PluginDictionary.SelectMany(r => r.Value).FirstOrDefault(t => t.MyType == pluginType));
 }
Example #8
0
        public PluginManager(PRoConClient cpcClient) {
            AppDomainSandbox = null;
            Plugins = new PluginDictionary();
            //this.m_dicLoadedPlugins = new Dictionary<string, IPRoConPluginInterface>();
            //this.m_dicEnabledPlugins = new Dictionary<string, IPRoConPluginInterface>();

            //this.CacheFailCompiledPluginVariables = new Dictionary<string, Dictionary<string, string>>();

            ProconClient = cpcClient;
            //this.LoadedClassNames = new List<string>();
            MatchedInGameCommands = new Dictionary<string, MatchCommand>();
            CommandsNeedingConfirmation = new ConfirmationDictionary();

            // Handle plugin invocation timeouts.
            Invocations = new List<PluginInvocation>();
            IgnoredPluginClassNames = new List<String>();

            this.InvocationMaxRuntime = ProconClient.PluginMaxRuntimeSpan;

            if (this.InvocationMaxRuntime.TotalMilliseconds < 10) {
                this.InvocationMaxRuntime = PluginInvocation.MaximumRuntime;
            }

            // Default maximum runtime = 5 seconds, divided by 20
            // check every 250 milliseconds.
            this.InvocationTimeoutTimer = new Timer(state => this.InvocationTimeoutCheck(), null, (int)(this.InvocationMaxRuntime.TotalMilliseconds / 20.0), (int)(this.InvocationMaxRuntime.TotalMilliseconds / 20.0));

            AssignEventHandler();
        }