예제 #1
0
    public int m_index;                        //如果是数组类型时,改变的位置

    public PropertyChangeEventArgs(PropertyChangeType changeTpye, object oldValue, object newValue, int index)
    {
        m_changeType = changeTpye;
        m_oldValue   = oldValue;
        m_newValue   = newValue;
        m_index      = index;
    }
예제 #2
0
        private void FormatPropertyChange(PSWhatIfPropertyChange propertyChange, int maxPathLength, int indentLevel)
        {
            //this.FormatHead(propertyChange, maxPathLength, indentLevel);

            PropertyChangeType             propertyChangeType = propertyChange.PropertyChangeType;
            string                         path     = propertyChange.Path;
            JToken                         before   = propertyChange.Before;
            JToken                         after    = propertyChange.After;
            IList <PSWhatIfPropertyChange> children = propertyChange.Children;

            switch (propertyChange.PropertyChangeType)
            {
            case PropertyChangeType.Create:
                this.FormatPropertyChangePath(propertyChangeType, path, after, children, maxPathLength, indentLevel);
                this.FormatPropertyCreate(after, indentLevel + 1);
                break;

            case PropertyChangeType.Delete:
                this.FormatPropertyChangePath(propertyChangeType, path, before, children, maxPathLength, indentLevel);
                this.FormatPropertyDelete(before, indentLevel + 1);
                break;

            case PropertyChangeType.Modify:
                this.FormatPropertyChangePath(propertyChangeType, path, before, children, maxPathLength, indentLevel);
                this.FormatPropertyModify(propertyChange, indentLevel + 1);
                break;

            case PropertyChangeType.Array:
                this.FormatPropertyArrayChange(propertyChange.Children, indentLevel + 1);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #3
0
	public int m_index;                        //如果是数组类型时,改变的位置
	
	public PropertyChangeEventArgs(PropertyChangeType changeTpye, object oldValue, object newValue, int index)
	{
		m_changeType = changeTpye;
		m_oldValue = oldValue;
		m_newValue = newValue;
		m_index = index;
	}
예제 #4
0
        public void ObserveModelProperty()
        {
            int numEvents = 0;

            object[]           recordedPath       = null;
            PropertyChangeType recordedChangeType = PropertyChangeType.Property;
            object             recordedValue      = null;

            void onPropertyChanged(object[] path, PropertyChangeType changeType, object value)
            {
                numEvents++;
                recordedChangeType = changeType;
                recordedPath       = path;
                recordedValue      = value;

                TestContext.Out.WriteLine("Change {0} ({1}) -> {2}", string.Join('.', path), changeType, value);
            }

            DuetControlServer.Model.Observer.OnPropertyPathChanged += onPropertyChanged;

            // job.build[]
            Build newBuild = new Build();

            Provider.Get.Job.Build = newBuild;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "job", "build" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreSame(newBuild, recordedValue);

            // End
            DuetControlServer.Model.Observer.OnPropertyPathChanged -= onPropertyChanged;
        }
        private void FormatPropertyChangePath(
            PropertyChangeType propertyChangeType,
            string path,
            JToken valueAfterPath,
            IList <PSWhatIfPropertyChange> children,
            int maxPathLength,
            int indentLevel)
        {
            int  paddingWidth = maxPathLength - path.Length + 1;
            bool hasChildren  = children != null && children.Count > 0;

            if (valueAfterPath.IsNonEmptyArray() || (propertyChangeType == PropertyChangeType.Array && hasChildren))
            {
                paddingWidth = 1;
            }
            if (valueAfterPath.IsNonEmptyObject())
            {
                paddingWidth = 0;
            }
            if (propertyChangeType == PropertyChangeType.Modify && hasChildren)
            {
                paddingWidth = 0;
            }

            this.FormatPath(
                path,
                paddingWidth,
                indentLevel,
                () => this.FormatPropertyChangeType(propertyChangeType),
                this.FormatColon);
        }
예제 #6
0
        private OrderChange CreateOrderChangeByChangedProperties(ChangedProperty changedPropery)
        {
            PropertyChangeType changeProperties = PropertyChangeType.None;

            if (string.Compare(changedPropery.AutoLimitPrice, this.AutoLimitPrice) != 0)
            {
                changeProperties |= PropertyChangeType.AutoLimitPrice;
            }

            if (string.Compare(changedPropery.AutoStopPrice, this.AutoStopPrice) != 0)
            {
                changeProperties |= PropertyChangeType.AutoStopPrice;
            }

            if (changedPropery.PaidPledge != this.PaidPledge)
            {
                changeProperties |= PropertyChangeType.PaidPledge;
            }

            if (changedPropery.PaidPledgeBalance != this.PaidPledgeBalance)
            {
                changeProperties |= PropertyChangeType.PaidPledgeBalance;
            }

            if (changedPropery.IsInstalmentOverdue != this.IsInstalmentOverdue)
            {
                changeProperties |= PropertyChangeType.HasOverdue;
            }

            if (changeProperties != PropertyChangeType.None)
            {
                return(new OrderChange(this, Protocal.Commands.OrderChangeType.Changed, changeProperties));
            }
            return(null);
        }
예제 #7
0
        /// <summary>
        /// Represents an event fired when a script object property has been changed.
        /// </summary>
        /// <param name="instance">The instance of the script object that contains the property.</param>
        /// <param name="changeType">The type of the change.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="newValue">The new value of the property.</param>
        /// <param name="oldValue">The old value of the property.</param>
        public static void OnPropertyChange(ScriptObject instance, PropertyChangeType changeType, string propertyName, BoxedValue newValue, BoxedValue oldValue)
        {
            // Ignore identifier property
            if (propertyName == "$i")
                return;

            switch (changeType)
            {
                // Occurs when a new property is assigned to an object, either by
                // using the indexer, property access or array methods.
                case PropertyChangeType.Put:
                {
                    // We need to make sure the new value is marked as observed
                    // as well, so its members will notify us too.
                    if (newValue.IsStrictlyObject)
                        newValue.Object.Observe();

                    // Send the change through the current scope
                    Channel.Current.SendPropertyChange(PropertyChangeType.Put, instance.Oid, propertyName, newValue);
                    break;
                }

                // Occurs when a property change occurs, by using an assignment
                // operator, or the array indexer.
                case PropertyChangeType.Set:
                {
                    // We need to unmark the old value and ignore it, as we no
                    // longer require observations from that value.
                    if (oldValue.IsStrictlyObject)
                        oldValue.Object.Ignore();

                    // We need to make sure the new value is marked as observed
                    // as well, so its members will notify us too.
                    if (newValue.IsStrictlyObject)
                        newValue.Object.Observe();

                    // Send the change through the current scope
                    Channel.Current.SendPropertyChange(PropertyChangeType.Set, instance.Oid, propertyName, newValue);
                    break;
                }

                // Occurs when a property was deleted from the object, either by
                // using a 'delete' keyword or the array removal methods.
                case PropertyChangeType.Delete:
                {
                    // We need to unmark the old value and ignore it, as we no
                    // longer require observations from that value.
                    if (oldValue.IsStrictlyObject)
                        oldValue.Object.Ignore();

                    // Send the change through the current scope
                    Channel.Current.SendPropertyChange(PropertyChangeType.Delete, instance.Oid, propertyName, newValue);
                    break;
                }

            }

            //Console.WriteLine("Observe: [{0}] {1} = {2}", changeType.ToString(), propertyName, propertyValue);
        }
예제 #8
0
 internal WhatIfPropertyChange(string path, PropertyChangeType propertyChangeType, object before, object after, IReadOnlyList <WhatIfPropertyChange> children)
 {
     Path = path;
     PropertyChangeType = propertyChangeType;
     Before             = before;
     After    = after;
     Children = children;
 }
        internal static WhatIfPropertyChange DeserializeWhatIfPropertyChange(JsonElement element)
        {
            string             path = default;
            PropertyChangeType propertyChangeType = default;
            Optional <object>  before             = default;
            Optional <object>  after = default;
            Optional <IReadOnlyList <WhatIfPropertyChange> > children = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("path"))
                {
                    path = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("propertyChangeType"))
                {
                    propertyChangeType = property.Value.GetString().ToPropertyChangeType();
                    continue;
                }
                if (property.NameEquals("before"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    before = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("after"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    after = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("children"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <WhatIfPropertyChange> array = new List <WhatIfPropertyChange>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DeserializeWhatIfPropertyChange(item));
                    }
                    children = array;
                    continue;
                }
            }
            return(new WhatIfPropertyChange(path, propertyChangeType, before.Value, after.Value, Optional.ToList(children)));
        }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the WhatIfPropertyChange class.
 /// </summary>
 /// <param name="path">The path of the property.</param>
 /// <param name="propertyChangeType">The type of property change.
 /// Possible values include: 'Create', 'Delete', 'Modify', 'Array',
 /// 'NoEffect'</param>
 /// <param name="before">The value of the property before the
 /// deployment is executed.</param>
 /// <param name="after">The value of the property after the deployment
 /// is executed.</param>
 /// <param name="children">Nested property changes.</param>
 public WhatIfPropertyChange(string path, PropertyChangeType propertyChangeType, object before = default(object), object after = default(object), IList <WhatIfPropertyChange> children = default(IList <WhatIfPropertyChange>))
 {
     Path = path;
     PropertyChangeType = propertyChangeType;
     Before             = before;
     After    = after;
     Children = children;
     CustomInit();
 }
예제 #11
0
 /// <summary>
 /// Constructor. </summary>
 /// <param name="namespaceName"> the namespace of the key </param>
 /// <param name="propertyName"> the key whose value is changed </param>
 /// <param name="oldValue"> the value before change </param>
 /// <param name="newValue"> the value after change </param>
 /// <param name="changeType"> the change type </param>
 public ConfigChange(string namespaceName, string propertyName, string oldValue, string newValue,
                     PropertyChangeType changeType)
 {
     _namespaceName = namespaceName;
     _propertyName  = propertyName;
     _oldValue      = oldValue;
     _newValue      = newValue;
     _changeType    = changeType;
 }
예제 #12
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="namespaceName">命名空间</param>
 /// <param name="propertyName">属性名</param>
 /// <param name="oldValue">修改前的值</param>
 /// <param name="newValue">修改后的值</param>
 /// <param name="changeType">变动类型</param>
 public ConfigChange(string namespaceName, string propertyName, string oldValue, string newValue,
                     PropertyChangeType changeType)
 {
     Namespace    = namespaceName;
     PropertyName = propertyName;
     OldValue     = oldValue;
     NewValue     = newValue;
     ChangeType   = changeType;
 }
예제 #13
0
 /// <summary>
 /// Constructor. </summary>
 /// <param name="namespace"> the namespace of the key </param>
 /// <param name="propertyName"> the key whose value is changed </param>
 /// <param name="oldValue"> the value before change </param>
 /// <param name="newValue"> the value after change </param>
 /// <param name="changeType"> the change type </param>
 public ConfigChange(string namespaceName, string propertyName, string oldValue, string newValue,
                     PropertyChangeType changeType)
 {
     this.namespaceName = namespaceName;
     this.propertyName  = propertyName;
     this.oldValue      = oldValue;
     this.newValue      = newValue;
     this.changeType    = changeType;
 }
예제 #14
0
 /// <summary>
 /// Constructor. </summary>
 /// <param name="config"> the config of the key </param>
 /// <param name="propertyName"> the key whose value is changed </param>
 /// <param name="oldValue"> the value before change </param>
 /// <param name="newValue"> the value after change </param>
 /// <param name="changeType"> the change type </param>
 public ConfigChange(IConfig config, string propertyName, string?oldValue, string?newValue,
                     PropertyChangeType changeType)
 {
     Config       = config;
     PropertyName = propertyName;
     OldValue     = oldValue;
     NewValue     = newValue;
     ChangeType   = changeType;
 }
예제 #15
0
        public void ObserveModelGrowingCollectiion()
        {
            int numEvents = 0;

            object[]           recordedPath       = null;
            PropertyChangeType recordedChangeType = PropertyChangeType.Property;
            object             recordedValue      = null;

            void onPropertyChanged(object[] path, PropertyChangeType changeType, object value)
            {
                numEvents++;
                recordedChangeType = changeType;
                recordedPath       = path;
                recordedValue      = value;

                TestContext.Out.WriteLine("Change {0} ({1}) -> {2}", string.Join('.', path), changeType, value);
            }

            DuetControlServer.Model.Observer.OnPropertyPathChanged += onPropertyChanged;

            // Add item
            TestContext.Out.WriteLine("Add item");
            Message msg = new Message(MessageType.Success, "TEST");

            Provider.Get.Messages.Add(msg);

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "messages" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.GrowingCollection, recordedChangeType);
            if (recordedValue is IList list)
            {
                Assert.AreSame(msg, list[0]);
            }
            else
            {
                Assert.Fail("Invalid change value type");
            }

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Clear items
            TestContext.Out.WriteLine("Clear items");
            Provider.Get.Messages.Clear();

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(PropertyChangeType.GrowingCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "messages" }, recordedPath);
            Assert.AreEqual(null, recordedValue);

            // End
            DuetControlServer.Model.Observer.OnPropertyPathChanged -= onPropertyChanged;
        }
