Esempio n. 1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            SharedProperty.appSettings.PlayHotKey     = txtPlayScript.Text;
            SharedProperty.appSettings.RecordHotKey   = txtStartRecording.Text;
            SharedProperty.appSettings.AllowInputMode = !chkNoInput.Checked;
            var modifierText = cbModifiers.SelectedItem?.ToString();

            if (modifierText != null)
            {
                SharedProperty.appSettings.PlayModifier = modifierText.Trim();
            }
            if (cbLanguage.SelectedItem != null && !SharedProperty.appSettings.Language.ToLower().Equals(cbLanguage.SelectedItem))
            {
                SharedProperty.appSettings.Language = cbLanguage.SelectedItem.ToString().ToLower();
                MessageBox.Show(Language.Get("msg_language_changed"), Language.Get("info"));
            }
            SharedProperty.appSettings.Save(AppConstant.appSettings);
            SharedProperty.ToggleHotkey(this.Invoker, true);
            SharedProperty.UpdateHotkeys();
            //SharedProperty.ToggleHotkey(this.Invoker);
            if (ScriptGrid.Column("SendInput") != null)
            {
                ScriptGrid.Column("SendInput").Visible = !chkNoInput.Checked;
            }
            this.Close();
        }
Esempio n. 2
0
        private InterlockedPropertyInfo GetPropertyInfo(INotifyPropertyChanged target, string propertyName, params Type[] allowedTypes)
        {
            ObjectEntry entry;

            if ((target == null) || !this.Client.ObjectsManager.TryGetValue(target, out entry))
            {
                throw new ArgumentException("Target specified is not found or is not valid.", "target");
            }

            SharedProperty property = entry.Properties.Values.FirstOrDefault(p => p.Name == propertyName);

            if (property == null)
            {
                throw new ArgumentException("propertyName specified is not found or is not valid.", "propertyName");
            }

            Type propertyType = target.GetPropertyType(propertyName);

            if (allowedTypes.FirstOrDefault(t => t == propertyType) == null)
            {
                throw new ArgumentException("Property type is not supported or compatible with parameter", "propertyName");
            }

            return(new InterlockedPropertyInfo {
                ObjectId = entry.Id, Property = property, PropertyType = propertyType
            });
        }
        private void ConfigureSharedProperties(InfoBase infoBase, ConfigObject config)
        {
            // 3.1.8.0 = 15794563-ccec-41f6-a83c-ec5f7b9a5bc1 - идентификатор коллекции общих реквизитов
            Guid collectionUuid = config.GetUuid(new int[] { 3, 1, 8, 0 });

            if (collectionUuid == new Guid("15794563-ccec-41f6-a83c-ec5f7b9a5bc1"))
            {
                // количество объектов в коллекции
                int count = config.GetInt32(new int[] { 3, 1, 8, 1 });
                if (count == 0)
                {
                    return;
                }

                // 3.1.8 - коллекция общих реквизитов
                ConfigObject collection = config.GetObject(new int[] { 3, 1, 8 });

                int            offset = 2;
                SharedProperty property;
                for (int i = 0; i < count; i++)
                {
                    property = new SharedProperty()
                    {
                        FileName = collection.GetUuid(new int[] { i + offset })
                    };
                    ConfigureSharedProperty(property, infoBase);
                    infoBase.SharedProperties.Add(property.FileName, property);
                }
            }
        }
Esempio n. 4
0
        protected virtual void RaisePropertyChangedEvent(SharedProperty property)
        {
            var eventHandler = PropertyChanged;

            if (eventHandler != null)
            {
                eventHandler(this, new PropertyChangedEventArgs(property.ToString()));
            }
        }
Esempio n. 5
0
        private static void TestProperty
            (INotifyPropertyChanged model, SharedProperty propertyName, object oldValue,
            object newValue)
        {
            Console.WriteLine(propertyName + @"Test");
            object value = GetPropertyValue(model, propertyName.ToString());

            Assert.AreEqual(oldValue, value);
            model.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                Assert.AreEqual(propertyName.ToString(), e.PropertyName);
                Assert.AreEqual(newValue, GetPropertyValue(model, propertyName.ToString()));
                Console.WriteLine(propertyName + @" changed.");
            };
            SetPropertyValue(model, propertyName.ToString(), newValue);
        }
        private void ConfigureSharedProperty(SharedProperty property, InfoBase infoBase)
        {
            ConfigObject cfo = FileReader.ReadConfigObject(property.FileName.ToString());

            if (infoBase.Properties.TryGetValue(property.FileName, out MetadataProperty propertyInfo))
            {
                property.DbName = propertyInfo.DbName;
            }
            property.Name = cfo.GetString(new int[] { 1, 1, 1, 1, 2 });
            ConfigObject aliasDescriptor = cfo.GetObject(new int[] { 1, 1, 1, 1, 3 });

            if (aliasDescriptor.Values.Count == 3)
            {
                property.Alias = cfo.GetString(new int[] { 1, 1, 1, 1, 3, 2 });
            }
            property.AutomaticUsage = (AutomaticUsage)cfo.GetInt32(new int[] { 1, 6 });

            // 1.1.1.2 - описание типов значений общего реквизита
            ConfigObject propertyTypes = cfo.GetObject(new int[] { 1, 1, 1, 2 });

            property.PropertyType = (DataTypeInfo)TypeInfoConverter.Convert(propertyTypes);

            Configurator.ConfigureDatabaseFields(property);

            // 1.2.1 - количество объектов метаданных, у которых значение использования общего реквизита не равно "Автоматически"
            int count = cfo.GetInt32(new int[] { 1, 2, 1 });

            if (count == 0)
            {
                return;
            }
            int step = 2;

            count *= step;
            int uuidIndex   = 2;
            int usageOffset = 1;

            while (uuidIndex <= count)
            {
                Guid uuid = cfo.GetUuid(new int[] { 1, 2, uuidIndex });
                SharedPropertyUsage usage = (SharedPropertyUsage)cfo.GetInt32(new int[] { 1, 2, uuidIndex + usageOffset, 1 });
                property.UsageSettings.Add(uuid, usage);
                uuidIndex += step;
            }
        }
