コード例 #1
0
        private Object Reductor(String key, String value)
        {
            try
            {
                ProcessDescription process = m_processQueue[m_index];
                key = key.Trim().ToLower();

                foreach (ParaItem para in process.Inputs)
                {
                    if (String.Compare(key, para.Name, true) == 0)
                    {
                        return(InstanceManager.Instance.ProcessManager.CreateObject(para.DataType, value));
                    }
                }
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningStatusLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error(_LOG, ex.Message);
                }
            }

            return(value);
        }
コード例 #2
0
        protected override Boolean Run(XmlElement state)
        {
            try
            {
                if (!this.IsReady())
                {
                    return(false);
                }
                PopInputValue();

                _parameters = this.GetInputValue("Paras") as ParaItem[];
                ModelParameterWizardForm wizard       = new ModelParameterWizardForm();
                ProcessDescription[]     processQueue = new ProcessDescription[1];
                ProcessDescription       item         = new ProcessDescription("sample", 1, "sample", "sample");
                item.Inputs     = _parameters;
                processQueue[0] = item;

                wizard.ProcessQueue = processQueue;
                if (wizard.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    List <ParameterSet> paras = wizard.ParameterSetList; //这个地方速度慢
                    _para = paras[0];
                }
                else
                {
                    wizard.Close();
                    return(false);
                }

                PushOutputValue();
                return(true);
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error("sample.ProcessValidateModelFile", ex.Message);
                }
            }
            finally
            {
            }

            return(false);
        }
コード例 #3
0
        private void m_wizard_Finish(object sender, WizardForm.EventNextArgs e)
        {
            try
            {
                m_parameterSetList = new List <ParameterSet>();
                //由于控件不全,这里做一次转换,将String转成对应类型,后面做全了再删除
                ParameterSet paras = null;
                String       strValue;
                m_index = 0;
                ParameterSet parasResult = null;
                foreach (ParameterWizard wizPage in m_wizPages)
                {
                    paras            = wizPage.ParameterSet;
                    parasResult      = new ParameterSet();
                    parasResult.ID   = paras.ID;
                    parasResult.Name = paras.Name;
                    foreach (KeyValuePair <String, Object> pair in paras)
                    {
                        if (pair.Value is String)
                        {
                            parasResult[pair.Key] = Reductor(pair.Key, pair.Value as String);
                        }
                        else
                        {
                            parasResult[pair.Key] = pair.Value;
                        }
                    }

                    //m_parameterSetList.Add(wizPage.ParameterSet);
                    m_parameterSetList.Add(parasResult);
                    ++m_index;
                }
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningStatusLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error(_LOG, ex.Message);
                }
            }
        }
コード例 #4
0
        protected override Boolean Run(XmlElement state)
        {
            try
            {
                if (!this.IsReady())
                {
                    return(false);
                }
                PopInputValue();

                String fileModel = this.GetInputValue("ModelFile") as String;
                if (String.IsNullOrEmpty(fileModel))
                {
                    return(false);
                }
                ParameterSet paraSet = this.GetInputValue("ParaSet") as ParameterSet;
                if (null == paraSet)
                {
                    return(false);
                }

                ProcessChain chain = new ProcessChain();
                XmlDocument  doc   = new XmlDocument();
                doc.Load(fileModel);
                XmlElement root = doc.DocumentElement;
                foreach (XmlNode node in root.GetElementsByTagName("operation"))
                {
                    chain.AddProcess(node.Attributes["name"].Value, Int32.Parse(node.Attributes["id"].Value));
                }

                Int32 prevID = 0;
                Int32 backID = 0;
                foreach (XmlNode linknode in root.GetElementsByTagName("link"))
                {
                    prevID = Int32.Parse(linknode.Attributes["from"].Value);
                    backID = Int32.Parse(linknode.Attributes["to"].Value);
                    foreach (XmlNode assignnode in linknode.SelectNodes("assign"))
                    {
                        chain.ConnectProcesses(prevID, backID,
                                               assignnode.SelectNodes("from")[0].InnerText,
                                               assignnode.SelectNodes("to")[0].InnerText);
                    }
                }

                String[] strs    = null;
                IProcess process = null;
                foreach (String key in paraSet.Keys)
                {
                    strs = key.Split('.');
                    if (3 != strs.Length)
                    {
                        return(false);
                    }

                    process = chain.GetProcessById(Int32.Parse(strs[1]));
                    if (null == process)
                    {
                        return(false);
                    }
                    process.SetInputValue(strs[2], paraSet[key]);
                }

                return(chain.Execute());
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error("sample.ProcessValidateModelFile", ex.Message);
                }
            }
            finally
            {
            }

            return(false);
        }
