private static System.Xml.XmlDocument GetReportingXml(IMMPxApplication PxApp, IMMPersistentXML ListItem, LabelXmlType XmlType) { if (PxApp == null) throw new Exception("No Px Application found"); if (ListItem == null) throw new Exception("No item given to generate notes for"); /* Stack<ID8ListItem> items = new Stack<ID8ListItem>(); ((ID8List)ListItem).Reset(); items.Push((ID8ListItem)ListItem); int wlCount = 1; while (items.Count > 0) { var item = items.Pop(); if (item is ID8TopLevel || item is ID8WorkRequest || item is ID8Design) { ((ID8List)item).Reset(); for (ID8ListItem child = ((ID8List)item).Next(true); child != null; child = ((ID8List)item).Next(true)) items.Push(child); } else if (item is ID8WorkLocation) { ((ID8WorkLocation)item).ID = wlCount.ToString(); wlCount++; } else continue; } */ switch (XmlType) { case LabelXmlType.DesignTree: { Miner.Interop.msxml2.IXMLDOMDocument xDoc = new Miner.Interop.msxml2.DOMDocument(); ListItem.SaveToDOM(mmXMLFormat.mmXMLFDesign, xDoc); var newDoc = new System.Xml.XmlDocument(); newDoc.LoadXml(xDoc.xml); return newDoc; } default: case LabelXmlType.DesignerXml: { //Hidden packages int currentDesign = ((IMMPxApplicationEx)PxApp).CurrentNode.Id; return new System.Xml.XmlDocument() { InnerXml = DesignerUtility.GetClassicDesignXml(currentDesign) }; } case LabelXmlType.PxXml: { //Hidden packages int currentDesign = ((IMMPxApplicationEx)PxApp).CurrentNode.Id; IMMWMSDesign design = DesignerUtility.GetWmsDesign(PxApp, currentDesign); if (design == null) throw new Exception("Unable to load design with id of " + currentDesign); return new System.Xml.XmlDocument() { InnerXml = DesignerUtility.GetClassicPxXml(design, PxApp) }; } case LabelXmlType.CostEngine: { //get the px config, load it, run it, return it string costEngineProgID = DesignerUtility.GetPxConfig(PxApp, "WMSCostEngine"); if (string.IsNullOrEmpty(costEngineProgID)) throw new Exception("Cost Engine Xml Source Defined, but no cost engine is defined"); Type costEngineType = Type.GetTypeFromProgID(costEngineProgID); if (costEngineType == null) throw new Exception("Unable to load type for specified cost engine: " + costEngineProgID); var rawType = Activator.CreateInstance(costEngineType); if (rawType == null) throw new Exception("Unable to instantiate cost engine type " + costEngineType); IMMWMSCostEngine costEngine = rawType as IMMWMSCostEngine; if (costEngine == null) throw new Exception("Configured cost engine " + costEngineProgID + " is not of type IMMWMSCostEngine"); if (!costEngine.Initialize(PxApp)) throw new Exception("Failed to initialize cost engine"); return new System.Xml.XmlDocument() { InnerXml = costEngine.Calculate(((IMMPxApplicationEx)PxApp).CurrentNode) }; } case LabelXmlType.Custom: throw new Exception("No custom xml reporting source defined"); /*Or you can reference a custom cost / reporting engine CostingEngine.SimpleCostEngine SCE = new Telvent.Applications.Designer.CostingEngine.SimpleCostEngine(); SCE.Initialize(PxApp); CalculatedXml = SCE.Calculate(xDoc.xml); */ break; } //Fall through return null; }
private static System.Xml.XmlDocument GetReportingXml(IMMPxApplication PxApp, IMMPersistentXML ListItem, LabelXmlType XmlType) { if (PxApp == null) { throw new Exception("No Px Application found"); } if (ListItem == null) { throw new Exception("No item given to generate notes for"); } /* * Stack<ID8ListItem> items = new Stack<ID8ListItem>(); * ((ID8List)ListItem).Reset(); * items.Push((ID8ListItem)ListItem); * * int wlCount = 1; * while (items.Count > 0) * { * var item = items.Pop(); * if (item is ID8TopLevel || * item is ID8WorkRequest || * item is ID8Design) * { * ((ID8List)item).Reset(); * for (ID8ListItem child = ((ID8List)item).Next(true); * child != null; * child = ((ID8List)item).Next(true)) * items.Push(child); * } * else if (item is ID8WorkLocation) * { * ((ID8WorkLocation)item).ID = wlCount.ToString(); * wlCount++; * } * else * continue; * } */ switch (XmlType) { case LabelXmlType.DesignTree: { Miner.Interop.msxml2.IXMLDOMDocument xDoc = new Miner.Interop.msxml2.DOMDocument(); ListItem.SaveToDOM(mmXMLFormat.mmXMLFDesign, xDoc); var newDoc = new System.Xml.XmlDocument(); newDoc.LoadXml(xDoc.xml); return(newDoc); } default: case LabelXmlType.DesignerXml: { //Hidden packages int currentDesign = ((IMMPxApplicationEx)PxApp).CurrentNode.Id; return(new System.Xml.XmlDocument() { InnerXml = DesignerUtility.GetClassicDesignXml(currentDesign) }); } case LabelXmlType.PxXml: { //Hidden packages int currentDesign = ((IMMPxApplicationEx)PxApp).CurrentNode.Id; IMMWMSDesign design = DesignerUtility.GetWmsDesign(PxApp, currentDesign); if (design == null) { throw new Exception("Unable to load design with id of " + currentDesign); } return(new System.Xml.XmlDocument() { InnerXml = DesignerUtility.GetClassicPxXml(design, PxApp) }); } case LabelXmlType.CostEngine: { //get the px config, load it, run it, return it string costEngineProgID = DesignerUtility.GetPxConfig(PxApp, "WMSCostEngine"); if (string.IsNullOrEmpty(costEngineProgID)) { throw new Exception("Cost Engine Xml Source Defined, but no cost engine is defined"); } Type costEngineType = Type.GetTypeFromProgID(costEngineProgID); if (costEngineType == null) { throw new Exception("Unable to load type for specified cost engine: " + costEngineProgID); } var rawType = Activator.CreateInstance(costEngineType); if (rawType == null) { throw new Exception("Unable to instantiate cost engine type " + costEngineType); } IMMWMSCostEngine costEngine = rawType as IMMWMSCostEngine; if (costEngine == null) { throw new Exception("Configured cost engine " + costEngineProgID + " is not of type IMMWMSCostEngine"); } if (!costEngine.Initialize(PxApp)) { throw new Exception("Failed to initialize cost engine"); } return(new System.Xml.XmlDocument() { InnerXml = costEngine.Calculate(((IMMPxApplicationEx)PxApp).CurrentNode) }); } case LabelXmlType.Custom: throw new Exception("No custom xml reporting source defined"); /*Or you can reference a custom cost / reporting engine * CostingEngine.SimpleCostEngine SCE = new Telvent.Applications.Designer.CostingEngine.SimpleCostEngine(); * SCE.Initialize(PxApp); * CalculatedXml = SCE.Calculate(xDoc.xml); */ break; } //Fall through return(null); }