Esempio n. 1
0
        /// <summary>
        /// Generate Home Assistant configuration file entries for the actuators in the provided device.
        /// </summary>
        /// <param name="definition">Device properties</param>
        /// <returns>Configuration file entries covering all actuators defined in the device</returns>
        public KeyedCollection <ConfigEntry> TransformConfig(DeviceDefinition definition)
        {
            if (definition.Actuators == null)
            {
                return(new KeyedCollection <ConfigEntry>());
            }

            if (string.IsNullOrWhiteSpace(definition.DeviceId))
            {
                throw new ValidationException($"{nameof(definition.DeviceId)} requires a value.");
            }

            var configs = new KeyedCollection <ConfigEntry>();

            foreach (var actuator in definition.Actuators)
            {
                var config = FormatActuatorDefinition(new ActuatorConfig
                {
                    Type     = actuator.Type,
                    Name     = definition.Name,
                    Platform = definition.Platform,
                    DeviceId = definition.DeviceId,
                    Icon     = actuator.Icon,
                });
                configs.Add(config.Key, config.Value);
            }

            return(configs);
        }
Esempio n. 2
0
        public virtual PluginBase LoadPlugin(PluginLoadInfo plugin)
        {
            if (this.PluginsLoaded.ContainsKey(plugin.ClassName))
            {
                return(this.PluginsLoaded[plugin.ClassName]);
            }

            Assembly ass = null;

            if (_Assemblies.ContainsKey(plugin.Filename))
            {
                ass = _Assemblies[plugin.Filename];
            }
            else
            {
                string path = Path.Combine(this.AssemblySearchPath, plugin.Filename);

                ass = Assembly.LoadFile(path);

                _Assemblies.Add(plugin.Filename, ass);
            }

            PluginBase plug = (PluginBase)ass.CreateInstance(plugin.ClassName);

            this.PluginsLoaded.Add(plugin.ClassName, plug);

            if (plug.ShowMenuItem)
            {
                AddToPluginsMenu(plug);
            }

            return(plug);
        }