예제 #16
0
        internal WhatIfPropertyChange(string path, PropertyChangeType propertyChangeType)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            Path = path;
            PropertyChangeType = propertyChangeType;
        }
예제 #17
0
        public static Color ToColor(this PropertyChangeType propertyChangeType)
        {
            bool success = ColorsByPropertyChangeType.TryGetValue(propertyChangeType, out Color colorCode);

            if (!success)
            {
                throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
            }

            return(colorCode);
        }
예제 #18
0
        public static Symbol ToSymbol(this PropertyChangeType propertyChangeType)
        {
            bool success = SymbolsByPropertyChangeType.TryGetValue(propertyChangeType, out Symbol symbol);

            if (!success)
            {
                throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
            }

            return(symbol);
        }
예제 #19
0
        public static PSChangeType ToPSChangeType(this PropertyChangeType propertyChangeType)
        {
            bool success = PSChangeTypesByPropertyChangeType.TryGetValue(propertyChangeType, out PSChangeType changeType);

            if (!success)
            {
                throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
            }

            return(changeType);
        }
예제 #20
0
        internal WhatIfPropertyChange(string path, PropertyChangeType propertyChangeType)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            Path = path;
            PropertyChangeType = propertyChangeType;
            Children           = new ChangeTrackingList <WhatIfPropertyChange>();
        }
