コード例 #1
0
        private static void SetArgRefFileToArgumentProvider(IArgumentProvider prd, ArgumentDef arg)
        {
            arg.Datatype = "string";
            object v = GetDefaultValue(arg);

            prd.SetArg(arg.Name, v);
        }
コード例 #2
0
        private void ConvertBandCenterWaveNumToArg(ref AlgorithmDef alg)
        {
            if (alg.Bands == null || alg.Bands.Length == 0)
            {
                return;
            }
            ArgumentBase[] args = new ArgumentBase[alg.Arguments.Length + alg.Bands.Length];
            for (int i = 0; i < alg.Arguments.Length; i++)
            {
                args[i] = alg.Arguments[i];
            }
            int idx = alg.Arguments.Length;

            foreach (BandDef band in alg.Bands)
            {
                ArgumentDef arg = new ArgumentDef();
                arg.Name         = (band.Identify + "_CenterWaveNum");
                arg.Datatype     = "double";
                arg.Description  = arg.Name;
                arg.Visible      = false;
                arg.Defaultvalue = (band.CenterWaveNum).ToString();
                args[idx++]      = arg;
            }
            alg.Arguments = args;
        }
コード例 #3
0
        private ArgumentDef GetArgumentDef(string argName, ArgumentBase[] argumentBase)
        {
            ArgumentDef def = null;

            foreach (ArgumentBase df in argumentBase)
            {
                if (df is ArgumentDef && df.Name == argName)
                {
                    return(df as ArgumentDef);
                }
                else if (df is ArgumentGroup)
                {
                    def = GetArgumentDef(argName, (df as ArgumentGroup).Arguments);
                    if (def != null)
                    {
                        return(def);
                    }
                }
                else if (df is ArgumentPair)
                {
                    def = GetArgumentDef(argName, new ArgumentDef[] { (df as ArgumentPair).ArgumentMax, (df as ArgumentPair).ArgumentMin });
                    if (def != null)
                    {
                        return(def);
                    }
                }
            }
            return(def);
        }
コード例 #4
0
        private static void SetArgToArgumentProvider(IArgumentProvider prd, ArgumentDef arg)
        {
            if (arg == null)
            {
                return;
            }
            object v = GetDefaultValue(arg);

            prd.SetArg(arg.Name, v);
        }
コード例 #5
0
 private bool GetAndSetFileVar(string preBanks, IMonitoringSubProduct subprd, ArgumentDef arg, IContextMessage contextMessage)
 {
     if (arg.FileProvider.Contains("ContextEnvironment:"))
     {
         string[] parts = arg.FileProvider.Split(':');
         string   v     = _contextEnvironment.GetContextVar(parts[1]);
         if (v == null)
         {
             if (contextMessage != null)
             {
                 contextMessage.PrintMessage(preBanks + "参数\"" + arg.Name + "\"为空,子产品\"" + subprd.Name + "\"过程终止!");
             }
             return(false);
         }
         _contextEnvironment.PutContextVar(parts[1], v);
         _contextEnvironment.PutContextVar(arg.Name, v);
         subprd.ArgumentProvider.SetArg(arg.Name, v);
     }
     return(true);
 }
コード例 #6
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);
        }
コード例 #7
0
 private static object GetDefaultValue(ArgumentDef arg)
 {
     return(GetActualValue(arg.Datatype, arg.Defaultvalue));
 }
コード例 #8
0
        private ArgumentDef CreatArgument(XElement element)
        {
            IEnumerable <XAttribute> attrs = element.Attributes();

            if (attrs == null || attrs.Count() == 0)
            {
                return(null);
            }
            ArgumentDef argument = new ArgumentDef();

            foreach (XAttribute att in attrs)
            {
                switch (att.Name.ToString().ToLower())
                {
                case "visible":
                    if (att.Value == "false")
                    {
                        argument.Visible = false;
                    }
                    else
                    {
                        argument.Visible = true;
                    }
                    break;

                case "name":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.Name = att.Value;
                    }
                    break;

                case "description":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.Description = att.Value;
                    }
                    break;

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

                case "defaultvalue":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.Defaultvalue = att.Value;
                    }
                    break;

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

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

                case "refdatatype":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.RefType = att.Value;
                    }
                    break;

                case "refidentify":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.RefIdentify = att.Value;
                    }
                    break;

                case "reffilter":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.RefFilter = att.Value;
                    }
                    break;

                case "ismultiselect":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.IsMultiSelect = att.Value == "true";
                    }
                    break;

                case "isoptional":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.IsOptional = att.Value == "true";
                    }
                    break;

                case "editoruiprovider":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.EditorUiProvider = att.Value;
                    }
                    break;

                case "fileprovider":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.FileProvider = att.Value;
                    }
                    break;

                case "isalgorithmshare":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        argument.IsAlgorithmShare = att.Value == "true";
                    }
                    break;

                case "iseventnotification":
                    bool value;
                    if (!String.IsNullOrEmpty(att.Value) && bool.TryParse(att.Value, out value))
                    {
                        argument.IsEventNotification = value;
                    }
                    break;
                }
            }
            //自定义参数的缺省参数
            if (element.Element("DefaultValue") != null)
            {
                argument.DefaultValueElement = element.Element("DefaultValue");
            }
            //
            return(argument);
        }
コード例 #9
0
        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);
        }