Esempio n. 3
0
        public static void AddItems <TKey, TValue>(
            this KeyedCollection <TKey, TValue> collection,
            Func <TValue> generateItem,
            Func <TValue, TKey> getKey,
            int numItems,
            out TKey[] keys,
            out TValue[] items,
            out TValue[] itemsWithKeys)
        {
            items         = new TValue[numItems];
            keys          = new TKey[numItems];
            itemsWithKeys = new TValue[numItems];
            var keyIndex = 0;

            for (var i = 0; i < numItems; ++i)
            {
                TValue item = generateItem();
                TKey   key  = getKey(item);

                collection.Add(item);
                items[i] = item;

                if (null != key)
                {
                    keys[keyIndex]          = key;
                    itemsWithKeys[keyIndex] = item;
                    ++keyIndex;
                }
            }

            keys          = keys.Slice(0, keyIndex);
            itemsWithKeys = itemsWithKeys.Slice(0, keyIndex);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates Animations from a xnaMugen.IO.TextFile.
        /// </summary>
        /// <param name="textfile">A textfile whose xnaMugen.IO.TextSection can be used to create Animations.</param>
        /// <returns>A collection of Animations created from the supplied textfile.</returns>
        public KeyedCollection <Int32, Animation> LoadAnimations(TextFile textfile)
        {
            if (textfile == null)
            {
                throw new ArgumentNullException("textfile");
            }

            KeyedCollection <Int32, Animation> animations = new KeyedCollection <Int32, Animation>(x => x.Number);

            foreach (TextSection section in textfile)
            {
                Animation animation = CreateAnimation(section);
                if (animation != null)
                {
                    if (animations.Contains(animation.Number) == false)
                    {
                        animations.Add(animation);
                    }
                    else
                    {
                        Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Duplicate animation #{0}. Discarding duplicate.", animation.Number);
                    }
                }
            }

            return(animations);
        }
Esempio n. 5
0
 public void Add(string key, WizardPanel item)
 {
     m_Panels.Add(key, item);
     if (AddPanel != null)
     {
         AddPanel(item);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Adds the specified enumeration of values to this collection.
 /// </summary>
 /// <typeparam name="TKey">The type of the key.</typeparam>
 /// <typeparam name="TValue">The type of the value.</typeparam>
 /// <param name="collection">The collection to add the value to.</param>
 /// <param name="items">The items to add to the collection.</param>
 public static void AddRange <TKey, TValue>([NotNull] this KeyedCollection <TKey, TValue> collection, IEnumerable <TValue> items)
 {
     if (items != null)
     {
         foreach (var item in items)
         {
             collection.Add(item);
         }
     }
 }
 public void CacheFile(string filename)
 {
     if (!_files.ContainsKey(filename))
     {
         StreamReader sr = new StreamReader(filename);
         _currentBufferSize += sr.BaseStream.Length;
         EnsureCapacity();
         _files.Add(filename, CloneStream(sr.BaseStream));
         sr.Close();
     }
 }
Esempio n. 8
0
        public IniSection GetOrCreateSection(string sectionName)
        {
            IniSection?section = GetSection(sectionName);

            if (section == null)
            {
                section = new IniSection(sectionName);
                sections.Add(section);
            }

            return(section);
        }
Esempio n. 9
0
 public Stream OpenFile(string filename, bool forceReload)
 {
     if (!_files.Contains(filename) || forceReload)
     {
         StreamReader sr = new StreamReader(filename);
         _currentBufferSize += sr.BaseStream.Length;
         EnsureCapacity();
         _files.Add(filename, CloneStream(sr.BaseStream));
         sr.Close();
     }
     return(_files[filename]);
 }
Esempio n. 10
0
        /// <summary>
        /// Reads all device definition files from the source directory,
        /// generates Home Assistant entity configurations, and writes
        /// these to the config files in the output directory.
        /// </summary>
        /// <param name="sourceDirectory">Directory containig device definition files</param>
        /// <param name="outputDirectory">Directory containing Home Assistant config files</param>
        public async Task GenerateConfigAsync(string sourceDirectory, string outputDirectory)
        {
            var definitions = await GetDeviceDefinitionsAsync(sourceDirectory);

            var configs = new KeyedCollection <ConfigEntry>();

            foreach (var definition in definitions)
            {
                configs.Add(_actuatorTransformer.TransformConfig(definition));
                configs.Add(_sensorTransformer.TransformConfig(definition));
                configs.Add(_templateSensorTransformer.GetButtonActivitySensor(definition));
            }

            configs.Add(_templateSensorTransformer.GetLowBatteryAlertSensor(definitions));

            foreach (var key in configs.Keys)
            {
                await WriteToConfigFileAsync(key, configs[key].Select(i => i.Entity).ToArray(), Path.Combine(outputDirectory, $"{key}.yaml"));
                await WriteToConfigFileAsync(key, configs[key].Select(i => i.Customization).Where(i => i.Any()).ToArray(), Path.Combine(outputDirectory, $"customize.yaml"));
            }
        }
Esempio n. 11
0
            IDataValidationResults IDataValidationResults.Add(DataValidationResult value)
            {
                if (value.IsEmpty)
                {
                    throw new ArgumentException("", nameof(value));
                }

                if (!IsSealed)
                {
                    base.Add(value);
                    return(this);
                }

                var result = new KeyedCollection();

                foreach (var entry in this)
                {
                    result.Add(entry);
                }
                result.Add(value);
                return(result);
            }
        /// <summary>
        /// Initialize the cache
        /// </summary>
        protected void InitializeCache()
        {
            // WE LOAD FIXED REDIRECTS UP TO CACHE SIZE
            _CustomUrls = new KeyedCustomUrlCollection();
            CustomUrlCollection tempCustomUrls = CustomUrlDataSource.LoadForStore(this._CacheSize, 0);

            foreach (CustomUrl item in tempCustomUrls)
            {
                _CustomUrls.Add(item);
            }
            _CustomUrlCount = CustomUrlDataSource.CountForStore();
            _ValidCache     = true;
        }
Esempio n. 13
0
        /// <summary>
        /// Converts an AttributeChange of type 'add' to a new AttributeChange of type 'update'
        /// </summary>
        /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param>
        /// <param name="attribute">The attribute to create the AttributeChange for</param>
        /// <param name="valueChanges">The value changes to apply</param>
        /// <param name="existingChange">The existing attribute change that was found on the CSEntryChange</param>
        private static void ConvertAttributeChangeUpdateFromAdd(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges, AttributeChange existingChange)
        {
            IList <ValueChange> mergedList = MergeValueChangeLists(attribute, existingChange.ValueChanges, valueChanges);

            //if (mergedList.Count == 0)
            //{
            //    return;
            //}

            //if (mergedList.ContainsSameElements(attributeChanges[attribute.Name].ValueChanges) && attributeChanges[attribute.Name].ModificationType == AttributeModificationType.Update)
            //{
            //    return;
            //}

            attributeChanges.Remove(existingChange);

            switch (objectModificationType)
            {
            case ObjectModificationType.Add:
                attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, mergedList.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()));
                break;

            case ObjectModificationType.Delete:
                throw new DeletedObjectModificationException();

            case ObjectModificationType.Replace:
                attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, mergedList.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()));
                break;

            case ObjectModificationType.Update:
                attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, mergedList.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()));
                break;

            case ObjectModificationType.None:
            case ObjectModificationType.Unconfigured:
            default:
                throw new UnknownOrUnsupportedModificationTypeException(objectModificationType);
            }
        }
