Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="PxApp"></param>
        /// <param name="TopList"></param>
        /// <param name="FilterExtent">Optional, if not null it will be used to filter the notes to the current extent</param>
        /// <param name="UseLookupTable">Whether to perform a search / replace of the CUNames in the Design before outputting them</param>
        /// <returns></returns>
        public static string GetConstructionNotes(IMMPxApplication PxApp, IMMPersistentXML ListItem, IEnvelope FilterExtent)
        {
            if (PxApp == null)
            {
                throw new Exception("No Px Application found");
            }
            if (ListItem == null)
            {
                throw new Exception("No item given to generate notes for");
            }

            string XslPath = "";

            try
            {
                XslPath = DesignerUtility.GetPxConfig(PxApp, Constants.PxConfig_ContstructionNotesXslPath);
                if (string.IsNullOrEmpty(XslPath))
                {
                    throw new Exception("Obtained an empty reference to the Construction Notes Stylesheet.  Ask your administrator to verify the Px Configuration.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to find a Px Configuration for the Construction Notes Stylesheet.  Ask your administrator to verify the Px Configuration.", ex);
            }

            //Our resulting XML must have Work Locations / Gis Units in order to filter it
            System.Xml.XmlDocument modernDocument = null;
            string labelXmlType = DesignerUtility.GetPxConfig(PxApp, Constants.PxConfig_ContstructionNotesXmlSource);

            switch (labelXmlType)
            {
            case "DesignTree":
                modernDocument = GetReportingXml(PxApp, ListItem, LabelXmlType.DesignTree);
                break;

            default:
            case "DesignerXml":
                modernDocument = GetReportingXml(PxApp, ListItem, LabelXmlType.DesignerXml);
                break;

            case "PxXml":
                modernDocument = GetReportingXml(PxApp, ListItem, LabelXmlType.PxXml);
                break;

            case "CostEngine":
                modernDocument = GetReportingXml(PxApp, ListItem, LabelXmlType.CostEngine);
                break;

            case "Custom":
                modernDocument = GetReportingXml(PxApp, ListItem, LabelXmlType.Custom);
                break;
            }

            if (FilterExtent != null)
            {
                #region Fitler the Design Xml

                IRelationalOperator IRO = FilterExtent as IRelationalOperator;

                //Build up a list of Work Locations in the current extent
                List <string> BadWls = new List <string>();
                List <string> BadGus = new List <string>();

                ID8ListItem WlOrCu    = null;
                ID8ListItem GivenItem = ListItem as ID8ListItem;
                if (GivenItem == null)
                {
                    throw new ApplicationException("Selected item is not a valid list item");
                }

                if (GivenItem.ItemType == mmd8ItemType.mmd8itWorkRequest)
                {
                    ((ID8List)GivenItem).Reset();
                    ID8List Design = ((ID8List)GivenItem).Next(false) as ID8List;
                    GivenItem = Design as ID8ListItem;
                    ((ID8List)GivenItem).Reset();
                    WlOrCu = ((ID8List)GivenItem).Next(false);
                }
                else if (GivenItem.ItemType == mmd8ItemType.mmd8itDesign)
                {
                    ((ID8List)GivenItem).Reset();
                    WlOrCu = ((ID8List)GivenItem).Next(false);
                }
                else if (GivenItem.ItemType == mmd8ItemType.mmd8itWorkLocation)
                {
                    WlOrCu = (ID8ListItem)GivenItem;
                }
                else
                {
                    throw new ApplicationException("Construction notes are not supported on the selected item");
                }

                while (WlOrCu != null)
                {
                    if (WlOrCu.ItemType == mmd8ItemType.mmd8itWorkLocation)
                    {
                        if (!HasD8ChildInExtent(IRO, WlOrCu as ID8List))
                        {
                            BadWls.Add(((ID8WorkLocation)WlOrCu).ID);
                        }
                    }
                    else
                    {
                        if (WlOrCu.ItemType == mmd8ItemType.mmitMMGisUnit)
                        {
                            if (!HasD8ChildInExtent(IRO, WlOrCu as ID8List))
                            {
                                BadGus.Add(((IMMGisUnit)WlOrCu).GisUnitID.ToString());
                            }
                        }
                    }

                    WlOrCu = ((ID8List)GivenItem).Next(false);
                }

                string wlquery = "";
                foreach (string wlid in BadWls)
                {
                    if (!string.IsNullOrEmpty(wlid))
                    {
                        wlquery += "//WORKLOCATION[ID='" + wlid + "']|";
                    }
                }
                wlquery = wlquery.TrimEnd("|".ToCharArray());

                string guquery = "";
                foreach (string guid in BadGus)
                {
                    if (!string.IsNullOrEmpty(guid))
                    {
                        guquery += "//GISUNIT[DESIGNER_ID='" + guid + "']|";
                    }
                }
                guquery = guquery.TrimEnd("|".ToCharArray());

                string query = wlquery + "|" + guquery;
                query = query.Trim("|".ToCharArray());

                //Filter the xml document to remove the bad wls
                if (!string.IsNullOrEmpty(query))
                {
                    foreach (System.Xml.XmlNode BadNode in modernDocument.SelectNodes(query))
                    {
                        BadNode.ParentNode.RemoveChild(BadNode);
                    }
                }

                #endregion
            }

            return(TransformXml(modernDocument, XslPath));
        }
Esempio n. 2
0
        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);
        }