当前位置: 首页>>代码示例>>C#>>正文


C# Core.PhpCallback类代码示例

本文整理汇总了C#中PHP.Core.PhpCallback的典型用法代码示例。如果您正苦于以下问题:C# PhpCallback类的具体用法?C# PhpCallback怎么用?C# PhpCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PhpCallback类属于PHP.Core命名空间,在下文中一共展示了PhpCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOrCreateFilterCallback

		private PhpCallback/*!*/ GetOrCreateFilterCallback(ScriptContext/*!*/ context)
		{
			if (filterCallback == null)
				filterCallback = new PhpCallback(new RoutineDelegate(Filter), context);

			return filterCallback;
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:7,代码来源:UrlRewriter.CLR.cs

示例2: Invoke

        /// <summary>
        /// Invoke the specified method and args.
        /// </summary>
        /// <param name="method">Method.</param>
        /// <param name="args">Arguments.</param>
        /// <param name="func">Func.</param>
        public override object Invoke(string func, params object[] args)
        {
            try
            {
                if (State == PluginState.Loaded && Globals.Contains(func))
                {
                    object result = (object)null;

                    using (new Stopper(Name, func))
                    {
                        var caller = new PhpCallback(Class, func);
                        result = caller.Invoke(args);
                    }
                    return result;
                }
                else
                {
                    Logger.LogWarning("[Plugin] Function: " + func + " not found in plugin: " + Name + ", or plugin is not loaded.");
                    return null;
                }
            }
            catch (Exception ex)
            {
                string fileinfo = (String.Format("{0}<{1}>.{2}()", Name, Type, func) + Environment.NewLine);
                Logger.LogError(fileinfo + FormatException(ex));
                return null;
            }
        }
开发者ID:Notulp,项目名称:Pluton,代码行数:34,代码来源:PHPPlugin.cs

示例3: Main

        static void Main(string[] args)
        {
            ScriptContext context = ScriptContext.InitApplication(ApplicationContext.Default, null, null, null);

            var sb = new StringBuilder();
            using (TextWriter tw = new StringWriter(sb))
            {
                context.Output = tw;
                context.OutputStream = Console.OpenStandardOutput(); //TODO: Should also redirect binary output.

                context.Include("main.php", true);

                var klass = (PhpObject)context.NewObject("Klass", new object[] { "yipppy" });
                var foo = new PhpCallback(klass, "foo");
                foo.Invoke(null, new object[] { "param" });

                tw.Close();
            }

            string output = sb.ToString();
            const string EXPECTED = "yipppyparam";
            if (output != EXPECTED)
            {
                Console.WriteLine("FAIL");
                Console.Write("Expected: " + EXPECTED);
                Console.Write("Got: ");
                Console.WriteLine(output);
            }
            else
            {
                Console.WriteLine("PASS");
            }
        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:33,代码来源:Program.cs

示例4: CallUserFunction

		public static object CallUserFunction(DTypeDesc caller, PhpCallback function, params object[] args)
		{
			if (function == null)
			{
				PhpException.ArgumentNull("function");
				return null;
			}
			if (function.IsInvalid) return null;

			// invoke the callback:
			return PhpVariable.Dereference(function.Invoke(caller, args));
		}
开发者ID:kripper,项目名称:Phalanger,代码行数:12,代码来源:Functions.cs

示例5: InvokeHeaderFunction

        internal static void InvokeHeaderFunction(this HttpWebResponse response, PhpCurlResource curlResource, PhpCallback headerFunction)
        {
            StringBuilder builder = new StringBuilder(HTTP_HEADER_ROW_LENGTH);
            int startIndex = 0;

            IterateHtppHeaders(response, ref builder,
                delegate(ref StringBuilder sb)
                {
                    headerFunction.Invoke(curlResource, sb.ToString(startIndex, sb.Length - startIndex));
                    startIndex = sb.Length;
                }
                );

        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:14,代码来源:HttpUtils.cs

示例6: CreateClrThread

		public static bool CreateClrThread(ScriptContext/*!*/context, PhpCallback/*!*/ callback, params object[] args)
		{
			if (callback == null)
				PhpException.ArgumentNull("callback");

			if (!callback.Bind())
				return false;

			object[] copies = (args != null) ? new object[args.Length] : ArrayUtils.EmptyObjects;

			for (int i = 0; i < copies.Length; i++)
				copies[i] = PhpVariable.DeepCopy(args[i]);

            return ThreadPool.QueueUserWorkItem(new Worker(context, copies).Run, callback);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:15,代码来源:CLR.cs

示例7: CallUserFunctionArray

        public static object CallUserFunctionArray(DTypeDesc caller, PhpCallback function, PhpArray args)
		{
			object[] args_array;

            if (args != null)
            {
                args_array = new object[args.Count];
                args.CopyValuesTo(args_array, 0);
            }
            else
            {
                args_array = ArrayUtils.EmptyObjects;
            }

			return CallUserFunction(caller, function, args_array);
		}
开发者ID:kripper,项目名称:Phalanger,代码行数:16,代码来源:Functions.cs

示例8: BindOrBiteMyLegsOff

            public void BindOrBiteMyLegsOff(DTypeDesc caller, NamingContext namingContext)
            {
                if (Callback != null)
                {
                    if (Callback.TargetInstance == null && Parser._handlerObject != null)
                        _currentCallback = new PhpCallback(Parser._handlerObject, Callback.RoutineName);
                    else
                        _currentCallback = Callback;

                    Bound = _currentCallback.Bind(true, caller, namingContext);
                }
                else
                {
                    Bound = false;
                }
            }
开发者ID:toburger,项目名称:Phalanger,代码行数:16,代码来源:XmlParserResource.cs

示例9: Highlight

        public string Highlight(string code, string language)
        {
            ScriptContext context = ScriptContext.CurrentContext;

            // redirect PHP output to the console:
            context.Output = Console.Out; // Unicode text output
            context.OutputStream = Console.OpenStandardOutput(); // byte stream output

            context.Include("geshi.php", true);

            var geshi = (PhpObject)context.NewObject("GeSHi", code, language);
            var result = new PhpCallback(geshi, "parse_code").Invoke();
            var error = new PhpCallback(geshi, "error").Invoke();
            new PhpCallback(geshi, "enable_keyword_links").Invoke(false);

            return result.ToString();
        }
开发者ID:JeremySkinner,项目名称:Staticity,代码行数:17,代码来源:SyntaxHighlighter.cs

示例10: Apply

        public static int Apply(ScriptContext/*!*/context, PHP.Core.Reflection.DTypeDesc caller, Iterator/*!*/iterator, PhpCallback function, PhpArray args)
        {
            // check parameters:
            Debug.Assert(context != null);
            Debug.Assert(iterator != null, "Phalanger should not pass a null here.");

            if (function == null)
            {
                PhpException.ArgumentNull("function");
                return -1;
            }

            // copy args into object array:
            object[] args_array;

            if (args != null)
            {
                args_array = new object[args.Count];
                args.Values.CopyTo(args_array, 0);
            }
            else
            {
                args_array = ArrayUtils.EmptyObjects;
            }

            // iterate through the iterator:
            int n = 0;
            
            iterator.rewind(context);
            
            while (PHP.Core.Convert.ObjectToBoolean(iterator.valid(context)))
            {
                if (!PHP.Core.Convert.ObjectToBoolean(function.Invoke(caller, args_array)))
                    break;
		        n++;

		        iterator.next(context);
	        }

            // return amount of iterated elements:
            return n;
        }
开发者ID:hansdude,项目名称:Phalanger,代码行数:42,代码来源:Iterators.cs

示例11: LoadFile

        public static void LoadFile(string path, PhpCallback function)
        {
            string file = string.Empty;

            if (function == null)
            {
                PhpException.ArgumentNull("function");
                return;
            }
            if (function.IsInvalid) return;

            WebClient webclient = new WebClient();
            webclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(
                delegate(object sender, DownloadStringCompletedEventArgs downEventArgs)
                {
                    var canvas = ((ClrObject)ScriptContext.CurrentContext.AutoGlobals.Canvas.Value).RealObject as System.Windows.Controls.Canvas;

                    canvas.Dispatcher.BeginInvoke(() =>
                        {
                            function.Invoke(downEventArgs.Result);

                        });
                }
                );

            var source_root = ((ClrObject)ScriptContext.CurrentContext.AutoGlobals.Addr.Value).RealObject as string;

            Uri baseUri = new Uri(source_root + "/", UriKind.Absolute);
            Uri uriFile = new Uri(path, UriKind.RelativeOrAbsolute);
            Uri uri = new Uri(baseUri, uriFile);


            webclient.DownloadStringAsync(uri);

            //downloadFinished.WaitOne();

            //return XamlReader.Load(file);

        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:39,代码来源:Utils.CoreCLR.cs

示例12: VisitEntryOnWalk

		/// <summary>
		/// Visits an entyr of array which <see cref="Walk"/> or <see cref="WalkRecursive"/> is walking through.
		/// </summary>
		private static void VisitEntryOnWalk(PHP.Core.Reflection.DTypeDesc caller, KeyValuePair<IntStringKey, object> entry, IDictionary<IntStringKey, object> array,
			PhpCallback callback, object[] args)
		{
			PhpReference ref_item = entry.Value as PhpReference;

			// fills arguments for the callback:
			((PhpReference)args[0]).Value = (ref_item != null) ? ref_item.Value : entry.Value;
			args[1] = entry.Key.Object;

			// invoke callback:
            Core.Convert.ObjectToBoolean(callback.Invoke(caller, args));

			// loads a new value from a reference:
			if (ref_item != null)
			{
				ref_item.Value = ((PhpReference)args[0]).Value;
			}
			else
			{
				array[entry.Key] = ((PhpReference)args[0]).Value;
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:25,代码来源:Arrays.cs

示例13: Filter

		public static PhpArray Filter(PHP.Core.Reflection.DTypeDesc caller, PhpArray array, PhpCallback callback)
		{
			if (callback == null) { PhpException.ArgumentNull("callback"); return null; }
			if (array == null) { PhpException.ArgumentNull("array"); return null; }

			PhpArray result = new PhpArray();
			object[] args = new object[1];

			foreach (KeyValuePair<IntStringKey, object> entry in array)
			{
				// no deep copying needed because it is done so in callback:
				args[0] = entry.Value;

				// adds entry to the resulting array if callback returns true:
                if (Core.Convert.ObjectToBoolean(callback.Invoke(caller, args)))
				{
					result.Add(entry.Key, entry.Value);
				}
			}

			// values should be inplace deeply copied:
			result.InplaceCopyOnReturn = true;
			return result;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:24,代码来源:Arrays.cs

示例14: WalkRecursive

		public static bool WalkRecursive(PHP.Core.Reflection.DTypeDesc caller, [PhpRw] PhpHashtable array, PhpCallback callback, object data)
		{
			object[] args = PrepareWalk(array, callback, data);
			if (args == null) return false;

			using (PhpHashtable.RecursiveEnumerator iterator = array.GetRecursiveEnumerator(true,false))
			{
				while (iterator.MoveNext())
				{
					// visits the item unless it is an array or a reference to an array:
					PhpReference ref_value = iterator.Current.Value as PhpReference;
					if (!(iterator.Current.Value is PhpHashtable || (ref_value != null && ref_value.Value is PhpHashtable)))
						VisitEntryOnWalk(caller, iterator.Current, iterator.CurrentTable, callback, args);
				}
			}
			return true;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:17,代码来源:Arrays.cs

示例15: PrepareWalk

		/// <summary>
		/// Prepares a walk for <see cref="Walk"/> and <see cref="WalkRecursive"/> methods.
		/// </summary>
        /// <exception cref="PhpException"><paramref name="callback"/> or <paramref name="array"/> are <B>null</B> references.</exception>
		private static object[] PrepareWalk(IDictionary array, PhpCallback callback, object data)
		{
			if (callback == null) { PhpException.ArgumentNull("callback"); return null; }
			if (array == null) { PhpException.ArgumentNull("array"); return null; }

			// prepares an array of callback's arguments (no deep copying needed because it is done so in callback):
			if (data != null)
				return new object[3] { new PhpReference(), null, data };
			else
				return new object[2] { new PhpReference(), null };
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:15,代码来源:Arrays.cs


注:本文中的PHP.Core.PhpCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。