Esempio n. 14
0
        public void AddPlugin(string key, ref PluginBase plugin, bool loaded)
        {
            Assembly plugAss = plugin.GetType().Assembly;

            string fileName = Path.GetFileName(plugAss.Location);

            _Plugins.Add(key, new PluginLoadInfo(loaded, fileName, plugin.GetType().FullName));

            if (loaded)
            {
                _PluginsLoaded.Add(key, plugin);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SagaMetadataCollection"/> class.
        /// </summary>
        /// <param name="availableTypes">A <see cref="IEnumerable{T}">sequence</see> of all available types in the system.</param>
        public SagaMetadataCollection(IEnumerable <Type> availableTypes)
        {
            Arg.NotNull(availableTypes, nameof(availableTypes));

            var discoveredMetadata = from type in availableTypes
                                     where type.IsSaga()
                                     select SagaMetadata.Create(type);

            foreach (var metadata in discoveredMetadata)
            {
                bySaga.Add(metadata.SagaType, metadata);
                byData.Add(metadata);
            }
        }
Esempio n. 16
0
        public StateManager CreateManager(Combat.Character character, ReadOnlyList <String> filepaths)
        {
            if (character == null)
            {
                throw new ArgumentNullException("character");
            }
            if (filepaths == null)
            {
                throw new ArgumentNullException("filepaths");
            }

            KeyedCollection <Int32, State> states = new KeyedCollection <Int32, State>(x => x.Number);

            foreach (String filepath in filepaths)
            {
                ReadOnlyKeyedCollection <Int32, State> loadedstates = GetStates(filepath);
                foreach (State state in loadedstates)
                {
                    if (states.Contains(state.Number) == true)
                    {
                        states.Remove(state.Number);
                    }
                    states.Add(state);
                }
            }

            foreach (State state in m_internalstates)
            {
                if (states.Contains(state.Number) == false)
                {
                    states.Add(state);
                }
            }

            return(new StateManager(this, character, new ReadOnlyKeyedCollection <Int32, State>(states)));
        }
Esempio n. 17
0
        public StateManager CreateManager(Combat.Character character, ReadOnlyList<String> filepaths)
        {
            if (character == null) throw new ArgumentNullException("character");
            if (filepaths == null) throw new ArgumentNullException("filepaths");

            KeyedCollection<Int32, State> states = new KeyedCollection<Int32, State>(x => x.Number);

            foreach (String filepath in filepaths)
            {
                ReadOnlyKeyedCollection<Int32, State> loadedstates = GetStates(filepath);
                foreach (State state in loadedstates)
                {
                    if (states.Contains(state.Number) == true) states.Remove(state.Number);
                    states.Add(state);
                }
            }

            foreach (State state in m_internalstates)
            {
                if (states.Contains(state.Number) == false) states.Add(state);
            }

            return new StateManager(this, character, new ReadOnlyKeyedCollection<Int32, State>(states));
        }
Esempio n. 18
0
        public StateManager CreateManager(Combat.Character character, ReadOnlyList <string> filepaths)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }
            if (filepaths == null)
            {
                throw new ArgumentNullException(nameof(filepaths));
            }

            var states = new KeyedCollection <int, State>(x => x.Number);

            foreach (var filepath in filepaths)
            {
                var loadedstates = GetStates(filepath);
                foreach (var state in loadedstates)
                {
                    if (states.Contains(state.Number))
                    {
                        states.Remove(state.Number);
                    }
                    states.Add(state);
                }
            }

            foreach (var state in _internalstates)
            {
                if (states.Contains(state.Number) == false)
                {
                    states.Add(state);
                }
            }

            return(new StateManager(this, character, new ReadOnlyKeyedCollection <int, State>(states)));
        }
