Пример #1
0
        public int IncludeConfig(string inFile, Dictionary <String, String> myConfig, int lVariant = 0, bool bDeep = false)
        {
            //
            // Consume XML to create the XLator object.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            int                         rc            = -1;
            XmlTextReader               reader        = null;
            string                      connectString = XTRMObject.getDictionaryEntry("TaskConnectString");
            string                      outerXML;
            int                         lElementType       = 0;
            XDictionaryLoader           myDictionaryLoader = new XDictionaryLoader();
            Dictionary <String, String> elementAttributes;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                reader = new XmlTextReader(inFile);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult = reader.Read();
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        string elementName = reader.Name;
                        switch (elementName.ToUpper())
                        {
                        case "BASECONFIG":
                            outerXML           = reader.ReadOuterXml();
                            myDictionaryLoader = new XDictionaryLoader();
                            myConfig           = myDictionaryLoader.Augment(myConfig, outerXML);
                            bProcessed         = true;
                            break;

                        case "WITHCONFIG":
                            outerXML = reader.ReadOuterXml();
                            myDictionaryLoader.Augment(myConfig, outerXML);
                            bProcessed = true;
                            break;

                        case "EVENTFILTER":
                            outerXML = reader.ReadOuterXml();
                            XTRMEvent thisFilter = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 2, true);
                            eventFilters.Add(thisFilter);
                            bProcessed = true;
                            break;

                        case "XTRMEVENT":
                            outerXML = reader.ReadOuterXml();
                            XTRMEvent thisEvent = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 1, true);
                            events.Add(thisEvent);
                            bProcessed = true;
                            break;

                        case "XTRMWORKFLOW":
                            outerXML = reader.ReadOuterXml();
                            XTRMWorkFlow thisFlow = (XTRMWorkFlow)XTRMWorkFlow.consumeXML(myConfig, outerXML, 1, true);
                            workflows.Add(thisFlow);
                            bProcessed = true;
                            break;
                        }
                        if (!bProcessed)
                        {
                            // May wish to get all the  attributes here for new elements!
                            elementAttributes = new Dictionary <String, String>();
                            if (reader.HasAttributes)
                            {
                                reader.MoveToFirstAttribute();
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    elementAttributes.Add(reader.Name, reader.Value);
                                    reader.MoveToNextAttribute();
                                }
                                if (elementAttributes.ContainsKey("Name"))
                                {
                                    // Try to instantiate the XEvent Object!
                                    name = elementAttributes["Name"];
                                }
                                reader.MoveToElement();
                            }
                            // Need to see if we are interested in this element!
                            //string elementName = reader.Name;
                            switch (elementName.ToUpper())
                            //switch (reader.Name)
                            {
                            case "EVENTFOLDER":
                                lElementType = 1;
                                bResult      = reader.Read();
                                break;

                            case "XTRM":
                                // Advance into Elements!
                                reader.MoveToContent();
                                bResult = reader.Read();
                                break;

                            default:
                                bResult = reader.Read();
                                break;
                            }
                        }
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Comment:
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.EndElement:
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Text:
                        switch (lElementType)
                        {
                        case 1:             // EventFolder
                            eventFolders.Add(ResolveText(reader.Value, XDictionary));
                            break;

                        default:
                            break;
                        }
                        bResult = reader.Read();
                        break;

                    default:
                        bResult = reader.Read();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2402, -1, string.Format("XLator::IncludeConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }


            return(rc);
        }
