Ejemplo n.º 1
0
        public void ReadConfiguration(XPathNavigator nav)
        {
            name     = Helpers.GetRequiredNonEmptyAttribute(nav, "name");
            target   = Helpers.ConvertEnum <FeatureTarget> (Helpers.GetRequiredNonEmptyAttribute(nav, "target"), "target");
            fileName = Helpers.GetOptionalAttribute(nav, "fileName");

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = name;
            }

            sections = new Section();
            Helpers.BuildSectionTree(nav.Select("./section[string-length (@name) > 0]"), sections);
        }
        public void ReadConfiguration(XPathNavigator nav)
        {
            name   = Helpers.GetRequiredNonEmptyAttribute(nav, "name");
            target = Helpers.ConvertEnum <FeatureTarget> (Helpers.GetRequiredNonEmptyAttribute(nav, "target"), "target");

            XPathNodeIterator iter = nav.Select("blocks/block[string-length (@name) > 0]");

            while (iter.MoveNext())
            {
                blocks.Add(new FeatureBlock(iter.Current, target));
            }

            iter = nav.Select("description/text()");
            string val;

            while (iter.MoveNext())
            {
                val = iter.Current.Value;
                if (String.IsNullOrEmpty(val))
                {
                    continue;
                }
                description.Append(val);
            }

            FeatureAction action;

            iter = nav.Select("actions/action[string-length (@type) > 0 and string-length (@when) > 0]");
            while (iter.MoveNext())
            {
                action = new FeatureAction(iter.Current);
                switch (action.When)
                {
                case ActionWhen.Before:
                    actionsBefore.Add(action);
                    break;

                case ActionWhen.After:
                    actionsAfter.Add(action);
                    break;

                default:
                    throw new ApplicationException(
                              String.Format("Unknown 'when' attribute: {0}", action.When));
                }
            }
        }
Ejemplo n.º 3
0
        public void ReadConfiguration(XPathNavigator nav)
        {
            section = Helpers.GetRequiredNonEmptyAttribute(nav, "section");
            target  = Helpers.ConvertEnum <FeatureTarget>  (Helpers.GetRequiredNonEmptyAttribute(nav, "target"), "target");

            XPathNodeIterator iter = nav.Select("./text()");
            StringBuilder     sb   = new StringBuilder();

            while (iter.MoveNext())
            {
                sb.Append(iter.Current.Value);
            }
            if (sb.Length > 0)
            {
                contents = sb.ToString();
            }
        }
        public FeatureAction(XPathNavigator nav)
        {
            string val = Helpers.GetRequiredNonEmptyAttribute(nav, "type");

            type = Helpers.ConvertEnum <ActionType> (val, "type");

            val  = Helpers.GetRequiredNonEmptyAttribute(nav, "when");
            when = Helpers.ConvertEnum <ActionWhen> (val, "when");

            XPathNodeIterator iter;
            StringBuilder     sb = new StringBuilder();

            switch (type)
            {
            case ActionType.Message:
            case ActionType.ShellScript:
                iter = nav.Select("./text()");
                while (iter.MoveNext())
                {
                    sb.Append(iter.Current.Value);
                }
                if (type == ActionType.Message)
                {
                    message = sb.ToString();
                }
                else
                {
                    script = sb.ToString();
                }
                break;

            case ActionType.Exec:
                command          = Helpers.GetRequiredNonEmptyAttribute(nav, "command");
                commandArguments = Helpers.GetOptionalAttribute(nav, "commndArguments");
                break;
            }
        }
Ejemplo n.º 5
0
        int ProcessArgument(int idx, string argument, string[] args, int argsLen)
        {
            int  argnameIdx = 1;
            bool haveMoreDashes = false, badArg = false;
            int  argumentLen = argument.Length;

            if (argumentLen < 2)
            {
                badArg = true;
            }

            haveMoreDashes = !badArg && (argument [1] == '-');

            if (argumentLen == 2 && haveMoreDashes)
            {
                badArg = true;
            }

            if (badArg)
            {
                Console.Error.WriteLine("Invalid argument: {0}", argument);
                Environment.Exit(1);
            }

            if (haveMoreDashes)
            {
                argnameIdx++;
            }

            int  paramPos  = argument.IndexOfAny(paramStartChars, argnameIdx);
            bool haveParam = true;

            if (paramPos == -1)
            {
                haveParam = false;
                paramPos  = argumentLen;
            }

            string argName  = argument.Substring(argnameIdx, paramPos - argnameIdx);
            string argParam = haveParam ? argument.Substring(paramPos + 1) : null;

            int ret = 0;

            if (!haveParam && haveMoreDashes)
            {
                idx++;
                if (idx < argsLen)
                {
                    argParam = args [idx];
                    ret++;
                    haveParam = true;
                }
            }

            switch (argName)
            {
            case "?":
            case "h":
            case "help":
                Usage();
                break;

            case "v":
            case "version":
                ShowVersion();
                break;

            case "t":
            case "target":
                if (!haveParam)
                {
                    RequiredParameterMissing(argName);
                }

                try {
                    Target = Helpers.ConvertEnum <FeatureTarget> (argParam, "target");
                } catch (Exception ex) {
                    OptionParameterError(argName, ex.Message);
                }
                break;

            default:
                unknown_arguments.Add(argName, argParam);
                break;
            }

            return(ret);
        }