示例#1
0
		void OnPropertyChanged (IntPtr dependency_object, IntPtr propertyChangeArgs, ref MoonError error, IntPtr unused)
		{
			var l = Listener;
			if (l == null)
				Detach ();
			else
				l.OnPropertyChanged (dependency_object, propertyChangeArgs, ref error, unused);
		}
示例#2
0
		void IListenPropertyChanged.OnPropertyChanged (IntPtr dependency_object, IntPtr propertyChangeArgs, ref MoonError error, IntPtr unused)
		{
			try {
				// Type converting doesn't happen for TemplateBindings
				Updating = true;
				try {
					Target.SetValue (TargetProperty, GetValue (null));
				} catch {
					Target.SetValue (TargetProperty, TargetProperty.GetDefaultValue (Target));
				}
			}
			catch (Exception ex) {
				error = new MoonError (ex);
			} finally {
				Updating = false;
			}
		}
		private void PropertyChanged (IntPtr dependency_object, IntPtr propertyChangeArgs, ref MoonError error, IntPtr unused)
		{
			try {
				// Type converting doesn't happen for TemplateBindings
				Updating = true;
				try {
					Target.SetValueImpl (TargetProperty, Value.ToObject (SourceProperty.PropertyType,
											     NativeMethods.property_changed_event_args_get_new_value (propertyChangeArgs)));
				} catch {
					Target.SetValue (TargetProperty, TargetProperty.GetDefaultValue (Target));
				}
				Updating = false;
			}
			catch (Exception ex) {
				error = new MoonError (ex);
			}
		}
示例#4
0
		/*
		 * 
		 * Don't add any P/Invokes here.
		 * 
		 * Add annotations (@GeneratePInvoke) to your C/C++ methods to generate the P/Invokes.
		 * If the generator gets parameters wrong, you can add a @MarshalAs=<whatever> to override.
		 * 
		 */
		internal static Exception CreateManagedException (MoonError err)
		{
			string msg = err.Message;
			Exception ex = null;
			
			if (err.GCHandle.IsAllocated) {
				// We need to get this before calling Dispose.
				ex = err.GCHandle.Target as Exception;
			}

			err.Dispose ();
			
			switch (err.Number) {
			case 1:
			default:
				return new Exception (msg);
			case 2:
				return new ArgumentException (msg);
			case 3:
				return new ArgumentNullException (msg);
			case 4:
				return new ArgumentOutOfRangeException (msg);
			case 5:
				return new InvalidOperationException (msg);
			case 6:
				return new XamlParseException (err.LineNumber, err.CharPosition, msg);
			case 7:
				return new UnauthorizedAccessException (msg);
			case 8:
				return new ExecutionEngineException (msg);
			case 9:
				if (ex != null)
					return ex;
				return new Exception (msg);
			case 10:
				return new ListenFailedException (msg);
			case 11:
				return new SendFailedException (msg);
			case 12:
				return new NotImplementedException (msg);
			case 13:
				return new SecurityException (msg);
			case 14:
				return new NotSupportedException (msg);
			}
		}
示例#5
0
文件: XamlParser.cs 项目: shana/moon
		private static unsafe IntPtr ParseTemplate (Value *context_ptr, string resource_base, IntPtr surface, IntPtr binding_source, string xaml, ref MoonError error)
		{
			XamlContext context = Value.ToObject (typeof (XamlContext), context_ptr) as XamlContext;

			var parser = new XamlParser (context);

			var source = NativeDependencyObjectHelper.FromIntPtr (binding_source);
			if (source == null) {
				error = new MoonError (parser.ParseException ("Attempting to parse a template with an invalid binding source."));
				return IntPtr.Zero;
			}

			FrameworkElement fwe = source as FrameworkElement;
			if (fwe == null) {
				error = new MoonError (parser.ParseException ("Only FrameworkElements can be used as TemplateBinding sources."));
				return IntPtr.Zero;
			}

			context.IsExpandingTemplate = true;
			context.TemplateBindingSource = fwe;

			INativeEventObjectWrapper dob = null;
			try {
				dob = parser.ParseString (xaml) as INativeEventObjectWrapper;
			} catch (Exception e) {
				error = new MoonError (e);
				return IntPtr.Zero;
			}

			if (dob == null) {
				error = new MoonError (parser.ParseException ("Unable to parse template item."));
				return IntPtr.Zero;
			}

			return dob.NativeHandle;
		}
