Example #1
0
        /// <summary>
        /// To pack string argument in object.
        /// </summary>
        /// <param name="arg">Argument for packing.</param>
        /// <returns></returns>
        public static object packArgument(object arg)
        {
            if (arg == null)
            {
                return(null);
            }

            if (!(arg is string) || String.IsNullOrWhiteSpace((string)arg))
            {
                return(arg);
            }

            SNode.IPM      pm    = new SNode.PM(String.Format("_({0})", arg));
            SNode.Argument first = pm.FirstLevel.Args[0];

            if (first.type != SNode.ArgumentType.Object)
            {
                return(arg);
            }
            return(extract((SNode.Argument[])first.data));
        }
        protected string stSolution(string data)
        {
            Log.Trace("stSolution: started with '{0}'", data);
            IPM pm = new PM(data);

            if(!pm.Is(0, LevelType.Property, "solution")) {
                throw new SyntaxIncorrectException("Failed stSolution - '{0}'", data);
            }

            // solution.current.
            if(pm.Is(1, LevelType.Property, "current")) {
                return stSlnPMap(env.SolutionFile, pm.pinTo(2));
            }

            // solution.path("file").
            if(pm.Is(1, LevelType.Method, "path"))
            {
                Argument[] args = pm.Levels[1].Args;
                if(args.Length != 1 || args[0].type != ArgumentType.StringDouble) {
                    throw new InvalidArgumentException("stSolution: incorrect arguments to `solution.path(string sln)`");
                }
                return stSlnPMap((string)args[0].data, pm.pinTo(2));
            }

            throw new OperationNotFoundException("stSolution: not found - '{0}' /'{1}'", pm.Levels[1].Data, pm.Levels[1].Type);
        }
        protected string stHash(string data)
        {
            IPM pm = new PM(data);

            if(!pm.Is(0, LevelType.Property, "hash")) {
                throw new SyntaxIncorrectException("Failed stHash - '{0}'", data);
            }

            // hash.MD5("data")
            if(pm.FinalEmptyIs(1, LevelType.Method, "MD5"))
            {
                Argument[] args = pm.Levels[1].Args;
                if(args.Length != 1 || args[0].type != ArgumentType.StringDouble) {
                    throw new InvalidArgumentException("stHash: incorrect arguments to `hash.MD5(string data)`");
                }
                return ((string)args[0].data).MD5Hash();
            }

            // hash.SHA1("data")
            if(pm.FinalEmptyIs(1, LevelType.Method, "SHA1"))
            {
                Argument[] args = pm.Levels[1].Args;
                if(args.Length != 1 || args[0].type != ArgumentType.StringDouble) {
                    throw new InvalidArgumentException("stHash: incorrect arguments to `hash.SHA1(string data)`");
                }
                return ((string)args[0].data).SHA1Hash();
            }

            throw new OperationNotFoundException("stHash: not found - '{0}' /'{1}'", pm.Levels[1].Data, pm.Levels[1].Type);
        }