예제 #21
0
        public void ObserveModelObjectDictionary()
        {
            int numEvents = 0;

            object[]           recordedPath       = null;
            PropertyChangeType recordedChangeType = PropertyChangeType.Property;
            object             recordedValue      = null;

            void onPropertyChanged(object[] path, PropertyChangeType changeType, object value)
            {
                numEvents++;
                recordedChangeType = changeType;
                recordedPath       = path;
                recordedValue      = value;

                TestContext.Out.WriteLine("Change {0} ({1}) -> {2}", string.Join('.', path), changeType, value);
            }

            DuetControlServer.Model.Observer.OnPropertyPathChanged += onPropertyChanged;

            // plugins
            Plugin plugin = new() { Id = "Foobar" };

            Provider.Get.Plugins.Add("Foobar", plugin);

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "plugins", "Foobar" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreSame(plugin, recordedValue);

            // plugins.foobar.pid
            plugin.Pid = 1234;

            Assert.AreEqual(2, numEvents);
            Assert.AreEqual(new object[] { "plugins", "Foobar", "pid" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreEqual(plugin.Pid, recordedValue);

            // delete item
            Provider.Get.Plugins.Remove("Foobar");

            Assert.AreEqual(3, numEvents);
            Assert.AreEqual(new object[] { "plugins", "Foobar" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.IsNull(recordedValue);

            // End
            DuetControlServer.Model.Observer.OnPropertyPathChanged -= onPropertyChanged;
            Provider.Get.Plugins.Clear();
        }
        internal static string ToSerializedValue(this PropertyChangeType value)
        {
            switch (value)
            {
            case PropertyChangeType.Create:
                return("Create");

            case PropertyChangeType.Delete:
                return("Delete");

            case PropertyChangeType.Modify:
                return("Modify");

            case PropertyChangeType.Array:
                return("Array");
            }
            return(null);
        }
예제 #23
0
        public void ObserveModelDictionary()
        {
            int numEvents = 0;

            object[]           recordedPath       = null;
            PropertyChangeType recordedChangeType = PropertyChangeType.Property;
            object             recordedValue      = null;

            void onPropertyChanged(object[] path, PropertyChangeType changeType, object value)
            {
                numEvents++;
                recordedChangeType = changeType;
                recordedPath       = path;
                recordedValue      = value;

                TestContext.Out.WriteLine("Change {0} ({1}) -> {2}", string.Join('.', path), changeType, value);
            }

            DuetControlServer.Model.Observer.OnPropertyPathChanged += onPropertyChanged;

            // plugins
            Plugin plugin = new() { Id = "Foobar" };

            Provider.Get.Plugins.Add("Foobar", plugin);

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "plugins", "Foobar" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreSame(plugin, recordedValue);

            // plugins.foobar.data.test
            JsonElement customData = new();

            plugin.Data["test"] = customData;

            Assert.AreEqual(2, numEvents);
            Assert.AreEqual(new object[] { "plugins", "Foobar", "data", "test" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreEqual(customData, recordedValue);

            // End
            DuetControlServer.Model.Observer.OnPropertyPathChanged -= onPropertyChanged;
            Provider.Get.Plugins.Clear();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="com.rmc.projects.property_change_signal.vo.PropertyChangeSignalVO"/> class.
        /// </summary>
        /// <param name="aPropertyChangeType">A property change type.</param>
        /// <param name="aValue_object">A value_object.</param>
        public PropertyChangeSignalVO(PropertyChangeType aPropertyChangeType, object aValue_object)
        {
            //Debug.Log("--PropertyChangeSignalVO.constructor ("+aPropertyChangeType+","+aValue_object+")");
            //THESE 2 TYPES REQUIRE 2 ARGUMENTS, ALWAYS
            //
            switch (aPropertyChangeType)
            {
            case PropertyChangeType.UPDATE:
            case PropertyChangeType.UPDATED:
                _propertyChangeType = aPropertyChangeType;
                _value_object       = aValue_object;
                break;

            default:
                                #pragma warning disable 0162
                //ANY OTHER VALUES ARE NOT ACCEPTABLE IN THIS CONTEXT
                throw new SwitchStatementException(propertyChangeType.ToString());
                break;
                                #pragma warning restore 0162
            }
        }
예제 #25
0
        /// <summary>
        /// Method that is called when a property of the machine model has changed
        /// </summary>
        /// <param name="path">Path to the property</param>
        /// <param name="changeType">Type of the change</param>
        /// <param name="value">New value</param>
        private void MachineModelPropertyChanged(object[] path, PropertyChangeType changeType, object value)
        {
            if (!CheckFilters(path))
            {
                return;
            }

            lock (_patch)
            {
                try
                {
                    object node = GetPathNode(_patch, path);
                    if (node == null)
                    {
                        // Skip this update if the underlying object is about to be fully transferred anyway
                        return;
                    }

                    switch (changeType)
                    {
                    case PropertyChangeType.Property:
                        // Set new property value
                        Dictionary <string, object> propertyNode = (Dictionary <string, object>)node;
                        string propertyName = (string)path[^ 1];
예제 #26
0
 protected void OnPropertyChange(PropertyChangeType type, string name, double newValue, BoxedValue oldValue)
 {
     // Invoke the changed event
     if (ScriptObject.PropertyChange != null)
         ScriptObject.PropertyChange(this, type, name, BoxedValue.Box(newValue), oldValue);
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="com.rmc.projects.property_change_signal.vo.PropertyChangeSignalVO"/> class.
		/// </summary>
		/// <param name="aPropertyChangeType">A property change type.</param>
		/// <param name="aValue_object">A value_object.</param>
		public PropertyChangeSignalVO (PropertyChangeType aPropertyChangeType, object aValue_object )
		{

			//Debug.Log("--PropertyChangeSignalVO.constructor ("+aPropertyChangeType+","+aValue_object+")");
			//THESE 2 TYPES REQUIRE 2 ARGUMENTS, ALWAYS
			//
			switch (aPropertyChangeType) {
				
			case PropertyChangeType.UPDATE:
			case PropertyChangeType.UPDATED:
				_propertyChangeType = aPropertyChangeType;
				_value_object 		= aValue_object;
				break;
			default:
				#pragma warning disable 0162
				//ANY OTHER VALUES ARE NOT ACCEPTABLE IN THIS CONTEXT
				throw new SwitchStatementException(propertyChangeType.ToString());
				break;
				#pragma warning restore 0162
				
			}

		}
예제 #28
0
파일: Account.cs 프로젝트: dreamsql/Outter
 internal OrderChange(Order source, Protocal.Commands.OrderChangeType changeType, PropertyChangeType changeProperties = PropertyChangeType.None)
     : base(changeType, source)
 {
     this.PropertyType  = changeProperties;
     this.AffectedTrans = new List <Transaction>();
 }
예제 #29
0
        public void ObserveProperty()
        {
            int numEvents = 0;

            object[]           recordedPath       = null;
            PropertyChangeType recordedChangeType = PropertyChangeType.Property;
            object             recordedValue      = null;

            void onPropertyChanged(object[] path, PropertyChangeType changeType, object value)
            {
                numEvents++;
                recordedChangeType = changeType;
                recordedPath       = path;
                recordedValue      = value;

                TestContext.Out.WriteLine("Change {0} ({1}) -> {2}", string.Join('.', path), changeType, value);
            }

            DuetControlServer.Model.Observer.OnPropertyPathChanged += onPropertyChanged;

            // Simple property
            TestContext.Out.WriteLine("Simple property");
            Provider.Get.State.Status = MachineStatus.Halted;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "state", "status" }, recordedPath);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreEqual(MachineStatus.Halted, recordedValue);

            // Nested item property
            TestContext.Out.WriteLine("Adding new item");
            Board mainBoard = new Board();

            Provider.Get.Boards.Add(mainBoard);

            // Reset
            numEvents          = 0;
            recordedChangeType = PropertyChangeType.Property;
            recordedValue      = null;
            TestContext.Out.WriteLine();

            // Nested item propery
            TestContext.Out.WriteLine("Nested item property");
            mainBoard.V12.Current = 123F;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { new ItemPathNode("boards", 0, new object[1]), "v12", "current" }, recordedPath);
            Assert.AreEqual(123F, recordedValue);

            // Reset
            numEvents          = 0;
            recordedChangeType = PropertyChangeType.Property;
            recordedValue      = null;
            TestContext.Out.WriteLine();

            // Nested item propery 2
            TestContext.Out.WriteLine("Nested item property 2");
            Provider.Get.Inputs.HTTP.State = InputChannelState.AwaitingAcknowledgement;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { new ItemPathNode("inputs", (int)DuetAPI.CodeChannel.HTTP, new object[Inputs.Total]), "state" }, recordedPath);
            Assert.AreEqual(InputChannelState.AwaitingAcknowledgement, recordedValue);

            // Reset
            numEvents          = 0;
            recordedChangeType = PropertyChangeType.Property;
            recordedValue      = null;
            TestContext.Out.WriteLine();

            // Replaceable model object
            TestContext.Out.WriteLine("Assign MessageBox");
            MessageBox messageBox = new MessageBox
            {
                Message = "Test",
                Mode    = MessageBoxMode.OkCancel,
                Title   = "Test title"
            };

            Provider.Get.State.MessageBox = messageBox;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "state", "messageBox" }, recordedPath);
            Assert.AreSame(messageBox, recordedValue);

            // Reset
            numEvents          = 0;
            recordedChangeType = PropertyChangeType.Property;
            recordedValue      = null;
            TestContext.Out.WriteLine();

            // Replaceable model object property
            TestContext.Out.WriteLine("MessageBox property");
            Provider.Get.State.MessageBox.Message = "asdf";

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "state", "messageBox", "message" }, recordedPath);
            Assert.AreEqual("asdf", recordedValue);

            // Reset
            numEvents          = 0;
            recordedChangeType = PropertyChangeType.Property;
            recordedValue      = null;
            TestContext.Out.WriteLine();

            // Replaceable model object 2
            TestContext.Out.WriteLine("Remove MessageBox");
            Provider.Get.State.MessageBox = null;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(new object[] { "state", "messageBox" }, recordedPath);
            Assert.AreEqual(null, recordedValue);

            // End
            DuetControlServer.Model.Observer.OnPropertyPathChanged -= onPropertyChanged;
        }
예제 #30
0
        public void ObserveModelObjectCollection()
        {
            int numEvents = 0;
            PropertyChangeType recordedChangeType = PropertyChangeType.Property;

            object[] recordedPath  = null;
            object   recordedValue = null;

            void onPropertyChanged(object[] path, PropertyChangeType changeType, object value)
            {
                numEvents++;
                recordedChangeType = changeType;
                recordedPath       = path;
                recordedValue      = value;

                TestContext.Out.WriteLine("Change {0} ({1}) -> {2}", string.Join('.', path), changeType, value);
            }

            DuetControlServer.Model.Observer.OnPropertyPathChanged += onPropertyChanged;

            // Add first item
            TestContext.Out.WriteLine("Add item");
            Heater newHeater = new Heater();

            Provider.Get.Heat.Heaters.Add(newHeater);

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 0, new object[1]) }, recordedPath);
            Assert.AreSame(newHeater, recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Add second item
            TestContext.Out.WriteLine("Add item");
            newHeater = new Heater();
            Provider.Get.Heat.Heaters.Add(newHeater);

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 1, new object[2]) }, recordedPath);
            Assert.AreSame(newHeater, recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Modify first item
            TestContext.Out.WriteLine("Modify first item");
            Provider.Get.Heat.Heaters[0].Active = 123F;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(PropertyChangeType.Property, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 0, new object[2]), "active" }, recordedPath);
            Assert.AreEqual(123F, recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Move item
            TestContext.Out.WriteLine("Move item");
            Provider.Get.Heat.Heaters.Move(1, 0);

            Assert.AreEqual(2, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 1, new object[2]) }, recordedPath);
            Assert.AreSame(Provider.Get.Heat.Heaters[1], recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Replace item
            TestContext.Out.WriteLine("Replace item");
            newHeater = new Heater {
                Active = 10F
            };
            Provider.Get.Heat.Heaters[0] = newHeater;

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 0, new object[2]) }, recordedPath);
            Assert.AreSame(newHeater, recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Insert item
            TestContext.Out.WriteLine("Insert item");
            newHeater = new Heater {
                Standby = 20F
            };
            Provider.Get.Heat.Heaters.Insert(0, newHeater);

            Assert.AreEqual(3, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 2, new object[3]) }, recordedPath);
            Assert.AreEqual(Provider.Get.Heat.Heaters[2], recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Remove item
            TestContext.Out.WriteLine("Remove item");
            Provider.Get.Heat.Heaters.RemoveAt(0);

            Assert.AreEqual(3, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 1, new object[2]) }, recordedPath);
            Assert.AreEqual(Provider.Get.Heat.Heaters[1], recordedValue);

            // Reset
            numEvents     = 0;
            recordedPath  = null;
            recordedValue = null;
            TestContext.Out.WriteLine();

            // Clear items
            TestContext.Out.WriteLine("Clear items");
            Provider.Get.Heat.Heaters.Clear();

            Assert.AreEqual(1, numEvents);
            Assert.AreEqual(PropertyChangeType.ObjectCollection, recordedChangeType);
            Assert.AreEqual(new object[] { "heat", new ItemPathNode("heaters", 0, Array.Empty <object>()) }, recordedPath);
            Assert.AreEqual(null, recordedValue);

            // End
            DuetControlServer.Model.Observer.OnPropertyPathChanged -= onPropertyChanged;
        }