示例#6
0
		void DPChanged (IntPtr dependency_object, IntPtr property_changed_event_args, ref MoonError error, IntPtr closure)
		{
			try {
				UpdateValue ();
				if (Next != null)
					Next.SetSource (Value);
			} catch (Exception ex) {
				try {
					Console.WriteLine ("Unhandled exception in StandardPropertyPathNode.DBChanged: {0}", ex);
				} catch {
					// Ignore
				}
			}
		}
示例#7
0
		static Size InvokeArrangeOverride (IntPtr fwe_ptr, Size finalSize, ref MoonError error)
		{
			FrameworkElement fe = null;
			try {
				fe = (FrameworkElement) NativeDependencyObjectHelper.Lookup (fwe_ptr);
				return fe.ArrangeOverride (finalSize);
			} catch (Exception ex) {
				try {
					if (fe != null)
						LayoutInformation.SetLayoutExceptionElement (Deployment.Current.Dispatcher, fe);
					error = new MoonError (ex);
				} catch (Exception ex2) {
					try {
						Console.WriteLine ("Leaked exception: {0}", ex2);
					} catch {
						// Ignore
					}
				}
			}
			return new Size ();
		}
示例#8
0
 private static void UnmanagedPropertyChangedCallbackSafe(IntPtr dependency_object, IntPtr propertyChangeArgs, ref MoonError error, IntPtr unused)
 {
     try {
         try {
             UnmanagedPropertyChangedCallback (dependency_object,
                               NativeMethods.property_changed_event_args_get_property (propertyChangeArgs),
                               NativeMethods.property_changed_event_args_get_old_value (propertyChangeArgs),
                               NativeMethods.property_changed_event_args_get_new_value (propertyChangeArgs));
         } catch (Exception ex) {
             error = new MoonError (ex);
         }
     } catch (Exception ex) {
         try {
             Console.WriteLine ("Moonlight: Unhandled exception in DependencyProperty.UnmanagedPropertyChangedCallback: {0}",
                        ex.Message);
         } catch {
         }
     }
 }
示例#9
0
		void OnNativeMentorDataContextChangedSafe (IntPtr dependency_object, IntPtr propertyChangedEventArgs, ref MoonError error, IntPtr closure)
		{
			try {
				OnNativeMentorDataContextChanged (dependency_object, propertyChangedEventArgs, ref error, closure);
			} catch (Exception ex) {
				error = new MoonError (ex);
			}
		}
示例#10
0
        /*
         *
         * Don't add any P/Invokes here.
         *
         * Add annotations (@GeneratePInvoke) to your C/C++ methods to generate the P/Invokes.
         * If the generator gets parameters wrong, you can add a @MarshalAs=<whatever> to override.
         *
         */
        internal static Exception CreateManagedException(MoonError err)
        {
            string    msg = err.Message;
            Exception ex  = null;

            if (err.GCHandle.IsAllocated)
            {
                // We need to get this before calling Dispose.
                ex = err.GCHandle.Target as Exception;
            }

            err.Dispose();

            switch (err.Number)
            {
            case 1:
            default:
                return(new Exception(msg));

            case 2:
                return(new ArgumentException(msg));

            case 3:
                return(new ArgumentNullException(msg));

            case 4:
                return(new ArgumentOutOfRangeException(msg));

            case 5:
                return(new InvalidOperationException(msg));

            case 6:
                return(new XamlParseException(err.LineNumber, err.CharPosition, msg));

            case 7:
                return(new UnauthorizedAccessException(msg));

            case 8:
                return(new ExecutionEngineException(msg));

            case 9:
                if (ex != null)
                {
                    return(ex);
                }
                return(new Exception(msg));

            case 10:
                return(new ListenFailedException(msg));

            case 11:
                return(new SendFailedException(msg));

            case 12:
                return(new NotImplementedException(msg));

            case 13:
                return(new SecurityException(msg));

            case 14:
                return(new NotSupportedException(msg));
            }
        }
示例#11
0
		void DataContextChanged (IntPtr dependency_object, IntPtr propertyChangedEventArgs, ref MoonError error, IntPtr closure)
		{
			try {
				var fe = (FrameworkElement) NativeDependencyObjectHelper.Lookup (dependency_object);
				PropertyPathWalker.Update (fe.DataContext);
				// OneTime bindings refresh when the datacontext changes. As these bindings do not listen
				// for the ValueChanged notifications from the PropertyPathWalker we need to force a refresh
				if (Binding.Mode == BindingMode.OneTime)
					Refresh ();
			} catch (Exception ex) {
				try {
					error = new MoonError (ex);
				} catch {
				}
			}
		}
