示例#1
0
        public bool StaticInclude(int level, string relativeSourcePath, RuntimeTypeHandle includee, InclusionTypes inclusionType)
        {
            ApplicationConfiguration app_config = Configuration.Application;

            var included_full_path =
                //PhpSourceFile source_file = new PhpSourceFile(
                //	app_config.Compiler.SourceRoot,
                new FullPath(app_config.Compiler.SourceRoot, new RelativePath((sbyte)level, relativeSourcePath));

            //);

            if (scripts.ContainsKey(included_full_path.ToString()))
            {
                // the script has been included => returns whether it should be included again:
                return(!InclusionTypesEnum.IsOnceInclusion(inclusionType));
            }
            else
            {
                // the script has not been included yet:
                scripts.Add(included_full_path.ToString(), new ScriptInfo(Type.GetTypeFromHandle(includee)));

                // the script should be included:
                return(true);
            }
        }
示例#2
0
        public object DynamicInclude(
            string includedFilePath,
            string includerFileRelPath,
            Dictionary <string, object> variables,
            DObject self,
            DTypeDesc includer,
            InclusionTypes inclusionType)
        {
            ApplicationConfiguration app_config = Configuration.Application;

            // determines inclusion behavior:
            FullPath includer_full_path = new FullPath(includerFileRelPath, app_config.Compiler.SourceRoot);

            // searches for file:
            FullPath included_full_path = SearchForIncludedFile(
                InclusionTypesEnum.IsMustInclusion(inclusionType) ? PhpError.Error : PhpError.Warning,
                includedFilePath, includer_full_path);

            if (included_full_path.IsEmpty)
            {
                return(false);
            }

            ScriptInfo info;
            bool       already_included = scripts.TryGetValue(included_full_path.ToString(), out info);

            // skips inclusion if script has already been included and inclusion's type is "once":
            if (already_included && InclusionTypesEnum.IsOnceInclusion(inclusionType))
            {
                return(ScriptModule.SkippedIncludeReturnValue);
            }

            if (!already_included)
            {
                // loads script type:
                info = LoadDynamicScriptType(new PhpSourceFile(app_config.Compiler.SourceRoot, included_full_path));

                // script not found:
                if (info == null)
                {
                    return(false);
                }

                // adds included file into the script list
                scripts.Add(included_full_path.ToString(), info /* = new ScriptInfo(script)*/);
            }

            return(info.Main(this, variables, self, includer, false));
        }
示例#3
0
        public object DynamicInclude(
            string includedFilePath,
            string includerFileRelPath,//TODO: Now it's not relative because RelativePath class doesn't work properly with HTTP addresses
            Dictionary <string, object> variables,
            DObject self,
            DTypeDesc includer,
            InclusionTypes inclusionType)
        {
            ApplicationConfiguration app_config = Configuration.Application;

            // determines inclusion behavior:
            PhpError error_severity = InclusionTypesEnum.IsMustInclusion(inclusionType) ? PhpError.Error : PhpError.Warning;
            bool     once           = InclusionTypesEnum.IsOnceInclusion(inclusionType);


            System.Threading.AutoResetEvent downloadFinished = null;
            string eval = string.Empty;

            downloadFinished = new System.Threading.AutoResetEvent(false);

            WebClient webclient = new WebClient();

            webclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(
                delegate(object sender, DownloadStringCompletedEventArgs downEventArgs)
            {
                if (downEventArgs.Error == null)
                {
                    eval = downEventArgs.Result;

                    // workaround for Firefox BrowserHttpWebRequest bug -
                    // assuming that we're downloading PHP source starting with '<?'
                    int srcStart = 0;
                    while (!(eval[srcStart] == '<' && eval[srcStart + 1] == '?') && (srcStart + 1 < eval.Length))
                    {
                        srcStart++;
                    }
                    eval = eval.Substring(srcStart);

                    downloadFinished.Set();
                }
            }
                );

            Uri baseUri = new Uri(app_config.Compiler.SourceRoot + "/", UriKind.Absolute);
            Uri uriFile = new Uri(includedFilePath, UriKind.RelativeOrAbsolute);
            Uri uri     = new Uri(baseUri, uriFile);

            webclient.DownloadStringAsync(uri);

            ThreadStart ts = new ThreadStart(() => {
                downloadFinished.WaitOne();

                try
                {
                    DynamicCode.EvalFile(eval, ScriptContext.CurrentContext, variables, self, null, includedFilePath, 0, 0, -1);
                }
                catch (Exception ex)
                {
                    var canvas = ((ClrObject)ScriptContext.CurrentContext.AutoGlobals.Canvas.Value).RealObject as System.Windows.Controls.Canvas;

                    canvas.Dispatcher.BeginInvoke(() =>
                    {
                        throw ex;
                    });
                }
            });

            if (inclusionType == InclusionTypes.RunSilverlight) // new thread have to be created
            {
                new Thread(ts).Start();
            }
            else
            {
                ts(); // just continue on this thread
            }

            return(null);
        }