Esempio n. 7
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.client.VerifyAccess();
            this.client.VerifyConnected();

            // Check if object is ignored
            if (this.IgnoreChanges)
            {
                return;
            }

            if (!this.IsDynamic && this.IsIgnoredProperty(e.PropertyName))
            {
                return;
            }

            // Check if object is connected
            if (!this.IsConnected)
            {
                throw new InvalidOperationException("Changes cannot be made to this named object until it is connected with the server");
            }

            // Try to extract property information
            SharedProperty property;

            // If dynamic, pull value from dictionary
            object dynamicVal = null;
            if (this.IsDynamic)
            {
                var dictionary = this.Object as IDictionary<string, object>;
                if (!dictionary.TryGetValue(e.PropertyName, out dynamicVal))
                {
                    throw new ArgumentException("Dictionary doesn't contains the value: " + e.PropertyName);
                }
            }
            if (!this.Properties.TryGetValue(e.PropertyName, out property))
            {
                if (this.IsDynamic)
                {
                    // Add new property if dynamic
                    if (dynamicVal != null)
                    {
                        property = new SharedProperty()
                                       {
                                           Attributes = new SharedAttributes(),
                                           Index = -1,
                                           ETag = new ETag(this.client.ClientId),
                                           Name = e.PropertyName,
                                           PropertyType = DynamicTypeMapping.Instance.GetValueFromType(dynamicVal.GetType())
                                       };
                    }
                }
                if (property == null)
                {
                    throw new ArgumentException("Dictionary doesn't contains the value: " + e.PropertyName);
                }
            }
            // Throw exception if property cannot be updated by the client
            if (property.IsServerAppliedProperty())
            {
                 throw new InvalidOperationException("Client cannot modify properties with server-applied attributes");
            }

            // Create payload
            PropertyChangedPayload data = new PropertyChangedPayload(this.client.ClientId, property.Index, this.Id, property.ETag, this.IsDynamic ? dynamicVal : this.Object.GetPropertyValue(e.PropertyName));
            if (this.IsDynamic)
            {
                data.PropertyName = e.PropertyName;
                // Property type might change, we need to re-get each time
                data.PropertyType = DynamicTypeMapping.Instance.GetValueFromType(dynamicVal.GetType());
            }

            // Add to pending update list
            property.LocalUpdates.Add(new PropertyUpdateOperation() { Payload = data, ReapplyUpdate = false });

            // Send to server
            this.client.SendPublishEvent(data);
        }