示例#12
0
		private unsafe bool cb_add_child (XamlCallbackData *data, Value* parent_parent, bool parent_is_property, string parent_xmlns, Value *parent, IntPtr parent_data, Value* child, IntPtr child_data, ref MoonError error)
		{
			try {
				return AddChild (data, parent_parent, parent_is_property, parent_xmlns, parent, parent_data, child, child_data);
			} catch (Exception ex) {
				Console.Error.WriteLine (ex);
				error = new MoonError (ex);
				return false;
			}
				
		}
示例#13
0
		private unsafe bool cb_import_xaml_xmlns (XamlCallbackData *data, string xmlns, ref MoonError error)
		{
			try {
				if (!ValidateXmlns (xmlns))
					return false;
				Application.ImportXamlNamespace (xmlns);
				return true;
			} catch (Exception ex) {
				Console.WriteLine ("Application::ImportXamlNamespace ({0}) threw an exception: {1}", xmlns, ex);
				error = new MoonError (ex);
				return false;
			}

		}
示例#14
0
		//
		// Proxy so that we return bool in case of any failures, instead of
		// generating an exception and unwinding the stack.
		//
		private unsafe bool cb_set_property (XamlCallbackData *data, string xmlns, Value* target, IntPtr target_data, Value* target_parent, string prop_xmlns, string name, Value* value_ptr, IntPtr value_data, ref MoonError error)
		{
			try {
				return SetProperty (data, xmlns, target, target_data, target_parent, prop_xmlns, name, value_ptr, value_data);
			} catch (Exception ex) {
				try {
					Console.Error.WriteLine ("ManagedXamlLoader::SetProperty ({0}, {1}, {2}, {3}, {4}) threw an exception: {5}", (IntPtr) data->top_level, xmlns, (IntPtr)target, name, (IntPtr)value_ptr, ex.Message);
					Console.Error.WriteLine (ex);
					error = new MoonError (ex);
					return false;
				}
				catch {
					return false;
				}
			}
		}
示例#15
0
		///
		///
		/// Callbacks invoked by the xaml.cpp C++ parser
		///
		///

#region Callbacks from xaml.cpp
		//
		// Proxy so that we return IntPtr.Zero in case of any failures, instead of
		// genereting an exception and unwinding the stack.
		//
		private unsafe bool cb_lookup_object (XamlCallbackData *data, Value* parent, string xmlns, string name, bool create, bool is_property, out Value value, ref MoonError error)
		{
			value = Value.Empty;
			try {
				return LookupObject (data->top_level, parent, xmlns, name, create, is_property, out value);
			} catch (Exception ex) {
				NativeMethods.value_free_value (ref value);
				value = Value.Empty;
				Console.Error.WriteLine ("ManagedXamlLoader::LookupObject ({0}, {1}, {2}, {3}) failed: {3} ({4}).", (IntPtr) data->top_level, xmlns, create, name, ex.Message, ex.GetType ().FullName);
				Console.WriteLine (ex);
				error = new MoonError (ex);
				return false;
			}
		}
示例#16
0
文件: XamlParser.cs 项目: dfr0/moon
		private static unsafe IntPtr ParseTemplate (Value *context_ptr, IntPtr resource_base, IntPtr surface, IntPtr binding_source, string xaml, ref MoonError error)
		{
			XamlContext context = Value.ToObject (typeof (XamlContext), context_ptr) as XamlContext;

			var parser = new XamlParser (context) {
				ResourceBase = UriHelper.FromNativeUri (resource_base),
			};

			FrameworkElement fwe = null;
			var source = NativeDependencyObjectHelper.FromIntPtr (binding_source);

			if (source != null) {
				fwe = source as FrameworkElement;
				if (fwe == null) {
					error = new MoonError (parser.ParseException ("Only FrameworkElements can be used as TemplateBinding sources."));
					return IntPtr.Zero;
				}
			}

			Log ("222222 ParseTemplateElement {0}", source);
			Log ("{0}", xaml);

			context.IsExpandingTemplate = true;
			context.TemplateOwner = source as DependencyObject;
			context.TemplateBindingSource = fwe;
			parser.HydrateObject = context.Template;

			
			INativeEventObjectWrapper dob = null;
			try {
				FrameworkTemplate template = parser.Parse (context.Node) as FrameworkTemplate;
				
				if (template != null) {
					dob = template.Content as INativeEventObjectWrapper;
					template.Content = null;
				}

				// No errors, but the template was just empty.
				if (dob == null)
					return IntPtr.Zero;
			} catch (Exception e) {
				error = new MoonError (e);
				return IntPtr.Zero;
			} finally {
				context.IsExpandingTemplate = false;
				context.TemplateOwner = null;
				context.TemplateBindingSource = null;
			}

			// XamlParser needs to ref its return value otherwise we can end up returning a an object to native
			// code with a refcount of '1' and it could then get GC'ed before we use it.
			Mono.NativeMethods.event_object_ref (dob.NativeHandle);
			return dob.NativeHandle;
		}
