예제 #1
0
        private static string GetStepParametersForCommandLine(Step step)
        {
            string[] commonSettings = new CommonStep().SettingNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            string[] stepSettings   = step.SettingNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            Dictionary <string, string> settings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string settingName in commonSettings)
            {
                settings.Upsert(settingName, SettingEntityModel.GetSingle(settingName, true).SettingValue);
            }

            foreach (string settingName in stepSettings)
            {
                settings.Upsert(settingName, SettingEntityModel.GetSingle(settingName, true).SettingValue);
            }

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> setting in settings)
            {
                string parameter = " /" + setting.Key + ":\"{0}\"";
                // Important! /folder:"C:\folder\" will cause problem by escape the last double quote ".
                string settingValue = setting.Value.TrimEnd('\\');
                parameter = parameter.FormatWith(settingValue);

                sb.Append(parameter);
            }

            return(sb.ToString());
        }
예제 #2
0
        /// <summary>
        /// Assigns the values to argument object.
        /// </summary>
        /// <param name="argumentObject">The argument object.</param>
        /// <param name="optionName">Name of the option.</param>
        /// <param name="argPairs">The argument pairs.</param>
        /// <param name="attrs">The attributes.</param>
        /// <exception cref="System.ArgumentException">parameter: + pair.Key +  is not defined in the argument object</exception>
        private static void AssignValuesToArgumentObject(object argumentObject, string optionName, List <KeyValuePair <string, string> > argPairs, Dictionary <string, ArgumentParameterAttribute> attrs)
        {
            foreach (var pair in argPairs)
            {
                if (!attrs.ContainsKey(pair.Key))
                {
                    throw new ArgumentException("parameter:" + pair.Key + " is not defined in the argumentobject");
                }

                try
                {
                    SettingEntityModel setting = SettingEntityModel.GetSingle(pair.Key);
                    setting.SettingValue = pair.Value;
                    setting.Update();
                    ////SetValue(argumentObject, attrs[pair.Key], pair.Value);
                }
                catch (ArgumentException ae)
                {
                    throw new ArgumentException(string.Format(
                                                    "Failed to set value to ArgumentObject.{0} from parameter:{1} value:{2}. Detail Message:{3}",
                                                    attrs[pair.Key].PropertyInfo.Name,
                                                    pair.Key,
                                                    pair.Value.SafeToString(),
                                                    ae.Message));
                }
            }

            // SaveAll may fail in the multi-thread case.
            //SettingEntityModel.SaveAll();

            // set default value

            /*
             * foreach (var attr in attrs.Values)
             * {
             *  if (attr.SetCount < attr.MinOccur)
             *  {
             *      throw new ArgumentException(string.Format("parameter:{0} has been set for {1} times, but min={2}",
             *          attr.ParameterName,
             *          attr.SetCount,
             *          attr.MinOccur));
             *  }
             *  if (attr.SetCount == 0 && attr.DefaultValue != null)
             *  {
             *      attr.PropertyInfo.SetValue(argumentObject, attr.DefaultValue, null);
             *  }
             * }*/
        }