Ejemplo n.º 1
0
Archivo: Queen.cs Proyecto: kigh143/bee
        public static void extend(ref JObject nector, JObject exP)
        {
            dynamic extendCommand = exP["_"];

            if (extendCommand != null)
            {
                List <string> keySents = new List <string>()
                {
                    "_c", "_f_", "_f"
                };
                List <string> nectorRoots = new List <string>();
                foreach (var nectorNode in nector)
                {
                    if (!keySents.Contains(nectorNode.Key))
                    {
                        nectorRoots.Add(nectorNode.Key);
                    }
                }
                //extensions are arrays having a one to one mapping to the nector
                JArray extensions = (JArray)exP["_"];
                for (int extIndex = 0; extIndex < extensions.Count() && extIndex < nectorRoots.Count(); extIndex++)
                {
                    JObject  jo                 = (JObject)extensions[extIndex];
                    string   combNameForExt     = nectorRoots[extIndex];
                    string   realCombNameForExt = Hive.GetRealCombName(combNameForExt);
                    Bee.Trap tempTrap           = new Trap();
                    Bee.Workers.PrepareAttributes(ref jo, realCombNameForExt, ref tempTrap);

                    //add this to the nector
                    foreach (var joNode in jo)
                    {
                        if (joNode.Key.Equals(Bee.Scents.Attribute))
                        {
                            dynamic  xxa = joNode.Value;
                            string   xa  = xxa;
                            string[] xax = xa.Split(' ');
                            if (Workers.HasNode((JObject)nector[combNameForExt], Bee.Scents.Attribute))
                            {
                                dynamic       foo       = ((JObject)nector[combNameForExt])[Bee.Scents.Attribute];
                                string        xfoo      = foo;
                                List <string> xfooParts = xfoo.Split(' ').ToList <string>();
                                for (int ixa = 0; ixa < xax.Length; ixa++)
                                {
                                    string tempXa = xax[ixa];
                                    tempXa = tempXa.Trim();
                                    if (string.IsNullOrEmpty(tempXa))
                                    {
                                        continue;
                                    }
                                    if (xfooParts.Contains(tempXa))
                                    {
                                        continue;
                                    }
                                    xfooParts.Add(tempXa);
                                }
                                string paticoz = "";
                                foreach (var xfooPart in xfooParts)
                                {
                                    paticoz = paticoz + " " + xfooPart;
                                }
                                ((JObject)nector[combNameForExt])[Bee.Scents.Attribute] = paticoz;
                            }
                            else
                            {
                                ((JObject)nector[combNameForExt]).Add(Bee.Scents.Attribute, xa);
                            }
                        }
                        else
                        {
                            ((JObject)nector[combNameForExt]).Add(joNode.Key, joNode.Value);
                        }
                    }
                }
            }
        }