Esempio n. 19
0
        protected void InitializeCache()
        {
            // WE ALWAYS LOAD ALL DYNAMIC REDIRECTS TO CACHE
            _DynamicRedirects = RedirectDataSource.LoadDynamicRedirects();

            // WE LOAD FIXED REDIRECTS UP TO CACHE SIZE
            _FixedRedirects = new KeyedRedirectCollection();
            RedirectCollection tempFixedRedirects = RedirectDataSource.LoadFixedRedirects(this._CacheSize, 0);

            foreach (Redirect item in tempFixedRedirects)
            {
                _FixedRedirects.Add(item);
            }
            _FixedRedirectCount = RedirectDataSource.CountFixedRedirects();
            _ValidCache         = true;
        }
Esempio n. 20
0
        public void AddValue(string key, object value)
        {
            IniValue?iniValue = GetValue(key);

            if (iniValue != null)
            {
                iniValue.Value = value?.ToString() ?? string.Empty;
            }
            else
            {
                iniValue = new IniValue(key)
                {
                    Value = value?.ToString() ?? string.Empty,
                };

                values.Add(iniValue);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Builds the resource links from the state.
        /// </summary>
        /// <typeparam name="T">The source type.</typeparam>
        /// <param name="resource">The resource.</param>
        /// <param name="mappingConfiguration">The mapping configuration.</param>
        /// <exception cref="System.UriFormatException">Invalid URI: The current request url is not valid.</exception>
        private void BuildLinks <T>(Resource <T> resource, IClassMapping mappingConfiguration)
        {
            var l = new KeyedCollection <Link>();

            if (mappingConfiguration != null)
            {
                foreach (var map in mappingConfiguration.LinkResolvers)
                {
                    Uri v;

                    if (map.Value.Resolve(resource, out v))
                    {
                        l.Add(new Link(map.Key, v));
                    }
                }

                resource.Links = l;
            }
        }
Esempio n. 22
0
        private static void AddStateToCollection(KeyedCollection <int, State> collection, State state)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            if (collection.Contains(state.Number))
            {
                Log.Write(LogLevel.Warning, LogSystem.StateSystem, "Duplicate state #{0}. Discarding duplicate", state.Number);
            }
            else
            {
                collection.Add(state);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SagaMetadata"/> class.
        /// </summary>
        /// <param name="sagaType">The type of saga.</param>
        /// <param name="sagaDataType">The type of saga type.</param>
        /// <param name="correlationProperty">The <see cref="CorrelationProperty">property</see> the saga is correlated on.</param>
        /// <param name="messages">A <see cref="IReadOnlyCollection{T}">read-only collection</see> of
        /// <see cref="SagaMessage">messages</see> associated with the saga.</param>
        /// <param name="searchMethods">A <see cref="IReadOnlyCollection{T}">read-only collection</see> of
        /// <see cref="SagaSearchMethod">search methods</see> used to find the saga.</param>
        public SagaMetadata(
            Type sagaType,
            Type sagaDataType,
            PropertyInfo correlationProperty,
            IReadOnlyCollection <SagaMessage> messages,
            IReadOnlyCollection <SagaSearchMethod> searchMethods)
        {
            Arg.NotNull(sagaType, nameof(sagaType));
            Arg.NotNull(sagaDataType, nameof(sagaDataType));
            Arg.NotNull(messages, nameof(messages));
            Arg.NotNull(correlationProperty, nameof(correlationProperty));
            Arg.NotNull(searchMethods, nameof(searchMethods));

            SagaType            = sagaType;
            SagaDataType        = sagaDataType;
            CorrelationProperty = correlationProperty;
            VerifyCorrelatedPropertyTypeIsAllowed(sagaType, CorrelationProperty);

            var hasAtLeastOneStartMessage = false;

            foreach (var message in messages)
            {
                hasAtLeastOneStartMessage |= message.StartsSaga;
                associatedMessages.Add(message);
            }

            if (!hasAtLeastOneStartMessage)
            {
                throw new SagaConfigurationException(
                          SR.MissingSagaStartMessage.FormatDefault(
                              typeof(IStartWith <>).Name,
                              typeof(IStartWhen <>).Name,
                              sagaType.Name));
            }

            foreach (var searchMethod in searchMethods)
            {
                this.searchMethods.Add(searchMethod);
            }
        }
Esempio n. 24
0
        public async void DoRefresh()
        {
            Exception exception = null;

            try
            {
                IEnumerable <Server> newServers = await _serverList.Refresh();

                ISet <ServerObservable> removedServers = new HashSet <ServerObservable>(_servers.Values);
                foreach (Server serverData in newServers)
                {
                    ServerObservable server = Mapper.Map <Server, ServerObservable>(serverData);

                    if (_servers.Contains(server.Key))
                    {
                        ServerObservable existingServer = _servers[serverData.Address];
                        Mapper.Map(server, existingServer);
                    }
                    else
                    {
                        _servers.Add(server);
                    }
                    removedServers.Remove(server);
                }

                foreach (ServerObservable serverData in removedServers)
                {
                    _servers.Remove(serverData.Key);
                }

                DoPingAll();
            }
            catch (Exception e) { exception = e; }

            if (exception != null)
            {
                await _popupService.ShowMessageBox("Error refreshing server list",
                                                   "Could not refresh the server list. " + exception.Message, MessageBoxImage.Error);
            }
        }
Esempio n. 25
0
            public IRowAsyncValidators Add(RowAsyncValidator value)
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                if (!IsSealed)
                {
                    _list.Add(value);
                    return(this);
                }

                Debug.Assert(Count > 0);
                var result = new KeyedRowAsyncValidators();

                for (int i = 0; i < Count; i++)
                {
                    result.Add(this[i]);
                }
                result.Add(value);
                return(result);
            }
Esempio n. 26
0
		/// <summary>
		/// Creates Animations from a xnaMugen.IO.TextFile.
		/// </summary>
		/// <param name="textfile">A textfile whose xnaMugen.IO.TextSection can be used to create Animations.</param>
		/// <returns>A collection of Animations created from the supplied textfile.</returns>
		public KeyedCollection<Int32, Animation> LoadAnimations(TextFile textfile)
		{
			if (textfile == null) throw new ArgumentNullException("textfile");

			KeyedCollection<Int32, Animation> animations = new KeyedCollection<Int32, Animation>(x => x.Number);

			foreach (TextSection section in textfile)
			{
				Animation animation = CreateAnimation(section);
				if (animation != null)
				{
					if (animations.Contains(animation.Number) == false)
					{
						animations.Add(animation);
					}
					else
					{
						Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Duplicate animation #{0}. Discarding duplicate.", animation.Number);
					}
				}
			}

			return animations;
		}
Esempio n. 27
0
 /// <summary>
 /// Used internally handled with indices for performance considerations
 /// </summary>
 internal int ShowVector3(Vector3 baseVector, Vector3 vector, Color color)
 {
     return(vector3Collection.Add(new Vector3VisualHelper(baseVector, vector, color)));
 }
        /// <summary>
        /// Generate Home Assistant configuration file entries for the sensors in the provided device.
        /// </summary>
        /// <param name="definition">Device properties</param>
        /// <returns>Configuration file entries covering all sensors defined in the device</returns>
        public KeyedCollection <ConfigEntry> TransformConfig(DeviceDefinition definition)
        {
            if (definition.Sensors == null)
            {
                return(new KeyedCollection <ConfigEntry>());
            }

            if (string.IsNullOrWhiteSpace(definition.DeviceId))
            {
                throw new ValidationException($"{nameof(definition.DeviceId)} requires a value.");
            }

            var configs = new KeyedCollection <ConfigEntry>();

            foreach (var sensor in definition.Sensors)
            {
                if (sensor.Type.EndsWith("button"))
                {
                    // Buttons processed separately below.
                }
                else if (sensor.Type.EndsWith(SensorType.Threshold))
                {
                    var attribute = Regex.Replace(sensor.Type, $"-?{SensorType.Threshold}$", string.Empty);

                    if (string.IsNullOrWhiteSpace(attribute))
                    {
                        throw new ValidationException("Threshold attribute is missing");
                    }

                    if (string.IsNullOrWhiteSpace(sensor.OnCondition))
                    {
                        throw new ValidationException("Threshold on condition is missing");
                    }

                    var config = FormatSensorDefinition(EntityType.BinarySensor, new SensorConfig
                    {
                        Type                 = SensorType.Threshold,
                        Name                 = definition.Name,
                        Platform             = definition.Platform,
                        DeviceId             = definition.DeviceId,
                        DeviceName           = definition.Name,
                        DeviceClass          = sensor.DeviceClass,
                        Icon                 = sensor.Icon,
                        ThresholdAttribute   = attribute,
                        ThresholdOnCondition = sensor.OnCondition,
                        Customize            = sensor.Customize,
                    });
                    configs.Add(EntityType.BinarySensor, config);
                }
                else if (sensor.Type == SensorType.PowerCycleOnOff)
                {
                    if (!definition.Sensors.Any(i => i.Type == SensorType.PowerCycle))
                    {
                        throw new ValidationException("Can't have a power cycle on-off sensor without a power cycle sensor.");
                    }

                    var config = FormatTemplateDefinition(EntityType.BinarySensor, new TemplateSensorConfig
                    {
                        Name          = definition.Name,
                        Icon          = sensor.Icon,
                        ValueTemplate = $"states.{GetSensorEntityId(SensorType.PowerCycle, definition)}.state not in ['unknown','off']",
                    });
                    configs.Add(EntityType.BinarySensor, config);
                }
                else
                {
                    // Figure out whether it should be a binary sensor
                    var entityType = GetSensorEntityType(sensor.Type);

                    // Generate a reasonably human-friendly name, depending on the type of sensor.
                    var name         = GetSensorName(sensor.Type, definition);
                    var friendlyName = GetSensorFriendlyName(sensor.Type, definition);
                    if (friendlyName != name && (sensor.Customize == null || !sensor.Customize.ContainsKey("friendly_name")))
                    {
                        if (sensor.Customize == null)
                        {
                            sensor.Customize = new Dictionary <string, string>();
                        }

                        sensor.Customize.Add("friendly_name", friendlyName);
                    }

                    // Identify sensors which are set by Home Assistant
                    var platform = new[] { SensorType.PowerCycle }.Contains(sensor.Type)
                        ? Platform.HomeAssistant
                        : definition.Platform;

                    var config = FormatSensorDefinition(entityType, new SensorConfig
                    {
                        Type        = sensor.Type,
                        Name        = name,
                        Platform    = platform,
                        DeviceId    = definition.DeviceId,
                        DeviceName  = definition.Name,
                        DeviceClass = sensor.DeviceClass,
                        Icon        = sensor.Icon,
                        Customize   = sensor.Customize,
                    });
                    configs.Add(entityType, config);
                }
            }

            var buttonConfigs = ProcessButtonDefinition(definition);

            configs.AddMany(EntityType.BinarySensor, buttonConfigs);

            return(configs);
        }
Esempio n. 29
0
            public IDataValidationResults Add(DataValidationResult validationEntry)
            {
                IDataValidationResults result = new KeyedCollection();

                return(result.Add(validationEntry));
            }
Esempio n. 30
0
 /// <summary>
 /// Used internally handled with indices for performance considerations
 /// </summary>
 internal int ShowTransform(Matrix matrix)
 {
     return(MatrixCollection.Add(new MatrixVisualHelper(matrix)));
 }
        public datastruct2()
        {
            //personsSortedList.Add(1, new Person("James Scott", "10/10/1977"));
            //personsSortedList.Add(5, new Person("Andrew Simon", "10/08/1976"));



            dictionary.Add("1", "ONE");
            dictionary.Add("2", "TWO");
            dictionary.Add("3", "THREE");

            concurrentDictionary.TryAdd("4", "FOUR");
            concurrentDictionary.TryAdd("5", "FIVE");
            concurrentDictionary.TryAdd("6", "SIX");
            sortedList.Add(7, "SEVEN");
            sortedList.Add(8, "EIGHT");
            sortedList.Add(9, "NINE");
            personsSortedList.Add(1, new Person("James Scott", "10/10/1977"));
            personsSortedList.Add(5, new Person("Andrew Simon", "10/08/1976"));
            keyedCollection.Add(new TestDataStructure()
            {
                ID = 10
            });
            keyedCollection.Add(new TestDataStructure()
            {
                ID = 11
            });
            keyedCollection.Add(new TestDataStructure()
            {
                ID = 12
            });

            ConcurrentDictionary <string, object> _concurrentDictionary = new ConcurrentDictionary <string, object>();

            _concurrentDictionary.TryAdd("20", "Twenty");
            _concurrentDictionary.TryAdd("21", "Twenty one");
            _concurrentDictionary.TryAdd("22", "Twenty two");
            List <string> _lista = new List <string>();
            List <object> _listb = new List <object>();

            _lista.Add("_hello1");
            _lista.Add("_hello2");
            _listb.Add(_concurrentDictionary);
            list2.Add(keyedCollection);


            concurrentDictionary2.TryAdd("7", _lista);
            concurrentDictionary2.TryAdd("8", _listb);
            concurrentDictionary2.TryAdd("9", "value100");


            concurrentDictionary3.TryAdd("10", "TEN");
            concurrentDictionary3.TryAdd("11", "ELEVEN");
            concurrentDictionary3.TryAdd("12", "TWELVE");

            sortedList2.Add(2, concurrentDictionary2);
            sortedList2.Add(3, concurrentDictionary3);

            Hashtable _hash1 = new Hashtable();

            _hash1.Add("key1", "val1");
            _hash1.Add("key2", "val2");
            _hash1.Add("key3", "val3");

            Hashtable _hash2 = new Hashtable();

            _hash2.Add("key4", 400);
            _hash2.Add("key5", 500);
            _hash2.Add("key6", 600);

            list3.Add(_hash1);
            list3.Add(_hash2);
        }
Esempio n. 32
-1
        static void AddStateToCollection(KeyedCollection<Int32, State> collection, State state)
        {
            if (collection == null) throw new ArgumentNullException("collection");
            if (state == null) throw new ArgumentNullException("state");

            if (collection.Contains(state.Number) == true)
            {
                Log.Write(LogLevel.Warning, LogSystem.StateSystem, "Duplicate state #{0}. Discarding duplicate", state.Number);
            }
            else
            {
                collection.Add(state);
            }
        }