Beispiel #1
0
        /// <summary>
        /// Wires an event handler to fire when the property of the dataItem is changed
        /// </summary>
        /// <param name="dataItem">object to detect changes on</param>
        /// <param name="handler">handler to fire when the property changes on the specified dataItem</param>
        /// <returns>binding reference used to track the event hookup, to pass to <see cref="RemoveValueChangedHandler"/> when removing the handler</returns>
        public override object AddValueChangedHandler(object dataItem, EventHandler <EventArgs> handler)
        {
            if (dataItem == null)
            {
                return(false);
            }
            var notify = dataItem as INotifyPropertyChanged;

            if (notify != null)
            {
                var helper = new ValueChangedHandler {
                    Binding  = this,
                    DataItem = dataItem,
                    Handler  = handler
                };
                notify.PropertyChanged += helper.HandlePropertyChanged;
                return(helper);
            }
            else
            {
                var type         = dataItem.GetType();
                var changedEvent = type.GetEvent(Property + "Changed");
                if (changedEvent != null)
                {
                    changedEvent.AddEventHandler(dataItem, handler);
                }
                return(dataItem);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Wires an event handler to fire when the property of the dataItem is changed
        /// </summary>
        /// <param name="dataItem">object to detect changes on</param>
        /// <param name="handler">handler to fire when the property changes on the specified dataItem</param>
        /// <returns>binding reference used to track the event hookup, to pass to <see cref="RemoveValueChangedHandler"/> when removing the handler</returns>
        public override object AddValueChangedHandler(object dataItem, EventHandler <EventArgs> handler)
        {
#if WINRT
            throw new NotImplementedException();
#else
            if (dataItem == null)
            {
                return(false);
            }
            var notify = dataItem as INotifyPropertyChanged;
            if (notify != null)
            {
                var helper = new ValueChangedHandler {
                    Binding  = this,
                    DataItem = dataItem,
                    Handler  = handler
                };
                notify.PropertyChanged += helper.HandlePropertyChanged;
                return(helper);
            }
            else
            {
                var type         = dataItem.GetType();
                var changedEvent = type.GetEvent(Property + "Changed");
                if (changedEvent != null)
                {
                    try {
                        changedEvent.AddEventHandler(dataItem, handler);
                    }
                    catch {}
                }
                return(dataItem);
            }
#endif
        }
Beispiel #3
0
 private static void RaiseValueChanged(IntPtr cPtr, float oldValue, float newValue)
 {
     try {
         if (!_ValueChanged.ContainsKey(cPtr))
         {
             throw new InvalidOperationException("Delegate not registered for ValueChanged event");
         }
         if (oldValue == -1234.5678f && newValue == -1234.5678f)
         {
             _ValueChanged.Remove(cPtr);
             return;
         }
         if (Noesis.Extend.Initialized)
         {
             ValueChangedHandler handler = _ValueChanged[cPtr];
             if (handler != null)
             {
                 handler(oldValue, newValue);
             }
         }
     }
     catch (Exception exception) {
         Noesis.Error.SetNativePendingError(exception);
     }
 }
Beispiel #4
0
        public static MenuItem AddMItem <T>(this Menu menu, string name, T value, ValueChangedHandler <T> handler, string internalName = "")
        {
            var menuItem = new MenuItem(string.IsNullOrEmpty(internalName) ? GetValidName(menu, name) : internalName, name).SetValue(GetValidValue(value));

            menuItem.ValueChanged += (sender, args) => handler(args.GetNewValue <T>());
            handler(menuItem.GetValue <T>());
            return(menu.AddItem(menuItem));
        }
Beispiel #5
0
 private void OnTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
 {
     Debug.WriteLine($"Cancellation, reason: {reason}.");
     ValueChanged -= BroadcastReceivedMessage;
     if (_deferral != null)
     {
         _deferral.Complete();
     }
 }
Beispiel #6
0
        public static void SafeSendEvent(ValueChangedHandler handler, object sender, double oldValue, double newValue)
        {
            var tmp = handler;

            if (tmp != null)
            {
                tmp(sender, oldValue, newValue);
            }
        }
Beispiel #7
0
        protected virtual void OnValueChanged(ValueChangedEventArgs e)
        {
            ValueChangedHandler handler = ValueChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #8
0
        protected virtual void OnValueChanged(uint value)
        {
            ValueChangedHandler handler = ValueChanged;

            if (handler != null)
            {
                handler(this, value);
            }
        }
Beispiel #9
0
        public void SetValueChangedEventHandler()
        {
            if (addViewPage == null)
            {
                return;
            }

            ValueChanged            += new ValueChangedHandler(addViewPage.ValueChanged);
            IncorrectValueSpecified += new IncorrectValueSpecifiedHandler(addViewPage.IncorrectValueSpecified);
        }
    // Raises the ValueChanged event.
    private void OnValueChanged(Int32 oldValue, Int32 newValue)
    {
        // Copy the event handlers - this is for thread safty to
        // avoid that somebody changes the handler to null after
        // we checked that it is not null but before we called
        // the handler.
        ValueChangedHandler valueChangedHandler = this.ValueChanged;

        // Check if we must notify anybody.
        if (valueChangedHandler != null)
        {
            // Call all methods added to this event.
            valueChangedHandler(this, oldValue, newValue);
        }
    }
 public void SetValueChangedHandlerForSubParams(ValueChangedHandler action)
 {
     ValueChanged += action;
     foreach (Parameter p in GetSubParameters().GetAllParameters())
     {
         if (p is IntParam || p is DoubleParam)
         {
             p.ValueChanged += action;
         }
         else if (p is SingleChoiceWithSubParams)
         {
             ((SingleChoiceWithSubParams)p).SetValueChangedHandlerForSubParams(action);
         }
     }
 }
Beispiel #12
0
 public SecondaryAttribute(string name,
                           Formula formula,
                           BaseAttribute[] attributes,
                           float minValue = float.MinValue,
                           float maxValue = float.MaxValue) : base(name,
                                                                   minValue,
                                                                   maxValue)
 {
     _formula    = formula;
     _attributes = attributes;
     _handlers   = new ValueChangedHandler[attributes.Length];
     for (int i = 0; i < Attributes.Length; i++)
     {
         _handlers[i] = new ValueChangedHandler(ValueOfFormulatAttributeChanged);
         Attributes[i].OnValueChanged += _handlers[i];
     }
 }
Beispiel #13
0
        private bool SetupConnection(AppServiceTriggerDetails triggerDetails)
        {
            if (triggerDetails == null)
            {
                Debug.WriteLine("ForegroundBridgeService started without details, exiting.");
                return(false);
            }
            if (!triggerDetails.Name.Equals("com.microsoft.showcase.appservice"))
            {
                Debug.WriteLine("Trigger details name doesn't match com.microsoft.showcase.bridge, exiting.");
                return(false);
            }
            Debug.WriteLine("New service connection.");
            _connection = triggerDetails.AppServiceConnection;
            _connection.RequestReceived += OnRequestReceived;
            ValueChanged += BroadcastReceivedMessage;

            return(true);
        }
Beispiel #14
0
 public void On(string listenOnName, ValueChangedHandler callback)
 {
     if (_on.TryGetValue(listenOnName, out var list))
     {
         foreach (var reg in list)
         {
             if (reg == callback)
             {
                 return;
             }
         }
     }
     else
     {
         list = new List <ValueChangedHandler>();
         _on.Add(listenOnName, list);
     }
     list.Add(callback);
 }
Beispiel #15
0
 public VolumeAttribute(string name,
                        Formula formula,
                        BaseAttribute[] attributes,
                        float minValue = float.MinValue,
                        float maxValue = float.MaxValue) : base()
 {
     Name        = name;
     _formula    = formula;
     _attributes = attributes;
     _handlers   = new ValueChangedHandler[attributes.Length];
     for (int i = 0; i < Attributes.Length; i++)
     {
         _handlers[i] = new ValueChangedHandler(ValueOfFormulatAttributeChanged);
         Attributes[i].OnValueChanged += _handlers[i];
     }
     MinValue          = minValue;
     MaxValue          = maxValue;
     _currentValue     = BaseValue;
     _absoluteMaxValue = maxValue;
 }
Beispiel #16
0
		public override object AddValueChangedHandler (object dataItem, EventHandler<EventArgs> handler)
		{
			if (dataItem == null)
				return false;
			var notify = dataItem as INotifyPropertyChanged;
			if (notify != null) {
				var helper = new ValueChangedHandler {
					Binding = this,
					DataItem = dataItem,
					Handler = handler
				};
				notify.PropertyChanged += helper.HandlePropertyChanged;
				return helper;
			} else {
				var type = dataItem.GetType ();
				var changedEvent = type.GetEvent (Property + "Changed");
				if (changedEvent != null)
					changedEvent.AddEventHandler (dataItem, handler);
				return dataItem;
			}
		}
        public static ConfigPropertyInfo FromConfigPropertyAttribute(ConfigPropertyAttribute attribute, string propertyName,
                                                                     object value, Type type, ValueChangedHandler valueChangedDelegate)
        {
            // Process list types
            var attributeList = attribute as ConfigListPropertyAttribute;

            if (attributeList != null)
            {
                var info = new ConfigListPropertyInfo
                {
                    DisplayName           = attribute.DisplayName,
                    PropertyName          = propertyName,
                    Description           = attribute.Description,
                    DefaultValue          = attribute.DefaultValue,
                    Value                 = value,
                    Type                  = type,
                    _valueChangedDelegate = valueChangedDelegate
                };

                // Set brush color
                var color = ColorConverter.ConvertFromString(attributeList.Color);
                info.Brush = color != null ? new SolidColorBrush((Color)color) : PickBrush();

                // Determine default item type
                if (info.Type.GenericTypeArguments.Length > 0)
                {
                    info.DefaultListItemType = info.Type.GenericTypeArguments[0];
                }

                return(info);
            }

            // Return default object
            return(new ConfigPropertyInfo
            {
                DisplayName = attribute.DisplayName,
                PropertyName = propertyName,
                Description = attribute.Description,
                DefaultValue = attribute.DefaultValue,
                Value = value,
                Type = type,
                _valueChangedDelegate = valueChangedDelegate
            });
        }
Beispiel #18
0
 private void OnValueChanged(string id, double value)
 {
     ValueChangedHandler?.Invoke(id, value);
 }
Beispiel #19
0
		/// <summary>
		/// Wires an event handler to fire when the property of the dataItem is changed
		/// </summary>
		/// <param name="dataItem">object to detect changes on</param>
		/// <param name="handler">handler to fire when the property changes on the specified dataItem</param>
		/// <returns>binding reference used to track the event hookup, to pass to <see cref="RemoveValueChangedHandler"/> when removing the handler</returns>
		public override object AddValueChangedHandler (object dataItem, EventHandler<EventArgs> handler)
		{
#if WINRT
			throw new NotImplementedException();
#else
			if (dataItem == null)
				return false;
			var notify = dataItem as INotifyPropertyChanged;
			if (notify != null) {
				var helper = new ValueChangedHandler {
					Binding = this,
					DataItem = dataItem,
					Handler = handler
				};
				notify.PropertyChanged += helper.HandlePropertyChanged;
				return helper;
			} else {
				var type = dataItem.GetType ();
				var changedEvent = type.GetEvent (Property + "Changed");
				if (changedEvent != null) {
					try {
						changedEvent.AddEventHandler (dataItem, handler);
					}
					catch {}
				}
				return dataItem;
			}
#endif
		}
Beispiel #20
0
        public static TableAdapter WriteDataTable(DataTable dataTable,
                                                  TableName tname, Locator locator,
                                                  string[] columnNames,
                                                  RowChangedHandler rowChangedHandler, ValueChangedHandler columnHandler)
        {
            if (dataTable == null)
            {
                return(null);
            }

            if (locator == null)
            {
                locator = new Locator(tname);
            }

            TableAdapter adapter = new TableAdapter(dataTable, tname, locator);

            if (rowChangedHandler != null)
            {
                adapter.DataRowChangedHandler += rowChangedHandler;
            }

            if (columnHandler != null)
            {
                adapter.ValueChangedHandler = columnHandler;
            }

            adapter.AddFields(columnNames);
            adapter.Save();

            return(adapter);
        }
Beispiel #21
0
        public virtual bool Save(Selector columnNames, RowChangedHandler rowHandler, ValueChangedHandler columnHandler)
        {
            if (dataTable == null || dataTable.Rows.Count == 0)
            {
                return(false);
            }

            //update this.dataTable
            // this.AcceptChanges();

            objectPermission = ObjectPermission.DenyUpdateObject;
            RowAdapter d = this.NewSqlRow(columnNames);

            d.RowChanged += RowChanged;

            if (rowHandler != null)
            {
                d.RowChanged += rowHandler;
            }

            if (columnHandler != null)
            {
                d.ValueChangedHandler = columnHandler;
            }
            else
            {
                d.ValueChangedHandler = ValueChanged;
            }

            int count = 0;

            foreach (DataRow dataRow in dataTable.Rows)
            {
                BeforeSave(dataRow);

                if (dataRow.RowState != DataRowState.Deleted)
                {
                    if (dataRow.RowState != DataRowState.Unchanged)
                    {
                        d.CopyFrom(dataRow);
                        d.Fill();
                        d.Save();
                        if (dataRow.RowState == DataRowState.Added)   //in case of existing identity columns
                        {
                            d.CopyTo(dataRow);
                            UpdateObject(dataRow);
                        }

                        //slow version
                        //T t = this[dataRow];
                        //t.Save(d);
                        count++;
                    }
                }
                else
                {
                    dataRow.RejectChanges();
                    d.CopyFrom(dataRow);
                    d.Fill();
                    d.Delete();

                    //slow version
                    //T t = this[dataRow];
                    //t.Delete();
                    dataRow.Delete();
                }

                AfterSave(dataRow);
            }

            dataTable.AcceptChanges();

            objectPermission = ObjectPermission.AllowUpdateObject;
            return(true);
        }
Beispiel #22
0
        public static TableAdapter WriteDataTable(DataTable dataTable, 
            TableName tname, Locator locator, 
            string[] columnNames,
            RowChangedHandler rowChangedHandler, ValueChangedHandler columnHandler)
        {
            if (dataTable == null)
                return null;

            if (locator == null)
                locator = new Locator(tname);

            TableAdapter adapter = new TableAdapter(dataTable, tname, locator);

            if(rowChangedHandler != null)
                adapter.DataRowChangedHandler += rowChangedHandler;

            if (columnHandler != null)
                adapter.ValueChangedHandler = columnHandler;

            adapter.AddFields(columnNames);
            adapter.Save();

            return adapter;
        }