Пример #1
0
 public void AddSubProcess(DAMLProcess data)
 {
     if (ProcessType == enuProcessType.CompositeProcess)
     {
         m_arrSubProcesses.Add(data);
     }
     else
     {
         throw new InvalidOperationException("Only Composite Processes can have SubProcesses");
     }
 }
        private DAMLProcess[] GetSubProcesses(string strProcessName)
        {
            ArrayList lstSubProcesses = new ArrayList();

            try
            {
                XmlNode root       = m_doc.DocumentElement;
                string  strBaseUri = GetNamespaceBaseUri(DAMLConstants.PROCESS_NS);

                string  strXPath       = DAMLConstants.DAML_CLASS + "[@" + DAMLConstants.RDF_ID + "='" + strProcessName + "']" + "/" + DAMLConstants.RDFS_SUBCLASSOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.DAML_COMPOSITE_PROCESS + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_SUBCLASSOF;
                XmlNode SubClassOfNode = root.SelectSingleNode(strXPath, m_mgr);

                if (SubClassOfNode == null)
                {
                    return((DAMLProcess[])lstSubProcesses.ToArray(typeof(DAMLProcess)));
                }

                // Use fuzzy paths from here -> "//" operator looking for any matching
                // child node - more expensive but intermediate nodes are not
                // interesting/contain no info we can use

                strXPath = ".//" + DAMLConstants.DAML_LIST_OF_INSTANCES_OF + "/" + DAMLConstants.DAML_CLASS;
                XmlNodeList lstInstances = SubClassOfNode.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstInstances)
                {
                    string strProcess = node.Attributes[DAMLConstants.RDF_ABOUT].Value;
                    strProcess = strProcess.Trim(new Char[] { '#' });
                    enuProcessType processType = GetProcessType(strProcess);
                    DAMLProcess    process     = GetProcessData(strProcess, processType);
                    lstSubProcesses.Add(process);
                }
            }
            catch (Exception e)
            {
                m_EvtLog.WriteEntry(e.Message, EventLogEntryType.Error);
            }
            return((DAMLProcess[])lstSubProcesses.ToArray(typeof(DAMLProcess)));
        }
        public DAMLProcess GetProcessData(string strProcessName, enuProcessType processType)
        {
            DAMLProcess retVal = new DAMLProcess();

            try
            {
                XmlNode root       = m_doc.DocumentElement;
                string  strBaseUri = GetNamespaceBaseUri(DAMLConstants.PROCESS_NS);
                string  strUri     = "";
                strUri = strBaseUri;

                switch (processType)
                {
                case enuProcessType.AtomicProcess: strUri += DAMLConstants.DAML_ATOMIC_PROCESS;
                    break;

                case enuProcessType.CompositeProcess: strUri += DAMLConstants.DAML_COMPOSITE_PROCESS;
                    break;

                case enuProcessType.SimpleProcess: strUri += DAMLConstants.DAML_SIMPLE_PROCESS;
                    break;

                default:  throw new ArgumentException("Invalid processType value");
                }
                ;

                string strXPath = DAMLConstants.DAML_CLASS + "[@" + DAMLConstants.RDF_ID + "='" + strProcessName + "']" + "/" + DAMLConstants.RDFS_SUBCLASSOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strUri + "']";

                XmlNode processNode = root.SelectSingleNode(strXPath, m_mgr).ParentNode;

                // No such process exists so just exit - should throw exception since
                // returned DAMLProcess is useless
                if (processNode == null)
                {
                    return(retVal);
                }

                // Set process name
                retVal.Name = processNode.Attributes[DAMLConstants.RDF_ID].Value;
                // Set process type
                retVal.ProcessType = processType;

                // Get inputs from querying RDFProperty nodes in document
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.INPUT + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                XmlNodeList lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddInput(data);
                }

                // Get additional inputs from the process node itself
                // they may be hidden under restictions tagged with
                // daml:sameValueAs
                strXPath = DAMLConstants.DAML_CLASS + "[@" + DAMLConstants.RDF_ID + "='" + retVal.Name + "']" + "/" + DAMLConstants.RDFS_SUBCLASSOF + "/" + DAMLConstants.DAML_RESTRICTION + "/" + DAMLConstants.DAML_ON_PROPERTY + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.INPUT + "']" + "/" + "following-sibling::" + DAMLConstants.DAML_SAMEVALUESAS;
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    string strSameValueAs = node.Attributes[DAMLConstants.RDF_RESOURCE].Value;
                    strSameValueAs = strSameValueAs.Trim(new char[] { '#' });

                    // Go get RDFProperty data
                    strXPath = DAMLConstants.RDF_PROPERTY + "[@" + DAMLConstants.RDF_ID + "='" + strSameValueAs + "']" + "/" + DAMLConstants.RDFS_DOMAIN;
                    XmlNode domainNode = root.SelectSingleNode(strXPath, m_mgr);

                    // Add to list of inputs
                    if (domainNode != null)
                    {
                        RDFProperty data = GetNodeData(domainNode);
                        retVal.AddInput(data);
                    }
                }

                // Get outputs
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.OUTPUT + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddOutput(data);
                }

                // Get preconditions
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.PRECONDITION + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddPrecondition(data);
                }

                // Get effects
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.EFFECT + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddEffect(data);
                }

                // Get conditional outputs
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.CONDITIONAL_OUTPUT + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddConditionalOutput(data);
                }

                // Get co-conditions
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.CO_CONDITION + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddCoCondition(data);
                }

                // Get co-outputs
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.CO_OUTPUT + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddCoOutput(data);
                }

                // Get parameters
                strXPath = DAMLConstants.RDF_PROPERTY + "/" + DAMLConstants.RDFS_SUBPROPERTYOF + "[@" + DAMLConstants.RDF_RESOURCE + "='" + strBaseUri + DAMLConstants.PARAMETER + "']" + "/" + "following-sibling::" + DAMLConstants.RDFS_DOMAIN + "[@" + DAMLConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
                lstNodes = root.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstNodes)
                {
                    RDFProperty data = GetNodeData(node);
                    retVal.AddParameter(data);
                }

                // For each input, fill the process' InputRestrictionMap
                // search on process name
                if (retVal.HasInputs)
                {
                    foreach (RDFProperty Input in retVal.Inputs)
                    {
                        int nRestriction = GetInputRestrictions(retVal.Name, Input.Name);
                        if (nRestriction == 0)
                        {
                            nRestriction = DEFAULT_RESTRICTION;
                        }
                        retVal.AddInputRestriction(Input.Name, nRestriction);
                    }
                }

                // If we are dealing with a complex process we must go get
                // the substeps - need to get process:<type> data
                if (processType == enuProcessType.CompositeProcess)
                {
                    retVal.SubTaskType = GetProcessSubTaskType(retVal.Name);
                    retVal.AddSubProcess(GetSubProcesses(retVal.Name));
                }
            }
            catch (Exception e)
            {
                m_EvtLog.WriteEntry(e.Message, EventLogEntryType.Error);
            }
            return(retVal);
        }