Beispiel #1
0
        public List <string> GetActiveCodeletNames()
        {
            List <string> names = new List <string>();

            foreach (Assembly asm in assemblies)
            {
                foreach (Type t in asm.GetExportedTypes())
                {
                    foreach (Attribute a in t.GetCustomAttributes(false))
                    {
                        CodeletAttribute ca = a as CodeletAttribute;
                        if (ca != null)
                        {
                            if (ca.Active)
                            {
                                Codelet c = (Codelet)asm.CreateInstance(t.FullName, false, BindingFlags.CreateInstance, null,
                                                                        new object[] { ca.DefaultUrgency, null, this, workspace, slipnet },
                                                                        null, null);
                                names.Add(c.Name);
                            }
                        }
                    }
                }
            }
            return(names);
        }
Beispiel #2
0
        public void Populate()
        {
            //Reset();


            if (Constants.SHOW_CODERACK_URGENCIES_CONSOLE)
            {
                Log("Coderack size: " + codelets.Count.ToString());

                // Show % of each type.
                SortedDictionary <string, double> urgencies = new SortedDictionary <string, double>();
                double total = 0;
                foreach (Codelet c in codelets)
                {
                    if (urgencies.ContainsKey(c.Name))
                    {
                        urgencies[c.Name] += c.Urgency;
                    }
                    else
                    {
                        urgencies[c.Name] = c.Urgency;
                    }
                    total += c.Urgency;
                }

                Log("\nCoderack state:");


                foreach (KeyValuePair <string, double> p in urgencies)
                {
                    Console.WriteLine("{0:0.0}%:\t{1}", 100.0 * p.Value / total, p.Key);
                }
            }



            ///


            // Initialize Coderack with the codelets we find via reflection.
            // TODO: Do this at compile-time, with PostSharp
            int numAdded = 0;

            foreach (Assembly asm in assemblies)
            {
                foreach (Type t in asm.GetExportedTypes())
                {
                    foreach (Attribute a in t.GetCustomAttributes(false))
                    {
                        CodeletAttribute ca = a as CodeletAttribute;
                        if (ca != null)
                        {
                            if (ca.Active)
                            {
                                // Add 1 copy of each codelet.
                                for (int i = 0; i < 1; i++)
                                {
                                    lock (CodeletsLock) {
                                        Codelet c = (Codelet)asm.CreateInstance(t.FullName, false, BindingFlags.CreateInstance, null,
                                                                                new object[] { ca.DefaultUrgency, null, this, workspace, slipnet },
                                                                                null, null);
                                        c.PostTime = workspace.CurrentTime;
                                        codelets.Add(c);
                                        numAdded++;
                                    }
                                }
                            }
                            else
                            {
                                //throw new Exception("Deprecated: Codelet disabled in attribute: " + t.FullName);
                            }
                        }
                    }
                }
            }
            Log("Number of codelets added in populate: " + numAdded.ToString());

            UpdateView();
        }