Пример #2
0
 //public Dictionary<String, String> createDictionary()
 //{
 // Populate the Dictionary!
 //    XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
 //    return myDictionaryLoader.ParseXML();
 //}
 /*
 public new static XObject consumeXML(Dictionary<String, String> myConfig, string XmlElement, bool bDeep = false)
 {
     //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
     //myDictionaryLoader.Augment();
     //
     // Consume XML to create the XComponent object.
     // if bDeep is false, then ONLY do this object.
     // if bDeep is true, then also do recursive objects.
     return new XComponent();
 }
  * */
 public static new XTRMObject consumeXML(Dictionary<String, String> existingConfig, string XmlFragment, int lVariant = 0, bool bDeep = false)
 {
     //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
     //myDictionaryLoader.Augment();
     //
     // Consume XML to create the XComponent object.
     // if bDeep is false, then ONLY do this object.
     // if bDeep is true, then also do recursive objects.
     XmlTextReader reader = null;
     XmlParserContext context = null;
     Dictionary<String, String> myConfig = new Dictionary<string, string>(existingConfig);
     XTRMWorkFlow thisWorkflow = new XTRMWorkFlow();
     int lElementType = 0;
     XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
     Dictionary<String, String> elementAttributes;
     try
     {
         // Load the reader with the data file and ignore all white space nodes.
         context = new XmlParserContext(null, null, null, XmlSpace.None);
         reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
         reader.WhitespaceHandling = WhitespaceHandling.None;
         // Parse the file and display each of the nodes.
         bool bResult = reader.Read();
         string outerXML;
         //XDictionaryLoader myDictionaryLoader;
         while (bResult)
         {
             bool bProcessed = false;
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                     string elementName = reader.Name;
                     switch (elementName.ToUpper())
                     {
                         case "IFEVENT": // XEvent
                             outerXML = reader.ReadOuterXml();
                             XTRMEvent thisEvent = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 1, true);
                             thisWorkflow.workflowEvents.Add(thisEvent);
                             bProcessed = true;
                             break;
                         // Reset Dictionary!
                         // XConfig
                         case "BASECONFIG":
                             outerXML = reader.ReadOuterXml();
                             //myDictionaryLoader = new XDictionaryLoader();
                             myConfig = new Dictionary<string, string>();
                             myDictionaryLoader.Augment(myConfig, outerXML);
                             bProcessed = true;
                             break;
                         //   Add to the current dictionary!
                         // XConfig
                         case "WITHCONFIG":
                             outerXML = reader.ReadOuterXml();
                             myDictionaryLoader = new XDictionaryLoader();
                             myDictionaryLoader.Augment(myConfig, outerXML);
                             bProcessed = true;
                             break;
                     }
                     if (!bProcessed)
                     {
                         // May wish to get all the  attributes here for new elements!
                         elementAttributes = new Dictionary<String, String>();
                         if (reader.HasAttributes)
                         {
                             reader.MoveToFirstAttribute();
                             for (int i = 0; i < reader.AttributeCount; i++)
                             {
                                 //reader.GetAttribute(i);
                                 elementAttributes.Add(reader.Name, reader.Value);
                                 reader.MoveToNextAttribute();
                             }
                             if (elementAttributes.ContainsKey("Name"))
                             {
                                 // Try to instantiate the XEvent Object!
                                 thisWorkflow.name = elementAttributes["Name"];
                             }
                             if (elementAttributes.ContainsKey("ID"))
                             {
                                 // Try to instantiate the XEvent Object!
                                 thisWorkflow.name = elementAttributes["ID"];
                             }
                             reader.MoveToElement();
                         }
                         // Need to see if we are interested in this element!
                         //string elementName = reader.Name;
                         switch (elementName.ToUpper())
                         {
                             //case "IFEVENT": // XEvent
                             //    outerXML = reader.ReadOuterXml();
                             //    XEvent thisEvent = (XEvent)XEvent.consumeXML(myConfig, outerXML, 1, true);
                             //    thisWorkflow.workflowEvents.Add(thisEvent);
                             //    break;
                             // Reset Dictionary!
                             // XConfig
                             //case "BASECONFIG":
                             //    outerXML = reader.ReadOuterXml();
                             //    //myDictionaryLoader = new XDictionaryLoader();
                             //    myConfig = new Dictionary<string, string>();
                             //    myDictionaryLoader.Augment(myConfig, outerXML);
                             //    break;
                             //   Add to the current dictionary!
                             // XConfig
                             //case "WITHCONFIG":
                             //    outerXML = reader.ReadOuterXml();
                             //    myDictionaryLoader = new XDictionaryLoader();
                             //    myDictionaryLoader.Augment(myConfig, outerXML);
                             //    break;
                             default:
                                 bResult = reader.Read();
                                 break;
                         }
                     }
                     break;
                 case XmlNodeType.XmlDeclaration:
                 case XmlNodeType.ProcessingInstruction:
                     //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                     bResult = reader.Read();
                     break;
                 case XmlNodeType.Comment:
                     //writer.WriteComment(reader.Value);
                     bResult = reader.Read();
                     break;
                 case XmlNodeType.EndElement:
                     //writer.WriteFullEndElement();
                     bResult = reader.Read();
                     break;
                 case XmlNodeType.Text:
                     //Console.Write(reader.Value);
                     switch (lElementType)
                     {
                         //case 1:     // PARMS
                         //    thisTask.parms.Add(reader.Value);
                         default:
                             break;
                     }
                     bResult = reader.Read();
                     break;
                 default:
                     bResult = reader.Read();
                     break;
             }
         }
     }
     catch (Exception ex)
     {
         exCount_XML++;
         XLogger(3100, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
     }
     finally
     {
         if (reader != null)
             reader.Close();
     }
     thisWorkflow.config = myConfig;
     return thisWorkflow;
 }