コード例 #5
0
        protected override Boolean Run(XmlElement state)
        {
            try
            {
                if (!this.IsReady())
                {
                    return(false);
                }
                PopInputValue();

                String strModelFile = this.GetInputValue("ModelFile") as String;
                if (!System.IO.File.Exists(strModelFile))
                {
                    return(false);
                }
                IProcessListParser processList = InstanceManager.Instance.ProcessListParser;
                if (null == processList)
                {
                    return(false);
                }

                XmlDocument doc = new XmlDocument();
                doc.Load(strModelFile);
                XmlElement               root   = doc.DocumentElement;
                ParaItem                 para   = null;
                XmlAttribute             attri  = null;
                ProcessDefineDescription pdd    = null;
                ParaItem[]               inputs = null;
                ParaItem                 pid    = null;
                foreach (XmlNode node in root.GetElementsByTagName("operation"))
                {
                    pdd = processList.GetProcess(node.Attributes["name"].Value);
                    if (null == pdd)
                    {
                        continue;
                    }
                    inputs = pdd.Inputs;
                    foreach (XmlNode item in node.SelectSingleNode("inputs").ChildNodes)
                    {
                        if (String.IsNullOrEmpty(item.Attributes["variable"].Value))
                        {
                            para = new ParaItem(node.Attributes["name"].Value + "." + node.Attributes["id"].Value + "." + item.Attributes["name"].Value, item.Attributes["type"].Value);
                            pid  = FindPara(inputs, item.Attributes["name"].Value);
                            if (null != pid)
                            {
                                para.Abstract = pid.Abstract;
                                para.UIType   = pid.UIType;
                                para.Option   = pid.Option;
                                para.Title    = pid.Title;
                            }
                            attri = item.Attributes["title"];
                            if (null != attri)
                            {
                                para.Title = attri.Value;
                            }
                            _parameters.Add(para);
                        }
                    }
                }

                PushOutputValue();
                return(true);
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error("sample.ProcessValidateModelFile", ex.Message);
                }
            }
            finally
            {
            }

            return(false);
        }