示例#17
0
		void OnNativeMentorDataContextChanged (IntPtr dependency_object, IntPtr propertyChangedEventArgs, ref MoonError error, IntPtr closure)
		{
			try {
				MentorDataContextChanged ();
			} catch (Exception ex) {
				try {
					Console.WriteLine ("Moonlight: Unhandled exception in BindingExpressionBase.OnNativeMentorDataContextChanged: {0}", ex);
				} catch {
					// Ignore
				}
			}
		}
示例#18
0
		extern static IntPtr dependency_object_get_value_with_error (IntPtr dep_ob, IntPtr dp, out MoonError error);
示例#19
0
		private Size InvokeArrangeOverride (Size finalSize, ref MoonError error)
		{
			try {
				return ArrangeOverride (finalSize);
			} catch (Exception ex) {
				try {
					LayoutInformation.SetLayoutExceptionElement (Dispatcher, this);
					error = new MoonError (ex);
				} catch (Exception ex2) {
					try {
						Console.WriteLine ("Leaked exception: {0}", ex2);
					} catch {
						// Ignore
					}
				}
			}
			return new Size ();
		}
示例#20
0
		internal ExceptionRoutedEventArgs (MoonError err)
		{
			ErrorException = NativeMethods.CreateManagedException (err);
		}
示例#21
0
 extern static IntPtr dependency_object_get_value_with_error(IntPtr dep_ob, IntPtr dp, out MoonError error);
示例#22
0
		static void InvokePropertyChangeHandler (int token, IntPtr sender, IntPtr args, ref MoonError error, IntPtr closure)
		{
			try {
				var o = (DependencyObject) NativeDependencyObjectHelper.Lookup (sender);
				if (o != null) {
					for (int i = 0; i < o.propertyChangedHandlers.Count; i ++) {
						if (o.propertyChangedHandlers [i].Key == token) {
							o.propertyChangedHandlers [i].Value (sender, args, ref error, closure);
							break;
						}
					}
				}
			} catch (Exception ex) {
				try {
					Console.WriteLine ("Unhandled exception in DependencyObject.PropertyChangeHandler_cb: {0}", ex);
				} catch {

				}
			}
		}
示例#23
0
		void ViewChanged (IntPtr dependency_object, IntPtr propertyChangedEventArgs, ref MoonError error, IntPtr closure)
		{
			var oldValue = Mono.Value.ToObject (null, NativeMethods.property_changed_event_args_get_old_value (propertyChangedEventArgs));
			var newValue = Mono.Value.ToObject (null, NativeMethods.property_changed_event_args_get_new_value (propertyChangedEventArgs));

			DisconnectViewHandlers ((ICollectionView) oldValue);
			ConnectViewHandlers ((ICollectionView) newValue);

			HandleSourceViewCurrentChanged (this, EventArgs.Empty);
		}
示例#24
0
        private static void CustomUnmanagedPropertyChangedCallbackSafe(IntPtr dependency_object, IntPtr propertyChangeArgs, ref MoonError error, IntPtr unused)
        {
            DependencyProperty property;
            DependencyObject obj;

            try {
                try {
                    IntPtr uprop = NativeMethods.property_changed_event_args_get_property (propertyChangeArgs);
                    if (!properties.TryGetValue (uprop, out property)) {
                        Console.Error.WriteLine ("DependencyProperty.CustomUnmanagedPropertyChangedCallback: Couldn't find the managed DependencyProperty corresponding with native {0}/{1}", uprop, NativeMethods.property_changed_event_args_get_id (propertyChangeArgs));
                        return;
                    }

                    obj = NativeDependencyObjectHelper.Lookup (dependency_object) as DependencyObject;

                    if (obj == null)
                        return;

                    InvokeChangedCallback (obj, property, property.change_cb,
                           Value.ToObject (property.PropertyType, NativeMethods.property_changed_event_args_get_old_value (propertyChangeArgs)),
                           Value.ToObject (property.PropertyType, NativeMethods.property_changed_event_args_get_new_value (propertyChangeArgs)));
                } catch (Exception ex) {
                    error = new MoonError (ex);
                }
            } catch (Exception ex) {
                try {
                    Console.WriteLine ("Moonlight: Unhandled exception in DependencyProperty.UnmanagedPropertyChangedCallback: {0}", ex.Message);
                } catch {
                }
            }
        }