Пример #3
0
        //public Dictionary<String, String> createDictionary()
        //{
        // Populate the Dictionary!
        //    XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
        //    return myDictionaryLoader.ParseXML();
        //}

        /*
         * public new static XObject consumeXML(Dictionary<String, String> myConfig, string XmlElement, bool bDeep = false)
         * {
         *  //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
         *  //myDictionaryLoader.Augment();
         *  //
         *  // Consume XML to create the XComponent object.
         *  // if bDeep is false, then ONLY do this object.
         *  // if bDeep is true, then also do recursive objects.
         *  return new XComponent();
         * }
         * */
        public new static XTRMObject consumeXML(Dictionary <String, String> existingConfig, string XmlFragment, int lVariant = 0, bool bDeep = false)
        {
            //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
            //myDictionaryLoader.Augment();
            //
            // Consume XML to create the XComponent object.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader               reader             = null;
            XmlParserContext            context            = null;
            Dictionary <String, String> myConfig           = new Dictionary <string, string>(existingConfig);
            XTRMWorkFlow                thisWorkflow       = new XTRMWorkFlow();
            int                         lElementType       = 0;
            XDictionaryLoader           myDictionaryLoader = new XDictionaryLoader();
            Dictionary <String, String> elementAttributes;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                context = new XmlParserContext(null, null, null, XmlSpace.None);
                reader  = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool   bResult = reader.Read();
                string outerXML;
                //XDictionaryLoader myDictionaryLoader;
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        string elementName = reader.Name;
                        switch (elementName.ToUpper())
                        {
                        case "IFEVENT":         // XEvent
                            outerXML = reader.ReadOuterXml();
                            XTRMEvent thisEvent = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 1, true);
                            thisWorkflow.workflowEvents.Add(thisEvent);
                            bProcessed = true;
                            break;

                        // Reset Dictionary!
                        // XConfig
                        case "BASECONFIG":
                            outerXML = reader.ReadOuterXml();
                            //myDictionaryLoader = new XDictionaryLoader();
                            myConfig = new Dictionary <string, string>();
                            myDictionaryLoader.Augment(myConfig, outerXML);
                            bProcessed = true;
                            break;

                        //   Add to the current dictionary!
                        // XConfig
                        case "WITHCONFIG":
                            outerXML           = reader.ReadOuterXml();
                            myDictionaryLoader = new XDictionaryLoader();
                            myDictionaryLoader.Augment(myConfig, outerXML);
                            bProcessed = true;
                            break;
                        }
                        if (!bProcessed)
                        {
                            // May wish to get all the  attributes here for new elements!
                            elementAttributes = new Dictionary <String, String>();
                            if (reader.HasAttributes)
                            {
                                reader.MoveToFirstAttribute();
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    //reader.GetAttribute(i);
                                    elementAttributes.Add(reader.Name, reader.Value);
                                    reader.MoveToNextAttribute();
                                }
                                if (elementAttributes.ContainsKey("Name"))
                                {
                                    // Try to instantiate the XEvent Object!
                                    thisWorkflow.name = elementAttributes["Name"];
                                }
                                if (elementAttributes.ContainsKey("ID"))
                                {
                                    // Try to instantiate the XEvent Object!
                                    thisWorkflow.name = elementAttributes["ID"];
                                }
                                reader.MoveToElement();
                            }
                            // Need to see if we are interested in this element!
                            //string elementName = reader.Name;
                            switch (elementName.ToUpper())
                            {
                            //case "IFEVENT": // XEvent
                            //    outerXML = reader.ReadOuterXml();
                            //    XEvent thisEvent = (XEvent)XEvent.consumeXML(myConfig, outerXML, 1, true);
                            //    thisWorkflow.workflowEvents.Add(thisEvent);
                            //    break;
                            // Reset Dictionary!
                            // XConfig
                            //case "BASECONFIG":
                            //    outerXML = reader.ReadOuterXml();
                            //    //myDictionaryLoader = new XDictionaryLoader();
                            //    myConfig = new Dictionary<string, string>();
                            //    myDictionaryLoader.Augment(myConfig, outerXML);
                            //    break;
                            //   Add to the current dictionary!
                            // XConfig
                            //case "WITHCONFIG":
                            //    outerXML = reader.ReadOuterXml();
                            //    myDictionaryLoader = new XDictionaryLoader();
                            //    myDictionaryLoader.Augment(myConfig, outerXML);
                            //    break;
                            default:
                                bResult = reader.Read();
                                break;
                            }
                        }
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Comment:
                        //writer.WriteComment(reader.Value);
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.EndElement:
                        //writer.WriteFullEndElement();
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Text:
                        //Console.Write(reader.Value);
                        switch (lElementType)
                        {
                        //case 1:     // PARMS
                        //    thisTask.parms.Add(reader.Value);
                        default:
                            break;
                        }
                        bResult = reader.Read();
                        break;

                    default:
                        bResult = reader.Read();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(3100, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            thisWorkflow.config = myConfig;
            return(thisWorkflow);
        }