PHP.Core.ScriptContext.DynamicInclude C# (CSharp) Method

DynamicInclude() private method

private DynamicInclude ( string includedFilePath, string includerFileRelPath, object>.Dictionary variables, DObject self, DTypeDesc includer, InclusionTypes inclusionType ) : object
includedFilePath string
includerFileRelPath string
variables object>.Dictionary
self DObject
includer DTypeDesc
inclusionType InclusionTypes
return object
		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);
		}

Usage Example

        public static EventHandler RunSilverlightApplication(System.Windows.Controls.Canvas c, string source)
        {
            ApplicationContext app_context = ApplicationContext.Default;

            // try to preload configuration (to prevent exceptions during InitApplication)
            Configuration.Load(app_context);
            ApplicationConfiguration app_config = Configuration.Application;


            string url       = HtmlPage.Document.DocumentUri.AbsoluteUri;
            int    lastSlash = url.Replace('\\', '/').LastIndexOf('/');

            app_config.Compiler.SourceRoot = new FullPath(url.Substring(0, lastSlash), false);

            int    sourcelastSlash = source.Replace('\\', '/').LastIndexOf('/');
            string sourceRelPath   = source.Substring(lastSlash + 1);



            // Silverlight language features
            app_config.Compiler.LanguageFeatures = LanguageFeatures.PhpClr;

            // ..
            ScriptContext context = InitApplication(app_context);

            Debug.Fail("Update versions below!");
            ConfigurationContext.AddLibrary("mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            ConfigurationContext.AddLibrary("System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            ConfigurationContext.AddLibrary("System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            ConfigurationContext.AddLibrary("System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            //ConfigurationContext.AddLibrary("System.SilverLight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null, "");
            //ConfigurationContext.AddLibrary("agclr, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null, "");

            ConfigurationContext.AddLibrary("PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb", null, "");

            //
            Configuration.Application.Compiler.Debug = true;

            // ..
            Dictionary <string, object> vars = new Dictionary <string, object>();

            currentContext.AutoGlobals.Canvas.Value = ClrObject.Wrap(c);
            currentContext.AutoGlobals.Addr.Value   = ClrObject.Wrap(app_config.Compiler.SourceRoot.ToString());

            //Operators.SetVariableRef(currentContext, vars, "_CANVAS", Operators.GetItemRef("_CANVAS", ref currentContext.AutoGlobals.Globals.value));
            //Operators.SetVariable(currentContext, vars, "_CANVAS", ClrObject.Wrap(c));


            context.DynamicInclude(source, sourceRelPath, vars, null, null, InclusionTypes.RunSilverlight);

            return(new EventHandler(delegate(object sender, EventArgs e)
            {
                if (context.ResolveFunction("OnLoad", null, true) != null)
                {
                    PhpCallback load = new PhpCallback("OnLoad");
                    load.Invoke(sender, e);
                }
            }));
        }