Пример #1
0
        public bool Remove([NotNull] PropertyKey propertyKey)
        {
            var removed = false;

            var previousValue = Get(propertyKey);

            if (PropertyUpdated != null || propertyKey.PropertyUpdateCallback != null)
            {
                if (properties != null)
                {
                    removed = properties.Remove(propertyKey);
                }
                var tagValue = Get(propertyKey);

                if (!ArePropertyValuesEqual(propertyKey, tagValue, previousValue))
                {
                    propertyKey.PropertyUpdateCallback?.Invoke(ref this, propertyKey, tagValue, previousValue);
                    PropertyUpdated?.Invoke(ref this, propertyKey, tagValue, previousValue);
                }
            }
            else
            {
                if (properties != null)
                {
                    removed = properties.Remove(propertyKey);
                }
            }

            propertyKey.ObjectInvalidationMetadata?.Invalidate(Owner, propertyKey, previousValue);

            return(removed);
        }
Пример #2
0
        public void Add(TextBoxBase control, Func <TDocument, string> setProperty, Action <TDocument> setControl)
        {
            _setControls.Add(setControl);

            string propertyName = null;

            control.TextChanged += delegate(object sender, EventArgs e)
            {
                if (_suspend)
                {
                    return;
                }
                propertyName          = setProperty.Invoke(Document);
                IsDirty               = true;
                _textChanged[control] = true;
            };

            control.Leave += delegate(object sender, EventArgs e)
            {
                if (_textChanged.ContainsKey(control) && _textChanged[control])
                {
                    PropertyUpdated?.Invoke(this, Document, propertyName);
                    _textChanged[control] = false;
                }
            };
        }
Пример #3
0
        private OCEntityHandlerResult OCEntityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest entityHandlerRequest, IntPtr callbackParam)
        {
            OCEntityHandlerResult result         = OCEntityHandlerResult.OC_EH_OK;
            RepPayload            payload        = null;
            RepPayload            requestPayload = entityHandlerRequest.payload == IntPtr.Zero ? null : new RepPayload(entityHandlerRequest.payload);

            if (entityHandlerRequest != null && (flag.HasFlag(OCEntityHandlerFlag.OC_REQUEST_FLAG)))
            {
                switch (entityHandlerRequest.method)
                {
                case OCMethod.OC_REST_GET:
                {
                    var rpayload = payload = new RepPayload();
                    rpayload.SetUri(_uri);
                    foreach (var resource in _resourceProperties)
                    {
                        if (requestPayload != null && !requestPayload.Types.Contains(resource.Key))
                        {
                            continue;
                        }
                        var repayload = new RepPayload(resource.Value);
                        repayload.Types.Add(resource.Key);
                        rpayload.Next = repayload;
                        rpayload      = repayload;
                    }
                    payload = rpayload;
                }
                break;

                case OCMethod.OC_REST_POST:
                case OCMethod.OC_REST_PUT:
                {
                    var p = new RepPayload(entityHandlerRequest.payload);
                    result = OnPropertyUpdated(p);
                    PropertyUpdated?.Invoke(this, p);
                }
                break;

                default:
                    result = OCEntityHandlerResult.OC_EH_METHOD_NOT_ALLOWED;
                    break;
                }
                var response = new OCEntityHandlerResponse();
                response.requestHandle  = entityHandlerRequest.requestHandle;
                response.resourceHandle = entityHandlerRequest.resource;
                response.ehResult       = result;
                response.payload        = payload == null ? IntPtr.Zero : payload.AsOCRepPayload();
                response.numSendVendorSpecificHeaderOptions = 0;
                response.sendVendorSpecificHeaderOptions    = IntPtr.Zero;
                response.resourceUri          = string.Empty;
                response.persistentBufferFlag = 0;
                OCStack.OCDoResponse(response);
            }
            return(result);
        }