コード例 #6
0
ファイル: ModelActuator.cs プロジェクト: zenwalk/goldenmonkey
        public static Boolean ExecuteXmlModel(String filePath, Boolean isWithParameter)
        {
            try
            {
                String _filePath = filePath;
                if (!File.Exists(_filePath))
                {
                    return(false);
                }
                //解析文件
                IModelParser parser = InstanceManager.Instance.NewParser;
                if (null == parser)
                {
                    return(false);
                }
                parser.File = filePath;
                Boolean _isStepByStep = parser.IsStepByStepMode;
                //建立地理空间处理模型
                Graph gpm = new Graph();
                ProcessDescription[] processes = parser.ProcessList;

//                List<ProcessDescription> processQueue = null;
//                if (_isStepByStep)
//                {
//                    processQueue = new List<ProcessDescription>();
//                    //从空间处理列表查找SpatialProcess
//                    IProcessListParser processListParser = InstanceManager.Instance.ProcessListParser;
//                    if (null == processListParser)
//                    {
//                        return false;
//                    }

//                    ProcessDefineDescription processDefine = null;
//                    //ProcessDescription item = null;
//                    List<ParaItem> parameters = null;
//                    //ParaItem parameter = null;
//                    foreach (ProcessDescription process in processes)
//                    {
//                        //如果是开始结点,就不添加到列表中
//                        if (process.Name.Equals(_XMLTag.g_ValueStart))
//                        {
//                            continue;
//                        }

//                        processDefine = processListParser.GetProcess(process.Name);
//                        //item = new ProcessDescription(processDefine.Name, process.Id, processDefine.Caption, processDefine.Description);
//                        parameters = new List<ParaItem>();
//                        foreach (ParaItem paraitem in processDefine.Inputs)
//                        {
//                            if (IsParameterInProcess(process, paraitem.Name))
//                            {
////                                paraitem.Value = GetVariable(process, paraitem.Name);
//                                parameters.Add(paraitem);
//                            }
//                        }
//                        item.Inputs = parameters;
//                        processQueue.Add(item);
//                    }
//                }
//                else
//                {
                foreach (ProcessDescription process in processes)
                {
                    gpm.CreateNode(process.Id, process);
                }
                //}
                LinkDescription[] links = parser.LinkList;
                foreach (LinkDescription link in links)
                {
                    gpm.Link(gpm.NodeById(link.FromId), gpm.NodeById(link.ToId), link);
                }

                IModelJob job = InstanceManager.Instance.ProcessManager.CreateJob("xmlModel") as IModelJob;
                if (null == job)
                {
                    return(false);
                }
                job.JobValue = gpm;

                if (!isWithParameter)
                {
                    if (_isStepByStep)
                    {
                        ModelParameterWizardForm wizard = new ModelParameterWizardForm();
                        //List<ProcessDescription> processQueue = new List<ProcessDescription>();
                        ////从空间处理列表查找SpatialProcess
                        //IProcessListParser processListParser = InstanceManager.Instance.ProcessListParser;
                        //if (null == processListParser)
                        //{
                        //    return false;
                        //}

                        //ProcessDefineDescription processDefine = null;
                        //ProcessDescription item = null;
                        //List<ParaItem> parameters = null;
                        ////ParaItem parameter = null;
                        //foreach (ProcessDescription process in parser.ProcessList)
                        //{
                        //    //如果是开始结点,就不添加到列表中
                        //    if (process.Name.Equals(_XMLTag.g_ValueStart))
                        //    {
                        //        continue;
                        //    }

                        //    processDefine = processListParser.GetProcess(process.Name);
                        //    item = new ProcessDescription(processDefine.Name, process.Id, processDefine.Caption, processDefine.Description);
                        //    parameters = new List<ParaItem>();
                        //    foreach (ParaItem paraitem in processDefine.Inputs)
                        //    {
                        //        if (IsParameterInProcess(process, paraitem.Name))
                        //        {
                        //            paraitem.Value = GetVariable(process, paraitem.Name);
                        //            parameters.Add(paraitem);
                        //        }
                        //    }
                        //    item.Inputs = parameters;
                        //    processQueue.Add(item);
                        //}

//                        wizard.ProcessQueue = processQueue;
                        wizard.ProcessQueue = processes;
                        if (wizard.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            List <ParameterSet> paras = wizard.ParameterSetList; //这个地方速度慢
                            if (!job.SetParameters(paras.ToArray()))
                            {
                                throw new Exception("设置参数失败");
                            }
                        }
                        else
                        {
                            wizard.Close();
                            return(false);
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException("该场景未实现");
                }

                return(job.Execute());
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningStatusLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error(_LOG, ex.Message);
                }
            }

            return(false);
        }
コード例 #7
0
        protected override Boolean Run(XmlElement state)
        {
            XmlReader xmlRead = null;
            Boolean   bProcessDescriptionsValidated = false;
            Int32     nGroupItem   = 0;
            Int32     nProcessItem = 0;

            try
            {
                if (!this.IsReady())
                {
                    return(false);
                }
                PopInputValue();

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ValidationEventHandler += new ValidationEventHandler(this.ValidationEventCallBack);
                settings.ValidationType          = ValidationType.Schema;
                String strValidateFile = this.GetInputValue("ProcessDescriptionsValidateFile") as String;
                settings.Schemas.Add(null, strValidateFile);

                lock (_obj)
                {
                    if (1 != _state && 4 != _state)
                    {
                        RunException ex = new RunException();
                        throw ex;
                    }
                }

                String strValue = this.GetState(state, "IsValidateProcessDescriptionsFile");
                if (!String.IsNullOrEmpty(strValue))
                {
                    bProcessDescriptionsValidated = Boolean.Parse(strValue);
                }
                String strProcessListFile = "";
                if (!bProcessDescriptionsValidated)
                {
                    strProcessListFile = this.GetInputValue("ProcessListFile") as String;
                    xmlRead            = XmlReader.Create(strProcessListFile, settings);
                    while (xmlRead.Read())
                    {
                    }
                    xmlRead.Close();
                    xmlRead = null;

                    bProcessDescriptionsValidated = true;
                }

                lock (_obj)
                {
                    if (1 != _state && 4 != _state)
                    {
                        RunException ex = new RunException();
                        throw ex;
                    }
                }

                //验证分组文件
                settings = new XmlReaderSettings();
                settings.ValidationEventHandler += new ValidationEventHandler(this.ValidationEventCallBack);
                settings.ValidationType          = ValidationType.Schema;
                strValidateFile = this.GetInputValue("GroupValidateFile") as String;
                settings.Schemas.Add(null, strValidateFile);

                strValue = this.GetState(state, "GroupValidateItem");
                if (!String.IsNullOrEmpty(strValue))
                {
                    nGroupItem = Int32.Parse(strValue);
                }

                XmlDocument doc = new XmlDocument();
                doc.Load(strProcessListFile);
                XmlElement  xmlListFile      = doc.DocumentElement;
                XmlNodeList nodeLists        = xmlListFile.GetElementsByTagName("Group");
                String      strFile          = "";
                String      strBaseDirectory = InstanceManager.Instance.Context.GetVariable("BaseDirectory") as String;
                XmlNode     node             = null;
                for (; nGroupItem < nodeLists.Count; ++nGroupItem)
                {
                    lock (_obj)
                    {
                        if (1 != _state && 4 != _state)
                        {
                            RunException ex = new RunException();
                            throw ex;
                        }
                    }

                    node    = nodeLists[nGroupItem];
                    strFile = strBaseDirectory + "../Config/ProcessGroups/" + node.InnerText + ".xml";
                    strFile = System.IO.Path.GetFullPath(strFile);
                    xmlRead = XmlReader.Create(strFile, settings);
                    while (xmlRead.Read())
                    {
                    }
                    xmlRead.Close();
                    xmlRead = null;

                    //验证地理空间处理文件
                    XmlReaderSettings settings2 = new XmlReaderSettings();
                    settings2.ValidationEventHandler += new ValidationEventHandler(this.ValidationEventCallBack);
                    settings2.ValidationType          = ValidationType.Schema;
                    strValidateFile = this.GetInputValue("ProcessDescriptionValidateFile") as String;
                    settings2.Schemas.Add(null, strValidateFile);

                    strValue     = this.GetState(state, "ProcessValidateItem");
                    nProcessItem = 0;
                    if (!String.IsNullOrEmpty(strValue))
                    {
                        nProcessItem = Int32.Parse(strValue);
                    }

                    doc = new XmlDocument();
                    doc.Load(strFile);
                    XmlElement  xmlGroupFile = doc.DocumentElement;
                    XmlNodeList processLists = xmlGroupFile.GetElementsByTagName("ProcessDescription");
                    for (; nProcessItem < processLists.Count; ++nProcessItem)
                    {
                        lock (_obj)
                        {
                            if (1 != _state && 4 != _state)
                            {
                                RunException ex = new RunException();
                                throw ex;
                            }
                        }

                        node    = processLists[nProcessItem];
                        strFile = strBaseDirectory + "../Config/ProcessDescriptions/" + node.InnerText + ".xml";
                        strFile = System.IO.Path.GetFullPath(strFile);
                        xmlRead = XmlReader.Create(strFile, settings);
                        while (xmlRead.Read())
                        {
                        }
                        xmlRead.Close();
                        xmlRead = null;
                    }
                }

                PushOutputValue();
                return(true);
            }
            catch (RunException rex)
            {
                //                if (this.Pausing != null)
                {
                    lock (_obj)
                    {
                        if (2 == _state)
                        {
                            return(false);
                        }
                        else if (3 == _state)
                        {
                            XmlDocument  doc       = new XmlDocument();
                            XmlElement   stateNode = doc.CreateElement("process");
                            XmlAttribute xattri    = doc.CreateAttribute("name");
                            xattri.Value = this.Name;
                            stateNode.Attributes.Append(xattri);
                            xattri       = doc.CreateAttribute("id");
                            xattri.Value = this.ID.ToString();
                            stateNode.Attributes.Append(xattri);

                            SetState(stateNode, "IsValidateProcessDescriptionsFile", bProcessDescriptionsValidated.ToString());
                            SetState(stateNode, "GroupValidateItem", nGroupItem.ToString());
                            SetState(stateNode, "ProcessValidateItem", nProcessItem.ToString());
                        }
                    }
                }
                //if (this.Pausing != null)
                //{
                //    PausingEventArgs e = new PausingEventArgs();
                //    Pausing(this, e);
                //}
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error("sample.ProcessValidateModelFile", ex.Message);
                }
            }
            finally
            {
                if (null != xmlRead)
                {
                    xmlRead.Close();
                }
            }
            return(false);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        /// <!--
        /// <process name="" id="">
        ///     <state key="" value="" />
        ///     <state key="" value="" />
        /// </process>
        /// -->
        protected override Boolean Run(XmlElement state)
        {
            XmlReader xmlRead    = null;
            Int32     nIndexFile = 0;

            try
            {
                if (!this.IsReady())
                {
                    return(false);
                }
                PopInputValue();

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ValidationEventHandler += new ValidationEventHandler(this.ValidationEventCallBack);
                settings.ValidationType          = ValidationType.Schema;
                String _strValidateFile = this.GetInputValue("ValidateFile") as String;
                settings.Schemas.Add(null, _strValidateFile);

                lock (_obj)
                {
                    if (1 != _state && 4 != _state)
                    {
                        RunException ex = new RunException();
                        throw ex;
                    }
                }

                Int32    nStartIndex = 0;
                String[] _fileArray  = this.GetInputValue("FileArray") as String[];
                String   strValue    = this.GetState(state, "StartFile");
                if (!String.IsNullOrEmpty(strValue))
                {
                    nStartIndex = Int32.Parse(strValue);
                }

                nIndexFile = nStartIndex;
                String file = String.Empty;
                for (; nIndexFile < _fileArray.Length; ++nIndexFile)
                {
                    lock (_obj)
                    {
                        if (1 != _state && 4 != _state)
                        {
                            RunException ex = new RunException();
                            throw ex;
                        }
                    }

                    file    = _fileArray[nIndexFile];
                    xmlRead = XmlReader.Create(file, settings);
                    while (xmlRead.Read())
                    {
                    }
                    xmlRead.Close();
                    xmlRead = null;
                }

                PushOutputValue();
                return(true);
            }
            catch (RunException rex)
            {
//                if (this.Pausing != null)
                {
                    lock (_obj)
                    {
                        if (2 == _state)
                        {
                            return(false);
                        }
                        else if (3 == _state)
                        {
                            XmlDocument  doc       = new XmlDocument();
                            XmlElement   stateNode = doc.CreateElement("process");
                            XmlAttribute xattri    = doc.CreateAttribute("name");
                            xattri.Value = this.Name;
                            stateNode.Attributes.Append(xattri);
                            xattri       = doc.CreateAttribute("id");
                            xattri.Value = this.ID.ToString();
                            stateNode.Attributes.Append(xattri);

                            SetState(stateNode, "StartFile", nIndexFile.ToString());
                        }
                    }
                }
                //if (this.Pausing != null)
                //{
                //    PausingEventArgs e = new PausingEventArgs();
                //    Pausing(this, e);
                //}
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error("sample.ProcessValidateModelFile", ex.Message);
                }
            }
            finally
            {
                if (null != xmlRead)
                {
                    xmlRead.Close();
                }
            }

            return(false);
        }
