Exemple #1
0
        private static StringList GetAsyncCompletedArguments(
            Uri uri,
            string method,
            byte[] rawData,
            NameValueCollection collection,
            string fileName,
            AsyncCompletedEventArgs eventArgs
            )
        {
            StringList result = new StringList();

            if (uri != null)
            {
                result.Add("uri");
                result.Add(uri.ToString());
            }

            if (method != null)
            {
                result.Add("method");
                result.Add(method);
            }

            if (rawData != null)
            {
                result.Add("rawData");
                result.Add(ArrayOps.ToHexadecimalString(rawData));
            }

            if (collection != null)
            {
                result.Add("collection");
                result.Add(ListOps.FromNameValueCollection(
                               collection, new StringList()).ToString());
            }

            if (fileName != null)
            {
                result.Add("fileName");
                result.Add(fileName);
            }

            if (eventArgs != null)
            {
                bool canceled = eventArgs.Cancelled;

                result.Add("canceled");
                result.Add(canceled.ToString());

                Exception exception = eventArgs.Error;

                if (exception != null)
                {
                    result.Add("exception");
                    result.Add(exception.GetType().ToString());
                    result.Add("error");
                    result.Add(exception.ToString());
                }
            }

            return(result);
        }
Exemple #2
0
        ///////////////////////////////////////////////////////////////////////

        public static string RegsubCommandMatchCallback(
            Match match
            )
        {
            //
            // NOTE: Attempt to obtain the parameters that were passed in
            ///      from the [regsub] command caller and verify them.
            //
            Interpreter      interpreter;
            RegsubClientData regsubClientData;

            RegsubMatchCallbackPrologue(
                out interpreter, out regsubClientData);

            string     replacement = regsubClientData.Replacement;
            StringList words       = null;
            Result     result      = null; /* REUSED */

            if (Parser.SplitList(
                    interpreter, replacement, 0, Length.Invalid, true,
                    ref words, ref result) != ReturnCode.Ok)
            {
                throw new ScriptException(ReturnCode.Error, result);
            }

            if (words.Count < 1)
            {
                throw new ScriptException(ReturnCode.Error,
                                          "command prefix must be a list of at least one element");
            }

            IScriptLocation replacementLocation =
                regsubClientData.ReplacementLocation;

            bool verbatim = regsubClientData.Verbatim;

            StringList matches = GetMatchList(match);

            if (matches == null)
            {
                throw new ScriptException(
                          ReturnCode.Error, "could not build match list");
            }

            ReturnCode code;

            result = null;

            code = interpreter.EvaluateScript(
                ListOps.Concat(words.ToString(), matches.ToString()),
                replacementLocation, ref result);

            if (code != ReturnCode.Ok)
            {
                Engine.AddErrorInformation(
                    interpreter, result, String.Format(
                        "{0}    (-command substitution computation script)",
                        Environment.NewLine));

                //
                // NOTE: This is our only way out of here.  This exception
                //       will be caught by the command handler for regsub
                //       and converted into a script error.
                //
                throw new ScriptException(code, result);
            }

            return(!verbatim ? (string)result : GetMatchValue(match));
        }