예제 #31
0
        internal static WhatIfPropertyChange DeserializeWhatIfPropertyChange(JsonElement element)
        {
            string             path = default;
            PropertyChangeType propertyChangeType = default;
            object             before             = default;
            object             after = default;
            IReadOnlyList <WhatIfPropertyChange> children = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("path"))
                {
                    path = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("propertyChangeType"))
                {
                    propertyChangeType = property.Value.GetString().ToPropertyChangeType();
                    continue;
                }
                if (property.NameEquals("before"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    before = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("after"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    after = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("children"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <WhatIfPropertyChange> array = new List <WhatIfPropertyChange>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(DeserializeWhatIfPropertyChange(item));
                        }
                    }
                    children = array;
                    continue;
                }
            }
            return(new WhatIfPropertyChange(path, propertyChangeType, before, after, children));
        }
예제 #32
0
        public void RecordPropertyChange(QualifiedTopicRevision topic, string propertyName, PropertyChangeType aType)
        {
            switch (aType)
            {
                case PropertyChangeType.PropertyAdd:
                    AddToDictionaries(_addedPropertiesByProperty, _addedPropertiesByTopic, topic, propertyName);
                    break;

                case PropertyChangeType.PropertyRemove:
                    AddToDictionaries(_removedPropertiesByProperty, _removedPropertiesByTopic, topic, propertyName);
                    break;

                case PropertyChangeType.PropertyUpdate:
                    AddToDictionaries(_changedPropertiesByProperty, _changedPropertiesByTopic, topic, propertyName);
                    break;
            }
        }
예제 #33
0
 internal static bool Contains(this PropertyChangeType source, PropertyChangeType item)
 {
     return(source.HasFlag(item));
 }
예제 #34
0
 public PropertyChange(string name, PropertyChangeType changeType, object oldValue, object newValue)
 {
     Name = name;
     ChangeType = changeType;
     OldValue = oldValue;
     NewValue = newValue;
 }
예제 #35
0
 public static void InvokePropertyChange(ScriptObject instance, PropertyChangeType type, string name, double newValue, BoxedValue oldValue)
 {
     // Invoke the changed event
     if (ScriptObject.PropertyChange != null)
         ScriptObject.PropertyChange(instance, type, name, BoxedValue.Box(newValue), oldValue);
 }
 private void FormatPropertyChangeType(PropertyChangeType propertyChangeType)
 {
     this.Builder
     .Append(propertyChangeType.ToSymbol(), propertyChangeType.ToColor())
     .Append(Symbol.WhiteSpace);
 }
예제 #37
0
 public static string ToSerialString(this PropertyChangeType value) => value switch
 {