Exemple #1
0
        private bool ArgsIsFull()
        {
            if (_argumentProvider == null)
            {
                _error = "未提供[" + _subProductDef.Name + "]子产品参数提供者.";
                return(false);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                _error = "未提供[" + _subProductDef.Name + "]子产品所用算法名.";
                return(false);
            }
            string       algorithmName = _argumentProvider.GetArg("AlgorithmName").ToString();
            AlgorithmDef algorithmDef  = _subProductDef.GetAlgorithmDefByIdentify(algorithmName);

            if (algorithmDef == null)
            {
                _error = "当前[" + _subProductDef.Name + "]子产品不包含\"" + algorithmName + "\"算法.";
                return(false);
            }
            if (algorithmDef != null)
            {
                object bandArg = null;
                foreach (BandDef arg in algorithmDef.Bands)
                {
                    bandArg = _argumentProvider.GetArg(arg.Identify);
                    if (bandArg == null)
                    {
                        _error = "未提供波段[" + arg.Identify + "]信息.";
                        return(false);
                    }
                    if (bandArg.ToString() == "-1")
                    {
                        _error = "波段[" + arg.Identify + "]未找到对应的波段映射.";
                        return(false);
                    }
                }
            }
            ArgumentPair argPair = null;
            ArgumentDef  argDef  = null;

            foreach (ArgumentBase arg in algorithmDef.Arguments)
            {
                if (arg is ArgumentPair)
                {
                    argPair = arg as ArgumentPair;
                    if (argPair.ArgumentMax != null && _argumentProvider.GetArg(argPair.ArgumentMax.Name) == null)
                    {
                        _error = "参数[" + argPair.ArgumentMax.Name + "]未提供.";
                        return(false);
                    }
                    if (argPair.ArgumentMin != null && _argumentProvider.GetArg(argPair.ArgumentMin.Name) == null)
                    {
                        _error = "参数[" + argPair.ArgumentMin.Name + "]未提供.";
                        return(false);
                    }
                }
                else if (arg is ArgumentDef)
                {
                    argDef = arg as ArgumentDef;
                    if (_argumentProvider.GetArg(argDef.Name) == null)
                    {
                        _error = "参数[" + argDef.Name + "]未提供.";
                        return(false);
                    }

                    if (argDef.RefType == "file")
                    {
                        string filename = _argumentProvider.GetArg(argDef.Name).ToString();
                        if (!File.Exists(filename))
                        {
                            _error = "参数文件[" + Path.GetFileName(filename) + "]不存在.";
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        private ArgumentBase CreatArgumentPair(XElement element)
        {
            IEnumerable <XAttribute> attrs = element.Attributes();

            if (attrs == null || attrs.Count() == 0)
            {
                return(null);
            }
            ArgumentPair argPair = new ArgumentPair();

            foreach (XAttribute att in attrs)
            {
                switch (att.Name.ToString().ToLower())
                {
                case "description":
                    if (!String.IsNullOrWhiteSpace(att.Value))
                    {
                        argPair.Description = att.Value;
                    }
                    break;

                case "datatype":
                    if (!String.IsNullOrWhiteSpace(att.Value))
                    {
                        argPair.Datatype = att.Value;
                    }
                    break;

                case "minvalue":
                    if (!String.IsNullOrWhiteSpace(att.Value))
                    {
                        argPair.MinValue = att.Value;
                    }
                    break;

                case "maxvalue":
                    if (!String.IsNullOrWhiteSpace(att.Value))
                    {
                        argPair.MaxValue = att.Value;
                    }
                    break;

                case "visible":
                    if (att.Value == "false")
                    {
                        argPair.Visible = false;
                    }
                    else
                    {
                        argPair.Visible = true;
                    }
                    break;

                case "finetuning":
                    if (!String.IsNullOrWhiteSpace(att.Value))
                    {
                        argPair.FineTuning = att.Value;
                    }
                    break;
                }
            }
            IEnumerable <XElement> eleArgs = element.Elements();

            if (eleArgs == null || eleArgs.Count() == 0)
            {
                return(null);
            }
            ArgumentDef argMin = null;
            ArgumentDef argMax = null;

            foreach (XElement ele in eleArgs)
            {
                string endpointtype = ele.Attribute("endpointtype").Value;
                if (endpointtype == "min")
                {
                    argMin = CreatArgument(ele);
                }
                else if (endpointtype == "max")
                {
                    argMax = CreatArgument(ele);
                }
            }
            if (argMax != null)
            {
                argMax.Datatype     = argPair.Datatype;
                argPair.ArgumentMax = argMax;
            }
            if (argMin != null)
            {
                argMin.Datatype     = argPair.Datatype;
                argPair.ArgumentMin = argMin;
            }
            return(argPair);
        }