Esempio n. 8
0
        private void UpdateSharedObject(PropertyChangedPayload data)
        {
            Debug.Assert(this.client.CheckAccess());

            ObjectEntry entry = null;

            try
            {
                if (!this.TryGetValue(data.ObjectId, out entry))
                {
                    // Received update for an object we are not tracking
                    Debug.WriteLine("[PropertyChanged] Missing shared object for update in incoming event.");
                    return;
                }

                SharedProperty property = entry.IsDynamic ? entry.Properties[data.PropertyName] : entry.Properties[data.PropertyIndex];

                // In case of dynamic properties, this could be the first time this property is seen
                if (property == null && entry.IsDynamic)
                {
                    property = new SharedProperty()
                    {
                        Attributes   = new SharedAttributes(),
                        Index        = (short)entry.Properties.Count,
                        Name         = data.PropertyName,
                        ETag         = new ETag(this.client.ClientId),
                        PropertyType = data.PropertyType
                    };
                    entry.Properties.Add(property.Index, property);
                }

                // Ignore changes for given object, add to list
                entry.IgnoreChanges = true;

                // Don't apply update if we made it locally
                bool applyUpdate      = data.ClientId != this.client.ClientId;
                bool conflictDetected = false;

                PropertyUpdateOperation matchingUpdate = property.LocalUpdates.Where(x => x.Payload.Equals(data)).FirstOrDefault();
                if (matchingUpdate != null)
                {
                    // Remove update from pending list
                    Debug.WriteLine("[PropertyChanged] Received acknowledgement of matching property update");
                    if (matchingUpdate.ReapplyUpdate)
                    {
                        applyUpdate = true;
                    }
                    property.LocalUpdates.Remove(matchingUpdate);
                }
                // Check for conflict, but won't stop us from applying update
                conflictDetected = data.IsConflict(property.LocalUpdates) &&
                                   !property.IsServerAppliedProperty() && (property.Attributes.ConcurrencyAttribute != ConcurrencyPolicy.Overwrite);

                if (applyUpdate)
                {
                    // Mark pending updates to re-apply if we are applying a change from another endpoint
                    if (data.ClientId != this.client.ClientId)
                    {
                        property.LocalUpdates.ForEach(x => x.ReapplyUpdate = true);
                    }
                    if (entry.IsDynamic)
                    {
                        var dictionary = entry.Object as IDictionary <string, object>;
                        if (dictionary == null)
                        {
                            throw new ArgumentException("Dictionary is null");
                        }

                        // Insert up-to-date value for property
                        dictionary[data.PropertyName] = Json.ReadObject(DynamicTypeMapping.Instance.GetTypeFromValue(data.PropertyType), data.PropertyValue);
                    }
                    else
                    {
                        Json.AssignProperty(entry.Object, property.Name, data.PropertyValue);
                    }
                    property.Value = data.PropertyValue;
                }
                property.ETag = data.ETag;

                if (conflictDetected)
                {
                    Debug.WriteLine("[PropertyChanged] Conflict detected on property update");
                    IEnumerable <PropertyChangedPayload> rejectedUpdates = property.LocalUpdates.Select(x => x.Payload);
                    if (property.Attributes.ConcurrencyAttribute == ConcurrencyPolicy.RejectAndNotify)
                    {
                        var notify = new ConcurrencyUpdateRejectedEventArgs(entry.Object, property.Name, rejectedUpdates.Select(x => Json.ReadProperty(entry.Object, property.Name, x.PropertyValue)));
                        this.client.RaiseError(notify);
                    }
                    property.LocalUpdates.Clear();
                }
            }
            finally
            {
                if (entry != null)
                {
                    entry.IgnoreChanges = false;
                }
            }
        }
Esempio n. 9
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.client.VerifyAccess();
            this.client.VerifyConnected();

            // Check if object is ignored
            if (this.IgnoreChanges)
            {
                return;
            }

            if (!this.IsDynamic && this.IsIgnoredProperty(e.PropertyName))
            {
                return;
            }

            // Check if object is connected
            if (!this.IsConnected)
            {
                throw new InvalidOperationException("Changes cannot be made to this named object until it is connected with the server");
            }

            // Try to extract property information
            SharedProperty property;

            // If dynamic, pull value from dictionary
            object dynamicVal = null;

            if (this.IsDynamic)
            {
                var dictionary = this.Object as IDictionary <string, object>;
                if (!dictionary.TryGetValue(e.PropertyName, out dynamicVal))
                {
                    throw new ArgumentException("Dictionary doesn't contains the value: " + e.PropertyName);
                }
            }
            if (!this.Properties.TryGetValue(e.PropertyName, out property))
            {
                if (this.IsDynamic)
                {
                    // Add new property if dynamic
                    if (dynamicVal != null)
                    {
                        property = new SharedProperty()
                        {
                            Attributes   = new SharedAttributes(),
                            Index        = -1,
                            ETag         = new ETag(this.client.ClientId),
                            Name         = e.PropertyName,
                            PropertyType = DynamicTypeMapping.Instance.GetValueFromType(dynamicVal.GetType())
                        };
                    }
                }
                if (property == null)
                {
                    throw new ArgumentException("Dictionary doesn't contains the value: " + e.PropertyName);
                }
            }
            // Throw exception if property cannot be updated by the client
            if (property.IsServerAppliedProperty())
            {
                throw new InvalidOperationException("Client cannot modify properties with server-applied attributes");
            }

            // Create payload
            PropertyChangedPayload data = new PropertyChangedPayload(this.client.ClientId, property.Index, this.Id, property.ETag, this.IsDynamic ? dynamicVal : this.Object.GetPropertyValue(e.PropertyName));

            if (this.IsDynamic)
            {
                data.PropertyName = e.PropertyName;
                // Property type might change, we need to re-get each time
                data.PropertyType = DynamicTypeMapping.Instance.GetValueFromType(dynamicVal.GetType());
            }

            // Add to pending update list
            property.LocalUpdates.Add(new PropertyUpdateOperation()
            {
                Payload = data, ReapplyUpdate = false
            });

            // Send to server
            this.client.SendPublishEvent(data);
        }