Пример #4
0
        private void SetObject([NotNull] PropertyKey propertyKey, object tagValue, bool tryToAdd)
        {
            var oldValue = Get(propertyKey, true);

            // Allow to validate the metadata before storing it.
            propertyKey.ValidateValueMetadata?.Validate(ref tagValue);

            // First, check if there is an accessor
            if (propertyKey.AccessorMetadata != null)
            {
                propertyKey.AccessorMetadata.SetValue(ref this, tagValue);
                return;
            }

            if (properties == null)
            {
                properties = new Dictionary <PropertyKey, object>();
            }

            var valueToSet = propertyKey.IsValueType ? propertyKey.CreateValueHolder(tagValue) : tagValue;

            if (PropertyUpdated != null || propertyKey.PropertyUpdateCallback != null)
            {
                var previousValue = GetNonRecursive(propertyKey);

                if (tryToAdd)
                {
                    properties.Add(propertyKey, valueToSet);
                }
                else
                {
                    properties[propertyKey] = valueToSet;
                }

                if (!ArePropertyValuesEqual(propertyKey, tagValue, previousValue))
                {
                    PropertyUpdated?.Invoke(ref this, propertyKey, tagValue, previousValue);
                    propertyKey.PropertyUpdateCallback?.Invoke(ref this, propertyKey, tagValue, previousValue);
                }
            }
            else
            {
                if (tryToAdd)
                {
                    properties.Add(propertyKey, valueToSet);
                }
                else
                {
                    properties[propertyKey] = valueToSet;
                }
            }

            propertyKey.ObjectInvalidationMetadata?.Invalidate(Owner, propertyKey, oldValue);
        }
Пример #5
0
        public void Update(Property property)
        {
            Property cachedProperty = properties.FirstOrDefault(x => x.Name == property.Name);

            if (cachedProperty != null)
            {
                cachedProperty.Update(property);
                PropertyUpdated?.Invoke(cachedProperty);
                return;
            }
        }
Пример #6
0
        public void Update(Property property)
        {
            Property cachedProperty = properties.FirstOrDefault(x => x.Name == property.Name);

            if (cachedProperty != null)
            {
                cachedProperty.Update(property);
                PropertyUpdated?.Invoke(cachedProperty);
                GetOrAddGroup(cachedProperty.GroupName).Update(property);
                return;
            }
            Log("'" + property.DeviceName + "' '" + property.Name + "' not found!");
        }
Пример #7
0
        public void Add(ToolStripTextBox control, Func <T, string> setProperty, Action <T> setControl)
        {
            _setControls.Add(setControl);

            control.TextChanged += (sender, args) =>
            {
                if (_suspend)
                {
                    return;
                }
                var propertyName = setProperty.Invoke(Object);
                IsDirty = true;
                PropertyUpdated?.Invoke(this, Object, propertyName);
            };
        }
Пример #8
0
        public void Add(ToolStripTextBox control, Func <TDocument, string> setProperty, Action <TDocument> setControl)
        {
            _setControls.Add(setControl);

            control.TextChanged += delegate(object sender, EventArgs e)
            {
                if (_suspend)
                {
                    return;
                }
                var propertyName = setProperty.Invoke(Document);
                IsDirty = true;
                PropertyUpdated?.Invoke(this, Document, propertyName);
            };
        }
Пример #9
0
        /// <summary>
        /// Called, when a value becomes dirty
        /// </summary>
        /// <param name="property"></param>
        protected virtual void OnDirtyProperty(IObservableProperty property)
        {
            _notBroadcastedProperties.Add(property);
            UnsavedProperties.Add(property);

            // TODO Possible optimisation, by not invoking OnChanged event.
            // Need to do more research, if this event is necessary to be invoked
            // on every change
            if (Modified != null)
            {
                Modified.Invoke(this);
            }

            if (PropertyUpdated != null)
            {
                PropertyUpdated.Invoke(property.Key, property);
            }
        }
Пример #10
0
        public void AddItems <TItem>(ToolStripComboBox control, Func <TDocument, string> setProperty, Action <TDocument> setControl, IEnumerable <TItem> items)
        {
            ToolStripComboBoxExtensions.Fill(control, items);

            _clearControls.Add(() => control.SelectedIndex = -1);
            _setControls.Add(setControl);

            control.SelectedIndexChanged += delegate(object sender, EventArgs e)
            {
                if (_suspend)
                {
                    return;
                }
                var propertyName = setProperty.Invoke(Document);
                IsDirty = true;
                PropertyUpdated?.Invoke(this, Document, propertyName);
            };
        }
Пример #11
0
        public void AddEnum <TEnum>(ComboBox control, Func <TDocument, string> setProperty, Action <TDocument> setControl)
        {
            control.Fill <TEnum>();

            _clearControls.Add(() => control.SelectedIndex = -1);
            _setControls.Add(setControl);

            control.SelectedIndexChanged += delegate(object sender, EventArgs e)
            {
                if (_suspend)
                {
                    return;
                }
                var propertyName = setProperty.Invoke(Document);
                IsDirty = true;
                PropertyUpdated?.Invoke(this, Document, propertyName);
            };
        }
