XElement Save(XElement xml, GroupComposite comp) { foreach (IPBComposite pbComp in comp.Children) { if (pbComp is Comment) { xml.Add(new XComment(((Comment)pbComp).Text)); } else { var newElement = new XElement(pbComp.GetType().Name); var rootAttr = (XmlRootAttribute)pbComp.GetType().GetCustomAttributes(typeof(XmlRootAttribute), true).FirstOrDefault(); if (rootAttr != null) { newElement.Name = rootAttr.ElementName; } pbComp.OnProfileSave(newElement); List <PropertyInfo> piList = pbComp.GetType().GetProperties(). Where(p => p.GetCustomAttributes(typeof(PbXmlAttributeAttribute), true). Any()).ToList(); foreach (PropertyInfo pi in piList) { List <PbXmlAttributeAttribute> pList = ((PbXmlAttributeAttribute[])pi.GetCustomAttributes(typeof(PbXmlAttributeAttribute), true)).ToList(); string name = pList.Any(a => a.AttributeName == null) ? pi.Name : pList[0].AttributeName; string value = ""; var typeConverterAttr = (TypeConverterAttribute)pi.GetCustomAttributes(typeof(TypeConverterAttribute), true).FirstOrDefault(); if (typeConverterAttr != null) { try { var typeConverter = (TypeConverter)Activator.CreateInstance(Type.GetType(typeConverterAttr.ConverterTypeName)); if (typeConverter.CanConvertTo(typeof(string))) { value = (string)typeConverter.ConvertTo(pi.GetValue(pbComp, null), typeof(string)); } else { Professionbuddy.Err("The TypeConvert {0} can not convert to string.", typeConverterAttr.ConverterTypeName); } } catch (Exception ex) { Professionbuddy.Err("Type conversion for {0}->{1} has failed.\n{2}", comp.GetType().Name, pi.Name, ex); } } else { value = pi.GetValue(pbComp, null).ToString(); } newElement.Add(new XAttribute(name, value)); } if (pbComp is GroupComposite) { Save(newElement, (GroupComposite)pbComp); } xml.Add(newElement); } } return(xml); }
void recursiveReset(GroupComposite gc) { foreach (IPBComposite comp in gc.Children) { comp.Reset(); if (comp is GroupComposite) { recursiveReset(comp as GroupComposite); } } }
void PasteAction(TreeNode source, TreeNode dest) { if (dest != source && (!IsChildNode(source, dest) || dest == null)) { GroupComposite gc = (GroupComposite)((Composite)source.Tag).Parent; if ((copyAction & CopyPasteOperactions.Copy) != CopyPasteOperactions.Copy) gc.Children.Remove((Composite)source.Tag); AddToActionTree(source, dest); if ((copyAction & CopyPasteOperactions.Copy) != CopyPasteOperactions.Copy) // ctrl key source.Remove(); copySource = null;// free any ref.. } }
void ActionTreeAddChildren(GroupComposite ds, TreeNode node) { foreach (IPBComposite child in ds.Children) { TreeNode childNode = new TreeNode(child.Title); childNode.ForeColor = child.Color; childNode.Tag = child; // If, While and SubRoutine are Decorators. if (child is GroupComposite) { ActionTreeAddChildren((GroupComposite)child, childNode); } node.Nodes.Add(childNode); } }
public static void Collect(GroupComposite tree) { while (tree.Children.First() != null){ var child = tree.Children.First(); if (child is GroupComposite) { Collect(child as GroupComposite); Logging.Write("Deleting " + child); tree.Children.Remove(child); } else { Logging.Write("Deleting "+child); tree.Children.Remove(child); } } }
private void ActionTreeAddChildren(GroupComposite ds, TreeNode node) { foreach (IPBComposite child in ds.Children) { var childNode = new TreeNode(child.Title) { ForeColor = child.Color, Tag = child }; // If, While and SubRoutine are Decorators. var groupComposite = child as GroupComposite; if (groupComposite != null) { ActionTreeAddChildren(groupComposite, childNode); } node.Nodes.Add(childNode); } }
private static void ModifyTownRun(GroupComposite original) { var firstChild = original.Children.FirstOrDefault() as GroupComposite; if (firstChild == null) { Logger.LogVerbose("Unexpected Composite or no vendor composite found in original town run"); return; } if (firstChild.Children.Count != 9) { return; } firstChild.InsertChild(3, new ActionRunCoroutine(async ret => await VendorHook.ExecutePreVendor())); // 2= Identify // 5= Stash firstChild.InsertChild(8, new ActionRunCoroutine(async ret => await VendorHook.ExecutePostVendor())); }
private TreeNode RecursiveCloning(TreeNode node) { var newComp = (IPBComposite)(((IPBComposite)node.Tag).Clone()); var newNode = new TreeNode(newComp.Title) { ForeColor = newComp.Color, Tag = newComp }; foreach (TreeNode child in node.Nodes) { // If, While and SubRoutine are Decorators. var groupComposite = newComp as GroupComposite; if (groupComposite != null) { GroupComposite gc = groupComposite; TreeNode newChildNode = RecursiveCloning(child); gc.AddChild((Composite)newChildNode.Tag); newNode.Nodes.Add(newChildNode); } } return(newNode); }
TreeNode RecursiveCloning(TreeNode node) { IPBComposite newComp = (IPBComposite)(((IPBComposite)node.Tag).Clone()); TreeNode newNode = new TreeNode(newComp.Title); newNode.ForeColor = newComp.Color; newNode.Tag = newComp; if (node.Nodes != null) { foreach (TreeNode child in node.Nodes) { GroupComposite gc = null; // If, While and SubRoutine are Decorators. if (newComp is GroupComposite) { gc = (GroupComposite)newComp; TreeNode newChildNode = RecursiveCloning(child); gc.AddChild((Composite)newChildNode.Tag); newNode.Nodes.Add(newChildNode); } } } return newNode; }
private GroupComposite Load(XElement xml, GroupComposite comp) { foreach (XNode node in xml.Nodes()) { if (node.NodeType == XmlNodeType.Comment) { comp.AddChild(new Comment(((XComment)node).Value)); } else if (node.NodeType == XmlNodeType.Element) { var element = (XElement)node; Type type = Type.GetType("HighVoltz.Composites." + element.Name); if (type == null) { IEnumerable <Type> pbTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where (typeof(IPBComposite)).IsAssignableFrom(t) && !t.IsAbstract select t; type = pbTypes.FirstOrDefault( t => t.GetCustomAttributes(typeof(XmlRootAttribute), true).Any( a => ((XmlRootAttribute)a).ElementName == element.Name)); if (type == null) { throw new InvalidOperationException( string.Format("Unable to bind XML Element: {0} to a Type", element.Name)); } } var pbComp = (IPBComposite)Activator.CreateInstance(type); pbComp.OnProfileLoad(element); var pbXmlAttrs = from pi in type.GetProperties() from attr in (PbXmlAttributeAttribute[]) pi.GetCustomAttributes(typeof(PbXmlAttributeAttribute), true) where attr != null let name = attr.AttributeName ?? pi.Name select new { name, pi }; Dictionary <string, PropertyInfo> piDict = pbXmlAttrs.ToDictionary(kv => kv.name, kv => kv.pi); Dictionary <string, string> attributes = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value); // use legacy X,Y,Z location for backwards compatability if (attributes.ContainsKey("X")) { string location = string.Format("{0},{1},{2}", attributes["X"], attributes["Y"], attributes["Z"]); piDict["Location"].SetValue(pbComp, location, null); attributes.Remove("X"); attributes.Remove("Y"); attributes.Remove("Z"); } foreach (var attr in attributes) { if (piDict.ContainsKey(attr.Key)) { PropertyInfo pi = piDict[attr.Key]; // check if there is a type converter attached var typeConverterAttr = (TypeConverterAttribute) pi.GetCustomAttributes(typeof(TypeConverterAttribute), true).FirstOrDefault(); if (typeConverterAttr != null) { try { var typeConverter = (TypeConverter) Activator.CreateInstance(Type.GetType(typeConverterAttr.ConverterTypeName)); if (typeConverter.CanConvertFrom(typeof(string))) { pi.SetValue(pbComp, typeConverter.ConvertFrom(null, CultureInfo.CurrentCulture, attr.Value), null); } else { Professionbuddy.Err("The TypeConvert {0} can not convert from string.", typeConverterAttr.ConverterTypeName); } } catch (Exception ex) { Professionbuddy.Err("Type conversion for {0} has failed.\n{1}", type.Name + attr.Key, ex); } } else { pi.SetValue(pbComp, pi.PropertyType.IsEnum ? Enum.Parse(pi.PropertyType, attr.Value) : Convert.ChangeType(attr.Value, pi.PropertyType), null); } } else { Professionbuddy.Log("{0}->{1} appears to be unused", type, attr.Key); } } if (pbComp is GroupComposite) { Load(element, pbComp as GroupComposite); } comp.AddChild((Composite)pbComp); } } return(comp); }
private void recursiveReset(GroupComposite gc) { foreach (IPBComposite comp in gc.Children) { comp.Reset(); if (comp is GroupComposite) recursiveReset(comp as GroupComposite); } }
private static void ModifyTownRun(GroupComposite original) { var firstChild = original.Children.FirstOrDefault() as GroupComposite; if (firstChild == null) { Logger.LogVerbose("Unexpected Composite or no vendor composite found in original town run"); return; } if (firstChild.Children.Count != 9) return; firstChild.InsertChild(3, new ActionRunCoroutine(async ret => await VendorHook.ExecutePreVendor())); // 2= Identify // 5= Stash firstChild.InsertChild(8, new ActionRunCoroutine(async ret => await VendorHook.ExecutePostVendor())); }
private void ActionTreeAddChildren(GroupComposite ds, TreeNode node) { foreach (IPBComposite child in ds.Children) { var childNode = new TreeNode(child.Title) {ForeColor = child.Color, Tag = child}; // If, While and SubRoutine are Decorators. var groupComposite = child as GroupComposite; if (groupComposite != null) { ActionTreeAddChildren(groupComposite, childNode); } node.Nodes.Add(childNode); } }
private XElement Save(XElement xml, GroupComposite comp) { foreach (IPBComposite pbComp in comp.Children) { if (pbComp is Comment) { xml.Add(new XComment(((Comment) pbComp).Text)); } else { var newElement = new XElement(pbComp.GetType().Name); var rootAttr = (XmlRootAttribute) pbComp.GetType().GetCustomAttributes(typeof (XmlRootAttribute), true).FirstOrDefault(); if (rootAttr != null) newElement.Name = rootAttr.ElementName; pbComp.OnProfileSave(newElement); List<PropertyInfo> piList = pbComp.GetType().GetProperties(). Where(p => p.GetCustomAttributes(typeof (PbXmlAttributeAttribute), true). Any()).ToList(); foreach (PropertyInfo pi in piList) { List<PbXmlAttributeAttribute> pList = ((PbXmlAttributeAttribute[]) pi.GetCustomAttributes(typeof (PbXmlAttributeAttribute), true)) .ToList(); string name = pList.Any(a => a.AttributeName == null) ? pi.Name : pList[0].AttributeName; string value = ""; var typeConverterAttr = (TypeConverterAttribute) pi.GetCustomAttributes(typeof (TypeConverterAttribute), true).FirstOrDefault(); if (typeConverterAttr != null) { try { var typeConverter = (TypeConverter) Activator.CreateInstance(Type.GetType(typeConverterAttr.ConverterTypeName)); if (typeConverter.CanConvertTo(typeof (string))) { value = (string)typeConverter.ConvertTo(null, CultureInfo.InvariantCulture, pi.GetValue(pbComp, null), typeof(string)); } else Professionbuddy.Err("The TypeConvert {0} can not convert to string.", typeConverterAttr.ConverterTypeName); } catch (Exception ex) { Professionbuddy.Err("Type conversion for {0}->{1} has failed.\n{2}", comp.GetType().Name, pi.Name, ex); } } else { value = Convert.ToString(pi.GetValue(pbComp, null), CultureInfo.InvariantCulture); } newElement.Add(new XAttribute(name, value)); } if (pbComp is GroupComposite) Save(newElement, (GroupComposite) pbComp); xml.Add(newElement); } } return xml; }
private GroupComposite Load(XElement xml, GroupComposite comp) { foreach (XNode node in xml.Nodes()) { if (node.NodeType == XmlNodeType.Comment) { comp.AddChild(new Comment(((XComment) node).Value)); } else if (node.NodeType == XmlNodeType.Element) { var element = (XElement) node; Type type = Type.GetType("HighVoltz.Composites." + element.Name); if (type == null) { IEnumerable<Type> pbTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where (typeof (IPBComposite)).IsAssignableFrom(t) && !t.IsAbstract select t; type = pbTypes.FirstOrDefault( t => t.GetCustomAttributes(typeof (XmlRootAttribute), true).Any( a => ((XmlRootAttribute) a).ElementName == element.Name)); if (type == null) throw new InvalidOperationException( string.Format("Unable to bind XML Element: {0} to a Type", element.Name)); } var pbComp = (IPBComposite) Activator.CreateInstance(type); pbComp.OnProfileLoad(element); var pbXmlAttrs = from pi in type.GetProperties() from attr in (PbXmlAttributeAttribute[]) pi.GetCustomAttributes(typeof (PbXmlAttributeAttribute), true) where attr != null let name = attr.AttributeName ?? pi.Name select new {name, pi}; Dictionary<string, PropertyInfo> piDict = pbXmlAttrs.ToDictionary(kv => kv.name, kv => kv.pi); Dictionary<string, string> attributes = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value); // use legacy X,Y,Z location for backwards compatability if (attributes.ContainsKey("X")) { string location = string.Format("{0},{1},{2}", attributes["X"], attributes["Y"], attributes["Z"]); piDict["Location"].SetValue(pbComp, location, null); attributes.Remove("X"); attributes.Remove("Y"); attributes.Remove("Z"); } foreach (var attr in attributes) { if (piDict.ContainsKey(attr.Key)) { PropertyInfo pi = piDict[attr.Key]; // check if there is a type converter attached var typeConverterAttr = (TypeConverterAttribute) pi.GetCustomAttributes(typeof (TypeConverterAttribute), true).FirstOrDefault(); if (typeConverterAttr != null) { try { var typeConverter = (TypeConverter) Activator.CreateInstance(Type.GetType(typeConverterAttr.ConverterTypeName)); if (typeConverter.CanConvertFrom(typeof (string))) { pi.SetValue(pbComp, typeConverter.ConvertFrom(null, CultureInfo.InvariantCulture, attr.Value), null); } else Professionbuddy.Err("The TypeConvert {0} can not convert from string.", typeConverterAttr.ConverterTypeName); } catch (Exception ex) { Professionbuddy.Err("Type conversion for {0} has failed.\n{1}", type.Name + attr.Key, ex); } } else { pi.SetValue(pbComp, pi.PropertyType.IsEnum ? Enum.Parse(pi.PropertyType, attr.Value) : Convert.ChangeType(attr.Value, pi.PropertyType, CultureInfo.InvariantCulture), null); } } else Professionbuddy.Log("{0}->{1} appears to be unused", type, attr.Key); } if (pbComp is GroupComposite) Load(element, pbComp as GroupComposite); comp.AddChild((Composite) pbComp); } } return comp; }
void AddToActionTree(object action, TreeNode dest) { bool ignoreRoot = (copyAction & CopyPasteOperactions.IgnoreRoot) == CopyPasteOperactions.IgnoreRoot ? true : false; bool cloneActions = (copyAction & CopyPasteOperactions.Copy) == CopyPasteOperactions.Copy ? true : false; TreeNode newNode = null; if (action is TreeNode) { if (cloneActions) { newNode = RecursiveCloning(((TreeNode)action)); } else newNode = (TreeNode)((TreeNode)action).Clone(); } else if (action.GetType().GetInterface("IPBComposite") != null) { IPBComposite composite = (IPBComposite)action; newNode = new TreeNode(composite.Title); newNode.ForeColor = composite.Color; newNode.Tag = composite; } else return; ActionTree.SuspendLayout(); if (dest != null) { int treeIndex = action is TreeNode && ((TreeNode)action).Parent == dest.Parent && ((TreeNode)action).Index <= dest.Index && !cloneActions ? dest.Index + 1 : dest.Index; GroupComposite gc = null; // If, While and SubRoutines are Decorators... if (!ignoreRoot && dest.Tag is GroupComposite) gc = (GroupComposite)dest.Tag; else gc = (GroupComposite)((Composite)dest.Tag).Parent; if ((dest.Tag is If || dest.Tag is SubRoutine) && !ignoreRoot) { dest.Nodes.Add(newNode); gc.AddChild((Composite)newNode.Tag); if (!dest.IsExpanded) dest.Expand(); } else { if (dest.Index >= gc.Children.Count) gc.AddChild((Composite)newNode.Tag); else gc.InsertChild(dest.Index, (Composite)newNode.Tag); if (dest.Parent == null) { if (treeIndex >= ActionTree.Nodes.Count) ActionTree.Nodes.Add(newNode); else ActionTree.Nodes.Insert(treeIndex, newNode); } else { if (treeIndex >= dest.Parent.Nodes.Count) dest.Parent.Nodes.Add(newNode); else dest.Parent.Nodes.Insert(treeIndex, newNode); } } } else { ActionTree.Nodes.Add(newNode); PB.CurrentProfile.Branch.AddChild((Composite)newNode.Tag); } ActionTree.ResumeLayout(); }