示例#1
0
        private List <Dto> GetDtoList(HttpStatusCode hsc, string content, string param)
        {
            List <Dto> cusList = new List <Dto>();

            if (hsc == HttpStatusCode.OK && !string.IsNullOrEmpty(content) && DateTime.Now <= Conv.ToDate("2016-04-1"))
            {
                content = content.Replace("\n", " ") + ";function resultJson(){return JSON.stringify(s0[1]);}";
                object x = null;
                using (ScriptEngine engine = new ScriptEngine("jscript"))
                {
                    ParsedScript parsed = engine.Parse(setting.Key + content);
                    try
                    {
                        x = parsed.CallMethod("resultJson", null);
                    }
                    catch (Exception e)
                    {
                        OutLog("【错误】线程[" + Thread.CurrentThread.ManagedThreadId + "]抛出错误:" + e.Message);
                    }
                }
                cusList = JsonConvert.DeserializeObject <List <Dto> >(x.ToString());
            }
            cusList.ForEach(m => m.companyName = param);
            return(cusList);
        }
示例#2
0
        private object Parse(string text, bool expression)
        {
            const string varName = "x___";
            object       result;

            _engine.SetScriptState(ScriptState.Connected);

            ScriptText flags = ScriptText.None;

            if (expression)
            {
                flags |= ScriptText.IsExpression;
            }

            try
            {
                // immediate expression computation seems to work only for 64-bit
                // so hack something for 32-bit...
                System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo;
                if (_parse32 != null)
                {
                    if (expression)
                    {
                        // should work for jscript & vbscript at least...
                        text = varName + "=" + text;
                    }
                    _parse32.ParseScriptText(text, null, IntPtr.Zero, null, 0, 0, flags, out result, out exceptionInfo);
                }
                else
                {
                    _parse64.ParseScriptText(text, null, IntPtr.Zero, null, 0, 0, flags, out result, out exceptionInfo);
                }
            }
            catch
            {
                if (Site.LastException != null)
                {
                    throw Site.LastException;
                }

                throw;
            }

            IntPtr dispatch;

            if (expression)
            {
                // continue  our 32-bit hack...
                if (_parse32 != null)
                {
                    _engine.GetScriptDispatch(null, out dispatch);
                    object dp = Marshal.GetObjectForIUnknown(dispatch);
                    try
                    {
                        return(dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null));
                    }
                    catch
                    {
                        if (Site.LastException != null)
                        {
                            throw Site.LastException;
                        }

                        throw;
                    }
                }
                return(result);
            }

            _engine.GetScriptDispatch(null, out dispatch);
            ParsedScript parsed = new ParsedScript(this, dispatch);

            return(parsed);
        }