Пример #12
0
 /// <summary>
 /// Calls <see cref="UpdateProperties"/> and the <see cref="PropertyUpdated"/> event.
 /// </summary>
 protected void OnPropertyUpdated()
 {
     UpdateProperties();
     PropertyUpdated.Invoke(this);
 }
Пример #13
0
 internal void RaisePropertyContainerUpdated(PropertyKey propertyKey, object newValue, object oldValue)
 {
     PropertyUpdated?.Invoke(ref this, propertyKey, newValue, oldValue);
 }
Пример #14
0
        /// <summary>
        /// Sets the specified tag value.
        /// </summary>
        /// <typeparam name="T">Type of the tag value</typeparam>
        /// <param name="propertyKey">The tag property.</param>
        /// <param name="tagValue">The tag value.</param>
        public void Set <T>([NotNull] PropertyKey <T> propertyKey, T tagValue)
        {
            if (propertyKey.IsValueType)
            {
                ValueHolder <T> valueHolder = null;
                T oldValue;

                // Fast path for value types
                // Fast path for value type
                // First, check if there is an accessor
                if (propertyKey.AccessorMetadata != null)
                {
                    // TODO: Not optimal, but not used so far
                    oldValue = (T)propertyKey.AccessorMetadata.GetValue(ref this);
                }
                else
                {
                    object value;

                    // Get bound value, if any.
                    if (properties != null && properties.TryGetValue(propertyKey, out value))
                    {
                        valueHolder = (ValueHolder <T>)value;
                        oldValue    = valueHolder.Value;
                    }
                    else if (propertyKey.DefaultValueMetadata != null)
                    {
                        // Get default value.
                        oldValue = propertyKey.DefaultValueMetadataT.GetDefaultValueT(ref this);
                    }
                    else
                    {
                        oldValue = default(T);
                    }
                }

                // Allow to validate the metadata before storing it.
                if (propertyKey.ValidateValueMetadata != null)
                {
                    // TODO: Use typed validate?
                    propertyKey.ValidateValueMetadataT.ValidateValueCallback(ref tagValue);
                }

                // First, check if there is an accessor
                if (propertyKey.AccessorMetadata != null)
                {
                    // TODO: Not optimal, but not used so far
                    propertyKey.AccessorMetadata.SetValue(ref this, tagValue);
                    return;
                }

                if (properties == null)
                {
                    properties = new Dictionary <PropertyKey, object>();
                }

                if (valueHolder != null)
                {
                    valueHolder.Value = tagValue;
                }
                else
                {
                    valueHolder = new ValueHolder <T>(tagValue);
                }

                if (PropertyUpdated != null || propertyKey.PropertyUpdateCallback != null)
                {
                    var previousValue = GetNonRecursive(propertyKey);

                    properties[propertyKey] = valueHolder;

                    if (!ArePropertyValuesEqual(propertyKey, tagValue, previousValue))
                    {
                        PropertyUpdated?.Invoke(ref this, propertyKey, tagValue, previousValue);
                        propertyKey.PropertyUpdateCallback?.Invoke(ref this, propertyKey, tagValue, previousValue);
                    }
                }
                else
                {
                    properties[propertyKey] = valueHolder;
                }

                if (propertyKey.ObjectInvalidationMetadata != null)
                {
                    propertyKey.ObjectInvalidationMetadataT.Invalidate(Owner, propertyKey, ref oldValue);
                }

                return;
            }

            SetObject(propertyKey, tagValue, false);
        }
Пример #15
0
 /// <summary>
 /// Calls the <see cref="UpdateArucoHashCode"/> method and the <see cref="PropertyUpdated"/> event.
 /// </summary>
 protected virtual void OnPropertyUpdated()
 {
     UpdateArucoHashCode();
     AdjustGameObjectScale();
     PropertyUpdated.Invoke(this);
 }
Пример #16
0
 /// <summary>
 /// Raises the on property updated event.
 /// </summary>
 /// <param name="name">The property name.</param>
 protected internal void OnPropertyUpdated(string name) => PropertyUpdated?.Invoke(this, new PropertyChangedEventArgs(name));