コード例 #9
0
        protected override Boolean Run(XmlElement state)
        {
            XmlReader xmlRead = null;

            try
            {
                if (!this.IsReady())
                {
                    return(false);
                }
                PopInputValue();

                String strModelFile = this.GetInputValue("ModelFile") as String;
                if (!System.IO.File.Exists(strModelFile))
                {
                    return(false);
                }
                String strProcessListFile = this.GetInputValue("ProcessListFile") as String;
                if (!System.IO.File.Exists(strProcessListFile))
                {
                    return(false);
                }

                IProcessListParser processListParser = InstanceManager.Instance.ProcessListParser;
                if (null == processListParser)
                {
                    return(false);
                }

                XmlDocument doc = new XmlDocument();
                doc.Load(strModelFile);
                XmlElement rootModelFile = doc.DocumentElement;
                doc.Load(strProcessListFile);
                XmlElement rootProcessListFile = doc.DocumentElement;

                ProcessDefineDescription pdd = null;
                String   strProcessName      = String.Empty;
                String   strParaName         = String.Empty;
                ParaItem para        = null;
                String   strParaType = String.Empty;
                foreach (XmlNode node in rootModelFile.GetElementsByTagName("operation"))
                {
                    strProcessName = node.Attributes["name"].Value;
                    pdd            = processListParser.GetProcess(strProcessName);
                    if (null == pdd)
                    {
                        _strValidationInfo += strProcessName + "不存在;";
                        continue;
                    }

                    ParaItem[] inputs = pdd.Inputs;
                    foreach (XmlNode nodeInput in node.SelectSingleNode("inputs").SelectNodes("input"))
                    {
                        strParaName = nodeInput.Attributes["name"].Value;
                        para        = FindPara(inputs, strParaName);
                        if (null == para)
                        {
                            _strValidationInfo += strProcessName + "的参数\"" + strParaName + "\"不正确;";
                        }
                        strParaType = nodeInput.Attributes["type"].Value;
                        if (String.Compare(strParaType, para.DataType, true) != 0)
                        {
                            _strValidationInfo += strProcessName + "的参数\"" + strParaName + "\"的类型不正确;";
                        }
                    }
                }

                PushOutputValue();
                return(true);
            }
            catch (Exception ex)
            {
                IRunningLogger logger = InstanceManager.Instance.Context.GetVariable("RunningLogger") as IRunningLogger;
                if (null != logger)
                {
                    logger.Error("sample.ProcessValidateModelFile", ex.Message);
                }
            }
            finally
            {
                if (null != xmlRead)
                {
                    xmlRead.Close();
                }
            }

            return(false);
        }